This repository was archived by the owner on Jul 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
47 lines (39 loc) · 1.25 KB
/
Copy pathdeploy.js
File metadata and controls
47 lines (39 loc) · 1.25 KB
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
const path = require("path")
const fs = require("fs/promises")
const deployDir = path.resolve("00_deploy")
const distPath = path.resolve("01_frontend", "dist")
const buildPath = path.resolve("02_backend", "build")
const removedDeploy = fs.rmdir(deployDir, { recursive: true })
const buildBackend = fs
.rmdir(buildPath, { recursive: true })
.then(() => exec("cd 02_backend && npm run build"))
const buildFrontend = fs
.rmdir(distPath, { recursive: true })
.then(() => exec("cd 01_frontend && npm run build"))
const backendDeployed = Promise.all([buildBackend, removedDeploy]).then(() =>
fs.rename(buildPath, deployDir)
)
Promise.all([buildFrontend, backendDeployed]).then(() => {
fs.rename(distPath, path.join(deployDir, "static"))
})
const filesToCopy = [
"docker-compose.yml",
"Dockerfile_node",
path.join("02_backend", "package.json"),
]
filesToCopy.forEach((filename) => {
backendDeployed.then(() => {
fs.copyFile(path.resolve(filename), path.join(deployDir, path.basename(filename)))
})
})
function exec(cmd) {
const { exec } = require("child_process")
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(error)
}
resolve(stdout ? stdout : stderr)
})
})
}