UNPKG

1.13 kBtext/coffeescriptView Raw
1fs = require("fs-extra")
2cp = require("child_process")
3path = require("path")
4Promise = require("bluebird")
5minimist = require("minimist")
6paths = require("./paths")
7install = require("./install")
8
9fs = Promise.promisifyAll(fs)
10
11module.exports = {
12 installIfNeeded: ->
13 install.check()
14
15 install: ->
16 install.package.apply(install, arguments)
17
18 cli: (argv = []) ->
19 opts = minimist(argv)
20
21 pathToApp = argv[0]
22
23 switch
24 when opts.install
25 @installIfNeeded()
26 when pathToApp
27 @open(pathToApp, argv)
28 else
29 throw new Error("No path to your app was provided.")
30
31 open: (appPath, argv, cb) ->
32 appPath = path.resolve(appPath)
33 dest = paths.getPathToResources("app")
34
35 ## make sure this path exists!
36 fs.statAsync(appPath)
37 .then ->
38 fs.ensureSymlinkAsync(appPath, dest, "dir")
39 .then ->
40 cp.spawn(paths.getPathToExec(), argv, {stdio: "inherit"})
41 .on "close", (code) ->
42 if cb
43 cb(code)
44 else
45 process.exit(code)
46
47 .catch (err) ->
48 console.log(err.stack)
49 process.exit(1)
50}
\No newline at end of file