-
Notifications
You must be signed in to change notification settings - Fork 342
/
index.js
66 lines (53 loc) · 1.58 KB
/
index.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
const build = require('@netlify/build')
const { getConfigPath } = require('@netlify/config')
const { flags } = require('@oclif/command')
const Command = require('../../utils/command')
const { parseRawFlags } = require('../../utils/parse-raw-flags')
class BuildCommand extends Command {
// Run Netlify Build
async run() {
const options = await this.getOptions()
await this.config.runHook('analytics', {
eventName: 'command',
payload: { command: 'build', dry: options.dry }
})
const success = await build(options)
const exitCode = success ? 0 : 1
this.exit(exitCode)
}
// Retrieve Netlify Build options
async getOptions() {
const { raw } = this.parse(BuildCommand)
const { dry = false } = parseRawFlags(raw)
const [token] = this.getConfigToken()
const config = await this.getConfig()
return { config, token, dry }
}
// Try current directory first, then site root
async getConfig() {
try {
return await getConfigPath()
} catch (error) {
try {
return await getConfigPath(undefined, this.netlify.site.root)
} catch (error) {
console.error(error.message)
this.exit(1)
}
}
}
}
// Netlify Build programmatic options
BuildCommand.flags = {
dry: flags.boolean({
description: 'Dry run: show instructions without running them'
}),
context: flags.string({
description: 'Build context'
})
}
BuildCommand.description = `Beta - Netlify build`
BuildCommand.examples = ['netlify build']
BuildCommand.strict = false
BuildCommand.hidden = true
module.exports = BuildCommand