-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.js
62 lines (54 loc) · 2.36 KB
/
build.js
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
const path = require('path')
const child_process = require('child_process')
// Cross platform build script
let elmApps = {
elmToAst: {
name: 'elm-to-ast',
folder: path.join(__dirname, 'src', 'features', 'shared', 'elm-to-ast'),
entrypoint: path.join(__dirname, 'src', 'features', 'shared', 'elm-to-ast', 'src', 'Worker.elm'),
dist_output: path.join(__dirname, 'dist', 'features', 'shared', 'elm-to-ast', 'worker.min.js'),
},
offlinePackageDocs: {
name: 'offline-package-docs',
folder: path.join(__dirname, 'src', 'features', 'offline-package-docs'),
entrypoint: path.join(__dirname, 'src', 'features', 'offline-package-docs', 'src', 'Main.elm'),
dist_output: path.join(__dirname, 'dist', 'features', 'offline-package-docs', 'elm.compiled.js'),
},
htmlToElm: {
name: 'html-to-elm',
folder: path.join(__dirname, 'src', 'features', 'html-to-elm'),
entrypoint: path.join(__dirname, 'src', 'features', 'html-to-elm', 'src', 'Main.elm'),
dist_output: path.join(__dirname, 'dist', 'features', 'html-to-elm', 'elm.compiled.js'),
}
}
let bold = str => '\033[36m' + str + '\033[0m'
let copyElmFindScripts = () => {
let isWindows = process.platform === 'win32'
let command = isWindows
? `xcopy /sy src\\experiments\\find-usages\\elm-find\\scripts\\* dist\\experiments\\find-usages\\elm-find\\scripts\\`
: `cp -r src/experiments/find-usages/elm-find/scripts/* dist/experiments/find-usages/elm-find/scripts`
child_process.exec(command, (err, stdout, stderr) => {
if (err) {
console.error(err)
process.exit(err.code)
} else {
console.log(` ✅ Copied ${bold('elm-find')} scripts`)
}
})
}
const buildElmProject = ({ name, folder, entrypoint, dist_output }) => {
child_process.exec(`cd ${folder} && npx elm make ${entrypoint} --optimize --output=${dist_output} && npx terser ${dist_output} --compress "pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe" | npx terser --mangle --output ${dist_output}`,
(err, stdout, stderr) => {
if (err) {
console.error(err)
process.exit(err.code)
} else {
console.log(` ✅ Compiled ${bold(name)} project`)
}
}
)
}
console.log(`Building Elm projects...`)
buildElmProject(elmApps.elmToAst)
buildElmProject(elmApps.offlinePackageDocs)
buildElmProject(elmApps.htmlToElm)