Skip to content

Commit fab2173

Browse files
committed
Simplified build script
1 parent 5fca22a commit fab2173

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

bin/build

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,18 @@
44
const { execFileSync } = require('child_process')
55
const fs = require('fs')
66
const path = require('path')
7+
process.chdir(path.join(__dirname, '../'))
78

8-
console.log('Cleaning up old build')
9-
rmdirsSync(relativePathname('build'))
9+
console.log('Cleaning up any previous builds')
10+
require('rimraf').sync('build')
1011

1112
console.log('Building')
12-
fs.mkdirSync(relativePathname('build/app'), { recursive: true })
13-
fs.mkdirSync(relativePathname('build/boot'))
14-
babelCompileSync(relativePathname('app'), relativePathname('build/app'))
15-
babelCompileSync(relativePathname('boot'), relativePathname('build/boot'))
16-
17-
console.log('Setting up bins')
18-
fs.mkdirSync('build/bin')
19-
fs.copyFileSync('bin/cli', 'build/bin/cli')
20-
21-
console.log('Finalizing boot files')
22-
stripBabelSync(relativePathname('build/boot/Cli.js'))
23-
stripBabelSync(relativePathname('build/boot/Http.js'))
24-
25-
console.log('Finished')
26-
27-
function stripBabelSync(file) {
28-
let content = fs.readFileSync(file).toString()
29-
content = content.replace(/require\('@babel\/register'\)/g, '')
30-
return fs.writeFileSync(file, content)
31-
}
32-
33-
function babelCompileSync(input, output) {
34-
return execFileSync('node', [
13+
for(const [ input, output ] of Object.entries({
14+
app: 'build/app',
15+
boot: 'build/boot',
16+
})) {
17+
fs.mkdirSync(output, { recursive: true })
18+
execFileSync('node', [
3519
require.resolve('@babel/cli/lib/babel'),
3620
'--copy-files',
3721
'--source-maps', 'inline',
@@ -40,20 +24,15 @@ function babelCompileSync(input, output) {
4024
])
4125
}
4226

43-
function rmdirsSync(pathname) {
44-
if(!fs.existsSync(pathname)) {
45-
return
46-
} else if(!fs.lstatSync(pathname).isDirectory()) {
47-
return fs.unlinkSync(pathname)
48-
}
49-
50-
for(const child of fs.readdirSync(pathname)) {
51-
rmdirsSync(path.join(pathname, child))
52-
}
27+
console.log('Setting up bins')
28+
fs.mkdirSync('build/bin')
29+
fs.copyFileSync('bin/cli', 'build/bin/cli')
5330

54-
fs.rmdirSync(pathname)
31+
console.log('Finalizing boot files')
32+
for(const file of [ 'build/boot/Cli.js', 'build/boot/Http.js' ]) {
33+
let content = fs.readFileSync(file).toString()
34+
content = content.replace(/require\('@babel\/register'\)/g, '')
35+
fs.writeFileSync(file, content)
5536
}
5637

57-
function relativePathname(pathname) {
58-
return path.join(__dirname, '../', pathname)
59-
}
38+
console.log('Finished')

0 commit comments

Comments
 (0)