@multiplatform.one/cli 7.90.2 → 7.90.4

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.
@@ -0,0 +1,262 @@
1
+ import fsSync from "node:fs";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import {
5
+ type WaitService,
6
+ waitForFrappe,
7
+ waitForKeycloak,
8
+ waitForMariaDB,
9
+ waitForPostgres,
10
+ } from "@multiplatform.one/utils/dev";
11
+ import nanoSpawn from "nano-spawn";
12
+ import YAML from "yaml";
13
+ import { discoverE2EApp } from "./e2e";
14
+
15
+ type Spawn = typeof nanoSpawn;
16
+
17
+ export const availableServices = ["frappe", "solana", "ethereum", "sui"];
18
+
19
+ /** Map a service name to its relative directory from the project root. */
20
+ function serviceDir(name: string): string {
21
+ return `apps/${name}`;
22
+ }
23
+
24
+ /** Apps that exist under apps/ and have package.json (discovered from filesystem). */
25
+ async function getPresentApps(root: string): Promise<string[]> {
26
+ const appsDir = path.join(root, "apps");
27
+ try {
28
+ const entries = await fs.readdir(appsDir, { withFileTypes: true });
29
+ const names: string[] = [];
30
+ for (const e of entries) {
31
+ if (!e.isDirectory()) continue;
32
+ const pkgPath = path.join(appsDir, e.name, "package.json");
33
+ try {
34
+ await fs.access(pkgPath);
35
+ names.push(e.name);
36
+ } catch {
37
+ // no package.json
38
+ }
39
+ }
40
+ return names;
41
+ } catch {
42
+ return [];
43
+ }
44
+ }
45
+
46
+ /** Root-level services that exist and have package.json (discovered from filesystem). */
47
+ async function getPresentServices(root: string): Promise<string[]> {
48
+ const names: string[] = [];
49
+ for (const name of availableServices) {
50
+ const dir = path.join(root, serviceDir(name));
51
+ const pkgPath = path.join(dir, "package.json");
52
+ try {
53
+ const stat = await fs.stat(dir);
54
+ if (!stat.isDirectory()) continue;
55
+ await fs.access(pkgPath);
56
+ names.push(name);
57
+ } catch {
58
+ // dir or package.json missing
59
+ }
60
+ }
61
+ return names;
62
+ }
63
+
64
+ /** Turbo --filter args to exclude root-level workspaces that are not present (so turbo only runs where they exist).
65
+ * Only generates exclude filters for directories that exist on disk (turbo errors on non-existent filter paths). */
66
+ async function getTurboExcludeFiltersForMissing(root: string): Promise<string[]> {
67
+ const present = await getPresentServices(root);
68
+ const filters: string[] = [];
69
+ for (const s of availableServices) {
70
+ if (present.includes(s)) continue;
71
+ const dir = serviceDir(s);
72
+ try {
73
+ const stat = await fs.stat(path.join(root, dir));
74
+ if (stat.isDirectory()) filters.push(`!./${dir}`);
75
+ } catch {
76
+ // directory doesn't exist; turbo won't find it, no filter needed
77
+ }
78
+ }
79
+ return filters;
80
+ }
81
+
82
+ /** Discover frappe apps from frappe.yaml that have local source paths.
83
+ * Supports both string entries (`- ./apps/core`) and object entries (`- name: core\n source: ./apps/core`). */
84
+ async function getFrappeApps(root: string): Promise<{ name: string; absolutePath: string }[]> {
85
+ const frappeDir = path.join(root, "apps", "frappe");
86
+ const frappeYamlPath = path.join(frappeDir, "frappe.yaml");
87
+ if (!fsSync.existsSync(frappeYamlPath)) return [];
88
+ const raw = await fs.readFile(frappeYamlPath, "utf8");
89
+ const config = YAML.parse(raw) as { apps?: (string | { name?: string; source?: string })[] };
90
+ const out: { name: string; absolutePath: string }[] = [];
91
+ for (const app of config?.apps ?? []) {
92
+ let src: string;
93
+ let name: string;
94
+ if (typeof app === "string") {
95
+ src = app;
96
+ name = path.basename(app);
97
+ } else {
98
+ if (!app.source || !app.name) continue;
99
+ src = app.source;
100
+ name = app.name;
101
+ }
102
+ src = src.startsWith("file://") ? src.slice(7) : src;
103
+ if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) continue;
104
+ const absPath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
105
+ if (!fsSync.existsSync(absPath)) continue;
106
+ out.push({ name, absolutePath: absPath });
107
+ }
108
+ return out;
109
+ }
110
+
111
+ export const testTiers = ["unit", "integration", "e2e", "visual"] as const;
112
+
113
+ export type TestTier = (typeof testTiers)[number];
114
+
115
+ /** The tiers `mpo test` was asked for (comma or space separated); unit when none is named. */
116
+ export function parseTestTiers(args: string[]): TestTier[] {
117
+ const parsed = args.flatMap((arg) => arg.split(",")).filter(Boolean);
118
+ for (const tier of parsed) {
119
+ if (!(testTiers as readonly string[]).includes(tier)) {
120
+ throw new Error(`unknown test tier ${tier} (${testTiers.join(", ")})`);
121
+ }
122
+ }
123
+ return parsed.length ? (parsed as TestTier[]) : ["unit"];
124
+ }
125
+
126
+ /**
127
+ * `bench run-tests` for every frappe app with a pyproject.toml, limited to the
128
+ * pytest marker expression. Skipped when the bench is not bootstrapped
129
+ * (no apps/frappe/sites); once it is, any app whose run fails fails the tier.
130
+ */
131
+ async function runBenchTests(projectRoot: string, marker: string, spawn: Spawn): Promise<void> {
132
+ const benchDir = path.join(projectRoot, "apps", "frappe");
133
+ const apps = (await getFrappeApps(projectRoot)).filter((app) =>
134
+ fsSync.existsSync(path.join(app.absolutePath, "pyproject.toml")),
135
+ );
136
+ if (!apps.length) return;
137
+ if (!fsSync.existsSync(path.join(benchDir, "sites"))) {
138
+ console.warn(`no frappe bench (apps/frappe/sites): skipped bench tests -m "${marker}"`);
139
+ return;
140
+ }
141
+ const failed: string[] = [];
142
+ for (const app of apps) {
143
+ try {
144
+ await spawn("bench", ["run-tests", "--app", app.name, "--", "-m", marker], {
145
+ stdio: "inherit",
146
+ cwd: benchDir,
147
+ });
148
+ } catch (error) {
149
+ console.error((error as Error).message);
150
+ failed.push(app.name);
151
+ }
152
+ }
153
+ if (failed.length) {
154
+ throw new Error(`bench tests -m "${marker}" failed: ${failed.join(", ")}`);
155
+ }
156
+ }
157
+
158
+ /** The unit tier: turbo test minus missing services and the e2e app, then the bench's non-integration tests. */
159
+ export async function runUnitTests(projectRoot: string, spawn: Spawn = nanoSpawn): Promise<void> {
160
+ const excludeFilters = await getTurboExcludeFiltersForMissing(projectRoot);
161
+ const e2eApp = await discoverE2EApp(projectRoot);
162
+ const filters = [
163
+ ...excludeFilters.flatMap((f) => ["--filter", f]),
164
+ ...(e2eApp ? ["--filter", `'!./apps/${e2eApp}'`] : []),
165
+ ];
166
+ await spawn("pnpm", ["turbo", "run", "test", ...filters], {
167
+ stdio: "inherit",
168
+ shell: true,
169
+ cwd: projectRoot,
170
+ });
171
+ await runBenchTests(projectRoot, "not integration", spawn);
172
+ }
173
+
174
+ /** The integration tier: the bench's integration-marked tests only; the JS suite belongs to unit. */
175
+ export async function runIntegrationTests(
176
+ projectRoot: string,
177
+ spawn: Spawn = nanoSpawn,
178
+ ): Promise<void> {
179
+ await runBenchTests(projectRoot, "integration", spawn);
180
+ }
181
+
182
+ /** `mpo build`: the packages, then every present app with a build script, each once. */
183
+ export async function runBuild(
184
+ args: string[],
185
+ projectRoot: string,
186
+ spawn: Spawn = nanoSpawn,
187
+ ): Promise<void> {
188
+ const parsed = args.flatMap((arg) => arg.split(","));
189
+ const packages = parsed.includes("packages");
190
+ const projects = parsed.filter((arg) => arg !== "packages");
191
+ const presentApps = await getPresentApps(projectRoot);
192
+ const presentServices = await getPresentServices(projectRoot);
193
+ if ((!projects.length && !packages) || packages) {
194
+ await spawn(
195
+ "pnpm",
196
+ [
197
+ "turbo",
198
+ "run",
199
+ "build",
200
+ "--filter",
201
+ "'!./apps/*'",
202
+ ...presentServices.flatMap((s) => ["--filter", `'!./${serviceDir(s)}'`]),
203
+ ],
204
+ {
205
+ stdio: "inherit",
206
+ shell: true,
207
+ cwd: projectRoot,
208
+ },
209
+ );
210
+ }
211
+ for (const platform of presentApps) {
212
+ if ((!projects.length && !packages) || projects.includes(platform)) {
213
+ const hasBuild = await fs
214
+ .access(path.join(projectRoot, "apps", platform, "package.json"))
215
+ .then(
216
+ () =>
217
+ JSON.parse(
218
+ fsSync.readFileSync(path.join(projectRoot, "apps", platform, "package.json"), "utf8"),
219
+ ).scripts?.build,
220
+ )
221
+ .catch(() => false);
222
+ if (hasBuild) {
223
+ await spawn("pnpm", ["turbo", "run", "build", `--filter=./apps/${platform}`], {
224
+ stdio: "inherit",
225
+ shell: true,
226
+ cwd: projectRoot,
227
+ });
228
+ }
229
+ }
230
+ }
231
+ }
232
+
233
+ /** `mpo lint`'s turbo half: the root `//#lint` task. Resolves true when it failed. */
234
+ export async function runTurboLint(
235
+ projectRoot: string,
236
+ spawn: Spawn = nanoSpawn,
237
+ ): Promise<boolean> {
238
+ try {
239
+ await spawn("turbo", ["run", "lint", "--filter=//"], { stdio: "inherit", cwd: projectRoot });
240
+ return false;
241
+ } catch {
242
+ return true;
243
+ }
244
+ }
245
+
246
+ /** `mpo frappe bench [args...]`: frappe.sh's bench command with the arguments passed through as given. */
247
+ export async function runFrappeBench(
248
+ args: string[],
249
+ frappeScript: string,
250
+ projectRoot: string,
251
+ spawn: Spawn = nanoSpawn,
252
+ ): Promise<void> {
253
+ await spawn("sh", [frappeScript, "bench", ...args], { stdio: "inherit", cwd: projectRoot });
254
+ }
255
+
256
+ /** The readiness probe behind each `mpo wait` service. */
257
+ export const waitFunctions: Record<WaitService, (interval: number) => Promise<void>> = {
258
+ frappe: waitForFrappe,
259
+ postgres: waitForPostgres,
260
+ mariadb: waitForMariaDB,
261
+ keycloak: waitForKeycloak,
262
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"multiplatformOne.d.ts","sourceRoot":"","sources":["../../src/bin/multiplatformOne.ts"],"names":[],"mappings":"AA8FA,gHAAgH;AAChH,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC"}
1
+ {"version":3,"file":"multiplatformOne.d.ts","sourceRoot":"","sources":["../../src/bin/multiplatformOne.ts"],"names":[],"mappings":"AAsCA,gHAAgH;AAChH,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type WaitService } from "@multiplatform.one/utils/dev";
2
+ import nanoSpawn from "nano-spawn";
3
+ type Spawn = typeof nanoSpawn;
4
+ export declare const availableServices: string[];
5
+ export declare const testTiers: readonly ["unit", "integration", "e2e", "visual"];
6
+ export type TestTier = (typeof testTiers)[number];
7
+ /** The tiers `mpo test` was asked for (comma or space separated); unit when none is named. */
8
+ export declare function parseTestTiers(args: string[]): TestTier[];
9
+ /** The unit tier: turbo test minus missing services and the e2e app, then the bench's non-integration tests. */
10
+ export declare function runUnitTests(projectRoot: string, spawn?: Spawn): Promise<void>;
11
+ /** The integration tier: the bench's integration-marked tests only; the JS suite belongs to unit. */
12
+ export declare function runIntegrationTests(projectRoot: string, spawn?: Spawn): Promise<void>;
13
+ /** `mpo build`: the packages, then every present app with a build script, each once. */
14
+ export declare function runBuild(args: string[], projectRoot: string, spawn?: Spawn): Promise<void>;
15
+ /** `mpo lint`'s turbo half: the root `//#lint` task. Resolves true when it failed. */
16
+ export declare function runTurboLint(projectRoot: string, spawn?: Spawn): Promise<boolean>;
17
+ /** `mpo frappe bench [args...]`: frappe.sh's bench command with the arguments passed through as given. */
18
+ export declare function runFrappeBench(args: string[], frappeScript: string, projectRoot: string, spawn?: Spawn): Promise<void>;
19
+ /** The readiness probe behind each `mpo wait` service. */
20
+ export declare const waitFunctions: Record<WaitService, (interval: number) => Promise<void>>;
21
+ export {};
22
+ //# sourceMappingURL=verbs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verbs.d.ts","sourceRoot":"","sources":["../../src/commands/verbs.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,K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 @@
1
- export { };
package/src/types.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * CLI type definitions placeholder.
3
- * Add CLI-specific types here as needed.
4
- */
5
- export {};
package/types/types.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * CLI type definitions placeholder.
3
- * Add CLI-specific types here as needed.
4
- */
5
- export {};
6
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,CAAC"}