UNPKG

3.73 kBtext/coffeescriptView Raw
1###
20000000 000 000 000 000 0000000
3000 000 000 000 000 000 000 000
40000000 000 000 000 000 000 000
5000 000 000 000 000 000 000 000
60000000 0000000 000 0000000 0000000
7###
8
9{ args, childp, fs, karg, kerror, kolor, os, slash } = require 'kxk'
10
11args = karg """
12
13build
14 compile . ? compile sources . = true
15 npminst . ? run npm install . = false
16 pnpm . ? run pnpm install . = true
17 builder . ? electron-builder . = true
18 install . ? move to /Applications . = true
19 prune . ? prune package . = false . -P
20 start . ? run executable . = true
21 verbose . = true
22"""
23
24config = require '../js/config'
25
26exec = (msg, cmd, opt={shell:true encoding:'utf8'}) ->
27
28 if args.verbose then log kolor.y5 msg
29 childp.execSync cmd, opt
30
31try
32 pkgdir = slash.pkg process.cwd()
33 pkgpth = slash.join pkgdir, 'package.json'
34 pkg = require pkgpth
35 bindir = "dist/mac-#{os.arch()}/" # fix needed for windows!
36
37 exeext = switch os.platform()
38 when 'win32' then '.exe'
39 when 'darwin' then '.app'
40 else '' # linux?
41 exepth = slash.resolve slash.join bindir, "#{pkg.name}#{exeext}"
42
43 if args.verbose then log kolor.y3('cwd '), kolor.w2 slash.tilde pkgdir
44 process.chdir pkgdir
45
46 if slash.dirExists bindir
47 try
48 if os.platform() == 'win32'
49 if exec 'quit' "taskkill /f /im #{slash.file exepth} /t"
50 childp.execSync 'sleep 2'
51 else
52 childp.execSync "killall #{pkg.name}"
53 catch err
54 kerror "kill failed: #{err}"
55 if args.verbose then log kolor.y4('remove '), kolor.b6 bindir
56 fs.removeSync bindir
57
58 if args.compile then exec 'compile' 'node --trace-warnings ' + slash.join __dirname, 'konrad'
59 if args.npminst then exec 'npminst' 'npm install'
60 if args.pnpm then exec 'pnpm -i' 'pnpm install'
61 if args.builder then exec 'builder' "#{slash.resolve('./node_modules/.bin/electron-builder')} --dir"
62 if args.install and not slash.win()
63 log kolor.y5 'install'
64 appDir = "/Applications/#{slash.file exepth}"
65 if slash.dirExists appDir
66 fs.removeSync appDir
67 fs.moveSync exepth, appDir
68 fs.removeSync slash.resolve 'dist'
69 exepth = appDir
70 fs.removeSync slash.join exepth, 'Contents/Resources/app/node_modules'
71 process.chdir slash.join exepth, 'Contents/Resources/app/'
72 childp.execSync 'pnpm i'
73 if args.prune
74 if args.verbose then log kolor.y4('prune')
75 for d in ['inno' 'x64']
76 dir = slash.join bindir, 'resources' 'app' d # needs to change on mac
77 if slash.dirExists dir
78 if args.verbose then log kolor.r5 dir
79 fs.removeSync dir
80
81 if prune = config.obj(pkgpth)?.build?.prune
82 for d in prune
83 dir = slash.join bindir, 'resources' 'app' d # needs to change on mac
84 if slash.dirExists dir
85 if args.verbose then log kolor.r5 dir
86 fs.removeSync dir
87 else
88 log 'no path to prune' dir
89 if args.start
90 if args.verbose then log kolor.y3('start '), kolor.w2 slash.tilde exepth
91 if os.platform() == 'win32'
92 childp.spawn exepth, encoding:'utf8' detached:true
93 else
94 childp.spawn "open" [exepth], encoding:'utf8' shell:true detached:true stdio:'inherit'
95 process.exit 0
96
97catch err
98 error String err
99 process.exit 1
100
\No newline at end of file