summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/build.go30
-rw-r--r--cmd/main.go71
-rw-r--r--cmd/root.go58
-rw-r--r--cmd/serve.go61
-rw-r--r--cmd/themes.go13
5 files changed, 162 insertions, 71 deletions
diff --git a/cmd/build.go b/cmd/build.go
new file mode 100644
index 0000000..3877721
--- /dev/null
+++ b/cmd/build.go
@@ -0,0 +1,30 @@
+package cmd
+
+import (
+ "fmt"
+ "log"
+ "os"
+
+ "github.com/HimanshuSardana/kite/internal/build"
+)
+
+func runBuild(args []string) {
+ themeName := DefaultTheme
+
+ if len(args) > 2 {
+ themeName = args[2]
+ }
+
+ opts := build.BuildOptions{
+ ThemeName: themeName,
+ }
+
+ fmt.Printf("Building with theme: %s\n", themeName)
+
+ if err := build.Build(opts); err != nil {
+ log.Fatalf("Build failed: %v", err)
+ os.Exit(1)
+ }
+
+ fmt.Println("Build completed successfully!")
+}
diff --git a/cmd/main.go b/cmd/main.go
deleted file mode 100644
index 13970cc..0000000
--- a/cmd/main.go
+++ /dev/null
@@ -1,71 +0,0 @@
-package main
-
-import (
- "fmt"
- "io"
- "log"
- "net/http"
- "os"
- "path/filepath"
- "strings"
-
- internal "github.com/HimanshuSardana/kite/internal/build"
-)
-
-func copyFile(src, dst string) error {
- in, err := os.Open(src)
- if err != nil {
- return err
- }
- defer in.Close()
-
- if err := os.MkdirAll(filepath.Dir(dst), os.ModePerm); err != nil {
- return err
- }
-
- out, err := os.Create(dst)
- if err != nil {
- return err
- }
- defer out.Close()
-
- _, err = io.Copy(out, in)
- return err
-}
-
-var defaultThemeName = "modern-dark"
-
-func main() {
- args := os.Args
- if len(args) > 1 {
- switch args[1] {
- case "serve":
- copyFile("./themes/"+defaultThemeName+"/style.css", "./output/style.css")
-
- fs := http.FileServer(http.Dir("./output/"))
- http.Handle("/", fs)
-
- log.Println("Serving on http://localhost:8000")
-
- err := http.ListenAndServe(":8000", nil)
- if err != nil {
- log.Fatalf("Error occured %s\n", err)
- }
- case "build":
- if len(os.Args) <= 2 {
- themeName := defaultThemeName
- internal.Build(themeName)
- } else {
- themeName := os.Args[2]
- internal.Build(themeName)
- }
- case "list-themes":
- themeList := internal.ListThemes()
- fmt.Println(strings.Join(themeList, "\n"))
- default:
- internal.ShowHelpMessage()
- }
- } else {
- internal.ShowHelpMessage()
- }
-}
diff --git a/cmd/root.go b/cmd/root.go
new file mode 100644
index 0000000..79bb257
--- /dev/null
+++ b/cmd/root.go
@@ -0,0 +1,58 @@
+package cmd
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/HimanshuSardana/kite/internal/build"
+)
+
+const (
+ DefaultTheme = "modern-light"
+ DefaultPort = "8000"
+)
+
+func Execute() {
+ args := os.Args
+ if len(args) < 2 {
+ build.ShowHelpMessage()
+ return
+ }
+
+ switch args[1] {
+ case "build":
+ runBuild(args)
+ case "serve":
+ runServe(args)
+ case "list-themes":
+ runListThemes(args)
+ default:
+ build.ShowHelpMessage()
+ }
+}
+
+func ShowHelp() {
+ fmt.Println(`
+Kite — A lightweight static site generator
+
+USAGE:
+ kite <command> [options]
+
+COMMANDS:
+ build Build the static site into the output directory
+ serve Start a local development server with live reload
+ list-themes List all available themes
+
+OPTIONS:
+ -h, --help Show this help message
+
+EXAMPLES:
+ kite build
+ kite build gruvbox
+ kite serve
+ kite list-themes
+
+DESCRIPTION:
+ Kite converts your content into a static website using themes and templates.
+`)
+}
diff --git a/cmd/serve.go b/cmd/serve.go
new file mode 100644
index 0000000..9387d29
--- /dev/null
+++ b/cmd/serve.go
@@ -0,0 +1,61 @@
+package cmd
+
+import (
+ "fmt"
+ "io"
+ "log"
+ "net/http"
+ "os"
+ "path/filepath"
+)
+
+func runServe(args []string) {
+ themeName := DefaultTheme
+ port := DefaultPort
+
+ for i := 2; i < len(args); i++ {
+ if args[i] == "--port" && i+1 < len(args) {
+ port = args[i+1]
+ }
+ if args[i] != "--port" && args[i] != "--help" && args[i] != "-h" {
+ themeName = args[i]
+ }
+ }
+
+ themeCSS := fmt.Sprintf("./themes/%s/style.css", themeName)
+ outputCSS := "./output/style.css"
+
+ if err := copyFile(themeCSS, outputCSS); err != nil {
+ log.Printf("Warning: Could not copy theme CSS: %v", err)
+ }
+
+ fs := http.FileServer(http.Dir("./output/"))
+ http.Handle("/", fs)
+
+ log.Printf("Serving on http://localhost:%s", port)
+
+ if err := http.ListenAndServe(":"+port, nil); err != nil {
+ log.Fatalf("Server error: %s\n", err)
+ }
+}
+
+func copyFile(src, dst string) error {
+ in, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer in.Close()
+
+ if err := os.MkdirAll(filepath.Dir(dst), os.ModePerm); err != nil {
+ return err
+ }
+
+ out, err := os.Create(dst)
+ if err != nil {
+ return err
+ }
+ defer out.Close()
+
+ _, err = io.Copy(out, in)
+ return err
+}
diff --git a/cmd/themes.go b/cmd/themes.go
new file mode 100644
index 0000000..7a1457a
--- /dev/null
+++ b/cmd/themes.go
@@ -0,0 +1,13 @@
+package cmd
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/HimanshuSardana/kite/internal/build"
+)
+
+func runListThemes(args []string) {
+ themeList := build.ListThemes("")
+ fmt.Println(strings.Join(themeList, "\n"))
+}