#!/usr/bin/env coffee require "coffee-script" require "sugar" fs = require "fs" path = require "path" program = require "commander" program .version('1.4.0') .usage("start|compile [option]") .option("compile", "compile source code.") .option("start", "start mincer server. default: localhost:3000") .option("init", "create easy mincer project.") .option("-f, --file [file]", "use easy-mincer config. default is {cwd}/easy-mincer.json") .parse(process.argv) if program.file? program.file = path.resolve(program.file) else program.file = "#{process.cwd()}/easy-mincer.json" if program.compile Compiler = require("../lib/runtimes/compiler") compiler = new Compiler(program.file) compiler.clean() compiler.compile() if program.start Server = require("../lib/runtimes/server") server = new Server(program.file) server.useRewrite() server.usePublic() server.useMincer() server.start() if program.init ProjectCreator = require("../lib/runtimes/project-creator") projectCreator = new ProjectCreator(process.cwd()) itemSize = fs.readdirSync(process.cwd()).length if itemSize != 0 readline = require('readline'); rl = readline.createInterface({ input: process.stdin output: process.stdout }) question = (answer) -> switch answer when "y" rl.close() console.log("") console.log("clean #{process.cwd()}") projectCreator.clean() console.log("") console.log("create project #{process.cwd()}") try projectCreator.create(process) catch e projectCreator.clean() throw e console.log("success") when "n" process.exit() else rl.question("clean directory? [y/n] -> ", question) console.log("#{process.cwd()} is under #{itemSize} items.") question() else try projectCreator.create(process) catch e projectCreator.clean() throw e console.log("success")