summaryrefslogtreecommitdiff
path: root/cmd/main.go
blob: afef7bbf9fc6b0127ac73fc6f89a624c3a727c49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"path/filepath"

	internal "github.com/HimanshuSardana/kite/internal/build"
)

var themeName = "gruvbox"

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
}

func main() {
	args := os.Args
	if len(args) > 1 {
		switch args[1] {
		case "serve":
			copyFile("./themes/"+themeName+"/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":
			internal.Build()
		case "list-themes":
			themeList := make([]string, 0)
			themes, err := os.ReadDir("../themes/")
			if err != nil {
				log.Fatal("Error:", err)
			}
			for _, theme := range themes {
				if theme.IsDir() {
					themeList = append(themeList, string(theme.Name()))
				}
			}
		default:
			showHelpMessage()
		}
	} else {
		showHelpMessage()
	}
}

func showHelpMessage() {
	fmt.Println(`
Usage: 	kite <SUBCOMMAND>

SUBCOMMANDS:
build
serve
`)
}