-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
88 lines (77 loc) · 2.64 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const path = require('path')
const fs = require('fs')
const glob = require('glob')
const flatten = require('./src/utils').flatten
const colors = require('colors')
const deploy = require('./src/deploy').default
const buildConfig = require('./src/buildConfig')
module.exports = config => {
// something's wrong with the config, so let's rebuild it and exit
if (
!config ||
(typeof config == 'string' && !fs.existsSync(config)) ||
(typeof config == 'object' && Object.keys(config).length === 0)
) {
buildConfig()
return
}
// if config is a path, load the path
if (typeof config == 'string' || config instanceof String) {
config = require(config)
}
// 1.2.0+: find the environment matching the user input
if (config.environments) {
// get user-requested env
// node fh-deploy env-name
// 0 1 2
const targetEnv = process.argv[2]
const targetResult = targetEnv
? config.environments.find(e => e.name == targetEnv)
: false
// exit early if specified env not found
if (targetEnv && !targetResult) {
console.log(
`Can\'t find target environment "${targetEnv}"! No action taken.`
.red.bold
)
return false
}
// if there is no env name or if we can't find the env in the deployrc...
if (targetEnv === undefined || !targetResult) {
// ...and fall back to the first env
console.log(
'Using default deploy target ' +
config.environments[0].name.green +
'...'
)
config = config.environments[0]
} else {
// otherwise, get the desired env
console.log(`Using deploy target ` + `${targetEnv}`.green + `...`)
config = targetResult
}
}
if (config.target === undefined) {
console.warn('No deploy target specified! No action taken.'.red)
return false
}
let queue = config.queue
if (!config.hasOwnProperty('queue') || !config.queue.length) {
console.log(
'No queue in config file. Defaulting to package.json "files"...'
)
const package = require(path.resolve('./', 'package.json'))
queue = package.files
}
if (!queue || !queue.length) {
console.warn('No files in upload queue! No action taken.'.red.bold)
return
}
// Get all files from readable queue
queue = flatten(
queue.map(entry => {
return glob.sync(entry)
})
)
deploy(config, queue)
}