-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuse.ts
69 lines (61 loc) · 1.63 KB
/
fuse.ts
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
import { FuseBox, QuantumPlugin, JSONPlugin, RawPlugin } from 'fuse-box'
import { src, task } from 'fuse-box/sparky'
import { resolve } from 'path'
import { argv } from 'yargs'
import { execSync } from 'child_process'
import shabang from './tools/scripts/fuse-shebang'
// import { unlinkSync } from 'fs'
const appName = 'fng'
const outputDir = '.build'
const homeDir = './'
const outputPath = `${outputDir}/${appName}`
const absOutputPath = resolve(outputPath)
const isProdBuild = argv.build
const fuseConfig = FuseBox.init({
log: false,
cache: !isProdBuild,
target: 'server@es5',
homeDir,
output: `${outputDir}/$name`,
globals: {
default: '*'
},
package: {
name: 'default',
main: outputPath
},
plugins: [
JSONPlugin(),
RawPlugin(['.txt']),
isProdBuild &&
QuantumPlugin({
bakeApiIntoBundle: appName,
treeshake: true,
uglify: true
})
]
})
const bundle = fuseConfig.bundle(appName)
task('test', () => {
bundle.test('[spec/**/**.ts]', {})
})
task('cp.jest', () => {
return src('jest/**', { base: 'src/templates/unit-tests' }).dest('.build/')
})
task('bundle', ['cp.jest', 'ng.modules'], () => {
bundle.instructions('> [src/index.ts]')
!isProdBuild &&
bundle.watch(`src/**`).completed(fp => shabang(fp.bundle, absOutputPath))
fuseConfig.run().then(bp => {
const bundle = bp.bundles.get(appName)
bundle && shabang(bundle, absOutputPath)
})
})
task('ng.modules', () => {
return new Promise((res, rej) => {
const tsc = execSync(
resolve('node_modules/.bin/ngc --p src/modules/tsconfig.aot.json')
).toString()
return tsc ? rej() : res()
})
})