mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
This replaces the old ember-cli build with a modern Rolldown build. In local testing, this provides an 80% improvement in build times, while remaining 100% backwards compatible for themes and plugins. As part of this move, we have decided to stop using a proxy in front of Discourse for development. Development should now be done directly against the Rails server. `bin/ember-cli -u` has been replaced with `bin/dev`. This will launch Rails on `:3000`, and will run the rolldown build in the background. Log output from both processes will be shown with an appropriate prefix. You should visit `:3000` in your browser. `:4200` will no longer serve anything. To help with migration, `bin/ember-cli` is now a backwards-compatible shim. It will print help information, and will launch a lightweight server on `:4200` with instructions to move to `:3000`. If you prefer to launch Rails and the JS build as separate commands, you can still do that. Rails boot commands are unchanged, and the rolldown development builder can be run using `bin/dev --only ember`. https://meta.discourse.org/t/403908 --------- Co-authored-by: Jarek Radosz <jarek@cvx.dev> Co-authored-by: Chris Manson <chris@manson.ie>
89 lines
2.2 KiB
JavaScript
Executable file
Vendored
89 lines
2.2 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 { parseArgs } = require("util");
|
|
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 { values: args } = parseArgs({
|
|
options: { only: { type: "string" } },
|
|
});
|
|
|
|
const commands = [];
|
|
|
|
if (!args.only || args.only === "rails") {
|
|
commands.push({
|
|
name: "rails",
|
|
command: path.join(RAILS_ROOT, "bin/pitchfork"),
|
|
cwd: RAILS_ROOT,
|
|
env: serverEnv,
|
|
prefixColor: "#22c4f1",
|
|
});
|
|
}
|
|
|
|
if (!args.only || args.only === "ember") {
|
|
commands.push({
|
|
name: "ember",
|
|
command: "./rolldown.mjs",
|
|
cwd: path.join(RAILS_ROOT, "frontend/discourse"),
|
|
prefixColor: "#f27a21",
|
|
});
|
|
}
|
|
|
|
if (commands.length === 0) {
|
|
console.error(`[bin/dev] --only must be 'rails' or 'ember'`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const { result } = concurrently(commands, {
|
|
killOthersOn: ["success", "failure"],
|
|
killSignal: "SIGTERM",
|
|
});
|
|
|
|
result.then(
|
|
() => process.exit(0),
|
|
() => process.exit(1)
|
|
);
|