UNPKG

1.95 kBPlain TextView Raw
1#!/usr/bin/env coffee
2
3fs = require("fs")
4path = require("path")
5program = require("commander")
6
7program
8 .version('1.1.4')
9 .usage("start|compile [option]")
10 .option("compile", "compile source code.")
11 .option("start", "start mincer server. default: localhost:3000")
12 .option("init", "create easy mincer project.")
13 .option("-f, --file [file]", "use easy-mincer config. default is {cwd}/easy-mincer.json")
14 .parse(process.argv)
15
16if program.file?
17 program.file = path.resolve(program.file)
18else
19 program.file = "#{process.cwd()}/easy-mincer.json"
20
21if program.compile
22 EasyMincer = require("../lib/easy-mincer.coffee")
23 easyMincer = new EasyMincer(program.file)
24 easyMincer.compile()
25
26if program.start
27 EasyMincer = require("../lib/easy-mincer.coffee")
28 easyMincer = new EasyMincer(program.file)
29 easyMincer.start()
30
31if program.init
32
33 ProjectCreator = require("../lib/project-creator.coffee")
34 projectCreator = new ProjectCreator(process.cwd())
35
36 itemSize = fs.readdirSync(process.cwd()).length
37 if itemSize != 0
38 readline = require('readline');
39 rl = readline.createInterface({
40 input: process.stdin
41 output: process.stdout
42 })
43
44 question = (answer) ->
45 switch answer
46 when "y"
47 rl.close()
48 console.log("")
49 console.log("clean #{process.cwd()}")
50 projectCreator.clean()
51 console.log("")
52
53 console.log("create project #{process.cwd()}")
54 try
55 projectCreator.create(process)
56 catch e
57 projectCreator.clean()
58 throw e
59 console.log("success")
60 when "n"
61 process.exit()
62 else
63 rl.question("clean directory? [y/n] -> ", question)
64
65 console.log("#{process.cwd()} is under #{itemSize} items.")
66 question()
67
68 else
69 try
70 projectCreator.create(process)
71 catch e
72 projectCreator.clean()
73 throw e
74 console.log("success")
75
76
77
78
79
80
81
82
83
84