This repository has been archived by the owner on May 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_app
137 lines (117 loc) · 4.11 KB
/
build_app
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
"""
Build Script for Julius
This script builds Julius and dependencies, then packages.
"""
# Copyright 2018 Christopher Antila
from datetime import datetime
import pathlib
import shutil
import subprocess
APP_NAME = 'nCoda'
APP_VERSION = datetime.utcnow().strftime('%y%m-%d.%H%M')
EXECUTABLE_NAME = 'julius'
OUTPUT_DIRECTORY = 'build'
# list of the JS files to compile with Browserify; it's input filename, then output filename
_COMPILE_WITH_BROWSERIFY = [
('js/ncoda-init.js', 'js/ncoda-compiled.js'),
]
# list of the CSS files that must be compiled from LESS; it's the shell path we should ask Watchman
# to watch, then the input and output filenames for lessc.
_COMPILE_WITH_LESSC = [
('css/ncoda/main.less', 'css/ncoda/main.css'),
]
_PATH_TO_BROWSERIFY = 'node_modules/.bin/browserify'
_PATH_TO_LESSC = 'node_modules/.bin/lessc'
_PATH_TO_PACKAGER_1 = '/usr/bin/electron-packager'
_PATH_TO_PACKAGER_2 = 'node_modules/.bin/electron-packager'
def the_script():
"""
Do the build.
"""
# see if we can find/use Browserify
watchify = pathlib.Path(_PATH_TO_BROWSERIFY)
if not watchify.exists():
print('Could not find Browserify. Is it installed?')
raise SystemExit(1)
# see if we can find/use lessc
lessc = pathlib.Path(_PATH_TO_LESSC)
if not lessc.exists():
print('Could not find lessc. Is it installed?')
raise SystemExit(1)
# see if we can find/use electron-packager
packager = pathlib.Path(_PATH_TO_PACKAGER_1)
if not packager.exists():
packager = pathlib.Path(_PATH_TO_PACKAGER_2)
if not packager.exists():
print('Could not find "electron-packager" so we will not run it.')
# make sure we delete the previously-generated files
for _, js_asset_path in _COMPILE_WITH_BROWSERIFY:
js_asset = pathlib.Path(js_asset_path)
if js_asset.exists():
js_asset.unlink()
for _, css_asset_path in _COMPILE_WITH_LESSC:
css_asset = pathlib.Path(css_asset_path)
if css_asset.exists():
css_asset.unlink()
# hold the Popen instances
subprocesses = []
try:
# compile JS
for each_file in _COMPILE_WITH_BROWSERIFY:
try:
kummand = [
_PATH_TO_BROWSERIFY,
each_file[0],
'-o',
each_file[1],
'--ignore-missing',
]
subprocesses.append(subprocess.Popen(kummand))
except subprocess.CalledProcessError as cperr:
print(
'Encountered the following error while starting Browserify:\n%s' % cperr
)
raise SystemExit(1)
# compile CSS
for each_file in _COMPILE_WITH_LESSC:
try:
kummand = [
_PATH_TO_LESSC,
'--clean-css',
'--source-map',
each_file[0],
each_file[1],
]
subprocesses.append(subprocess.Popen(kummand))
except subprocess.CalledProcessError as cperr:
print(
'Encountered the following error while starting lessc:\n%s' % cperr
)
raise SystemExit(1)
finally:
print('Waiting for {} build subprocesses.'.format(len(subprocesses)))
for proc in subprocesses:
proc.wait(60)
if proc.returncode:
raise SystemExit(1)
if packager.exists():
build_dir = pathlib.Path(OUTPUT_DIRECTORY)
if build_dir.exists():
shutil.rmtree(OUTPUT_DIRECTORY)
result = subprocess.call(
[
str(packager),
'.',
APP_NAME,
'--app-version', APP_VERSION,
'--executable-name', EXECUTABLE_NAME,
'--out', OUTPUT_DIRECTORY,
]
)
if result:
raise SystemExit(result)
if __name__ == '__main__':
the_script()
else:
print('This script is only intended to be run from a commandline.')