-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.js
64 lines (48 loc) · 1.62 KB
/
deploy.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
const childProcess = require('child_process')
const { promisify } = require('util')
const copyfiles = require('copyfiles')
const path = require('path')
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})
const exec = promisify(childProcess.exec)
// Build package
const build = async () => {
const buildCommand = 'npm run prod'
console.log(`[COMMAND]: ${buildCommand}`)
const { stderr, stdout } = await exec(buildCommand);
if (stderr) {
throw new Error(`'${buildCommand}' failed with \n${stderr}`);
}
console.log(stdout)
}
// Copy files
const copyImportantFiles = async () => {
const packageFilePath = path.join('.', 'package.json')
const readmeFilePath = path.join('.', 'README.md')
const licenseFilePath = path.join('.', 'LICENSE')
const distPath = path.join('.', 'dist')
console.log(packageFilePath, distPath)
await copyfiles([packageFilePath, readmeFilePath, licenseFilePath, distPath], { flat: true }, () => { console.log('Copied files') })
}
// Publish
const publish = async (otp) => {
const publishCommand = `npm publish ./dist ---otp ${otp}`
console.log(`[COMMAND]: ${publishCommand}`)
const { stderr, stdout } = await exec(publishCommand);
if (stderr) {
console.log(`'${publishCommand}' failed with \n${stderr}`);
}
console.log(stdout)
}
// Deploy
const deploy = async () => {
await build()
await copyImportantFiles()
readline.question('\n\nOTP: ', async (_otp) => {
readline.close()
await publish(_otp)
})
}
deploy()