langaro-api 1.0.0 → 1.0.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/bin/langaro-api.js +51 -31
- package/lib/cli/init.js +769 -0
- package/lib/cli/migrate.js +99 -0
- package/lib/cli/new.js +258 -0
- package/lib/index.js +7 -1
- package/lib/loaders/controllers.js +61 -0
- package/lib/loaders/index.js +9 -0
- package/lib/loaders/jobs.js +34 -0
- package/lib/loaders/models.js +38 -0
- package/lib/loaders/routes.js +21 -0
- package/lib/loaders/services.js +48 -0
- package/lib/loaders/tasks.js +43 -0
- package/package.json +14 -3
package/bin/langaro-api.js
CHANGED
|
@@ -2,54 +2,74 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const { generateTypes, getWatchDirs } = require('../lib/index');
|
|
6
5
|
|
|
7
6
|
// Load config from langaro-api.config.js at cwd, or use defaults
|
|
8
7
|
function loadConfig() {
|
|
9
8
|
const configPath = path.resolve(process.cwd(), 'langaro-api.config.js');
|
|
10
9
|
if (fs.existsSync(configPath)) {
|
|
10
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
11
11
|
return require(configPath);
|
|
12
12
|
}
|
|
13
13
|
return {};
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
const config = loadConfig();
|
|
18
|
-
generateTypes(config);
|
|
19
|
-
console.log('[langaro-api] Types + JSDoc annotations generated.');
|
|
20
|
-
}
|
|
16
|
+
// ── Commands ──
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
run();
|
|
18
|
+
const command = process.argv[2];
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
if (command === 'init') {
|
|
21
|
+
// Project scaffolding
|
|
22
|
+
const runInit = require('../lib/cli/init');
|
|
23
|
+
runInit();
|
|
24
|
+
} else if (command === 'migrate') {
|
|
25
|
+
// Migrate existing project to use langaro-api loaders
|
|
26
|
+
const runMigrate = require('../lib/cli/migrate');
|
|
27
|
+
runMigrate();
|
|
28
|
+
} else if (command === 'new') {
|
|
29
|
+
// Interactive resource generator
|
|
30
|
+
const runNew = require('../lib/cli/new');
|
|
27
31
|
const config = loadConfig();
|
|
28
|
-
|
|
32
|
+
runNew(config);
|
|
33
|
+
} else {
|
|
34
|
+
// Default: generate types
|
|
35
|
+
const { generateTypes, getWatchDirs } = require('../lib/index');
|
|
36
|
+
|
|
37
|
+
function run() {
|
|
38
|
+
const config = loadConfig();
|
|
39
|
+
generateTypes(config);
|
|
40
|
+
console.log('[langaro-api] Types + JSDoc annotations generated.');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
run();
|
|
44
|
+
|
|
45
|
+
// Watch mode
|
|
46
|
+
if (process.argv.includes('--watch')) {
|
|
47
|
+
const config = loadConfig();
|
|
48
|
+
const dirs = getWatchDirs(config);
|
|
29
49
|
|
|
30
|
-
|
|
50
|
+
let debounceTimer = null;
|
|
31
51
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
52
|
+
function onChange() {
|
|
53
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
54
|
+
debounceTimer = setTimeout(() => {
|
|
55
|
+
try {
|
|
56
|
+
run();
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.error('[langaro-api] Error:', err.message);
|
|
59
|
+
}
|
|
60
|
+
}, 300);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
dirs.forEach((dir) => {
|
|
35
64
|
try {
|
|
36
|
-
|
|
65
|
+
fs.watch(dir, { recursive: true }, (eventType, filename) => {
|
|
66
|
+
if (filename && filename.endsWith('.js')) onChange();
|
|
67
|
+
});
|
|
37
68
|
} catch (err) {
|
|
38
|
-
console.
|
|
69
|
+
console.warn(`[langaro-api] Could not watch ${dir}: ${err.message}`);
|
|
39
70
|
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
71
|
+
});
|
|
42
72
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fs.watch(dir, { recursive: true }, (eventType, filename) => {
|
|
46
|
-
if (filename && filename.endsWith('.js')) onChange();
|
|
47
|
-
});
|
|
48
|
-
} catch (err) {
|
|
49
|
-
// Directory might not support recursive watching on some platforms
|
|
50
|
-
console.warn(`[langaro-api] Could not watch ${dir}: ${err.message}`);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
console.log(`[langaro-api] Watching ${dirs.length} directories for changes...`);
|
|
73
|
+
console.log(`[langaro-api] Watching ${dirs.length} directories for changes...`);
|
|
74
|
+
}
|
|
55
75
|
}
|