|
|
@@ -8,12 +8,16 @@ const domain = /VITE_API_DOMAIN=(?<domain>.*)/.exec(
|
|
|
fs.readFileSync(".env").toString()
|
|
|
)?.groups.domain;
|
|
|
|
|
|
-if (!domain) {
|
|
|
+const webdomain = /VITE_WEB_DOMAIN=(?<webdomain>.*)/.exec(
|
|
|
+ fs.readFileSync(".env").toString()
|
|
|
+)?.groups.webdomain;
|
|
|
+
|
|
|
+if (!domain || !webdomain) {
|
|
|
console.log("error domain");
|
|
|
process.exit(-1);
|
|
|
}
|
|
|
|
|
|
-console.log(domain);
|
|
|
+console.log(domain, webdomain);
|
|
|
|
|
|
function upload(src, dest) {
|
|
|
console.log(`scp ${src} root@${server}:${dest}`);
|
|
|
@@ -89,6 +93,22 @@ function rsync() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+function build(){
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const p = childProcess.spawn(`node`, ["build.js"]);
|
|
|
+ p.stdout.on("data", (data) => {
|
|
|
+ console.log(data.toString());
|
|
|
+ });
|
|
|
+ p.stderr.on("data", (data) => {
|
|
|
+ console.error(data.toString());
|
|
|
+ });
|
|
|
+ p.on("exit", (signal) => {
|
|
|
+ if (signal === 0) resolve();
|
|
|
+ else reject(`node build.js exit with code: ${signal}`);
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
const tmpDir = fs.mkdtempSync(os.tmpdir());
|
|
|
const api_conf_tmp = path.join(tmpDir, "api.conf");
|
|
|
const [part1, part2] = domain.split(".");
|
|
|
@@ -102,10 +122,28 @@ fs.writeFileSync(
|
|
|
);
|
|
|
console.log(api_conf_tmp);
|
|
|
|
|
|
+const web_conf_tmp = path.join(tmpDir, "web.conf");
|
|
|
+fs.writeFileSync(
|
|
|
+ web_conf_tmp,
|
|
|
+ fs
|
|
|
+ .readFileSync("nginx_conf/web.conf")
|
|
|
+ .toString()
|
|
|
+ .replace("{webdomain}", webdomain)
|
|
|
+);
|
|
|
+
|
|
|
upload(api_conf_tmp, "/etc/openresty/conf.d/api.conf")
|
|
|
+ .then(() => {
|
|
|
+ return upload(web_conf_tmp, "/etc/openresty/conf.d/web.conf");
|
|
|
+ })
|
|
|
.then(() => {
|
|
|
return exec("openresty -T");
|
|
|
})
|
|
|
+ .then(() => {
|
|
|
+ return exec("openresty -s reload");
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ return build();
|
|
|
+ })
|
|
|
.then(() => {
|
|
|
return rsync();
|
|
|
})
|