-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (44 loc) · 1.03 KB
/
main.go
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
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"sync"
"github.com/royalbhati/cssplit/extract"
"github.com/royalbhati/cssplit/walk"
)
func usage() {
meta :=
`
NAME:
CSSplit - Split your one big CSS files into modules
USAGE:
cssplit -dir ~/Desktop/myproject -css ~/Desktop/myproject/main.css -ext ".html,.js,.jsx" -exclude "utils,lib"
`
fmt.Println(meta)
}
func main() {
usage()
dir := flag.String("dir", ".", "Project Directory")
csspath := flag.String("css", "", "Path to CSS file")
ext := flag.String("ext", "[.html,.js,.jsx]", "File extensions to parse")
exclude := flag.String("exclude", "utils", "Files to exclude")
flag.Parse()
if _, err := os.Stat(*dir); os.IsNotExist(err) {
log.Fatal("Invalid Path")
}
if *csspath == "" {
log.Fatal("Path to css file must be provided")
}
exts := strings.Split(*ext, ",")
exc := strings.Split(*exclude, ",")
dirss, _ := walk.GetDir(*dir, exc, exts)
var wg sync.WaitGroup
for _, v := range dirss {
wg.Add(1)
go extract.CSS(v, *csspath, &wg)
}
wg.Wait()
}