-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·60 lines (48 loc) · 1.5 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
#!/usr/bin/env node
const path = require('path')
const exec = require('child_process').execSync
const getTemplates = require('./libs/getTemplates')
const fs = require('fs')
const samCommands = []
const rootPath = process.argv[2] ? path.resolve(process.argv[2]) : process.cwd()
const deployFile = process.argv[3] || path.resolve(rootPath, 'deploy.sh')
try {
samCommands.push(fs.readFileSync(deployFile).toString())
} catch (err) {
console.error('Deploy file not found.')
process.exit()
}
const templates = getTemplates(rootPath)
console.log('\nHANDLER COMMANDS...')
function packageOutputPath (key) {
return path.resolve(rootPath, '.packages', `${Date.now()}-${key}.yml`)
}
const commandsRun = templates.map(template => {
const commands = []
for (const key in samCommands) {
const packageOutput = packageOutputPath(key)
const comm = samCommands[key].replace(/\$templateBasePath/g, template[0])
.replace(/\$templateFilename/g, template[2])
.replace(/\$packagePath/g, packageOutput)
commands.push(comm)
}
return commands
})
console.log('\n---=INIT DEPLOY=---')
try {
commandsRun.forEach(command => {
try {
for (let i = 0; i < command.length; i++) {
console.log('\n-> Exec command', 1)
console.log(`\n${command[i]}`)
const stout = exec(command[i])
console.log(stout.toString())
}
} catch (err) {
throw new Error(err.message.toString())
}
})
console.log('\nFINISH!!!')
} catch (err) {
console.error(err.message)
}