@thesimonharms/basa 0.1.1 → 0.1.2
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/bin/basa.js +33 -2
- package/package.json +1 -1
package/bin/basa.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Basa CLI shim. Boots the Mudah app kernel and points it at this
|
|
3
3
|
// package's own `dist/` for providers and commands, so a published
|
|
4
4
|
// install works from any working directory (not just the project root).
|
|
5
|
-
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
6
6
|
import { dirname, join } from 'node:path';
|
|
7
|
-
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
8
|
import { Application } from '@mudah-cli/core';
|
|
9
9
|
import { run } from '@mudah-cli/mudah';
|
|
10
10
|
|
|
@@ -12,6 +12,15 @@ const here = dirname(fileURLToPath(import.meta.url));
|
|
|
12
12
|
const pkgDir = dirname(here);
|
|
13
13
|
const pkg = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8'));
|
|
14
14
|
|
|
15
|
+
// Application discovery defaults to <basePath>/src/{commands,providers}.
|
|
16
|
+
// The published package ships compiled output under dist/, so we pre-load
|
|
17
|
+
// the built providers and command modules from there and inject them via
|
|
18
|
+
// run({providers, commands}). This is the supported escape hatch for
|
|
19
|
+
// packages that don't follow the scaffolded-app layout.
|
|
20
|
+
const distDir = join(pkgDir, 'dist');
|
|
21
|
+
const commandModules = await loadModules(join(distDir, 'commands'));
|
|
22
|
+
const providerModules = await loadModules(join(distDir, 'providers'));
|
|
23
|
+
|
|
15
24
|
const manifest = {
|
|
16
25
|
name: pkg.name,
|
|
17
26
|
version: pkg.version,
|
|
@@ -20,6 +29,10 @@ const manifest = {
|
|
|
20
29
|
};
|
|
21
30
|
|
|
22
31
|
const app = new Application(pkgDir, manifest);
|
|
32
|
+
for (const mod of providerModules) {
|
|
33
|
+
const value = mod.default ?? mod;
|
|
34
|
+
if (typeof value === 'function') app.register(value);
|
|
35
|
+
}
|
|
23
36
|
|
|
24
37
|
const code = await run({
|
|
25
38
|
app,
|
|
@@ -29,6 +42,24 @@ const code = await run({
|
|
|
29
42
|
stdout: process.stdout,
|
|
30
43
|
stderr: process.stderr,
|
|
31
44
|
stdin: process.stdin,
|
|
45
|
+
commands: commandModules,
|
|
32
46
|
});
|
|
33
47
|
|
|
34
48
|
process.exitCode = code;
|
|
49
|
+
|
|
50
|
+
async function loadModules(dir) {
|
|
51
|
+
const modules = [];
|
|
52
|
+
let entries;
|
|
53
|
+
try {
|
|
54
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
55
|
+
} catch {
|
|
56
|
+
return modules;
|
|
57
|
+
}
|
|
58
|
+
for (const entry of entries) {
|
|
59
|
+
if (!entry.isFile() || !/\.(c?js|mjs)$/.test(entry.name)) continue;
|
|
60
|
+
const file = join(dir, entry.name);
|
|
61
|
+
const mod = await import(pathToFileURL(file).href);
|
|
62
|
+
if (mod.default) modules.push(mod);
|
|
63
|
+
}
|
|
64
|
+
return modules;
|
|
65
|
+
}
|