mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-26 14:00:42 +08:00
75 lines
1.8 KiB
JavaScript
Executable file
Vendored
75 lines
1.8 KiB
JavaScript
Executable file
Vendored
#!/usr/bin/env node
|
|
/* eslint-disable no-console */
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { spawnSync } = require("child_process");
|
|
const concurrently = require("concurrently");
|
|
|
|
const RAILS_ROOT = path.resolve(__dirname, "..");
|
|
|
|
let nodeModulesOutdated = false;
|
|
try {
|
|
const installed = fs.readFileSync(
|
|
path.join(RAILS_ROOT, "node_modules/.pnpm/lock.yaml"),
|
|
"utf8"
|
|
);
|
|
const lockfile = fs.readFileSync(
|
|
path.join(RAILS_ROOT, "pnpm-lock.yaml"),
|
|
"utf8"
|
|
);
|
|
nodeModulesOutdated = installed !== lockfile;
|
|
} catch (e) {
|
|
nodeModulesOutdated = true;
|
|
}
|
|
|
|
if (nodeModulesOutdated) {
|
|
console.log(
|
|
"[bin/dev] Detected outdated or missing node_modules. Running pnpm install..."
|
|
);
|
|
const result = spawnSync("pnpm", [`--dir=${RAILS_ROOT}`, "install"], {
|
|
stdio: "inherit",
|
|
});
|
|
if (result.status !== 0) {
|
|
if (result.error && result.error.code === "ENOENT") {
|
|
console.error("pnpm is not installed. run `npm install -g pnpm`");
|
|
}
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
const serverEnv = { ...process.env };
|
|
serverEnv.UNICORN_PORT ||= "3000";
|
|
|
|
if (process.env.CODESPACE_NAME) {
|
|
serverEnv.DISCOURSE_PORT = "443";
|
|
serverEnv.DISCOURSE_FORCE_HTTPS = "1";
|
|
serverEnv.DISCOURSE_FORCE_HOSTNAME = `${process.env.CODESPACE_NAME}-${serverEnv.UNICORN_PORT}.${process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}`;
|
|
}
|
|
|
|
const { result } = concurrently(
|
|
[
|
|
{
|
|
name: "rails",
|
|
command: path.join(RAILS_ROOT, "bin/pitchfork"),
|
|
cwd: RAILS_ROOT,
|
|
env: serverEnv,
|
|
prefixColor: "#22c4f1",
|
|
},
|
|
{
|
|
name: "ember",
|
|
command: "./rolldown.mjs",
|
|
cwd: path.join(RAILS_ROOT, "frontend/discourse"),
|
|
prefixColor: "#f27a21",
|
|
},
|
|
],
|
|
{
|
|
killOthersOn: ["success", "failure"],
|
|
killSignal: "SIGTERM",
|
|
}
|
|
);
|
|
|
|
result.then(
|
|
() => process.exit(0),
|
|
() => process.exit(1)
|
|
);
|