This repository has been archived by the owner on Dec 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·129 lines (114 loc) · 3.07 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env node
const { EventEmitter } = require('events')
const path = require('path')
const chalk = require('chalk')
const Ora = require('ora')
const yargs = require('yargs')
const deploy = require('salesforce-deploy')
const argv = yargs
.usage('Usage: $0 [options]')
.option('hostname', {
alias: 'h',
describe: 'Hostname of the SFCC instance',
demandOption: true
})
.option('username', {
alias: 'u',
describe: 'Business Manager username for instance',
demandOption: true
})
.option('password', {
alias: 'p',
describe: 'Business Manager password for instance',
demandOption: true
})
.option('cartridges', {
alias: 'c',
type: 'array',
describe: 'Paths to cartridges folder to deploy',
demandOption: true
})
.coerce('cartridges', args =>
args.map(c => {
const [source, exclude] = c.split(':')
return { source: path.resolve(source), exclude }
})
)
.option('code-version', {
alias: 'v',
describe: 'Name of the code version to deploy',
demandOption: true
})
.option('force', {
alias: 'f',
describe: 'Remove code version before deploy',
default: false
})
.demandCommand(0, 0)
.help()
.version().argv
;(async () => {
const spinner = new Ora()
const emitter = new EventEmitter()
emitter.on('force', codeVersion => {
spinner.start(
`Removing existing code version ${chalk.bold(codeVersion)} ${chalk.gray(
'(force)'
)}`
)
})
emitter.on('checkCodeVersion', codeVersion => {
argv.force && spinner.succeed()
spinner.start('Checking if the code version does not already exist')
})
emitter.on('mkdir', dest => {
spinner.succeed()
spinner.start(`Creating remote folder ${chalk.bold(dest)}`)
})
emitter.on('zip', () => {
const output = argv.cartridges
.map(c => {
const exclude = c.exclude ? ` (${c.exclude})` : ''
return chalk.cyan(`- ${c.source}`) + chalk.gray(exclude)
})
.join('\n ')
spinner.succeed()
spinner.start(
`Creating zip archive of the cartridges\n ${chalk.cyan(output)}`
)
})
emitter.on('upload', file => {
spinner.succeed()
spinner.start(`Uploading ${chalk.bold(file)}`)
})
emitter.on('unzip', file => {
spinner.succeed()
spinner.start(`Unzipping ${chalk.bold(file)}`)
})
emitter.on('rm', file => {
spinner.succeed()
spinner.start(`Removing ${chalk.bold(file)}`)
})
emitter.on('deployed', status => {
status ? spinner.succeed() : spinner.fail()
})
try {
console.log(
`Deploying ${chalk.cyan(argv.codeVersion)} ` +
`on ${chalk.cyan(argv.hostname)}`
)
const hrstart = process.hrtime()
await deploy({ ...argv, emitter })
const hrend = process.hrtime(hrstart)
const executionTime = ((hrend[0] * 1e9 + hrend[1]) / 1e9).toFixed(1)
console.log(
`${chalk.cyan('Success!')} Deployment ready ` +
chalk.gray('[' + executionTime + 's]')
)
process.exit(0)
} catch (e) {
spinner.fail(e.message)
console.log(chalk.red('Deploy failed'))
process.exit(1)
}
})()