-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.js
70 lines (64 loc) · 2.31 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
63
64
65
66
67
68
69
70
const fs = require('fs')
const ClosureCompiler = require('google-closure-compiler').compiler
const childProcess = require('child_process')
const spawnSync = require('child_process').spawnSync
childProcess.execSync('rm -rf build_cache')
childProcess.execSync('rm -rf dist')
childProcess.execSync('mkdir ./dist')
childProcess.execSync('mkdir ./build_cache')
childProcess.execSync('cp -r src build_cache/')
childProcess.execSync('rm -rf build_cache/src/cli')
childProcess.execSync('rm -rf build_cache/src/externs.js')
// childProcess.execSync("cp ./node_modules/xxhashjs/build/xxhash.min.js dist/silica.js");
// childProcess.execSync("cp ./node_modules/xxhashjs/build/xxhash.min.js dist/silica.min.js");
childProcess.execSync('cat libs/md5.min.js >> dist/silica.js')
childProcess.execSync('cat libs/md5.min.js >> dist/silica.min.js')
var flags = {
js: 'build_cache/**/*.js',
language_in: 'ECMASCRIPT6',
language_out: 'ECMASCRIPT5',
compilation_level: 'ADVANCED',
externs: 'src/externs.js',
generate_exports: 'true'
}
console.log('Compiling production version')
var closureCompiler = new ClosureCompiler(flags)
closureCompiler.run(function (exitCode, stdOut, stdErr) {
if (stdErr.length) {
console.error(stdErr)
}
fs.appendFileSync('dist/silica.min.js', '!function(){\n"use strict";\n' + stdOut + '}.call(window);')
let compress = spawnSync('gzip', ['-k', 'dist/silica.min.js'], {
stdio: [0, 1, 2],
cwd: process.cwd()
})
if (compress.error) {
console.log('An error occurred during compression')
console.error(compress.error)
} else {
console.log('Compression finished')
}
})
// Build debug version
flags['compilation_level'] = 'SIMPLE'
flags['debug'] = true
flags['formatting'] = 'pretty_print'
console.log('Compiling debug version')
closureCompiler = new ClosureCompiler(flags)
closureCompiler.run(function (exitCode, stdOut, stdErr) {
if (stdErr.length) {
console.error(stdErr)
}
fs.appendFileSync('dist/silica.js', '!function(){\n"use strict";\n' + stdOut + '}.call(window);')
console.log('Compressing results')
let compress = spawnSync('gzip', ['-k', 'dist/silica.js'], {
stdio: [0, 1, 2],
cwd: process.cwd()
})
if (compress.error) {
console.log('An error occurred during compression')
console.error(compress.error)
} else {
console.log('Compression finished')
}
})