@mantiq/cli 0.1.0 → 0.1.3
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/package.json +5 -5
- package/src/Kernel.ts +33 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantiq/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Command runner, code generators, dev server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"typecheck": "tsc --noEmit",
|
|
49
49
|
"clean": "rm -rf dist"
|
|
50
50
|
},
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"@mantiq/core": "^0.1.0",
|
|
53
|
-
"@mantiq/database": "^0.1.0"
|
|
54
|
-
},
|
|
55
51
|
"devDependencies": {
|
|
56
52
|
"bun-types": "latest",
|
|
57
53
|
"typescript": "^5.7.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@mantiq/core": "^0.1.0",
|
|
57
|
+
"@mantiq/database": "^0.1.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
package/src/Kernel.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { IO } from './IO.ts'
|
|
|
8
8
|
export class Kernel {
|
|
9
9
|
private commands = new Map<string, Command>()
|
|
10
10
|
private io = new IO()
|
|
11
|
+
private discovered = false
|
|
11
12
|
|
|
12
13
|
constructor(public readonly app: any = null) {}
|
|
13
14
|
|
|
@@ -21,7 +22,39 @@ export class Kernel {
|
|
|
21
22
|
return this
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Auto-discover and register command files from app/Console/Commands/.
|
|
27
|
+
* Each file must export a class that extends Command.
|
|
28
|
+
*/
|
|
29
|
+
async discover(basePath?: string): Promise<this> {
|
|
30
|
+
if (this.discovered) return this
|
|
31
|
+
|
|
32
|
+
const dir = (basePath ?? process.cwd()) + '/app/Console/Commands'
|
|
33
|
+
const glob = new Bun.Glob('**/*Command.ts')
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
for await (const file of glob.scan({ cwd: dir, absolute: false })) {
|
|
37
|
+
try {
|
|
38
|
+
const mod = await import(dir + '/' + file)
|
|
39
|
+
for (const exported of Object.values(mod)) {
|
|
40
|
+
if (typeof exported === 'function' && (exported as any).prototype?.name && (exported as any).prototype?.handle) {
|
|
41
|
+
this.register(new (exported as any)())
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
// Skip files that can't be imported
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
// Directory doesn't exist — no commands to discover
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.discovered = true
|
|
53
|
+
return this
|
|
54
|
+
}
|
|
55
|
+
|
|
24
56
|
async run(argv: string[] = process.argv): Promise<number> {
|
|
57
|
+
await this.discover()
|
|
25
58
|
const parsed = parse(argv)
|
|
26
59
|
|
|
27
60
|
if (parsed.command === 'help' || parsed.command === '--help' || parsed.command === '-h' || parsed.flags['help'] || parsed.flags['h']) {
|