From 0fadbb74b51bd20ea9692c0fdf53225dd13b28c5 Mon Sep 17 00:00:00 2001 From: Florian Dieminger Date: Tue, 17 Dec 2024 15:50:47 +0100 Subject: [PATCH] feat(rari): use rari as default BREAKING CHANGE: rari is used by default use :legacy commands for yari --- .github/workflows/prod-build.yml | 43 +++++++++++++------------- Procfile.rari.dev | 4 +++ bins/build.mjs | 5 +++ bins/server.mjs | 52 ++++++++++++++++++++++++++++++++ bins/tool.mjs | 5 +++ package.json | 29 +++++++++++------- yarn.lock | 2 +- 7 files changed, 106 insertions(+), 34 deletions(-) create mode 100644 Procfile.rari.dev create mode 100644 bins/build.mjs create mode 100644 bins/server.mjs create mode 100644 bins/tool.mjs diff --git a/.github/workflows/prod-build.yml b/.github/workflows/prod-build.yml index 99d983398106..b9ea8172d6d9 100644 --- a/.github/workflows/prod-build.yml +++ b/.github/workflows/prod-build.yml @@ -134,6 +134,13 @@ jobs: mv mdn/translated-content-de/files/de mdn/translated-content/files/ rm -rf mdn/translated-content-de + - name: Clean and commit de + if: ${{ ! vars.SKIP_BUILD || ! vars.SKIP_FUNCTION }} + working-directory: mdn/translated-content + run: | + git add files/de + git -c user.name='MDN' -c user.email='mdn-dev@mozilla.com' commit -m 'de' + - uses: actions/checkout@v4 if: ${{ ! vars.SKIP_BUILD }} with: @@ -151,7 +158,8 @@ jobs: if: ${{ ! vars.SKIP_BUILD }} run: yarn --frozen-lockfile env: - # https://github.com/microsoft/vscode-ripgrep#github-api-limit-note + # Use a GITHUB_TOKEN to bypass rate limiting for ripgrep and rari. + # See https://github.com/microsoft/vscode-ripgrep#github-api-limit-note GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Install Python @@ -198,6 +206,12 @@ jobs: GENERIC_CONTENT_ROOT: ${{ github.workspace }}/mdn/generic-content/files BASE_URL: "https://developer.mozilla.org" + # rari + BUILD_OUT_ROOT: "client/build" + LIVE_SAMPLES_BASE_URL: https://live.mdnplay.dev + INTERACTIVE_EXAMPLES_BASE_URL: https://interactive-examples.mdn.mozilla.net + ADDITIONAL_LOCALES_FOR_GENERICS_AND_SPAS: de + # The default for this environment variable is geared for writers # (aka. local development). Usually defaults are supposed to be for # secure production but this is an exception and default @@ -285,32 +299,17 @@ jobs: echo "CONTENT_ROOT=$CONTENT_ROOT" echo "CONTENT_TRANSLATED_ROOT=$CONTENT_TRANSLATED_ROOT" yarn build:sw - yarn build:prepare + yarn build:client + yarn build:ssr + yarn tool build-robots-txt - yarn tool sync-translated-content es fr ja ko pt-br ru zh-cn zh-tw + yarn rari content sync-translated-content + yarn rari git-history - # Build using one process per locale. - # Note: We have 4 cores, but 9 processes is a reasonable number. - for locale in en-us de es fr ja ko pt-br ru zh-cn zh-tw; do - yarn build:docs --locale $locale 2>&1 | sed "s/^/[$locale] /" & - pids+=($!) - done - - for pid in "${pids[@]}"; do - wait $pid - done + yarn rari build --all --issues client/build/issues.json --templ-stats du -sh client/build - # Build the blog - yarn build:blog - - # Build the curriculum - yarn build:curriculum - - # Generate sitemap index file - yarn build --sitemap-index - # SSR all pages yarn render:html diff --git a/Procfile.rari.dev b/Procfile.rari.dev new file mode 100644 index 000000000000..303a7b4a0548 --- /dev/null +++ b/Procfile.rari.dev @@ -0,0 +1,4 @@ +server: yarn start:rari-server +type-check: cd client && tsc --noEmit --watch +web: yarn start:client +ssr: yarn watch:ssr diff --git a/bins/build.mjs b/bins/build.mjs new file mode 100644 index 000000000000..3cb2d57890a7 --- /dev/null +++ b/bins/build.mjs @@ -0,0 +1,5 @@ +#!/usr/bin/env node +import { rariBin } from "@mdn/rari"; +import { spawn } from "cross-spawn"; + +spawn(rariBin, ["build"], { stdio: "inherit" }); diff --git a/bins/server.mjs b/bins/server.mjs new file mode 100644 index 000000000000..24d023c92700 --- /dev/null +++ b/bins/server.mjs @@ -0,0 +1,52 @@ +#!/usr/bin/env node +import { concurrently } from "concurrently"; +import { rariBin } from "@mdn/rari"; +import { filename } from "../server/filename.js"; +import { config } from "dotenv"; +import path from "node:path"; +import { cwd } from "node:process"; + +config({ + path: path.join(cwd(), process.env.ENV_FILE || ".env"), +}); + +const { commands, result } = concurrently( + [ + { + command: `node ${filename}`, + name: "server", + env: { + RARI: true, + }, + prefixColor: "red", + }, + { + command: `${rariBin} serve -vv`, + name: "rari", + prefixColor: "blue", + env: { + ...process.env, + }, + }, + ], + { + killOthers: ["failure", "success"], + restartTries: 0, + handleInput: true, + inputStream: process.stdin, + } +); + +const stop = new Promise((resolve, reject) => { + process.on("SIGINT", () => { + commands.forEach((cmd) => cmd.kill()); // Terminate all concurrently-run processes + reject(); + }); + result.finally(() => resolve(null)); +}); +try { + await stop; + console.log("All tasks completed successfully."); +} catch { + console.log("Killed ☠️"); +} diff --git a/bins/tool.mjs b/bins/tool.mjs new file mode 100644 index 000000000000..b050ef3d176b --- /dev/null +++ b/bins/tool.mjs @@ -0,0 +1,5 @@ +#!/usr/bin/env node +import { rariBin } from "@mdn/rari"; +import { spawn } from "cross-spawn"; + +spawn(rariBin, ["content"], { stdio: "inherit" }); diff --git a/package.json b/package.json index d6e3b60dbd9c..0b768d983117 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "author": "MDN Web Docs", "type": "module", "bin": { - "rari-server": "server/cli.js", + "rari-build": "bins/build.mjs", + "rari-server": "bins/server.mjs", + "rari-tool": "bins/tool.mjs", "yari-build": "build/cli.js", "yari-build-blog": "build/build-blog.js", "yari-filecheck": "filecheck/cli.js", @@ -17,19 +19,22 @@ "scripts": { "ai-help-macros": "cross-env NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node scripts/ai-help-macros.ts", "analyze": "(test -f client/build/stats.json || cross-env ANALYZE_BUNDLE=true yarn build:client) && webpack-bundle-analyzer client/build/stats.json", - "build": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/cli.ts", - "build:blog": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/build-blog.ts", + "build": "yarn rari build", "build:client": "cd client && cross-env NODE_ENV=production BABEL_ENV=production node scripts/build.js", - "build:curriculum": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/build-curriculum.ts", "build:dist": "tsc -p tsconfig.dist.json", - "build:docs": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/cli.ts -n", "build:glean": "cd client && cross-env VIRTUAL_ENV=venv glean translate src/telemetry/metrics.yaml src/telemetry/pings.yaml -f typescript -o src/telemetry/generated", - "build:prepare": "yarn build:client && yarn build:ssr && yarn tool popularities && yarn tool spas && yarn tool gather-git-history && yarn tool build-robots-txt", + "build:legacy": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/cli.ts", + "build:legacy::curriculum": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/build-curriculum.ts", + "build:legacy::docs": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/cli.ts -n", + "build:legacy:blog": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/build-blog.ts", + "build:legacy:prepare": "yarn build:client && yarn build:ssr && yarn tool:legacy popularities && yarn tool:legacy spas && yarn tool:legacy gather-git-history && yarn tool:legacy build-robots-txt", + "build:prepare": "yarn build:client && yarn build:ssr && yarn tool:legacy build-robots-txt", "build:ssr": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node ssr/prepare.ts && webpack --mode=production --config=ssr/webpack.config.js", "build:sw": "cd client/pwa && yarn && yarn build:prod", "build:sw-dev": "cd client/pwa && yarn && yarn build", "check:tsc": "find . -name 'tsconfig.json' ! -wholename '**/node_modules/**' -print0 | xargs -n1 -P 2 -0 sh -c 'cd `dirname $0` && echo \"🔄 $(pwd)\" && npx tsc --noEmit && echo \"☑️ $(pwd)\" || exit 255'", - "dev": "yarn build:prepare && nf -j Procfile.dev start", + "dev": "yarn build:prepare && nf -j Procfile.rari.dev start", + "dev:legacy": "yarn build:legacy:prepare && nf -j Procfile.dev start", "eslint": "eslint .", "filecheck": "cross-env NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node filecheck/cli.ts", "install:all": "find . -mindepth 2 -name 'yarn.lock' ! -wholename '**/node_modules/**' -print0 | xargs -n1 -0 sh -cx 'yarn --cwd $(dirname $0) install'", @@ -41,9 +46,9 @@ "prettier-check": "prettier --check .", "prettier-format": "prettier --write .", "render:html": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/ssr-cli.ts", - "start": "(test -f client/build/asset-manifest.json || yarn build:client) && (test -f ssr/dist/main.js || yarn build:ssr) && (test -f popularities.json || yarn tool popularities) && (test -d client/build/en-us/404 || yarn tool spas) && (test -d client/build/en-us/404/index.html || yarn render:html -s) && nf -j Procfile.start start", + "start": "(test -f client/build/asset-manifest.json || yarn build:client) && (test -f ssr/dist/main.js || yarn build:ssr) && cross-env RARI=true nf -j Procfile.rari start", "start:client": "cd client && cross-env NODE_ENV=development BABEL_ENV=development PORT=3000 node scripts/start.js", - "start:rari": "(test -f client/build/asset-manifest.json || yarn build:client) && (test -f ssr/dist/main.js || yarn build:ssr) && cross-env RARI=true nf -j Procfile.rari start", + "start:legacy": "(test -f client/build/asset-manifest.json || yarn build:client) && (test -f ssr/dist/main.js || yarn build:ssr) && (test -f popularities.json || yarn tool:legacy popularities) && (test -d client/build/en-us/404 || yarn tool spas) && (test -d client/build/en-us/404/index.html || yarn render:html -s) && nf -j Procfile.start start", "start:rari-external": "(test -f client/build/asset-manifest.json || yarn build:client) && (test -f ssr/dist/main.js || yarn build:ssr) && cross-env RARI=true nf -j Procfile.start start", "start:rari-server": "cross-env NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node server/cli.ts", "start:server": "node-dev --experimental-loader ts-node/esm server/index.ts", @@ -56,9 +61,10 @@ "test:headless": "playwright test headless", "test:kumascript": "yarn jest --rootDir kumascript --env=node", "test:libs": "yarn jest --rootDir libs --env=node", - "test:prepare": "yarn build:prepare && yarn build:docs && yarn render:html && yarn start:static-server", + "test:prepare": "yarn build:prepare && yarn build && yarn render:html && yarn start:static-server", "test:testing": "yarn jest --rootDir testing", - "tool": "cross-env NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node ./tool/cli.ts", + "tool": "yarn rari content", + "tool:legacy": "cross-env NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node ./tool/cli.ts", "watch:ssr": "webpack --mode=production --watch --config=ssr/webpack.config.js" }, "resolutions": { @@ -96,6 +102,7 @@ "concurrently": "^9.1.0", "cookie": "^0.7.2", "cookie-parser": "^1.4.7", + "cross-spawn": "^7.0.6", "css-tree": "^2.3.1", "dayjs": "^1.11.13", "dexie": "^4.0.10", diff --git a/yarn.lock b/yarn.lock index 2227d5d9187e..794c66e1b77d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5472,7 +5472,7 @@ cross-spawn@^6.0.0: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3: +cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6: version "7.0.6" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==