@open-mercato/cli 0.4.2-canary-17c386eb25 → 0.4.2-canary-a91dde3d1d

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.
@@ -15,6 +15,21 @@ import {
15
15
 
16
16
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
17
17
 
18
+ /**
19
+ * Find a module file, checking for both .ts (src) and .js (dist) extensions.
20
+ * Supports both simple names (e.g., 'cli') and nested paths (e.g., 'data/extensions').
21
+ * Returns the path if found, null otherwise.
22
+ */
23
+ function findModuleFile(basePath: string, ...segments: string[]): string | null {
24
+ const name = segments.pop()!
25
+ const dir = segments.length ? path.join(basePath, ...segments) : basePath
26
+ const tsPath = path.join(dir, `${name}.ts`)
27
+ if (fs.existsSync(tsPath)) return tsPath
28
+ const jsPath = path.join(dir, `${name}.js`)
29
+ if (fs.existsSync(jsPath)) return jsPath
30
+ return null
31
+ }
32
+
18
33
  export interface ModuleRegistryOptions {
19
34
  resolver: PackageResolver
20
35
  quiet?: boolean
@@ -79,9 +94,9 @@ export async function generateModuleRegistry(options: ModuleRegistryOptions): Pr
79
94
  let injectionTableImportName: string | null = null
80
95
 
81
96
  // Module metadata: index.ts (overrideable)
82
- const appIndex = path.join(roots.appBase, 'index.ts')
83
- const pkgIndex = path.join(roots.pkgBase, 'index.ts')
84
- const indexTs = fs.existsSync(appIndex) ? appIndex : fs.existsSync(pkgIndex) ? pkgIndex : null
97
+ const appIndex = findModuleFile(roots.appBase, 'index')
98
+ const pkgIndex = findModuleFile(roots.pkgBase, 'index')
99
+ const indexTs = appIndex ?? pkgIndex
85
100
  if (indexTs) {
86
101
  infoImportName = `I${importId++}_${toVar(modId)}`
87
102
  const importPath = indexTs.startsWith(roots.appBase) ? `${appImportBase}/index` : `${imps.pkgBase}/index`
@@ -190,10 +205,10 @@ export async function generateModuleRegistry(options: ModuleRegistryOptions): Pr
190
205
 
191
206
  // Entity extensions: src/modules/<module>/data/extensions.ts
192
207
  {
193
- const appFile = path.join(roots.appBase, 'data', 'extensions.ts')
194
- const pkgFile = path.join(roots.pkgBase, 'data', 'extensions.ts')
195
- const hasApp = fs.existsSync(appFile)
196
- const hasPkg = fs.existsSync(pkgFile)
208
+ const appFile = findModuleFile(roots.appBase, 'data', 'extensions')
209
+ const pkgFile = findModuleFile(roots.pkgBase, 'data', 'extensions')
210
+ const hasApp = !!appFile
211
+ const hasPkg = !!pkgFile
197
212
  if (hasApp || hasPkg) {
198
213
  const importName = `X_${toVar(modId)}_${importId++}`
199
214
  const importPath = hasApp ? `${appImportBase}/data/extensions` : `${imps.pkgBase}/data/extensions`
@@ -204,12 +219,12 @@ export async function generateModuleRegistry(options: ModuleRegistryOptions): Pr
204
219
 
205
220
  // RBAC feature declarations: module root acl.ts
206
221
  {
207
- const rootApp = path.join(roots.appBase, 'acl.ts')
208
- const rootPkg = path.join(roots.pkgBase, 'acl.ts')
209
- const hasRoot = fs.existsSync(rootApp) || fs.existsSync(rootPkg)
222
+ const rootApp = findModuleFile(roots.appBase, 'acl')
223
+ const rootPkg = findModuleFile(roots.pkgBase, 'acl')
224
+ const hasRoot = rootApp || rootPkg
210
225
  if (hasRoot) {
211
226
  const importName = `ACL_${toVar(modId)}_${importId++}`
212
- const useApp = fs.existsSync(rootApp) ? rootApp : rootPkg
227
+ const useApp = rootApp ?? rootPkg!
213
228
  const importPath = useApp.startsWith(roots.appBase) ? `${appImportBase}/acl` : `${imps.pkgBase}/acl`
214
229
  imports.push(`import * as ${importName} from '${importPath}'`)
215
230
  featuresImportName = importName
@@ -218,10 +233,10 @@ export async function generateModuleRegistry(options: ModuleRegistryOptions): Pr
218
233
 
219
234
  // Custom entities declarations: module root ce.ts
220
235
  {
221
- const appFile = path.join(roots.appBase, 'ce.ts')
222
- const pkgFile = path.join(roots.pkgBase, 'ce.ts')
223
- const hasApp = fs.existsSync(appFile)
224
- const hasPkg = fs.existsSync(pkgFile)
236
+ const appFile = findModuleFile(roots.appBase, 'ce')
237
+ const pkgFile = findModuleFile(roots.pkgBase, 'ce')
238
+ const hasApp = !!appFile
239
+ const hasPkg = !!pkgFile
225
240
  if (hasApp || hasPkg) {
226
241
  const importName = `CE_${toVar(modId)}_${importId++}`
227
242
  const importPath = hasApp ? `${appImportBase}/ce` : `${imps.pkgBase}/ce`
@@ -232,10 +247,10 @@ export async function generateModuleRegistry(options: ModuleRegistryOptions): Pr
232
247
 
233
248
  // Search module configuration: module root search.ts
234
249
  {
235
- const appFile = path.join(roots.appBase, 'search.ts')
236
- const pkgFile = path.join(roots.pkgBase, 'search.ts')
237
- const hasApp = fs.existsSync(appFile)
238
- const hasPkg = fs.existsSync(pkgFile)
250
+ const appFile = findModuleFile(roots.appBase, 'search')
251
+ const pkgFile = findModuleFile(roots.pkgBase, 'search')
252
+ const hasApp = !!appFile
253
+ const hasPkg = !!pkgFile
239
254
  if (hasApp || hasPkg) {
240
255
  const importName = `SEARCH_${toVar(modId)}_${importId++}`
241
256
  const importPath = hasApp ? `${appImportBase}/search` : `${imps.pkgBase}/search`
@@ -248,10 +263,10 @@ export async function generateModuleRegistry(options: ModuleRegistryOptions): Pr
248
263
 
249
264
  // Custom field declarations: src/modules/<module>/data/fields.ts
250
265
  {
251
- const appFile = path.join(roots.appBase, 'data', 'fields.ts')
252
- const pkgFile = path.join(roots.pkgBase, 'data', 'fields.ts')
253
- const hasApp = fs.existsSync(appFile)
254
- const hasPkg = fs.existsSync(pkgFile)
266
+ const appFile = findModuleFile(roots.appBase, 'data', 'fields')
267
+ const pkgFile = findModuleFile(roots.pkgBase, 'data', 'fields')
268
+ const hasApp = !!appFile
269
+ const hasPkg = !!pkgFile
255
270
  if (hasApp || hasPkg) {
256
271
  const importName = `F_${toVar(modId)}_${importId++}`
257
272
  const importPath = hasApp ? `${appImportBase}/data/fields` : `${imps.pkgBase}/data/fields`
@@ -468,9 +483,9 @@ export async function generateModuleRegistry(options: ModuleRegistryOptions): Pr
468
483
  }
469
484
 
470
485
  // CLI
471
- const cliApp = path.join(roots.appBase, 'cli.ts')
472
- const cliPkg = path.join(roots.pkgBase, 'cli.ts')
473
- const cliPath = fs.existsSync(cliApp) ? cliApp : fs.existsSync(cliPkg) ? cliPkg : null
486
+ const cliApp = findModuleFile(roots.appBase, 'cli')
487
+ const cliPkg = findModuleFile(roots.pkgBase, 'cli')
488
+ const cliPath = cliApp ?? cliPkg
474
489
  if (cliPath) {
475
490
  const importName = `CLI_${toVar(modId)}`
476
491
  const importPath = cliPath.startsWith(roots.appBase) ? `${appImportBase}/cli` : `${imps.pkgBase}/cli`
@@ -930,9 +945,9 @@ export async function generateModuleRegistryCli(options: ModuleRegistryOptions):
930
945
  let customFieldSetsExpr: string = '[]'
931
946
 
932
947
  // Module metadata: index.ts (overrideable)
933
- const appIndex = path.join(roots.appBase, 'index.ts')
934
- const pkgIndex = path.join(roots.pkgBase, 'index.ts')
935
- const indexTs = fs.existsSync(appIndex) ? appIndex : fs.existsSync(pkgIndex) ? pkgIndex : null
948
+ const appIndex = findModuleFile(roots.appBase, 'index')
949
+ const pkgIndex = findModuleFile(roots.pkgBase, 'index')
950
+ const indexTs = appIndex ?? pkgIndex
936
951
  if (indexTs) {
937
952
  infoImportName = `I${importId++}_${toVar(modId)}`
938
953
  const importPath = indexTs.startsWith(roots.appBase) ? `${appImportBase}/index` : `${imps.pkgBase}/index`
@@ -949,10 +964,10 @@ export async function generateModuleRegistryCli(options: ModuleRegistryOptions):
949
964
 
950
965
  // Entity extensions: src/modules/<module>/data/extensions.ts
951
966
  {
952
- const appFile = path.join(roots.appBase, 'data', 'extensions.ts')
953
- const pkgFile = path.join(roots.pkgBase, 'data', 'extensions.ts')
954
- const hasApp = fs.existsSync(appFile)
955
- const hasPkg = fs.existsSync(pkgFile)
967
+ const appFile = findModuleFile(roots.appBase, 'data', 'extensions')
968
+ const pkgFile = findModuleFile(roots.pkgBase, 'data', 'extensions')
969
+ const hasApp = !!appFile
970
+ const hasPkg = !!pkgFile
956
971
  if (hasApp || hasPkg) {
957
972
  const importName = `X_${toVar(modId)}_${importId++}`
958
973
  const importPath = hasApp ? `${appImportBase}/data/extensions` : `${imps.pkgBase}/data/extensions`
@@ -963,12 +978,12 @@ export async function generateModuleRegistryCli(options: ModuleRegistryOptions):
963
978
 
964
979
  // RBAC feature declarations: module root acl.ts
965
980
  {
966
- const rootApp = path.join(roots.appBase, 'acl.ts')
967
- const rootPkg = path.join(roots.pkgBase, 'acl.ts')
968
- const hasRoot = fs.existsSync(rootApp) || fs.existsSync(rootPkg)
981
+ const rootApp = findModuleFile(roots.appBase, 'acl')
982
+ const rootPkg = findModuleFile(roots.pkgBase, 'acl')
983
+ const hasRoot = rootApp || rootPkg
969
984
  if (hasRoot) {
970
985
  const importName = `ACL_${toVar(modId)}_${importId++}`
971
- const useApp = fs.existsSync(rootApp) ? rootApp : rootPkg
986
+ const useApp = rootApp ?? rootPkg!
972
987
  const importPath = useApp.startsWith(roots.appBase) ? `${appImportBase}/acl` : `${imps.pkgBase}/acl`
973
988
  imports.push(`import * as ${importName} from '${importPath}'`)
974
989
  featuresImportName = importName
@@ -977,10 +992,10 @@ export async function generateModuleRegistryCli(options: ModuleRegistryOptions):
977
992
 
978
993
  // Custom entities declarations: module root ce.ts
979
994
  {
980
- const appFile = path.join(roots.appBase, 'ce.ts')
981
- const pkgFile = path.join(roots.pkgBase, 'ce.ts')
982
- const hasApp = fs.existsSync(appFile)
983
- const hasPkg = fs.existsSync(pkgFile)
995
+ const appFile = findModuleFile(roots.appBase, 'ce')
996
+ const pkgFile = findModuleFile(roots.pkgBase, 'ce')
997
+ const hasApp = !!appFile
998
+ const hasPkg = !!pkgFile
984
999
  if (hasApp || hasPkg) {
985
1000
  const importName = `CE_${toVar(modId)}_${importId++}`
986
1001
  const importPath = hasApp ? `${appImportBase}/ce` : `${imps.pkgBase}/ce`
@@ -991,10 +1006,10 @@ export async function generateModuleRegistryCli(options: ModuleRegistryOptions):
991
1006
 
992
1007
  // Vector search configuration: module root vector.ts
993
1008
  {
994
- const appFile = path.join(roots.appBase, 'vector.ts')
995
- const pkgFile = path.join(roots.pkgBase, 'vector.ts')
996
- const hasApp = fs.existsSync(appFile)
997
- const hasPkg = fs.existsSync(pkgFile)
1009
+ const appFile = findModuleFile(roots.appBase, 'vector')
1010
+ const pkgFile = findModuleFile(roots.pkgBase, 'vector')
1011
+ const hasApp = !!appFile
1012
+ const hasPkg = !!pkgFile
998
1013
  if (hasApp || hasPkg) {
999
1014
  const importName = `VECTOR_${toVar(modId)}_${importId++}`
1000
1015
  const importPath = hasApp ? `${appImportBase}/vector` : `${imps.pkgBase}/vector`
@@ -1005,10 +1020,10 @@ export async function generateModuleRegistryCli(options: ModuleRegistryOptions):
1005
1020
 
1006
1021
  // Custom field declarations: src/modules/<module>/data/fields.ts
1007
1022
  {
1008
- const appFile = path.join(roots.appBase, 'data', 'fields.ts')
1009
- const pkgFile = path.join(roots.pkgBase, 'data', 'fields.ts')
1010
- const hasApp = fs.existsSync(appFile)
1011
- const hasPkg = fs.existsSync(pkgFile)
1023
+ const appFile = findModuleFile(roots.appBase, 'data', 'fields')
1024
+ const pkgFile = findModuleFile(roots.pkgBase, 'data', 'fields')
1025
+ const hasApp = !!appFile
1026
+ const hasPkg = !!pkgFile
1012
1027
  if (hasApp || hasPkg) {
1013
1028
  const importName = `F_${toVar(modId)}_${importId++}`
1014
1029
  const importPath = hasApp ? `${appImportBase}/data/fields` : `${imps.pkgBase}/data/fields`
@@ -1018,9 +1033,9 @@ export async function generateModuleRegistryCli(options: ModuleRegistryOptions):
1018
1033
  }
1019
1034
 
1020
1035
  // CLI
1021
- const cliApp = path.join(roots.appBase, 'cli.ts')
1022
- const cliPkg = path.join(roots.pkgBase, 'cli.ts')
1023
- const cliPath = fs.existsSync(cliApp) ? cliApp : fs.existsSync(cliPkg) ? cliPkg : null
1036
+ const cliApp = findModuleFile(roots.appBase, 'cli')
1037
+ const cliPkg = findModuleFile(roots.pkgBase, 'cli')
1038
+ const cliPath = cliApp ?? cliPkg
1024
1039
  if (cliPath) {
1025
1040
  const importName = `CLI_${toVar(modId)}`
1026
1041
  const importPath = cliPath.startsWith(roots.appBase) ? `${appImportBase}/cli` : `${imps.pkgBase}/cli`