Skip to content

Commit 89ce49a

Browse files
fix: add build command
1 parent 8f86b49 commit 89ce49a

File tree

2 files changed

+60
-46
lines changed

2 files changed

+60
-46
lines changed

src/commands/build.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import { command } from 'yargs'
22
import { logInfo } from '../utilities/log'
3+
import { serve } from './serve'
34

45
command(
5-
'build',
6+
'build [prod][sw]',
67
'build your application',
78
args => {
89
return args
910
},
1011
args => {
11-
build()
12+
logInfo('Launching Init Command')
13+
serve(args.prod, args.sw, true)
1214
}
1315
)
14-
15-
function build() {
16-
logInfo('Launching Init Command')
17-
}
16+
.option('prod', {
17+
default: false,
18+
description: 'Run with optimizations enabled'
19+
})
20+
.option('sw', {
21+
default: false,
22+
description: 'Enable service-worker'
23+
})

src/commands/serve.ts

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import clearTerminal from '../utilities/clear'
2828
import readConfig_ from '../utilities/read-config'
2929

3030
command(
31-
'serve [port][prod][aot][sw]',
31+
'serve [port][prod][sw]',
3232
'serve your application',
3333
args => {
3434
return args
@@ -54,7 +54,11 @@ function logServeCommandStart() {
5454
logInfo('Launching Serve Command')
5555
}
5656

57-
function serve(isProdBuild = false, isServiceWorkerEnabled = false) {
57+
export function serve(
58+
isProdBuild = false,
59+
isServiceWorkerEnabled = false,
60+
buildOnly = false
61+
) {
5862
readConfig_()
5963
.pipe(
6064
tap(logServeCommandStart),
@@ -175,52 +179,56 @@ function serve(isProdBuild = false, isServiceWorkerEnabled = false) {
175179
})
176180
fuseSw.bundle('ngsw-worker').instructions(' > [ngsw-worker.js]')
177181

178-
fuseBrowser
179-
.bundle('vendor')
180-
.watch(watchDir)
181-
.instructions(` ~ ${browserModule}`)
182-
.completed(fn => {
183-
isServiceWorkerEnabled &&
184-
execSync(
185-
`node_modules/.bin/ngsw-config .dist/public src/app/ngsw.json`
186-
)
187-
fuseServer
188-
.bundle('server')
189-
.instructions(` > [${config.fusebox.server.serverModule}]`)
190-
.completed(proc => {
191-
prevServerProcess && prevServerProcess.kill()
192-
clearTerminal()
193-
proc.start()
194-
prevServerProcess = proc
195-
})
196-
fuseServer.run()
197-
})
182+
// tslint:disable:no-if-statement
183+
const vendor = fuseBrowser.bundle('vendor')
184+
if (!buildOnly) vendor.watch(watchDir)
185+
vendor.instructions(` ~ ${browserModule}`).completed(fn => {
186+
isServiceWorkerEnabled &&
187+
execSync(
188+
`node_modules/.bin/ngsw-config .dist/public src/app/ngsw.json`
189+
)
190+
const serverBundle = fuseServer
191+
.bundle('server')
192+
.instructions(` > [${config.fusebox.server.serverModule}]`)
198193

199-
fuseBrowser
200-
.bundle('app')
201-
.watch(watchDir)
194+
if (!buildOnly) {
195+
serverBundle.completed(proc => {
196+
prevServerProcess && prevServerProcess.kill()
197+
clearTerminal()
198+
proc.start()
199+
prevServerProcess = proc
200+
})
201+
}
202+
fuseServer.run()
203+
})
204+
205+
const appBundle = fuseBrowser.bundle('app')
206+
if (!buildOnly) appBundle.watch(watchDir)
207+
appBundle
202208
.instructions(` !> [${browserModule}]`)
203209
.splitConfig({ dest: '../js/modules' })
204210

205211
logInfo('Bundling your application, this may take some time...')
206212

207213
renderSassDir()
208214

209-
const sass = exec(
210-
'node_modules/.bin/node-sass --watch src/**/*.scss --output-style compressed --output src/**'
211-
)
212-
sass.on('error', err => {
213-
console.log(err)
214-
process.exit(1)
215-
})
216-
sass.on('message', err => {
217-
console.error(err)
218-
process.exit(1)
219-
})
220-
sass.stderr.on('data', err => {
221-
console.log(err)
222-
process.exit(1)
223-
})
215+
if (!buildOnly) {
216+
const sass = exec(
217+
'node_modules/.bin/node-sass --watch src/**/*.scss --output-style compressed --output src/**'
218+
)
219+
sass.on('error', err => {
220+
console.log(err)
221+
process.exit(1)
222+
})
223+
sass.on('message', err => {
224+
console.error(err)
225+
process.exit(1)
226+
})
227+
sass.stderr.on('data', err => {
228+
console.log(err)
229+
process.exit(1)
230+
})
231+
}
224232

225233
copy(resolve('src/assets'), resolve('.dist/public/assets'))
226234
.then(() => fuseSw.run())

0 commit comments

Comments
 (0)