@mantiq/cli 0.1.2 → 0.1.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Kernel.ts +39 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantiq/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Command runner, code generators, dev server",
5
5
  "type": "module",
6
6
  "license": "MIT",
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,45 @@ 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') continue
41
+ try {
42
+ const instance = new (exported as any)()
43
+ if (instance.name && typeof instance.handle === 'function') {
44
+ this.register(instance)
45
+ }
46
+ } catch {
47
+ // Not instantiable or not a command
48
+ }
49
+ }
50
+ } catch {
51
+ // Skip files that can't be imported
52
+ }
53
+ }
54
+ } catch {
55
+ // Directory doesn't exist — no commands to discover
56
+ }
57
+
58
+ this.discovered = true
59
+ return this
60
+ }
61
+
24
62
  async run(argv: string[] = process.argv): Promise<number> {
63
+ await this.discover()
25
64
  const parsed = parse(argv)
26
65
 
27
66
  if (parsed.command === 'help' || parsed.command === '--help' || parsed.command === '-h' || parsed.flags['help'] || parsed.flags['h']) {