/
build.js
63 lines (52 loc) · 2.01 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
import path from 'path'
import { serialize } from '@canopycanopycanopy/b-ber-tasks'
import state from '@canopycanopycanopy/b-ber-lib/State'
import createBuildSequence from '@canopycanopycanopy/b-ber-shapes-sequences/create-build-sequence'
import sequences from '@canopycanopycanopy/b-ber-shapes-sequences/sequences'
import Project from '@canopycanopycanopy/b-ber-templates/Project'
import { ensure } from '@canopycanopycanopy/b-ber-lib/utils'
import log from '@canopycanopycanopy/b-ber-logger'
// note leading pipe - to ensure we can run the `all` command without arguments
const command = 'build [|epub|mobi|pdf|reader|sample|web]'
const describe = 'Build a project'
const handler = argv => {
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const sequence = createBuildSequence(argv)
const subSequence = sequence.reduce((a, c) => a.concat(...sequences[c]), [])
state.update('sequence', subSequence)
log.registerSequence(state, command, subSequence)
const run = buildTasks => {
const build = buildTasks.shift()
state.reset()
state.update('build', build)
return serialize(sequences[build]).then(() => {
if (buildTasks.length) run(buildTasks)
})
}
const projectPath = path.resolve(state.srcDir)
const files = [
...Project.javascripts(projectPath),
...Project.stylesheets(projectPath),
]
ensure({ files })
.then(() => run(sequence))
.catch(console.error)
}
const builder = yargs =>
yargs
.command('', 'Build all formats', () => {}, handler)
.command('epub', 'Build an Epub', () => {}, handler)
.command('mobi', 'Build a Mobi', () => {}, handler)
.command('pdf', 'Build a PDF', () => {}, handler)
.command('reader', 'Build for the b-ber-reader format', () => {}, handler)
.command('sample', 'Build a sample Epub', () => {}, handler)
.command('web', 'Build for web', () => {}, handler)
.command('xml', 'Build for XML', () => {}, handler)
.help('h')
.alias('h', 'help')
export default {
command,
describe,
builder,
handler,
}