1 | fs = require("fs-extra")
|
2 | cp = require("child_process")
|
3 | path = require("path")
|
4 | Promise = require("bluebird")
|
5 | minimist = require("minimist")
|
6 | paths = require("./paths")
|
7 | install = require("./install")
|
8 |
|
9 | fs = Promise.promisifyAll(fs)
|
10 |
|
11 | module.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 |
|
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 |