@open-mercato/cli 0.4.2-canary-f80d1bfa83 → 0.4.2-canary-5035717565

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.
@@ -10,15 +10,6 @@ import {
10
10
  logGenerationResult,
11
11
  createGeneratorResult
12
12
  } from "../utils.js";
13
- function findModuleFile(basePath, ...segments) {
14
- const name = segments.pop();
15
- const dir = segments.length ? path.join(basePath, ...segments) : basePath;
16
- const tsPath = path.join(dir, `${name}.ts`);
17
- if (fs.existsSync(tsPath)) return tsPath;
18
- const jsPath = path.join(dir, `${name}.js`);
19
- if (fs.existsSync(jsPath)) return jsPath;
20
- return null;
21
- }
22
13
  async function generateModuleRegistry(options) {
23
14
  const { resolver, quiet = false } = options;
24
15
  const result = createGeneratorResult();
@@ -69,9 +60,9 @@ async function generateModuleRegistry(options) {
69
60
  const dashboardWidgets = [];
70
61
  const injectionWidgets = [];
71
62
  let injectionTableImportName = null;
72
- const appIndex = findModuleFile(roots.appBase, "index");
73
- const pkgIndex = findModuleFile(roots.pkgBase, "index");
74
- const indexTs = appIndex ?? pkgIndex;
63
+ const appIndex = path.join(roots.appBase, "index.ts");
64
+ const pkgIndex = path.join(roots.pkgBase, "index.ts");
65
+ const indexTs = fs.existsSync(appIndex) ? appIndex : fs.existsSync(pkgIndex) ? pkgIndex : null;
75
66
  if (indexTs) {
76
67
  infoImportName = `I${importId++}_${toVar(modId)}`;
77
68
  const importPath = indexTs.startsWith(roots.appBase) ? `${appImportBase}/index` : `${imps.pkgBase}/index`;
@@ -170,10 +161,10 @@ async function generateModuleRegistry(options) {
170
161
  }
171
162
  }
172
163
  {
173
- const appFile = findModuleFile(roots.appBase, "data", "extensions");
174
- const pkgFile = findModuleFile(roots.pkgBase, "data", "extensions");
175
- const hasApp = !!appFile;
176
- const hasPkg = !!pkgFile;
164
+ const appFile = path.join(roots.appBase, "data", "extensions.ts");
165
+ const pkgFile = path.join(roots.pkgBase, "data", "extensions.ts");
166
+ const hasApp = fs.existsSync(appFile);
167
+ const hasPkg = fs.existsSync(pkgFile);
177
168
  if (hasApp || hasPkg) {
178
169
  const importName = `X_${toVar(modId)}_${importId++}`;
179
170
  const importPath = hasApp ? `${appImportBase}/data/extensions` : `${imps.pkgBase}/data/extensions`;
@@ -182,22 +173,22 @@ async function generateModuleRegistry(options) {
182
173
  }
183
174
  }
184
175
  {
185
- const rootApp = findModuleFile(roots.appBase, "acl");
186
- const rootPkg = findModuleFile(roots.pkgBase, "acl");
187
- const hasRoot = rootApp || rootPkg;
176
+ const rootApp = path.join(roots.appBase, "acl.ts");
177
+ const rootPkg = path.join(roots.pkgBase, "acl.ts");
178
+ const hasRoot = fs.existsSync(rootApp) || fs.existsSync(rootPkg);
188
179
  if (hasRoot) {
189
180
  const importName = `ACL_${toVar(modId)}_${importId++}`;
190
- const useApp = rootApp ?? rootPkg;
181
+ const useApp = fs.existsSync(rootApp) ? rootApp : rootPkg;
191
182
  const importPath = useApp.startsWith(roots.appBase) ? `${appImportBase}/acl` : `${imps.pkgBase}/acl`;
192
183
  imports.push(`import * as ${importName} from '${importPath}'`);
193
184
  featuresImportName = importName;
194
185
  }
195
186
  }
196
187
  {
197
- const appFile = findModuleFile(roots.appBase, "ce");
198
- const pkgFile = findModuleFile(roots.pkgBase, "ce");
199
- const hasApp = !!appFile;
200
- const hasPkg = !!pkgFile;
188
+ const appFile = path.join(roots.appBase, "ce.ts");
189
+ const pkgFile = path.join(roots.pkgBase, "ce.ts");
190
+ const hasApp = fs.existsSync(appFile);
191
+ const hasPkg = fs.existsSync(pkgFile);
201
192
  if (hasApp || hasPkg) {
202
193
  const importName = `CE_${toVar(modId)}_${importId++}`;
203
194
  const importPath = hasApp ? `${appImportBase}/ce` : `${imps.pkgBase}/ce`;
@@ -206,10 +197,10 @@ async function generateModuleRegistry(options) {
206
197
  }
207
198
  }
208
199
  {
209
- const appFile = findModuleFile(roots.appBase, "search");
210
- const pkgFile = findModuleFile(roots.pkgBase, "search");
211
- const hasApp = !!appFile;
212
- const hasPkg = !!pkgFile;
200
+ const appFile = path.join(roots.appBase, "search.ts");
201
+ const pkgFile = path.join(roots.pkgBase, "search.ts");
202
+ const hasApp = fs.existsSync(appFile);
203
+ const hasPkg = fs.existsSync(pkgFile);
213
204
  if (hasApp || hasPkg) {
214
205
  const importName = `SEARCH_${toVar(modId)}_${importId++}`;
215
206
  const importPath = hasApp ? `${appImportBase}/search` : `${imps.pkgBase}/search`;
@@ -220,10 +211,10 @@ async function generateModuleRegistry(options) {
220
211
  }
221
212
  }
222
213
  {
223
- const appFile = findModuleFile(roots.appBase, "data", "fields");
224
- const pkgFile = findModuleFile(roots.pkgBase, "data", "fields");
225
- const hasApp = !!appFile;
226
- const hasPkg = !!pkgFile;
214
+ const appFile = path.join(roots.appBase, "data", "fields.ts");
215
+ const pkgFile = path.join(roots.pkgBase, "data", "fields.ts");
216
+ const hasApp = fs.existsSync(appFile);
217
+ const hasPkg = fs.existsSync(pkgFile);
227
218
  if (hasApp || hasPkg) {
228
219
  const importName = `F_${toVar(modId)}_${importId++}`;
229
220
  const importPath = hasApp ? `${appImportBase}/data/fields` : `${imps.pkgBase}/data/fields`;
@@ -428,9 +419,9 @@ async function generateModuleRegistry(options) {
428
419
  }
429
420
  }
430
421
  }
431
- const cliApp = findModuleFile(roots.appBase, "cli");
432
- const cliPkg = findModuleFile(roots.pkgBase, "cli");
433
- const cliPath = cliApp ?? cliPkg;
422
+ const cliApp = path.join(roots.appBase, "cli.ts");
423
+ const cliPkg = path.join(roots.pkgBase, "cli.ts");
424
+ const cliPath = fs.existsSync(cliApp) ? cliApp : fs.existsSync(cliPkg) ? cliPkg : null;
434
425
  if (cliPath) {
435
426
  const importName = `CLI_${toVar(modId)}`;
436
427
  const importPath = cliPath.startsWith(roots.appBase) ? `${appImportBase}/cli` : `${imps.pkgBase}/cli`;
@@ -478,9 +469,8 @@ async function generateModuleRegistry(options) {
478
469
  if (e.isDirectory()) {
479
470
  if (e.name === "__tests__" || e.name === "__mocks__") continue;
480
471
  walk(path.join(dir, e.name), [...rel, e.name]);
481
- } else if (e.isFile() && (e.name.endsWith(".ts") || e.name.endsWith(".js"))) {
482
- if (/\.(test|spec)\.(ts|js)$/.test(e.name)) continue;
483
- if (e.name.endsWith(".d.ts")) continue;
472
+ } else if (e.isFile() && e.name.endsWith(".ts")) {
473
+ if (/\.(test|spec)\.ts$/.test(e.name)) continue;
484
474
  found.push([...rel, e.name].join("/"));
485
475
  }
486
476
  }
@@ -491,12 +481,11 @@ async function generateModuleRegistry(options) {
491
481
  for (const rel of files) {
492
482
  const segs = rel.split("/");
493
483
  const file = segs.pop();
494
- const name = file.replace(/\.(ts|js)$/, "");
484
+ const name = file.replace(/\.ts$/, "");
495
485
  const importName = `Subscriber${importId++}_${toVar(modId)}_${toVar([...segs, name].join("_") || "index")}`;
496
486
  const metaName = `SubscriberMeta${importId++}_${toVar(modId)}_${toVar([...segs, name].join("_") || "index")}`;
497
- const appFileTs = path.join(subApp, ...segs, `${name}.ts`);
498
- const appFileJs = path.join(subApp, ...segs, `${name}.js`);
499
- const fromApp = fs.existsSync(appFileTs) || fs.existsSync(appFileJs);
487
+ const appFile = path.join(subApp, ...segs, `${name}.ts`);
488
+ const fromApp = fs.existsSync(appFile);
500
489
  const importPath = `${fromApp ? appImportBase : imps.pkgBase}/subscribers/${[...segs, name].join("/")}`;
501
490
  imports.push(`import ${importName}, * as ${metaName} from '${importPath}'`);
502
491
  const sid = [modId, ...segs, name].filter(Boolean).join(":");
@@ -515,9 +504,8 @@ async function generateModuleRegistry(options) {
515
504
  if (e.isDirectory()) {
516
505
  if (e.name === "__tests__" || e.name === "__mocks__") continue;
517
506
  walk(path.join(dir, e.name), [...rel, e.name]);
518
- } else if (e.isFile() && (e.name.endsWith(".ts") || e.name.endsWith(".js"))) {
519
- if (/\.(test|spec)\.(ts|js)$/.test(e.name)) continue;
520
- if (e.name.endsWith(".d.ts")) continue;
507
+ } else if (e.isFile() && e.name.endsWith(".ts")) {
508
+ if (/\.(test|spec)\.ts$/.test(e.name)) continue;
521
509
  found.push([...rel, e.name].join("/"));
522
510
  }
523
511
  }
@@ -528,10 +516,9 @@ async function generateModuleRegistry(options) {
528
516
  for (const rel of files) {
529
517
  const segs = rel.split("/");
530
518
  const file = segs.pop();
531
- const name = file.replace(/\.(ts|js)$/, "");
532
- const appFileTs = path.join(wrkApp, ...segs, `${name}.ts`);
533
- const appFileJs = path.join(wrkApp, ...segs, `${name}.js`);
534
- const fromApp = fs.existsSync(appFileTs) || fs.existsSync(appFileJs);
519
+ const name = file.replace(/\.ts$/, "");
520
+ const appFile = path.join(wrkApp, ...segs, `${name}.ts`);
521
+ const fromApp = fs.existsSync(appFile);
535
522
  const importPath = `${fromApp ? appImportBase : imps.pkgBase}/workers/${[...segs, name].join("/")}`;
536
523
  if (!await moduleHasExport(importPath, "metadata")) continue;
537
524
  const importName = `Worker${importId++}_${toVar(modId)}_${toVar([...segs, name].join("_") || "index")}`;
@@ -832,9 +819,9 @@ async function generateModuleRegistryCli(options) {
832
819
  let customEntitiesImportName = null;
833
820
  let vectorImportName = null;
834
821
  let customFieldSetsExpr = "[]";
835
- const appIndex = findModuleFile(roots.appBase, "index");
836
- const pkgIndex = findModuleFile(roots.pkgBase, "index");
837
- const indexTs = appIndex ?? pkgIndex;
822
+ const appIndex = path.join(roots.appBase, "index.ts");
823
+ const pkgIndex = path.join(roots.pkgBase, "index.ts");
824
+ const indexTs = fs.existsSync(appIndex) ? appIndex : fs.existsSync(pkgIndex) ? pkgIndex : null;
838
825
  if (indexTs) {
839
826
  infoImportName = `I${importId++}_${toVar(modId)}`;
840
827
  const importPath = indexTs.startsWith(roots.appBase) ? `${appImportBase}/index` : `${imps.pkgBase}/index`;
@@ -847,10 +834,10 @@ async function generateModuleRegistryCli(options) {
847
834
  }
848
835
  }
849
836
  {
850
- const appFile = findModuleFile(roots.appBase, "data", "extensions");
851
- const pkgFile = findModuleFile(roots.pkgBase, "data", "extensions");
852
- const hasApp = !!appFile;
853
- const hasPkg = !!pkgFile;
837
+ const appFile = path.join(roots.appBase, "data", "extensions.ts");
838
+ const pkgFile = path.join(roots.pkgBase, "data", "extensions.ts");
839
+ const hasApp = fs.existsSync(appFile);
840
+ const hasPkg = fs.existsSync(pkgFile);
854
841
  if (hasApp || hasPkg) {
855
842
  const importName = `X_${toVar(modId)}_${importId++}`;
856
843
  const importPath = hasApp ? `${appImportBase}/data/extensions` : `${imps.pkgBase}/data/extensions`;
@@ -859,22 +846,22 @@ async function generateModuleRegistryCli(options) {
859
846
  }
860
847
  }
861
848
  {
862
- const rootApp = findModuleFile(roots.appBase, "acl");
863
- const rootPkg = findModuleFile(roots.pkgBase, "acl");
864
- const hasRoot = rootApp || rootPkg;
849
+ const rootApp = path.join(roots.appBase, "acl.ts");
850
+ const rootPkg = path.join(roots.pkgBase, "acl.ts");
851
+ const hasRoot = fs.existsSync(rootApp) || fs.existsSync(rootPkg);
865
852
  if (hasRoot) {
866
853
  const importName = `ACL_${toVar(modId)}_${importId++}`;
867
- const useApp = rootApp ?? rootPkg;
854
+ const useApp = fs.existsSync(rootApp) ? rootApp : rootPkg;
868
855
  const importPath = useApp.startsWith(roots.appBase) ? `${appImportBase}/acl` : `${imps.pkgBase}/acl`;
869
856
  imports.push(`import * as ${importName} from '${importPath}'`);
870
857
  featuresImportName = importName;
871
858
  }
872
859
  }
873
860
  {
874
- const appFile = findModuleFile(roots.appBase, "ce");
875
- const pkgFile = findModuleFile(roots.pkgBase, "ce");
876
- const hasApp = !!appFile;
877
- const hasPkg = !!pkgFile;
861
+ const appFile = path.join(roots.appBase, "ce.ts");
862
+ const pkgFile = path.join(roots.pkgBase, "ce.ts");
863
+ const hasApp = fs.existsSync(appFile);
864
+ const hasPkg = fs.existsSync(pkgFile);
878
865
  if (hasApp || hasPkg) {
879
866
  const importName = `CE_${toVar(modId)}_${importId++}`;
880
867
  const importPath = hasApp ? `${appImportBase}/ce` : `${imps.pkgBase}/ce`;
@@ -883,10 +870,10 @@ async function generateModuleRegistryCli(options) {
883
870
  }
884
871
  }
885
872
  {
886
- const appFile = findModuleFile(roots.appBase, "vector");
887
- const pkgFile = findModuleFile(roots.pkgBase, "vector");
888
- const hasApp = !!appFile;
889
- const hasPkg = !!pkgFile;
873
+ const appFile = path.join(roots.appBase, "vector.ts");
874
+ const pkgFile = path.join(roots.pkgBase, "vector.ts");
875
+ const hasApp = fs.existsSync(appFile);
876
+ const hasPkg = fs.existsSync(pkgFile);
890
877
  if (hasApp || hasPkg) {
891
878
  const importName = `VECTOR_${toVar(modId)}_${importId++}`;
892
879
  const importPath = hasApp ? `${appImportBase}/vector` : `${imps.pkgBase}/vector`;
@@ -895,10 +882,10 @@ async function generateModuleRegistryCli(options) {
895
882
  }
896
883
  }
897
884
  {
898
- const appFile = findModuleFile(roots.appBase, "data", "fields");
899
- const pkgFile = findModuleFile(roots.pkgBase, "data", "fields");
900
- const hasApp = !!appFile;
901
- const hasPkg = !!pkgFile;
885
+ const appFile = path.join(roots.appBase, "data", "fields.ts");
886
+ const pkgFile = path.join(roots.pkgBase, "data", "fields.ts");
887
+ const hasApp = fs.existsSync(appFile);
888
+ const hasPkg = fs.existsSync(pkgFile);
902
889
  if (hasApp || hasPkg) {
903
890
  const importName = `F_${toVar(modId)}_${importId++}`;
904
891
  const importPath = hasApp ? `${appImportBase}/data/fields` : `${imps.pkgBase}/data/fields`;
@@ -906,9 +893,9 @@ async function generateModuleRegistryCli(options) {
906
893
  fieldsImportName = importName;
907
894
  }
908
895
  }
909
- const cliApp = findModuleFile(roots.appBase, "cli");
910
- const cliPkg = findModuleFile(roots.pkgBase, "cli");
911
- const cliPath = cliApp ?? cliPkg;
896
+ const cliApp = path.join(roots.appBase, "cli.ts");
897
+ const cliPkg = path.join(roots.pkgBase, "cli.ts");
898
+ const cliPath = fs.existsSync(cliApp) ? cliApp : fs.existsSync(cliPkg) ? cliPkg : null;
912
899
  if (cliPath) {
913
900
  const importName = `CLI_${toVar(modId)}`;
914
901
  const importPath = cliPath.startsWith(roots.appBase) ? `${appImportBase}/cli` : `${imps.pkgBase}/cli`;
@@ -956,9 +943,8 @@ async function generateModuleRegistryCli(options) {
956
943
  if (e.isDirectory()) {
957
944
  if (e.name === "__tests__" || e.name === "__mocks__") continue;
958
945
  walk(path.join(dir, e.name), [...rel, e.name]);
959
- } else if (e.isFile() && (e.name.endsWith(".ts") || e.name.endsWith(".js"))) {
960
- if (/\.(test|spec)\.(ts|js)$/.test(e.name)) continue;
961
- if (e.name.endsWith(".d.ts")) continue;
946
+ } else if (e.isFile() && e.name.endsWith(".ts")) {
947
+ if (/\.(test|spec)\.ts$/.test(e.name)) continue;
962
948
  found.push([...rel, e.name].join("/"));
963
949
  }
964
950
  }
@@ -969,12 +955,11 @@ async function generateModuleRegistryCli(options) {
969
955
  for (const rel of files) {
970
956
  const segs = rel.split("/");
971
957
  const file = segs.pop();
972
- const name = file.replace(/\.(ts|js)$/, "");
958
+ const name = file.replace(/\.ts$/, "");
973
959
  const importName = `Subscriber${importId++}_${toVar(modId)}_${toVar([...segs, name].join("_") || "index")}`;
974
960
  const metaName = `SubscriberMeta${importId++}_${toVar(modId)}_${toVar([...segs, name].join("_") || "index")}`;
975
- const appFileTs = path.join(subApp, ...segs, `${name}.ts`);
976
- const appFileJs = path.join(subApp, ...segs, `${name}.js`);
977
- const fromApp = fs.existsSync(appFileTs) || fs.existsSync(appFileJs);
961
+ const appFile = path.join(subApp, ...segs, `${name}.ts`);
962
+ const fromApp = fs.existsSync(appFile);
978
963
  const importPath = `${fromApp ? appImportBase : imps.pkgBase}/subscribers/${[...segs, name].join("/")}`;
979
964
  imports.push(`import ${importName}, * as ${metaName} from '${importPath}'`);
980
965
  const sid = [modId, ...segs, name].filter(Boolean).join(":");
@@ -993,9 +978,8 @@ async function generateModuleRegistryCli(options) {
993
978
  if (e.isDirectory()) {
994
979
  if (e.name === "__tests__" || e.name === "__mocks__") continue;
995
980
  walk(path.join(dir, e.name), [...rel, e.name]);
996
- } else if (e.isFile() && (e.name.endsWith(".ts") || e.name.endsWith(".js"))) {
997
- if (/\.(test|spec)\.(ts|js)$/.test(e.name)) continue;
998
- if (e.name.endsWith(".d.ts")) continue;
981
+ } else if (e.isFile() && e.name.endsWith(".ts")) {
982
+ if (/\.(test|spec)\.ts$/.test(e.name)) continue;
999
983
  found.push([...rel, e.name].join("/"));
1000
984
  }
1001
985
  }
@@ -1006,10 +990,9 @@ async function generateModuleRegistryCli(options) {
1006
990
  for (const rel of files) {
1007
991
  const segs = rel.split("/");
1008
992
  const file = segs.pop();
1009
- const name = file.replace(/\.(ts|js)$/, "");
1010
- const appFileTs = path.join(wrkApp, ...segs, `${name}.ts`);
1011
- const appFileJs = path.join(wrkApp, ...segs, `${name}.js`);
1012
- const fromApp = fs.existsSync(appFileTs) || fs.existsSync(appFileJs);
993
+ const name = file.replace(/\.ts$/, "");
994
+ const appFile = path.join(wrkApp, ...segs, `${name}.ts`);
995
+ const fromApp = fs.existsSync(appFile);
1013
996
  const importPath = `${fromApp ? appImportBase : imps.pkgBase}/workers/${[...segs, name].join("/")}`;
1014
997
  if (!await moduleHasExport(importPath, "metadata")) continue;
1015
998
  const importName = `Worker${importId++}_${toVar(modId)}_${toVar([...segs, name].join("_") || "index")}`;