1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | { args, childp, fs, karg, kerror, kolor, os, slash } = require 'kxk'
|
10 |
|
11 | args = karg """
|
12 |
|
13 | build
|
14 | compile . ? compile sources . = true
|
15 | install . ? run npm install . = true
|
16 | rebuild . ? electron-rebuild . = true
|
17 | package . ? package project . = true
|
18 | prune . ? prune package . = true . -P
|
19 | start . ? run executable . = true
|
20 | verbose . = true
|
21 | """
|
22 |
|
23 | config = require '../js/config'
|
24 |
|
25 | exec = (msg, cmd, opt={shell:true encoding:'utf8'}) ->
|
26 |
|
27 | if args.verbose then log kolor.y5 msg
|
28 | childp.execSync cmd, opt
|
29 |
|
30 | try
|
31 | pkgdir = slash.pkg process.cwd()
|
32 | pkgpth = slash.join pkgdir, 'package.json'
|
33 | pkg = require pkgpth
|
34 | bindir = pkg.name + '-' + "#{os.platform()}-x64"
|
35 |
|
36 | exeext = switch os.platform()
|
37 | when 'win32' then '.exe'
|
38 | when 'darwin' then '.app'
|
39 | else ''
|
40 | exepth = slash.resolve slash.join bindir, "#{pkg.name}#{exeext}"
|
41 |
|
42 | if args.verbose then log kolor.y3('cwd '), kolor.w2 slash.tilde pkgdir
|
43 | process.chdir pkgdir
|
44 |
|
45 | if slash.dirExists bindir
|
46 | try
|
47 | if os.platform() == 'win32'
|
48 | if exec 'quit' "taskkill /f /im #{slash.file exepth} /t"
|
49 | childp.execSync 'sleep 2'
|
50 | else
|
51 | childp.execSync "killall #{pkg.name}"
|
52 | catch err
|
53 | kerror "kill failed: #{err}"
|
54 | if args.verbose then log kolor.y4('remove '), kolor.b6 bindir
|
55 | fs.removeSync bindir
|
56 |
|
57 | if args.compile then exec 'compile' 'node --trace-warnings ' + slash.join __dirname, 'konrad'
|
58 | if args.install then exec 'install' 'npm install'
|
59 | if args.rebuild then exec 'rebuild' slash.resolve './node_modules/.bin/electron-rebuild'
|
60 | if args.package
|
61 | exe = slash.resolve './node_modules/.bin/electron-packager'
|
62 | icn = slash.win() and 'ico' or 'icns'
|
63 | cmd = "#{exe} . --overwrite --icon=img/app.#{icn}"
|
64 | exec 'package' cmd
|
65 | if args.prune
|
66 | if args.verbose then log kolor.y4('prune')
|
67 | for d in ['inno' 'x64']
|
68 | dir = slash.join bindir, 'resources' 'app' d
|
69 | if slash.dirExists dir
|
70 | if args.verbose then log kolor.r5 dir
|
71 | fs.removeSync dir
|
72 |
|
73 | if prune = config.obj(pkgpth)?.build?.prune
|
74 | for d in prune
|
75 | dir = slash.join bindir, 'resources' 'app' d
|
76 | if slash.dirExists dir
|
77 | if args.verbose then log kolor.r5 dir
|
78 | fs.removeSync dir
|
79 | else
|
80 | log 'no path to prune' dir
|
81 |
|
82 | if args.start
|
83 | if args.verbose then log kolor.y3('start '), kolor.w2 slash.tilde exepth
|
84 | if os.platform() == 'win32'
|
85 | childp.spawn exepth, encoding:'utf8' detached:true
|
86 | else
|
87 | childp.spawn "open" [exepth], encoding:'utf8' shell:true detached:true stdio:'inherit'
|
88 | process.exit 0
|
89 |
|
90 | catch err
|
91 | error String err
|
92 | process.exit 1
|
93 | |
\ | No newline at end of file |