@babylonjsmarket/cli 1.0.2

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,43 @@
1
+ /**
2
+ * Pure classifiers for the inject engine.
3
+ *
4
+ * `detectTarget` decides whether a seed of project files belongs in
5
+ * `@babylonjsmarket/arcade-pro` (per-component, registered) or
6
+ * `@babylonjsmarket/viz-pro` (flat per-layer barrels).
7
+ *
8
+ * `detectLayer` decides which viz-pro layer (`core`, `solid`, `ecs`) owns a
9
+ * single source file. Order matters: rules are evaluated top-down and the
10
+ * first match wins. The order mirrors the plan.
11
+ */
12
+ type Target = "arcade-pro" | "viz-pro";
13
+ type VizLayer = "core" | "solid" | "ecs";
14
+ interface SeedFile {
15
+ path: string;
16
+ source: string;
17
+ }
18
+ /**
19
+ * Classify a closure of seed files to one of the two pro packages. Any single
20
+ * file extending a viz-pro System class or importing from `@babylonjsmarket/viz-pro`
21
+ * tips the whole seed to `viz-pro`.
22
+ */
23
+ declare function detectTarget(seedFiles: SeedFile[]): Target;
24
+ /**
25
+ * Classify a single source file to a viz-pro layer.
26
+ *
27
+ * Order is load-bearing:
28
+ * 1. *.test.ts(x) → route alongside the subject file (re-detect on the
29
+ * subject's source if known, else default 'core').
30
+ * 2. *.tsx that imports from 'solid-js' → 'solid'.
31
+ * 3. extends (PanelDebuggerSystem|StateStepperSystem|System) or filename
32
+ * ends in 'System.ts' → 'ecs'.
33
+ * 4. extends Component and no Solid import → 'ecs'.
34
+ * 5. contains `definePanel(` and no Solid import → 'core'.
35
+ * 6. fallback → 'core'.
36
+ *
37
+ * `subjectLayer` lets the caller pin a test file to its subject's layer; pass
38
+ * `undefined` when the subject isn't co-injected, which falls through to
39
+ * rule (1)'s default.
40
+ */
41
+ declare function detectLayer(filePath: string, source: string, subjectLayer?: VizLayer): VizLayer;
42
+
43
+ export { type SeedFile, type Target, type VizLayer, detectLayer, detectTarget };
@@ -0,0 +1,26 @@
1
+ // src/lib/inject/detect-target.ts
2
+ function detectTarget(seedFiles) {
3
+ for (const { source } of seedFiles) {
4
+ if (/from\s+['"]@babylonjsmarket\/viz-pro['"]/.test(source)) return "viz-pro";
5
+ if (/extends\s+(PanelDebuggerSystem|StateStepperSystem)\b/.test(source)) return "viz-pro";
6
+ }
7
+ return "arcade-pro";
8
+ }
9
+ function detectLayer(filePath, source, subjectLayer) {
10
+ const base = filePath.split(/[\\/]/).pop() ?? filePath;
11
+ if (/\.test\.tsx?$/.test(base)) {
12
+ return subjectLayer ?? "core";
13
+ }
14
+ const hasSolidImport = /from\s+['"]solid-js['"]/.test(source);
15
+ if (/\.tsx$/.test(base) && hasSolidImport) return "solid";
16
+ if (/extends\s+(PanelDebuggerSystem|StateStepperSystem|System)\b/.test(source)) return "ecs";
17
+ if (/System\.ts$/.test(base)) return "ecs";
18
+ if (/extends\s+Component\b/.test(source) && !hasSolidImport) return "ecs";
19
+ if (/\bdefinePanel\s*\(/.test(source) && !hasSolidImport) return "core";
20
+ return "core";
21
+ }
22
+ export {
23
+ detectLayer,
24
+ detectTarget
25
+ };
26
+ //# sourceMappingURL=detect-target.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/inject/detect-target.ts"],"sourcesContent":["/**\n * Pure classifiers for the inject engine.\n *\n * `detectTarget` decides whether a seed of project files belongs in\n * `@babylonjsmarket/arcade-pro` (per-component, registered) or\n * `@babylonjsmarket/viz-pro` (flat per-layer barrels).\n *\n * `detectLayer` decides which viz-pro layer (`core`, `solid`, `ecs`) owns a\n * single source file. Order matters: rules are evaluated top-down and the\n * first match wins. The order mirrors the plan.\n */\n\nexport type Target = \"arcade-pro\" | \"viz-pro\";\nexport type VizLayer = \"core\" | \"solid\" | \"ecs\";\n\nexport interface SeedFile {\n path: string;\n source: string;\n}\n\n/**\n * Classify a closure of seed files to one of the two pro packages. Any single\n * file extending a viz-pro System class or importing from `@babylonjsmarket/viz-pro`\n * tips the whole seed to `viz-pro`.\n */\nexport function detectTarget(seedFiles: SeedFile[]): Target {\n for (const { source } of seedFiles) {\n if (/from\\s+['\"]@babylonjsmarket\\/viz-pro['\"]/.test(source)) return \"viz-pro\";\n if (/extends\\s+(PanelDebuggerSystem|StateStepperSystem)\\b/.test(source)) return \"viz-pro\";\n }\n return \"arcade-pro\";\n}\n\n/**\n * Classify a single source file to a viz-pro layer.\n *\n * Order is load-bearing:\n * 1. *.test.ts(x) → route alongside the subject file (re-detect on the\n * subject's source if known, else default 'core').\n * 2. *.tsx that imports from 'solid-js' → 'solid'.\n * 3. extends (PanelDebuggerSystem|StateStepperSystem|System) or filename\n * ends in 'System.ts' → 'ecs'.\n * 4. extends Component and no Solid import → 'ecs'.\n * 5. contains `definePanel(` and no Solid import → 'core'.\n * 6. fallback → 'core'.\n *\n * `subjectLayer` lets the caller pin a test file to its subject's layer; pass\n * `undefined` when the subject isn't co-injected, which falls through to\n * rule (1)'s default.\n */\nexport function detectLayer(\n filePath: string,\n source: string,\n subjectLayer?: VizLayer,\n): VizLayer {\n const base = filePath.split(/[\\\\/]/).pop() ?? filePath;\n\n // (1) test files travel with their subject\n if (/\\.test\\.tsx?$/.test(base)) {\n return subjectLayer ?? \"core\";\n }\n\n const hasSolidImport = /from\\s+['\"]solid-js['\"]/.test(source);\n\n // (2) Solid .tsx\n if (/\\.tsx$/.test(base) && hasSolidImport) return \"solid\";\n\n // (3) System subclasses or *System.ts filenames\n if (/extends\\s+(PanelDebuggerSystem|StateStepperSystem|System)\\b/.test(source)) return \"ecs\";\n if (/System\\.ts$/.test(base)) return \"ecs\";\n\n // (4) Component subclasses (no Solid)\n if (/extends\\s+Component\\b/.test(source) && !hasSolidImport) return \"ecs\";\n\n // (5) definePanel files (no Solid)\n if (/\\bdefinePanel\\s*\\(/.test(source) && !hasSolidImport) return \"core\";\n\n // (6) fallback\n return \"core\";\n}\n"],"mappings":";AAyBO,SAAS,aAAa,WAA+B;AAC1D,aAAW,EAAE,OAAO,KAAK,WAAW;AAClC,QAAI,2CAA2C,KAAK,MAAM,EAAG,QAAO;AACpE,QAAI,uDAAuD,KAAK,MAAM,EAAG,QAAO;AAAA,EAClF;AACA,SAAO;AACT;AAmBO,SAAS,YACd,UACA,QACA,cACU;AACV,QAAM,OAAO,SAAS,MAAM,OAAO,EAAE,IAAI,KAAK;AAG9C,MAAI,gBAAgB,KAAK,IAAI,GAAG;AAC9B,WAAO,gBAAgB;AAAA,EACzB;AAEA,QAAM,iBAAiB,0BAA0B,KAAK,MAAM;AAG5D,MAAI,SAAS,KAAK,IAAI,KAAK,eAAgB,QAAO;AAGlD,MAAI,8DAA8D,KAAK,MAAM,EAAG,QAAO;AACvF,MAAI,cAAc,KAAK,IAAI,EAAG,QAAO;AAGrC,MAAI,wBAAwB,KAAK,MAAM,KAAK,CAAC,eAAgB,QAAO;AAGpE,MAAI,qBAAqB,KAAK,MAAM,KAAK,CAAC,eAAgB,QAAO;AAGjE,SAAO;AACT;","names":[]}
@@ -0,0 +1,41 @@
1
+ import { Target } from './detect-target.js';
2
+ export { SeedFile, VizLayer, detectLayer, detectTarget } from './detect-target.js';
3
+
4
+ interface InjectPatch {
5
+ /** Path of the file being patched, relative to the target package root. */
6
+ file: string;
7
+ kind: "registry-append" | "barrel-append";
8
+ /** The line that would be appended/inserted. */
9
+ line: string;
10
+ }
11
+ interface InjectFile {
12
+ /** Path relative to the target package root (e.g. `src/Components/Foo/Foo.ts`). */
13
+ path: string;
14
+ contents: string;
15
+ }
16
+ interface InjectCollectResult {
17
+ target: Target;
18
+ files: InjectFile[];
19
+ patches: InjectPatch[];
20
+ warnings: string[];
21
+ }
22
+ interface InjectOptions {
23
+ /**
24
+ * What the engine does with the resolved file list:
25
+ * - 'apply' → writes into the resolved packageRoot/vizProRoot (operator mode).
26
+ * - 'collect' → returns the file map + patch plan without touching disk
27
+ * (member mode; payload goes to the marketplace endpoint).
28
+ */
29
+ mode?: "apply" | "collect";
30
+ /** Tmpdir-friendly: the arcade-pro package root (the dir containing `src/registry.ts`). Apply mode only. */
31
+ packageRoot?: string;
32
+ /** Tmpdir-friendly: the viz-pro package root (the dir containing `src/{core,solid,ecs}/index.ts`). Apply mode only. */
33
+ vizProRoot?: string;
34
+ /** The project we're injecting FROM. Defaults to `cwd`. */
35
+ projectDir?: string;
36
+ /** Override for `process.cwd()`. Tests use this; the CLI entry passes `process.cwd()`. */
37
+ cwd?: string;
38
+ }
39
+ declare function inject(args: string[], opts?: InjectOptions): Promise<InjectCollectResult | void>;
40
+
41
+ export { type InjectCollectResult, type InjectFile, type InjectOptions, type InjectPatch, Target, inject };