mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-12 11:30:01 -04:00
Move a lot of shell stuff over to Node so that Windows users need not install git bash.
This commit is contained in:
parent
92909e4ab7
commit
bc858ebf22
4 changed files with 82 additions and 34 deletions
|
@ -1,8 +0,0 @@
|
||||||
# File created to force npm execution in shell (instead of potentially Windows batch).
|
|
||||||
# This script can be run manually if esbuild is replaced by the following:
|
|
||||||
# ./node_modules/.bin/esbuild
|
|
||||||
|
|
||||||
# Make the ./views/dist directory in case it doesn't exist, and also make it empty.
|
|
||||||
dist='./views/dist'; mkdir "$dist"; find "$dist" -mindepth 1 -delete &&
|
|
||||||
# Curly bracket wildcards are not supported by some clients, so this is quite long.
|
|
||||||
esbuild --platform=browser --sourcemap --minify --bundle --external:*.png --external:*.jpg --external:*.jpeg --external:*.webp --external:*.svg --outdir="$dist" ./views/uv/*.js ./views/assets/js/*.js ./views/assets/js/*/*.js ./views/assets/css/*.css
|
|
12
package.json
12
package.json
|
@ -6,12 +6,14 @@
|
||||||
"main": "backend.js",
|
"main": "backend.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "npm install && npm run build && npm run manual-start",
|
"start": "npm install && npm run build && npm run manual-start",
|
||||||
"restart": "npm stop; npm run manual-start",
|
"restart": "npm stop ; npm run manual-start",
|
||||||
"stop": "( pm2 stop ecosystem.config.js ) ; node shutdown.mjs",
|
"stop": "node run-command.mjs stop",
|
||||||
"test": "npm run proxy-validator",
|
"test": "npm run proxy-validator",
|
||||||
"monit": "pm2 monit",
|
"pm2-start": "pm2 start ecosystem.config.js --env production",
|
||||||
"manual-start": "node read-config.mjs 'production' && ( pm2 start ecosystem.config.js --env production ) || ( node backend.js & pkill -n npm || true )",
|
"pm2-stop": "pm2 stop ecosystem.config.js",
|
||||||
"build": "sh ./build-assets.sh && cd lib/rammerhead && npm install && npm run build",
|
"pm2-monit": "pm2 monit",
|
||||||
|
"manual-start": "node run-command.mjs start",
|
||||||
|
"build": "node run-command.mjs build && cd lib/rammerhead && npm install && npm run build",
|
||||||
"start-test-server": "timeout 5 node backend.js; test $? -eq 124 && ( npm run manual-start & ) || exit 1",
|
"start-test-server": "timeout 5 node backend.js; test $? -eq 124 && ( npm run manual-start & ) || exit 1",
|
||||||
"proxy-validator": "node proxyServiceValidator.js"
|
"proxy-validator": "node proxyServiceValidator.js"
|
||||||
},
|
},
|
||||||
|
|
75
run-command.mjs
Normal file
75
run-command.mjs
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
import { readFile, writeFile, unlink, mkdir, rm } from 'node:fs/promises';
|
||||||
|
import { exec, fork } from 'node:child_process';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { build } from 'esbuild';
|
||||||
|
|
||||||
|
const config = Object.freeze(JSON.parse(await readFile(new URL("./src/config.json", import.meta.url))));
|
||||||
|
|
||||||
|
const serverUrl = (base => {
|
||||||
|
try {
|
||||||
|
base = new URL(config.host);
|
||||||
|
} catch (e) {
|
||||||
|
base = new URL("http://a");
|
||||||
|
base.host = config.host;
|
||||||
|
}
|
||||||
|
base.port = process.env.PORT || config.port;
|
||||||
|
return Object.freeze(base);
|
||||||
|
})();
|
||||||
|
|
||||||
|
const shutdown = new URL("./src/.shutdown", import.meta.url);
|
||||||
|
|
||||||
|
for(let i = 2; i < process.argv.length; i++)
|
||||||
|
switch (process.argv[i]) {
|
||||||
|
case "start": {
|
||||||
|
if (config.production)
|
||||||
|
exec("npm run pm2-start", (error, stdout) => {
|
||||||
|
if (error) throw error;
|
||||||
|
console.log(stdout);
|
||||||
|
});
|
||||||
|
else {
|
||||||
|
const server = fork(
|
||||||
|
new URL("./backend.js", import.meta.url),
|
||||||
|
{detached: true}
|
||||||
|
);
|
||||||
|
server.unref();
|
||||||
|
server.disconnect();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "stop":
|
||||||
|
await writeFile(shutdown, "");
|
||||||
|
try {await fetch(new URL("/test-shutdown", serverUrl))}
|
||||||
|
catch (e) {await unlink(shutdown)}
|
||||||
|
if (config.production)
|
||||||
|
exec("npm run pm2-stop", (error, stdout) => {
|
||||||
|
if (error) throw error;
|
||||||
|
console.log(stdout);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "build": {
|
||||||
|
const dist = fileURLToPath(new URL("./views/dist", import.meta.url));
|
||||||
|
await rm(dist, {force: true, recursive: true});
|
||||||
|
await mkdir(dist);
|
||||||
|
await build({
|
||||||
|
entryPoints: [
|
||||||
|
"./views/uv/**/*.js",
|
||||||
|
"./views/assets/js/**/*.js",
|
||||||
|
"./views/assets/css/**/*.css"
|
||||||
|
],
|
||||||
|
platform: "browser",
|
||||||
|
sourcemap: true,
|
||||||
|
bundle: true,
|
||||||
|
minify: true,
|
||||||
|
external: ["*.png", "*.jpg", "*.jpeg", "*.webp", "*.svg"],
|
||||||
|
outdir: dist
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No default case.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
process.exitCode = 0;
|
21
shutdown.mjs
21
shutdown.mjs
|
@ -1,21 +0,0 @@
|
||||||
import { readFile, writeFile, unlink } from 'node:fs/promises';
|
|
||||||
|
|
||||||
const config = Object.freeze(JSON.parse(await readFile(new URL("./src/config.json", import.meta.url))));
|
|
||||||
|
|
||||||
const serverUrl = (base => {
|
|
||||||
try {
|
|
||||||
base = new URL(config.host);
|
|
||||||
} catch (e) {
|
|
||||||
base = new URL("http://a");
|
|
||||||
base.host = config.host;
|
|
||||||
}
|
|
||||||
base.port = process.env.PORT || config.port;
|
|
||||||
return Object.freeze(base);
|
|
||||||
})();
|
|
||||||
|
|
||||||
const shutdown = new URL("./src/.shutdown", import.meta.url);
|
|
||||||
|
|
||||||
await writeFile(shutdown, "");
|
|
||||||
try {await fetch(new URL("/test-shutdown", serverUrl))}
|
|
||||||
catch (e) {await unlink(shutdown)}
|
|
||||||
process.exitCode = 0;
|
|
Loading…
Add table
Add a link
Reference in a new issue