langaro-api 1.0.0 → 1.0.1

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.
@@ -2,54 +2,70 @@
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
- function run() {
17
- const config = loadConfig();
18
- generateTypes(config);
19
- console.log('[langaro-api] Types + JSDoc annotations generated.');
20
- }
16
+ // ── Commands ──
21
17
 
22
- // Initial run
23
- run();
18
+ const command = process.argv[2];
24
19
 
25
- // Watch mode
26
- if (process.argv.includes('--watch')) {
20
+ if (command === 'init') {
21
+ // Project scaffolding
22
+ const runInit = require('../lib/cli/init');
23
+ runInit();
24
+ } else if (command === 'new') {
25
+ // Interactive resource generator
26
+ const runNew = require('../lib/cli/new');
27
27
  const config = loadConfig();
28
- const dirs = getWatchDirs(config);
28
+ runNew(config);
29
+ } else {
30
+ // Default: generate types
31
+ const { generateTypes, getWatchDirs } = require('../lib/index');
32
+
33
+ function run() {
34
+ const config = loadConfig();
35
+ generateTypes(config);
36
+ console.log('[langaro-api] Types + JSDoc annotations generated.');
37
+ }
38
+
39
+ run();
40
+
41
+ // Watch mode
42
+ if (process.argv.includes('--watch')) {
43
+ const config = loadConfig();
44
+ const dirs = getWatchDirs(config);
29
45
 
30
- let debounceTimer = null;
46
+ let debounceTimer = null;
31
47
 
32
- function onChange() {
33
- if (debounceTimer) clearTimeout(debounceTimer);
34
- debounceTimer = setTimeout(() => {
48
+ function onChange() {
49
+ if (debounceTimer) clearTimeout(debounceTimer);
50
+ debounceTimer = setTimeout(() => {
51
+ try {
52
+ run();
53
+ } catch (err) {
54
+ console.error('[langaro-api] Error:', err.message);
55
+ }
56
+ }, 300);
57
+ }
58
+
59
+ dirs.forEach((dir) => {
35
60
  try {
36
- run();
61
+ fs.watch(dir, { recursive: true }, (eventType, filename) => {
62
+ if (filename && filename.endsWith('.js')) onChange();
63
+ });
37
64
  } catch (err) {
38
- console.error('[langaro-api] Error:', err.message);
65
+ console.warn(`[langaro-api] Could not watch ${dir}: ${err.message}`);
39
66
  }
40
- }, 300);
41
- }
67
+ });
42
68
 
43
- dirs.forEach((dir) => {
44
- try {
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...`);
69
+ console.log(`[langaro-api] Watching ${dirs.length} directories for changes...`);
70
+ }
55
71
  }