Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rari): use rari as default #12322

Merged
merged 8 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ cloud-function/**/*.js
filecheck/*.js
mdn/content/
tool/*.js
bins/*.mjs
4 changes: 2 additions & 2 deletions .github/workflows/npm-published-simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
REACT_APP_DISABLE_AUTH: true
CONTENT_ROOT: testing/content/files
run: |
yarn build:prepare
yarn build:legacy:prepare

- name: Build and install tarball
run: |
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
- name: SSR build a page
working-directory: mdn/content
run: |
yarn build files/en-us/mdn/kitchensink/index.md
yarn rari-build -f ${PWD}/files/en-us/mdn/kitchensink/index.md

- name: Debug server's stdout and stderr if tests failed
if: failure()
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ jobs:
BUILD_GOOGLE_ANALYTICS_MEASUREMENT_ID: G-XXXXXXXX
run: |
yarn build:prepare
# BUILD_FOLDERSEARCH=mdn/kitchensink yarn build:docs
BUILD_FOLDERSEARCH=web/javascript/reference/global_objects/array/foreach yarn build:docs
yarn build -f $CONTENT_ROOT/en-us/web/javascript/reference/global_objects/array/foreach -f $CONTENT_ROOT/en-us/mdn/kitchensink
yarn render:html

- name: Serve and lhci
Expand Down
43 changes: 21 additions & 22 deletions .github/workflows/prod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ jobs:
env:
ENV_FILE: .env.testing
run: |
yarn build:prepare
yarn build:docs
yarn build:legacy:prepare
yarn build:legacy
yarn render:html

yarn start:static-server > /tmp/stdout.log 2> /tmp/stderr.log &
Expand Down
4 changes: 4 additions & 0 deletions Procfile.rari.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
server: yarn start:rari-server
type-check: cd client && tsc --noEmit --watch
web: yarn start:client
ssr: yarn watch:ssr
16 changes: 16 additions & 0 deletions bins/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node
import { rariBin } from "@mdn/rari";
import { spawn } from "cross-spawn";
import { config } from "dotenv";
import path from "node:path";
import { cwd } from "node:process";

import { BUILD_OUT_ROOT } from "../libs/env/index.js";

config({
path: path.join(cwd(), process.env.ENV_FILE || ".env"),
});

process.env.BUILD_OUT_ROOT = process.env.BUILD_OUT_ROOT || BUILD_OUT_ROOT;

spawn(rariBin, ["build", ...process.argv.slice(2)], { stdio: "inherit" });
52 changes: 52 additions & 0 deletions bins/server.mjs
Original file line number Diff line number Diff line change
@@ -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 ☠️");
}
17 changes: 17 additions & 0 deletions bins/tool.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node
import { rariBin } from "@mdn/rari";
import { spawn } from "cross-spawn";

import { config } from "dotenv";
import path from "node:path";
import { cwd } from "node:process";

import { BUILD_OUT_ROOT } from "../libs/env/index.js";

config({
path: path.join(cwd(), process.env.ENV_FILE || ".env"),
});

process.env.BUILD_OUT_ROOT = process.env.BUILD_OUT_ROOT || BUILD_OUT_ROOT;

spawn(rariBin, ["content", ...process.argv.slice(2)], { stdio: "inherit" });
48 changes: 35 additions & 13 deletions docs/cli-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ Run the CLI tool:
yarn tool --help
```

## Commands

### validate-redirect

Validates the content of the `_redirects.txt` files(s). (This does not verify
that _to URLs_ exist)
### Or run the legacy version

### test-redirect
```sh
yarn tool:legacy --help
```

Test whether an URL path is a redirect and display the according target.
## Commands

### add-redirect

Expand All @@ -34,25 +31,50 @@ redirects).
Move a document and its children. Adds the according redirects and stages
changes in `git` (except for redirects).

### edit
### sync-translated-content

Syncs translated content for all or a list of locales.

### fmt-sidebars

Formats all sidebars in content.

### sync-sidebars

Sync sidebars with redirects in content.

### fix-redirects

Fixes redirects across all locales.

### validate-redirect (only in legacy)

Validates the content of the `_redirects.txt` files(s). (This does not verify
that _to URLs_ exist)

### test-redirect (only in legacy)

Test whether an URL path is a redirect and display the according target.

### edit (only in legacy)

Open a document by its slug in the preferred editor (as per the `EDITOR`
environment variable).

### create
### create (only in legacy)

Open a _new_ document by its slug in the preferred editor (as per the `EDITOR`
environment variable).

### validate
### validate (only in legacy)

Run basic validation for a document (only verifies the slug for now).

### preview
### preview (only in legacy)

Open a preview of a given slug in your browser. This depends on a running
dev-server (`yarn start`).

### flaws
### flaws (only in legacy)

Show and optionally fix fixable flaws for a given slug.
29 changes: 18 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": "node bins/build.mjs",
"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'",
Expand All @@ -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",
Expand All @@ -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": "node bins/tool.mjs",
"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": {
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ echo "----------------------"
export ENV_FILE=".env.testing"

yarn build:prepare
yarn build:docs
yarn build:legacy
yarn render:html

nohup yarn start:static-server > testing.log 2>&1 &
Expand Down
2 changes: 1 addition & 1 deletion testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To run these tests, first run:
```sh
export ENV_FILE=.env.testing
yarn build:prepare
yarn build:docs
yarn build:legacy
yarn render:html
yarn start:static-server
```
Expand Down
2 changes: 1 addition & 1 deletion testing/scripts/functional-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
export ENV_FILE=.env.testing

yarn build:prepare
yarn build:docs
yarn build:legacy
yarn render:html

yarn test:testing $@
Loading
Loading