-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployRender.js
53 lines (47 loc) · 1.56 KB
/
deployRender.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
const { execSync } = require("child_process");
const { existsSync, rmSync, writeFileSync } = require("fs");
const { copySync } = require("fs-extra");
const packageJson = {
name: "",
version: "3.0.0",
description: "",
scripts: {
start: "node ./server/*.js",
keywords: [],
author: "",
license: "ISC",
},
};
const path = require("path");
const cwd = path.resolve(".", "deploy");
console.log("Start building the app...");
execSync("npm run build");
console.log("Copy the client build folder to the deploy folder.");
const clientBuildPath = path.resolve(".", "src", "client", "build");
copySync(clientBuildPath, path.resolve(cwd, "server", "client"));
rmSync(clientBuildPath, { recursive: true, force: true });
console.log("Write new package.json");
const packageJsonPath = path.resolve(cwd, "package.json");
writeFileSync(packageJsonPath, JSON.stringify(packageJson));
console.log("Check git exist");
if (!existsSync(path.resolve(cwd, ".git"))) {
console.log(
"Git is not exist , init git repo. Please wait..."
);
execSync(
"git init && git add . && git commit -m 'init public' && git push origin main " ,
{ cwd }
);
console.log("Finish init git.");
} else {
const commitMessage = process.argv[2];
if (commitMessage) {
console.log("Commit the project.");
execSync(
`git add . && git commit -m '${commitMessage}' && git push origin main `,
{ cwd }
);
console.log("Finish commit.");
} else console.log("Please add commit message!");
}
console.log("The building was finished successfully");