@multiplatform.one/cli 8.0.0 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/lib/bin/multiplatformOne.mjs +17 -11
- package/lib/commands/e2e.mjs +6 -15
- package/lib/commands/pythonTools.mjs +81 -0
- package/lib/commands/scaffold.mjs +62 -3
- package/lib/commands/verbs.mjs +55 -33
- package/lib/source.json +2 -2
- package/package.json +2 -2
- package/scripts/scaffold.sh +12 -0
- package/src/bin/multiplatformOne.ts +19 -13
- package/src/commands/e2e.ts +16 -21
- package/src/commands/pythonTools.spec.ts +134 -0
- package/src/commands/pythonTools.ts +106 -0
- package/src/commands/scaffold.ts +60 -3
- package/src/commands/updateCleanups.spec.ts +282 -0
- package/src/commands/verbs.spec.ts +94 -5
- package/src/commands/verbs.ts +57 -33
- package/types/commands/e2e.d.ts +1 -1
- package/types/commands/e2e.d.ts.map +1 -1
- package/types/commands/pythonTools.d.ts +22 -0
- package/types/commands/pythonTools.d.ts.map +1 -0
- package/types/commands/scaffold.d.ts +1 -1
- package/types/commands/scaffold.d.ts.map +1 -1
- package/types/commands/verbs.d.ts +2 -2
- package/types/commands/verbs.d.ts.map +1 -1
- package/lib/commands/ruff.mjs +0 -52
- package/src/commands/ruff.spec.ts +0 -46
- package/src/commands/ruff.ts +0 -74
- package/types/commands/ruff.d.ts +0 -15
- package/types/commands/ruff.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -94,11 +94,16 @@ git add -A && git commit -m "chore: mpo update <old> → <new>"
|
|
|
94
94
|
|
|
95
95
|
A three-way merge: **base** is the scaffold at the commit recorded in
|
|
96
96
|
`.mpo.json` with the recorded apps and services, **ours** is your `HEAD`,
|
|
97
|
-
**theirs** is
|
|
98
|
-
`--source`/`--checkout`). Your commits are preserved, the
|
|
99
|
-
land as the diff, every product app receives the One
|
|
100
|
-
nothing is committed. Conflicts land with normal markers;
|
|
101
|
-
on a clean merge (`--skip-install` to skip it).
|
|
97
|
+
**theirs** is that selection scaffolded at the commit this CLI was built
|
|
98
|
+
from (or `--source`/`--checkout`). Your commits are preserved, the
|
|
99
|
+
monorepo's changes land as the diff, every product app receives the One
|
|
100
|
+
app's changes, and nothing is committed. Conflicts land with normal markers;
|
|
101
|
+
`pnpm install` runs on a clean merge (`--skip-install` to skip it).
|
|
102
|
+
|
|
103
|
+
Each side runs the `scaffold.sh` its own commit carries, so whatever the
|
|
104
|
+
scaffold changed since your recorded commit lands too: a root rule it now
|
|
105
|
+
drops is removed from your project. If you edited those lines, the file
|
|
106
|
+
conflicts instead.
|
|
102
107
|
|
|
103
108
|
`.updateignore` entries (exact files or directory prefixes, not globs) and
|
|
104
109
|
`pnpm-lock.yaml` stay pinned to your version. Dependency-range drift in
|
|
@@ -158,8 +163,8 @@ sh scripts/scaffold.sh [--app <name>]... [--service <name>]... [--mpo-version <r
|
|
|
158
163
|
| `mpo frappe types <doctype…>` | Emit doctype TypeScript types from getdoctype; `--check -o <file>` fails on drift |
|
|
159
164
|
| `mpo build` | Run the build command |
|
|
160
165
|
| `mpo test [tier]` | Run unit (default), integration, e2e or visual tests (E2E: `--up-only`, …) |
|
|
161
|
-
| `mpo lint` | Run the root `lint` script (`//#lint`), then `
|
|
162
|
-
| `mpo format` | Run the root `format` script (`//#format`), then `
|
|
166
|
+
| `mpo lint` | Run the root `lint` script (`//#lint`), then `black --check` and `basedpyright` |
|
|
167
|
+
| `mpo format` | Run the root `format` script (`//#format`), then `black` |
|
|
163
168
|
| `mpo count` | Count lines of code with `cloc` |
|
|
164
169
|
| `mpo generate` | Run the turbo `generate` task |
|
|
165
170
|
|
|
@@ -168,7 +173,8 @@ sh scripts/scaffold.sh [--app <name>]... [--service <name>]... [--mpo-version <r
|
|
|
168
173
|
`pnpm --filter @multiplatform.one/cli test` runs the vitest specs: the
|
|
169
174
|
provenance and merge units, and `updateApp.spec.ts`, which scaffolds from
|
|
170
175
|
this checkout at `HEAD`, updates from a second clone that moved ahead, and
|
|
171
|
-
adds an app
|
|
176
|
+
adds an app, and `updateCleanups.spec.ts`, which updates from a stand-in
|
|
177
|
+
monorepo whose scaffold gains a cleanup. `make -C public/cli test/bats` runs `tests/*.bats` against
|
|
172
178
|
`scripts/scaffold.sh` directly (needs `bats`). `pnpm build` stamps
|
|
173
179
|
`lib/source.json` from `git rev-parse HEAD` (`MPO_SOURCE_SHA` /
|
|
174
180
|
`MPO_SOURCE_URL` override it), unless `HEAD` carries another CLI version;
|
|
@@ -4,7 +4,7 @@ import { adoptApp } from "../commands/adoptApp.mjs";
|
|
|
4
4
|
import { generateDoctypeTypes, typesDrift } from "../commands/doctypeTypes.mjs";
|
|
5
5
|
import { runE2ESession } from "../commands/e2e.mjs";
|
|
6
6
|
import { SINGLETON_APPS, init } from "../commands/init.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { pythonFiles, runPythonTools } from "../commands/pythonTools.mjs";
|
|
8
8
|
import { updateApp } from "../commands/updateApp.mjs";
|
|
9
9
|
import { availableServices, parseTestTiers, runBuild, runFrappeBench, runIntegrationTests, runTurboLint, runUnitTests, testTiers, waitFunctions } from "../commands/verbs.mjs";
|
|
10
10
|
import fsSync from "node:fs";
|
|
@@ -272,14 +272,20 @@ program.command("test").argument("[args...]", `test to run: ${testTiers.join(",
|
|
|
272
272
|
}
|
|
273
273
|
});
|
|
274
274
|
/**
|
|
275
|
-
* Run
|
|
276
|
-
* Returns true if the
|
|
275
|
+
* Run black, or black --check and basedpyright, on the project's Python files (if any).
|
|
276
|
+
* Returns true if the Python step failed.
|
|
277
277
|
*/
|
|
278
|
-
async function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
278
|
+
async function pythonStep(mode) {
|
|
279
|
+
let files;
|
|
280
|
+
try {
|
|
281
|
+
files = await pythonFiles(projectRoot);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.error(`git ls-files could not list the Python files: ${error.message}`);
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
if (files.length === 0) return false;
|
|
287
|
+
console.log(`\n── ${mode === "format" ? "black" : "black --check, basedpyright"} (Python) ──`);
|
|
288
|
+
const reason = await runPythonTools(mode, files, projectRoot);
|
|
283
289
|
if (reason === void 0) return false;
|
|
284
290
|
console.error(reason);
|
|
285
291
|
return true;
|
|
@@ -293,12 +299,12 @@ program.command("format").description("format all supported files (TS, Python, e
|
|
|
293
299
|
stdio: "inherit",
|
|
294
300
|
cwd: projectRoot
|
|
295
301
|
});
|
|
296
|
-
await
|
|
302
|
+
await pythonStep("format");
|
|
297
303
|
});
|
|
298
304
|
program.command("lint").description("lint all supported files (TS, Python, etc.) via turbo").action(async () => {
|
|
299
305
|
const turboFailed = await runTurboLint(projectRoot);
|
|
300
|
-
const
|
|
301
|
-
if (turboFailed ||
|
|
306
|
+
const pythonFailed = await pythonStep("check");
|
|
307
|
+
if (turboFailed || pythonFailed) process.exit(1);
|
|
302
308
|
});
|
|
303
309
|
program.command("count").description("count lines of code").action(async () => {
|
|
304
310
|
await spawn("cloc", ["`git ls-files | grep -E '(html)|(s?css)|(md)|(json)|(yaml)|([jt]sx?)$'`"], {
|
package/lib/commands/e2e.mjs
CHANGED
|
@@ -53,21 +53,12 @@ async function getPresentAppNames(projectRoot) {
|
|
|
53
53
|
return [];
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
/** Discover app
|
|
56
|
+
/** Discover the app whose package.json names it the e2e app (`"mpo": { "e2e": true }`), for E2E test cwd. Returns app name (e.g. "one") or null. */
|
|
57
57
|
async function discoverE2EApp(projectRoot) {
|
|
58
|
-
const
|
|
59
|
-
for (const name of
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"playwright.config.ts",
|
|
63
|
-
"playwright.config.js",
|
|
64
|
-
"playwright.config.mjs"
|
|
65
|
-
]) try {
|
|
66
|
-
await fs.access(path.join(appPath, config));
|
|
67
|
-
return name;
|
|
68
|
-
} catch {}
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
58
|
+
const named = [];
|
|
59
|
+
for (const name of await getPresentAppNames(projectRoot)) if (JSON.parse(await fs.readFile(path.join(projectRoot, "apps", name, "package.json"), "utf8"))?.mpo?.e2e === true) named.push(name);
|
|
60
|
+
if (named.length > 1) throw new Error(`more than one app sets "mpo": { "e2e": true } in its package.json: ${named.join(", ")}. Keep it on the one app mpo test e2e should run and delete it from the others.`);
|
|
61
|
+
return named[0] ?? null;
|
|
71
62
|
}
|
|
72
63
|
async function detectServices(projectRoot) {
|
|
73
64
|
const services = [];
|
|
@@ -255,7 +246,7 @@ async function runE2ESession(projectRoot, options) {
|
|
|
255
246
|
if (options.upOnly) return;
|
|
256
247
|
const e2eApp = await discoverE2EApp(projectRoot);
|
|
257
248
|
if (!e2eApp) {
|
|
258
|
-
console.error("No E2E app found: no
|
|
249
|
+
console.error("No E2E app found: no apps/*/package.json sets \"mpo\": { \"e2e\": true }.");
|
|
259
250
|
await tearDown(projectRoot, sessionFilePath);
|
|
260
251
|
process.exit(1);
|
|
261
252
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import fsSync from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import spawn from "nano-spawn";
|
|
4
|
+
|
|
5
|
+
//#region src/commands/pythonTools.ts
|
|
6
|
+
const pinHint = "uv is pinned in .tool-versions; `make configure` installs it through mise or asdf";
|
|
7
|
+
function errorDetail(error) {
|
|
8
|
+
const e = error ?? {};
|
|
9
|
+
return {
|
|
10
|
+
code: e.cause?.code,
|
|
11
|
+
exitCode: e.exitCode,
|
|
12
|
+
signalName: e.signalName,
|
|
13
|
+
stderr: e.stderr?.trim() || void 0,
|
|
14
|
+
message: e.cause?.message ?? e.message ?? String(error)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Why `uv --version` did not answer, as one line for the lint output. */
|
|
18
|
+
function uvStartFailure(error) {
|
|
19
|
+
const d = errorDetail(error);
|
|
20
|
+
if (d.code === "ENOENT") return `uv is not on PATH. ${pinHint}.`;
|
|
21
|
+
return `uv did not start: ${d.stderr ?? d.message}. ${pinHint}.`;
|
|
22
|
+
}
|
|
23
|
+
/** Why a tool failed once uv had started it, as one line for the lint output. */
|
|
24
|
+
function toolFailure(tool, error) {
|
|
25
|
+
const d = errorDetail(error);
|
|
26
|
+
if (d.signalName) return `${tool} was killed by ${d.signalName}.`;
|
|
27
|
+
if (d.exitCode === 1 && tool === "black --check") return "black --check found files to reformat (listed above).";
|
|
28
|
+
if (d.exitCode === 1 && tool === "basedpyright") return "basedpyright found errors .basedpyright/baseline.json does not hold (listed above).";
|
|
29
|
+
if (d.exitCode !== void 0) return `${tool} exited ${d.exitCode}, a configuration or usage error (see above).`;
|
|
30
|
+
return `${tool} failed: ${d.message}.`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The Python files git knows under `cwd`, tracked or untracked and not
|
|
34
|
+
* ignored, that are still on disk: the set CI's frappe/lint job checks.
|
|
35
|
+
*/
|
|
36
|
+
async function pythonFiles(cwd, spawn$1 = spawn) {
|
|
37
|
+
const { stdout } = await spawn$1("git", [
|
|
38
|
+
"ls-files",
|
|
39
|
+
"-z",
|
|
40
|
+
"--cached",
|
|
41
|
+
"--others",
|
|
42
|
+
"--exclude-standard",
|
|
43
|
+
"--",
|
|
44
|
+
"*.py",
|
|
45
|
+
"*.pyi"
|
|
46
|
+
], { cwd });
|
|
47
|
+
return [...new Set(stdout.split("\0").filter(Boolean))].filter((file) => fsSync.existsSync(path.join(cwd, file)));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Run black, or black --check then basedpyright, on `files` through the uv
|
|
51
|
+
* project at `cwd`, first proving uv starts and the lock is there, so a missing
|
|
52
|
+
* install or project is reported as that instead of as a lint failure. Returns
|
|
53
|
+
* the reasons it failed, one per line, or undefined when it passed.
|
|
54
|
+
*/
|
|
55
|
+
async function runPythonTools(mode, files, cwd, spawn$2 = spawn) {
|
|
56
|
+
try {
|
|
57
|
+
await spawn$2("uv", ["--version"], { cwd });
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return uvStartFailure(error);
|
|
60
|
+
}
|
|
61
|
+
if (!fsSync.existsSync(path.join(cwd, "uv.lock"))) return "No uv.lock at the project root pins black and basedpyright; `mpo update` brings it and pyproject.toml.";
|
|
62
|
+
const steps = mode === "format" ? [["black", ["black"]]] : [["black --check", ["black", "--check"]], ["basedpyright", ["basedpyright"]]];
|
|
63
|
+
const reasons = [];
|
|
64
|
+
for (const [tool, args] of steps) try {
|
|
65
|
+
await spawn$2("uv", [
|
|
66
|
+
"run",
|
|
67
|
+
"--locked",
|
|
68
|
+
...args,
|
|
69
|
+
...files
|
|
70
|
+
], {
|
|
71
|
+
stdio: "inherit",
|
|
72
|
+
cwd
|
|
73
|
+
});
|
|
74
|
+
} catch (error) {
|
|
75
|
+
reasons.push(toolFailure(tool, error));
|
|
76
|
+
}
|
|
77
|
+
return reasons.length > 0 ? reasons.join("\n") : void 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { pythonFiles, runPythonTools, toolFailure, uvStartFailure };
|
|
@@ -25,9 +25,9 @@ function reportKept(stdout) {
|
|
|
25
25
|
for (const path of kept) console.log(` ${path}`);
|
|
26
26
|
}
|
|
27
27
|
/** Run scaffold.sh and return the provenance it wrote. */
|
|
28
|
-
async function runScaffold(request) {
|
|
28
|
+
async function runScaffold(request, script = scaffoldScript()) {
|
|
29
29
|
await checkSourceAccess(request.source);
|
|
30
|
-
const args = [
|
|
30
|
+
const args = [script];
|
|
31
31
|
for (const app of request.apps) args.push("--app", app);
|
|
32
32
|
for (const service of request.services) args.push("--service", service);
|
|
33
33
|
if (request.mpoVersion) args.push("--mpo-version", request.mpoVersion);
|
|
@@ -50,6 +50,62 @@ async function runScaffold(request) {
|
|
|
50
50
|
if (!provenance?.source) throw new ScaffoldError(`scaffold.sh wrote no provenance into ${request.target}`, request);
|
|
51
51
|
return provenance;
|
|
52
52
|
}
|
|
53
|
+
/** Where the monorepo keeps its scaffold, at every commit since MPO-310. */
|
|
54
|
+
const scaffoldPath = "public/cli/scripts/scaffold.sh";
|
|
55
|
+
/**
|
|
56
|
+
* Write the scaffold.sh that `source` carries at `ref` to `file`; false when
|
|
57
|
+
* that commit carries none. A merge baseline made with it is what that
|
|
58
|
+
* commit's own CLI scaffolded, so whatever the scaffold learned between two
|
|
59
|
+
* commits (a cleanup of root wiring, say) is part of the difference between
|
|
60
|
+
* their baselines and reaches the project, with no step of it named here. A
|
|
61
|
+
* url is fetched shallow and blobless, then the one blob, as scaffold.sh does.
|
|
62
|
+
*/
|
|
63
|
+
async function scaffoldScriptAt(source, ref, file) {
|
|
64
|
+
await checkSourceAccess(source);
|
|
65
|
+
const script = [
|
|
66
|
+
"set -eu",
|
|
67
|
+
"SOURCE=\"$1\"; REF=\"$2\"; SCRIPT=\"$3\"; OUT=\"$4\"",
|
|
68
|
+
"if [ -d \"$SOURCE\" ]; then",
|
|
69
|
+
" REPO=\"$SOURCE\"",
|
|
70
|
+
" COMMIT=\"$(git -C \"$REPO\" rev-parse --verify --quiet \"$REF^{commit}\")\" ||",
|
|
71
|
+
" { printf \"%s is not a commit in %s\\n\" \"$REF\" \"$REPO\" >&2; exit 1; }",
|
|
72
|
+
"else",
|
|
73
|
+
" REPO=\"$(mktemp -d \"${TMPDIR:-/tmp}/mpo-scaffold-script.XXXXXX\")\"",
|
|
74
|
+
" trap 'rm -rf \"$REPO\"' EXIT",
|
|
75
|
+
" git init -q \"$REPO\"",
|
|
76
|
+
" git -C \"$REPO\" remote add origin \"$SOURCE\"",
|
|
77
|
+
" git -C \"$REPO\" fetch -q --depth 1 --filter=blob:none origin \"$REF\"",
|
|
78
|
+
" COMMIT=\"$(git -C \"$REPO\" rev-parse --verify --quiet \"FETCH_HEAD^{commit}\")\"",
|
|
79
|
+
"fi",
|
|
80
|
+
"BLOB=\"$(git -C \"$REPO\" ls-tree \"$COMMIT\" -- \"$SCRIPT\" | awk '$2 == \"blob\" { print $3 }')\"",
|
|
81
|
+
"[ -n \"$BLOB\" ] || exit 3",
|
|
82
|
+
"if [ \"$(git -C \"$REPO\" config --get remote.origin.promisor || true)\" = true ]; then",
|
|
83
|
+
" printf \"%s\\n\" \"$BLOB\" | git -C \"$REPO\" -c fetch.negotiationAlgorithm=noop fetch -q \\",
|
|
84
|
+
" --no-tags --no-write-fetch-head --filter=blob:none --stdin origin",
|
|
85
|
+
"fi",
|
|
86
|
+
"git -C \"$REPO\" cat-file blob \"$BLOB\" >\"$OUT\""
|
|
87
|
+
].join("\n");
|
|
88
|
+
try {
|
|
89
|
+
await spawn("sh", [
|
|
90
|
+
"-c",
|
|
91
|
+
script,
|
|
92
|
+
"sh",
|
|
93
|
+
source,
|
|
94
|
+
ref,
|
|
95
|
+
scaffoldPath,
|
|
96
|
+
file
|
|
97
|
+
], { stdio: [
|
|
98
|
+
"ignore",
|
|
99
|
+
"ignore",
|
|
100
|
+
"pipe"
|
|
101
|
+
] });
|
|
102
|
+
return true;
|
|
103
|
+
} catch (err) {
|
|
104
|
+
if (err.exitCode === 3) return false;
|
|
105
|
+
const detail = (err.stderr ?? "").trim().split("\n").filter(Boolean).pop() ?? err.message;
|
|
106
|
+
throw new Error(`could not read ${scaffoldPath} at ${ref} from ${source}: ${detail}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
53
109
|
/** A scaffold in a temp dir (merge baselines). */
|
|
54
110
|
async function scaffoldToTemp(request) {
|
|
55
111
|
const parent = mkdtempSync(join(tmpdir(), "mpo-scaffold-"));
|
|
@@ -59,12 +115,15 @@ async function scaffoldToTemp(request) {
|
|
|
59
115
|
force: true
|
|
60
116
|
});
|
|
61
117
|
try {
|
|
118
|
+
const script = join(parent, "scaffold.sh");
|
|
119
|
+
const carried = await scaffoldScriptAt(request.source, request.ref, script);
|
|
120
|
+
if (!carried) console.warn(`⚠️ ${request.ref} carries no ${scaffoldPath}; using this CLI's for that side`);
|
|
62
121
|
return {
|
|
63
122
|
dir,
|
|
64
123
|
provenance: await runScaffold({
|
|
65
124
|
...request,
|
|
66
125
|
target: dir
|
|
67
|
-
}),
|
|
126
|
+
}, carried ? script : void 0),
|
|
68
127
|
cleanup
|
|
69
128
|
};
|
|
70
129
|
} catch (err) {
|
package/lib/commands/verbs.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { discoverE2EApp } from "./e2e.mjs";
|
|
2
1
|
import fsSync from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import fs from "node:fs/promises";
|
|
@@ -64,6 +63,29 @@ async function getTurboExcludeFiltersForMissing(root) {
|
|
|
64
63
|
}
|
|
65
64
|
return filters;
|
|
66
65
|
}
|
|
66
|
+
function frappeEntryName(entry) {
|
|
67
|
+
if (typeof entry === "string") return {
|
|
68
|
+
src: entry,
|
|
69
|
+
name: path.basename(entry)
|
|
70
|
+
};
|
|
71
|
+
if (!entry.source || !entry.name) return void 0;
|
|
72
|
+
return {
|
|
73
|
+
src: entry.source,
|
|
74
|
+
name: entry.name
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function resolveFrappeApp(frappeDir, entry) {
|
|
78
|
+
const named = frappeEntryName(entry);
|
|
79
|
+
if (!named) return void 0;
|
|
80
|
+
const src = named.src.startsWith("file://") ? named.src.slice(7) : named.src;
|
|
81
|
+
if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) return void 0;
|
|
82
|
+
const absolutePath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
|
|
83
|
+
if (!fsSync.existsSync(absolutePath)) return void 0;
|
|
84
|
+
return {
|
|
85
|
+
name: named.name,
|
|
86
|
+
absolutePath
|
|
87
|
+
};
|
|
88
|
+
}
|
|
67
89
|
/** Discover frappe apps from frappe.yaml that have local source paths.
|
|
68
90
|
* Supports both string entries (`- ./apps/core`) and object entries (`- name: core\n source: ./apps/core`). */
|
|
69
91
|
async function getFrappeApps(root) {
|
|
@@ -71,29 +93,7 @@ async function getFrappeApps(root) {
|
|
|
71
93
|
const frappeYamlPath = path.join(frappeDir, "frappe.yaml");
|
|
72
94
|
if (!fsSync.existsSync(frappeYamlPath)) return [];
|
|
73
95
|
const raw = await fs.readFile(frappeYamlPath, "utf8");
|
|
74
|
-
|
|
75
|
-
const out = [];
|
|
76
|
-
for (const app of config?.apps ?? []) {
|
|
77
|
-
let src;
|
|
78
|
-
let name;
|
|
79
|
-
if (typeof app === "string") {
|
|
80
|
-
src = app;
|
|
81
|
-
name = path.basename(app);
|
|
82
|
-
} else {
|
|
83
|
-
if (!app.source || !app.name) continue;
|
|
84
|
-
src = app.source;
|
|
85
|
-
name = app.name;
|
|
86
|
-
}
|
|
87
|
-
src = src.startsWith("file://") ? src.slice(7) : src;
|
|
88
|
-
if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) continue;
|
|
89
|
-
const absPath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
|
|
90
|
-
if (!fsSync.existsSync(absPath)) continue;
|
|
91
|
-
out.push({
|
|
92
|
-
name,
|
|
93
|
-
absolutePath: absPath
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return out;
|
|
96
|
+
return (YAML.parse(raw)?.apps ?? []).map((entry) => resolveFrappeApp(frappeDir, entry)).filter((app) => app !== void 0);
|
|
97
97
|
}
|
|
98
98
|
const testTiers = [
|
|
99
99
|
"unit",
|
|
@@ -110,13 +110,15 @@ function parseTestTiers(args) {
|
|
|
110
110
|
/**
|
|
111
111
|
* `bench run-tests` for every frappe app with a pyproject.toml, limited to the
|
|
112
112
|
* pytest marker expression. Skipped when the bench is not bootstrapped
|
|
113
|
-
* (no apps/frappe/sites)
|
|
113
|
+
* (no apps/frappe/sites), or failed when `required`; once it is, any app
|
|
114
|
+
* whose run fails fails the tier.
|
|
114
115
|
*/
|
|
115
|
-
async function runBenchTests(projectRoot, marker, spawn) {
|
|
116
|
+
async function runBenchTests(projectRoot, marker, spawn, required) {
|
|
116
117
|
const benchDir = path.join(projectRoot, "apps", "frappe");
|
|
117
118
|
const apps = (await getFrappeApps(projectRoot)).filter((app) => fsSync.existsSync(path.join(app.absolutePath, "pyproject.toml")));
|
|
118
119
|
if (!apps.length) return;
|
|
119
120
|
if (!fsSync.existsSync(path.join(benchDir, "sites"))) {
|
|
121
|
+
if (required) throw new Error(`no frappe bench (apps/frappe/sites): bench tests -m "${marker}" need one`);
|
|
120
122
|
console.warn(`no frappe bench (apps/frappe/sites): skipped bench tests -m "${marker}"`);
|
|
121
123
|
return;
|
|
122
124
|
}
|
|
@@ -139,25 +141,45 @@ async function runBenchTests(projectRoot, marker, spawn) {
|
|
|
139
141
|
}
|
|
140
142
|
if (failed.length) throw new Error(`bench tests -m "${marker}" failed: ${failed.join(", ")}`);
|
|
141
143
|
}
|
|
142
|
-
/** The unit tier: turbo test minus missing services
|
|
144
|
+
/** The unit tier: turbo test minus missing services, then the bench's non-integration tests. */
|
|
143
145
|
async function runUnitTests(projectRoot, spawn$1 = spawn) {
|
|
144
|
-
const excludeFilters = await getTurboExcludeFiltersForMissing(projectRoot);
|
|
145
|
-
const e2eApp = await discoverE2EApp(projectRoot);
|
|
146
146
|
await spawn$1("pnpm", [
|
|
147
147
|
"turbo",
|
|
148
148
|
"run",
|
|
149
149
|
"test",
|
|
150
|
-
...
|
|
150
|
+
...(await getTurboExcludeFiltersForMissing(projectRoot)).flatMap((f) => ["--filter", f])
|
|
151
151
|
], {
|
|
152
152
|
stdio: "inherit",
|
|
153
153
|
shell: true,
|
|
154
154
|
cwd: projectRoot
|
|
155
155
|
});
|
|
156
|
-
await runBenchTests(projectRoot, "not integration", spawn$1);
|
|
156
|
+
await runBenchTests(projectRoot, "not integration", spawn$1, false);
|
|
157
157
|
}
|
|
158
|
-
/** The integration tier: the bench's integration-marked tests
|
|
158
|
+
/** The integration tier: turbo test:integration, then the bench's integration-marked tests; a missing service fails it. */
|
|
159
159
|
async function runIntegrationTests(projectRoot, spawn$2 = spawn) {
|
|
160
|
-
await
|
|
160
|
+
const filters = (await getTurboExcludeFiltersForMissing(projectRoot)).flatMap((f) => ["--filter", f]);
|
|
161
|
+
const failures = [];
|
|
162
|
+
try {
|
|
163
|
+
await spawn$2("pnpm", [
|
|
164
|
+
"turbo",
|
|
165
|
+
"run",
|
|
166
|
+
"test:integration",
|
|
167
|
+
"--continue",
|
|
168
|
+
...filters
|
|
169
|
+
], {
|
|
170
|
+
stdio: "inherit",
|
|
171
|
+
shell: true,
|
|
172
|
+
cwd: projectRoot
|
|
173
|
+
});
|
|
174
|
+
} catch (error) {
|
|
175
|
+
failures.push(error.message);
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
await runBenchTests(projectRoot, "integration", spawn$2, true);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
failures.push(error.message);
|
|
181
|
+
}
|
|
182
|
+
if (failures.length) throw new Error(failures.join("\n"));
|
|
161
183
|
}
|
|
162
184
|
/** `mpo build`: the packages, then every present app with a build script, each once. */
|
|
163
185
|
async function runBuild(args, projectRoot, spawn$3 = spawn) {
|
package/lib/source.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "multiplatform.one cli — mpo init clones and prunes the monorepo, mpo update merges it back",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"create-multiplatform-app",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@multiplatform.one/utils": "^8.
|
|
60
|
+
"@multiplatform.one/utils": "^8.2.0",
|
|
61
61
|
"commander": "^15.0.0",
|
|
62
62
|
"dotenv": "^17.4.2",
|
|
63
63
|
"inquirer": "^14.2.3",
|
package/scripts/scaffold.sh
CHANGED
|
@@ -345,6 +345,18 @@ fi
|
|
|
345
345
|
for _app in $APPS; do
|
|
346
346
|
[ ! -e "$TREE/apps/$_app" ] || die "apps/$_app already exists in the source tree; pick another product name"
|
|
347
347
|
cp -R "$TREE/apps/one" "$TREE/apps/$_app"
|
|
348
|
+
if [ "$_app" != "$FIRST_APP" ]; then
|
|
349
|
+
node - "$TREE/apps/$_app/package.json" <<'NODE'
|
|
350
|
+
const fs = require("node:fs");
|
|
351
|
+
const [file] = process.argv.slice(2);
|
|
352
|
+
const text = fs
|
|
353
|
+
.readFileSync(file, "utf8")
|
|
354
|
+
.replace(/,\n {2}"mpo": \{\n {4}"e2e": true\n {2}\}(?=\n\}\n?$)/, "")
|
|
355
|
+
.replace(/\n {2}"mpo": \{\n {4}"e2e": true\n {2}\},/, "");
|
|
356
|
+
if (JSON.parse(text).mpo?.e2e) throw new Error(`${file}: could not drop "mpo": { "e2e": true }`);
|
|
357
|
+
fs.writeFileSync(file, text);
|
|
358
|
+
NODE
|
|
359
|
+
fi
|
|
348
360
|
# A feature module of that name already satisfies the app/features twin
|
|
349
361
|
# (features/pokemon is the One app's own pokemon feature). The index
|
|
350
362
|
# routes import features/<app>/screen, so a module without one gets
|
|
@@ -19,7 +19,7 @@ import { generateDoctypeTypes, typesDrift } from "../commands/doctypeTypes";
|
|
|
19
19
|
import { runE2ESession } from "../commands/e2e";
|
|
20
20
|
import { SINGLETON_APPS, init } from "../commands/init";
|
|
21
21
|
import { INIT_APP_PIECES } from "../commands/pieces";
|
|
22
|
-
import {
|
|
22
|
+
import { type PythonMode, pythonFiles, runPythonTools } from "../commands/pythonTools";
|
|
23
23
|
import { updateApp } from "../commands/updateApp";
|
|
24
24
|
import {
|
|
25
25
|
availableServices,
|
|
@@ -422,13 +422,13 @@ program
|
|
|
422
422
|
.action(async (args: string[], options) => {
|
|
423
423
|
const parsed = parseTestTiers(args);
|
|
424
424
|
|
|
425
|
-
// Handle unit tests (turbo test with dynamic excludes: missing services
|
|
425
|
+
// Handle unit tests (turbo test with dynamic excludes: missing services, plus frappe app unit tests)
|
|
426
426
|
if (parsed.includes("unit")) {
|
|
427
427
|
await runUnitTests(projectRoot);
|
|
428
428
|
if (parsed.length === 1) return;
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
-
// Handle integration tests (frappe app integration tests)
|
|
431
|
+
// Handle integration tests (turbo test:integration plus frappe app integration tests)
|
|
432
432
|
if (parsed.includes("integration")) {
|
|
433
433
|
await runIntegrationTests(projectRoot);
|
|
434
434
|
if (parsed.length === 1) return;
|
|
@@ -490,15 +490,21 @@ program
|
|
|
490
490
|
});
|
|
491
491
|
|
|
492
492
|
/**
|
|
493
|
-
* Run
|
|
494
|
-
* Returns true if the
|
|
493
|
+
* Run black, or black --check and basedpyright, on the project's Python files (if any).
|
|
494
|
+
* Returns true if the Python step failed.
|
|
495
495
|
*/
|
|
496
|
-
async function
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
496
|
+
async function pythonStep(mode: PythonMode): Promise<boolean> {
|
|
497
|
+
let files: string[];
|
|
498
|
+
try {
|
|
499
|
+
files = await pythonFiles(projectRoot);
|
|
500
|
+
} catch (error) {
|
|
501
|
+
console.error(`git ls-files could not list the Python files: ${(error as Error).message}`);
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
if (files.length === 0) return false;
|
|
505
|
+
const label = mode === "format" ? "black" : "black --check, basedpyright";
|
|
500
506
|
console.log(`\n── ${label} (Python) ──`);
|
|
501
|
-
const reason = await
|
|
507
|
+
const reason = await runPythonTools(mode, files, projectRoot);
|
|
502
508
|
if (reason === undefined) return false;
|
|
503
509
|
console.error(reason);
|
|
504
510
|
return true;
|
|
@@ -512,7 +518,7 @@ program
|
|
|
512
518
|
stdio: "inherit",
|
|
513
519
|
cwd: projectRoot,
|
|
514
520
|
});
|
|
515
|
-
await
|
|
521
|
+
await pythonStep("format");
|
|
516
522
|
});
|
|
517
523
|
|
|
518
524
|
program
|
|
@@ -520,8 +526,8 @@ program
|
|
|
520
526
|
.description("lint all supported files (TS, Python, etc.) via turbo")
|
|
521
527
|
.action(async () => {
|
|
522
528
|
const turboFailed = await runTurboLint(projectRoot);
|
|
523
|
-
const
|
|
524
|
-
if (turboFailed ||
|
|
529
|
+
const pythonFailed = await pythonStep("check");
|
|
530
|
+
if (turboFailed || pythonFailed) process.exit(1);
|
|
525
531
|
});
|
|
526
532
|
|
|
527
533
|
program
|
package/src/commands/e2e.ts
CHANGED
|
@@ -64,25 +64,22 @@ async function getPresentAppNames(projectRoot: string): Promise<string[]> {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/** Discover app
|
|
67
|
+
/** Discover the app whose package.json names it the e2e app (`"mpo": { "e2e": true }`), for E2E test cwd. Returns app name (e.g. "one") or null. */
|
|
68
68
|
export async function discoverE2EApp(projectRoot: string): Promise<string | null> {
|
|
69
|
-
const
|
|
70
|
-
for (const name of
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// continue
|
|
82
|
-
}
|
|
83
|
-
}
|
|
69
|
+
const named: string[] = [];
|
|
70
|
+
for (const name of await getPresentAppNames(projectRoot)) {
|
|
71
|
+
const pkg = JSON.parse(
|
|
72
|
+
await fs.readFile(path.join(projectRoot, "apps", name, "package.json"), "utf8"),
|
|
73
|
+
);
|
|
74
|
+
if (pkg?.mpo?.e2e === true) named.push(name);
|
|
75
|
+
}
|
|
76
|
+
if (named.length > 1) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`more than one app sets "mpo": { "e2e": true } in its package.json: ${named.join(", ")}. ` +
|
|
79
|
+
"Keep it on the one app mpo test e2e should run and delete it from the others.",
|
|
80
|
+
);
|
|
84
81
|
}
|
|
85
|
-
return null;
|
|
82
|
+
return named[0] ?? null;
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
export async function detectServices(projectRoot: string): Promise<string[]> {
|
|
@@ -319,12 +316,10 @@ export async function runE2ESession(projectRoot: string, options: E2EOptions): P
|
|
|
319
316
|
return;
|
|
320
317
|
}
|
|
321
318
|
|
|
322
|
-
// Run Playwright tests (discover app
|
|
319
|
+
// Run Playwright tests (discover the app its package.json names)
|
|
323
320
|
const e2eApp = await discoverE2EApp(projectRoot);
|
|
324
321
|
if (!e2eApp) {
|
|
325
|
-
console.error(
|
|
326
|
-
"No E2E app found: no app under apps/ has playwright.config.ts or playwright.config.js.",
|
|
327
|
-
);
|
|
322
|
+
console.error('No E2E app found: no apps/*/package.json sets "mpo": { "e2e": true }.');
|
|
328
323
|
await tearDown(projectRoot, sessionFilePath);
|
|
329
324
|
process.exit(1);
|
|
330
325
|
}
|