@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.
- package/dist/lib/db/commands.js +4 -2
- package/dist/lib/db/commands.js.map +2 -2
- package/dist/lib/generators/module-entities.js +4 -3
- package/dist/lib/generators/module-entities.js.map +2 -2
- package/dist/lib/generators/module-registry.js +61 -52
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/package.json +2 -2
- package/src/lib/db/commands.ts +5 -2
- package/src/lib/generators/module-entities.ts +4 -3
- package/src/lib/generators/module-registry.ts +67 -52
|
@@ -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 =
|
|
83
|
-
const pkgIndex =
|
|
84
|
-
const indexTs =
|
|
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 =
|
|
194
|
-
const pkgFile =
|
|
195
|
-
const hasApp =
|
|
196
|
-
const hasPkg =
|
|
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 =
|
|
208
|
-
const rootPkg =
|
|
209
|
-
const hasRoot =
|
|
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 =
|
|
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 =
|
|
222
|
-
const pkgFile =
|
|
223
|
-
const hasApp =
|
|
224
|
-
const hasPkg =
|
|
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 =
|
|
236
|
-
const pkgFile =
|
|
237
|
-
const hasApp =
|
|
238
|
-
const hasPkg =
|
|
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 =
|
|
252
|
-
const pkgFile =
|
|
253
|
-
const hasApp =
|
|
254
|
-
const hasPkg =
|
|
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 =
|
|
472
|
-
const cliPkg =
|
|
473
|
-
const cliPath =
|
|
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 =
|
|
934
|
-
const pkgIndex =
|
|
935
|
-
const indexTs =
|
|
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 =
|
|
953
|
-
const pkgFile =
|
|
954
|
-
const hasApp =
|
|
955
|
-
const hasPkg =
|
|
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 =
|
|
967
|
-
const rootPkg =
|
|
968
|
-
const hasRoot =
|
|
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 =
|
|
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 =
|
|
981
|
-
const pkgFile =
|
|
982
|
-
const hasApp =
|
|
983
|
-
const hasPkg =
|
|
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 =
|
|
995
|
-
const pkgFile =
|
|
996
|
-
const hasApp =
|
|
997
|
-
const hasPkg =
|
|
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 =
|
|
1009
|
-
const pkgFile =
|
|
1010
|
-
const hasApp =
|
|
1011
|
-
const hasPkg =
|
|
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 =
|
|
1022
|
-
const cliPkg =
|
|
1023
|
-
const cliPath =
|
|
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`
|