forked from linjackson78/taro-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·109 lines (90 loc) · 2.56 KB
/
cli.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env node
const path = require('path')
const { execSync} = require('child_process')
const merge = require('merge')
const fs = require('fs-extra')
const AlipayFlow = require('./alipay-flow')
const WeappFlow = require('./weapp-flow')
const sendDing = require('./send-ding')
const {argv} = require('yargs')
.option('config', {
default: './deploy-config.js',
describe: '配置文件路径'
})
const log = console.log
function getAbsPath(p) {
if (path.isAbsolute(p)) return p
return path.join(process.cwd(), p)
}
let absConfigPath = getAbsPath(argv.config)
let absConfigDir = path.dirname(absConfigPath)
if (!fs.existsSync(absConfigPath)) {
log(`配置文件 ${absConfigPath} 不存在`)
process.exit(1)
}
const defaultConfig = require('./defaultConfig')
const theConfig = merge(defaultConfig, require(absConfigPath))
if (theConfig.outDir) {
theConfig.outDir = getAbsPath(theConfig.outDir)
fs.ensureDirSync(theConfig.outDir)
}
async function sendDingMsg(alipayQRImgUrl, weappQRImgUrl) {
if (!alipayQRImgUrl && !weappQRImgUrl) {
log('缺少二维码,不推送钉钉消息')
return
}
if (!theConfig.dingTalkUrl) {
log('缺少 dingTalkUrl 配置,不推送钉钉消息')
return
}
const options = {
alipayQRImgUrl,
weappQRImgUrl,
isExperience: theConfig.isExperience,
dingTalkUrl: theConfig.dingTalkUrl,
absConfigDir,
}
await sendDing(options)
}
function npmInstall () {
if (!theConfig.npmInstall) {
log('Skip npm install.')
return
}
log('npm install...')
execSync('npm install --silent', {
cwd: absConfigDir,
})
}
async function main() {
try {
await npmInstall()
const promises = []
let alipayQRImgUrl, weappQRImgUrl
if (theConfig.alipay && theConfig.alipay.enable) {
const alipayFlow = new AlipayFlow({
...theConfig,
...theConfig.alipay,
keyPath: getAbsPath(theConfig.alipay.keyPath),
projectPath: getAbsPath(theConfig.alipay.projectPath),
})
promises.push(alipayFlow.run().then(val => alipayQRImgUrl = val))
}
if (theConfig.weapp && theConfig.weapp.enable) {
const weappFlow = new WeappFlow({
...theConfig,
...theConfig.weapp,
keyPath: getAbsPath(theConfig.weapp.keyPath),
projectPath: getAbsPath(theConfig.weapp.projectPath),
})
promises.push(weappFlow.run().then(val => weappQRImgUrl = val))
}
await Promise.all(promises)
await sendDingMsg(alipayQRImgUrl, weappQRImgUrl)
log('All done.')
} catch (e) {
console.error(e)
process.exit(1)
}
}
main()