@avleon/cli 0.0.47 → 0.4.0

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 (82) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin.d.ts +2 -0
  3. package/dist/bin.js +10 -0
  4. package/dist/commands/build.d.ts +11 -0
  5. package/dist/commands/build.js +65 -0
  6. package/dist/commands/doctor.d.ts +10 -0
  7. package/dist/commands/doctor.js +96 -0
  8. package/dist/commands/new.d.ts +19 -0
  9. package/dist/commands/new.js +306 -0
  10. package/dist/commands/route-list.d.ts +19 -0
  11. package/dist/commands/route-list.js +160 -0
  12. package/dist/commands/serve.d.ts +17 -0
  13. package/dist/commands/serve.js +238 -0
  14. package/dist/commands/start.d.ts +10 -0
  15. package/dist/commands/start.js +43 -0
  16. package/dist/compiler.d.ts +24 -0
  17. package/dist/compiler.js +83 -0
  18. package/dist/errors.d.ts +8 -0
  19. package/dist/errors.js +16 -0
  20. package/dist/generators/make.d.ts +24 -0
  21. package/dist/generators/make.js +157 -0
  22. package/dist/index.d.ts +17 -0
  23. package/dist/index.js +40 -15
  24. package/dist/program.d.ts +22 -0
  25. package/dist/program.js +178 -0
  26. package/dist/utils/entry.d.ts +15 -0
  27. package/dist/utils/entry.js +55 -0
  28. package/dist/utils/env-types.d.ts +8 -0
  29. package/dist/utils/env-types.js +19 -0
  30. package/dist/utils/log.d.ts +25 -0
  31. package/dist/utils/log.js +39 -0
  32. package/dist/utils/names.d.ts +27 -0
  33. package/dist/utils/names.js +58 -0
  34. package/dist/utils/process.d.ts +18 -0
  35. package/dist/utils/process.js +84 -0
  36. package/dist/utils/project.d.ts +17 -0
  37. package/dist/utils/project.js +91 -0
  38. package/dist/utils/stubs.d.ts +15 -0
  39. package/dist/utils/stubs.js +52 -0
  40. package/dist/utils/tsconfig.d.ts +13 -0
  41. package/dist/utils/tsconfig.js +102 -0
  42. package/package.json +28 -27
  43. package/readme.md +50 -11
  44. package/stubs/config/config.stub +9 -0
  45. package/stubs/controllers/basic-controller.stub +3 -3
  46. package/stubs/controllers/resource-controller.stub +45 -0
  47. package/stubs/controllers/rest-controller.stub +2 -2
  48. package/stubs/dtos/dto.stub +11 -0
  49. package/stubs/middlewares/middleware.stub +9 -0
  50. package/stubs/models/basic-model.stub +2 -2
  51. package/stubs/models/entity-model.stub +6 -8
  52. package/stubs/{app → project}/app-minimal.stub +1 -1
  53. package/stubs/{app/app-controller.stub → project/app.stub} +2 -7
  54. package/stubs/project/env.stub +3 -0
  55. package/stubs/project/gitignore.stub +5 -0
  56. package/stubs/project/home.controller.spec.stub +19 -0
  57. package/stubs/project/home.controller.stub +12 -0
  58. package/stubs/project/home.service.stub +8 -0
  59. package/stubs/{config.stub → project/openapi.config.stub} +4 -4
  60. package/stubs/project/readme.stub +26 -0
  61. package/stubs/{serve.stub → project/serve.stub} +1 -1
  62. package/stubs/project/tsconfig.build.stub +4 -0
  63. package/stubs/project/tsconfig.stub +18 -0
  64. package/stubs/project/vitest-e2e.config.stub +10 -0
  65. package/stubs/project/vitest.config.stub +17 -0
  66. package/stubs/services/basic-service.stub +1 -1
  67. package/stubs/services/orm-rest-service.stub +15 -14
  68. package/stubs/services/rest-service.stub +9 -9
  69. package/dist/av-cli.js +0 -60
  70. package/dist/avcli.js +0 -26
  71. package/dist/cli.interface.js +0 -2
  72. package/dist/cli.js +0 -332
  73. package/dist/commands.js +0 -63
  74. package/dist/controller.js +0 -96
  75. package/dist/create.js +0 -512
  76. package/dist/helpers/file-helper.js +0 -30
  77. package/dist/helpers/path-helper.js +0 -36
  78. package/dist/paths.js +0 -32
  79. package/dist/scripts/serve.js +0 -290
  80. package/dist/serve.js +0 -311
  81. package/dist/service.js +0 -69
  82. package/stubs/controllers/orm-rest-controller.stub +0 -45
@@ -1,290 +0,0 @@
1
- #!/usr/bin/env node
2
- const chokidar = require("chokidar");
3
- const { spawn } = require("child_process");
4
- const path = require("path");
5
- const fs = require("fs");
6
- const { transformFileSync } = require("@swc/core");
7
- const SRC_DIR = path.resolve(process.cwd(), "../src");
8
- const DIST_DIR = path.resolve(process.cwd(), "../dist");
9
- const ENTRY_FILE = path.join(DIST_DIR, "server.js");
10
- let nodeProcess = null;
11
- let isRestarting = false;
12
- // Unified logging with colors and timestamps
13
- function log(category, message, color = '\x1b[37m') {
14
- const timestamp = new Date().toTimeString().split(' ')[0];
15
- console.log(`\x1b[90m[${timestamp}]\x1b[0m ${color}[${category}]\x1b[0m ${message}`);
16
- }
17
- function logCompile(message) { log('SWC', message, '\x1b[36m'); }
18
- function logServer(message) { log('SERVER', message, '\x1b[32m'); }
19
- function logWatch(message) { log('WATCH', message, '\x1b[33m'); }
20
- function logError(category, message) { log(category, message, '\x1b[31m'); }
21
- // compile single TS file
22
- function compileFile(filePath) {
23
- try {
24
- const rel = path.relative(SRC_DIR, filePath);
25
- const outFile = path.join(DIST_DIR, rel).replace(/\.ts$/, ".js");
26
- const { code } = transformFileSync(filePath, {
27
- jsc: {
28
- parser: { syntax: "typescript", decorators: true },
29
- target: "es2022",
30
- transform: { decoratorMetadata: true },
31
- },
32
- module: { type: "commonjs" },
33
- sourceMaps: false,
34
- });
35
- fs.mkdirSync(path.dirname(outFile), { recursive: true });
36
- fs.writeFileSync(outFile, code, "utf8");
37
- logCompile(`✓ ${rel}`);
38
- return true;
39
- }
40
- catch (error) {
41
- logError('SWC', `✗ ${path.relative(SRC_DIR, filePath)} - ${error.message}`);
42
- return false;
43
- }
44
- }
45
- // compile all TS
46
- function compileAll(dir = SRC_DIR) {
47
- if (!fs.existsSync(dir)) {
48
- logError('SWC', `Source directory ${dir} does not exist`);
49
- return 0;
50
- }
51
- let compiled = 0;
52
- const files = fs.readdirSync(dir, { withFileTypes: true });
53
- for (const f of files) {
54
- const full = path.join(dir, f.name);
55
- if (f.isDirectory()) {
56
- compiled += compileAll(full);
57
- }
58
- else if (f.name.endsWith(".ts")) {
59
- if (f.name.includes('.test.') || f.name.includes('.spec.')) {
60
- logWatch(`⏭️ Skipping test file: ${path.relative(SRC_DIR, full)}`);
61
- continue;
62
- }
63
- if (compileFile(full))
64
- compiled++;
65
- }
66
- }
67
- return compiled;
68
- }
69
- // start Node with integrated output
70
- function startNode() {
71
- if (nodeProcess) {
72
- logServer("⚠️ Process already running, skipping start");
73
- return;
74
- }
75
- if (isRestarting) {
76
- // Reset the flag when actually starting
77
- isRestarting = false;
78
- }
79
- if (!fs.existsSync(ENTRY_FILE)) {
80
- logError('SERVER', `Entry file ${ENTRY_FILE} does not exist`);
81
- return;
82
- }
83
- logServer("🚀 Starting server...");
84
- try {
85
- nodeProcess = spawn("node", [ENTRY_FILE], {
86
- stdio: ['ignore', 'pipe', 'pipe'],
87
- env: { ...process.env, FORCE_COLOR: '1' },
88
- detached: false // Ensure process stays attached
89
- });
90
- // Forward stdout with server prefix
91
- nodeProcess.stdout?.on('data', (data) => {
92
- const lines = data.toString().split('\n').filter(line => line.trim());
93
- lines.forEach(line => logServer(line));
94
- });
95
- // Forward stderr with server prefix
96
- nodeProcess.stderr?.on('data', (data) => {
97
- const lines = data.toString().split('\n').filter(line => line.trim());
98
- lines.forEach(line => logError('SERVER', line));
99
- });
100
- nodeProcess.on("exit", (code, signal) => {
101
- const wasRestarting = isRestarting;
102
- nodeProcess = null;
103
- if (wasRestarting) {
104
- // This is expected during restart
105
- return;
106
- }
107
- if (code && code !== 0) {
108
- logError('SERVER', `Process exited with code ${code}`);
109
- }
110
- else if (signal) {
111
- logServer(`Process terminated by signal ${signal}`);
112
- }
113
- else {
114
- // logServer("Process exited normally");
115
- }
116
- isRestarting = false;
117
- });
118
- nodeProcess.on("error", (error) => {
119
- logError('SERVER', `Process error: ${error.message}`);
120
- nodeProcess = null;
121
- isRestarting = false;
122
- });
123
- // Add a small delay to let the server start
124
- setTimeout(() => {
125
- if (nodeProcess) {
126
- logServer("✅ Server started successfully");
127
- }
128
- }, 500);
129
- }
130
- catch (error) {
131
- logError('SERVER', `Failed to start server: ${error.message}`);
132
- nodeProcess = null;
133
- isRestarting = false;
134
- }
135
- }
136
- // kill Node
137
- function killNode() {
138
- return new Promise((resolve) => {
139
- if (!nodeProcess)
140
- return resolve();
141
- logServer("🛑 Stopping server...");
142
- let resolved = false;
143
- const cleanup = () => {
144
- if (!resolved) {
145
- resolved = true;
146
- nodeProcess = null;
147
- logServer("✓ Server stopped");
148
- resolve();
149
- }
150
- };
151
- nodeProcess.once("exit", cleanup);
152
- nodeProcess.once("close", cleanup);
153
- // Try graceful shutdown first
154
- try {
155
- nodeProcess.kill("SIGTERM");
156
- }
157
- catch (error) {
158
- logError('SERVER', `Error sending SIGTERM: ${error.message}`);
159
- }
160
- // Force kill after 1 second if still running
161
- const forceKillTimeout = setTimeout(() => {
162
- if (nodeProcess && !resolved) {
163
- logServer("⚠️ Force killing server...");
164
- try {
165
- nodeProcess.kill("SIGKILL");
166
- }
167
- catch (error) {
168
- logError('SERVER', `Error sending SIGKILL: ${error.message}`);
169
- }
170
- // Ensure cleanup happens even if SIGKILL fails
171
- setTimeout(cleanup, 100);
172
- }
173
- }, 1000);
174
- // Fallback timeout - always resolve within 3 seconds
175
- setTimeout(() => {
176
- clearTimeout(forceKillTimeout);
177
- if (!resolved) {
178
- logError('SERVER', 'Force cleanup - process may still be running');
179
- nodeProcess = null;
180
- resolved = true;
181
- resolve();
182
- }
183
- }, 3000);
184
- });
185
- }
186
- // restart Node
187
- async function restartNode() {
188
- if (isRestarting) {
189
- logServer("⏳ Already restarting, skipping...");
190
- return;
191
- }
192
- isRestarting = true;
193
- logServer("🔄 Restarting server...");
194
- try {
195
- await killNode();
196
- // Add delay to ensure process is fully cleaned up
197
- await new Promise(resolve => setTimeout(resolve, 200));
198
- startNode();
199
- }
200
- catch (error) {
201
- logError('SERVER', `Restart error: ${error.message}`);
202
- isRestarting = false;
203
- }
204
- }
205
- // watch src
206
- function watch() {
207
- logWatch(`👀 Watching ${path.relative(process.cwd(), SRC_DIR)} for changes...`);
208
- // Add debug logging
209
- logWatch(`📂 Source directory: ${SRC_DIR}`);
210
- logWatch(`📂 Output directory: ${DIST_DIR}`);
211
- const watcher = chokidar.watch(SRC_DIR, {
212
- ignoreInitial: true,
213
- ignored: /(^|[\/\\])\../, // ignore dotfiles
214
- persistent: true,
215
- followSymlinks: false,
216
- awaitWriteFinish: {
217
- stabilityThreshold: 100,
218
- pollInterval: 50
219
- }
220
- });
221
- // Debug: log when watcher is ready
222
- watcher.on('ready', () => {
223
- logWatch('✅ Initial scan complete. Ready for changes');
224
- });
225
- watcher.on("add", (file) => {
226
- const rel = path.relative(SRC_DIR, file);
227
- logWatch(`📄 File added: ${rel}`);
228
- if (compileFile(file)) {
229
- // For new files, restart if it's a .ts file
230
- if (file.endsWith('.ts')) {
231
- setTimeout(() => restartNode(), 100);
232
- }
233
- }
234
- });
235
- watcher.on("change", async (file) => {
236
- const rel = path.relative(SRC_DIR, file);
237
- logWatch(`📝 File changed: ${rel}`);
238
- if (file.endsWith('.ts') && compileFile(file)) {
239
- await restartNode();
240
- }
241
- });
242
- watcher.on("unlink", async (file) => {
243
- const rel = path.relative(SRC_DIR, file);
244
- logWatch(`🗑️ File removed: ${rel}`);
245
- const outFile = path
246
- .join(DIST_DIR, path.relative(SRC_DIR, file))
247
- .replace(/\.ts$/, ".js");
248
- if (fs.existsSync(outFile)) {
249
- fs.unlinkSync(outFile);
250
- logCompile(`✗ Removed ${path.relative(DIST_DIR, outFile)}`);
251
- }
252
- await restartNode();
253
- });
254
- // Debug: log all watcher events
255
- watcher.on('all', (eventName, path) => {
256
- if (!['add', 'change', 'unlink'].includes(eventName)) {
257
- logWatch(`🔍 Debug: ${eventName} -> ${path}`);
258
- }
259
- });
260
- watcher.on("error", (error) => {
261
- logError('WATCH', `Watcher error: ${error.message}`);
262
- });
263
- }
264
- // Graceful shutdown
265
- process.on("SIGINT", async () => {
266
- console.log();
267
- logWatch("🛑 Shutting down...");
268
- await killNode();
269
- process.exit(0);
270
- });
271
- process.on("SIGTERM", async () => {
272
- console.log();
273
- logWatch("🛑 Shutting down...");
274
- await killNode();
275
- process.exit(0);
276
- });
277
- // Main execution
278
- (async () => {
279
- console.log('\x1b[1m\x1b[36m🔧 Development Server\x1b[0m');
280
- console.log('━'.repeat(50));
281
- logWatch("🚀 Starting development server...");
282
- const compiled = compileAll();
283
- if (compiled > 0) {
284
- logCompile(`✅ Compiled ${compiled} file${compiled !== 1 ? 's' : ''}`);
285
- }
286
- startNode();
287
- watch();
288
- console.log('━'.repeat(50));
289
- logWatch("✨ Ready! Press Ctrl+C to stop");
290
- })();
package/dist/serve.js DELETED
@@ -1,311 +0,0 @@
1
- #!/usr/bin/env node
2
- const chokidar = require("chokidar");
3
- const { spawn } = require("child_process");
4
- const path = require("path");
5
- const fs = require("fs");
6
- const { transformFileSync } = require("@swc/core");
7
- const SRC_DIR = path.resolve(process.cwd(), "./src");
8
- const DIST_DIR = path.resolve(process.cwd(), "./dist");
9
- const pkg = fs.existsSync(path.join(process.cwd(), "package.json"))
10
- ? JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf8"))
11
- : {};
12
- const ENTRY_RELATIVE = pkg?.avleon?.entry || pkg?.main?.replace("src/", "dist/").replace(".ts", ".js") || "dist/server.js";
13
- const ENTRY_FILE = path.resolve(process.cwd(), ENTRY_RELATIVE);
14
- let nodeProcess = null;
15
- let isRestarting = false;
16
- // Color constants for better type safety
17
- const Colors = {
18
- RESET: '\x1b[0m',
19
- DIM: '\x1b[90m',
20
- WHITE: '\x1b[37m',
21
- CYAN: '\x1b[36m',
22
- GREEN: '\x1b[32m',
23
- YELLOW: '\x1b[33m',
24
- RED: '\x1b[31m',
25
- BOLD: '\x1b[1m'
26
- };
27
- // Unified logging with colors and timestamps
28
- function log(category, message, color = Colors.WHITE) {
29
- const timestamp = new Date().toTimeString().split(' ')[0];
30
- console.log(`${Colors.DIM}[${timestamp}]${Colors.RESET} ${color}[${category}]${Colors.RESET} ${message}`);
31
- }
32
- function logCompile(message) {
33
- log('COMPILE', message, Colors.CYAN);
34
- }
35
- function logServer(message) {
36
- log('AVLEON', message, Colors.GREEN);
37
- }
38
- function logWatch(message) {
39
- log('WATCH', message, Colors.YELLOW);
40
- }
41
- function logError(category, message) {
42
- log(category, message, Colors.RED);
43
- }
44
- // Helper function to check if file is a test file
45
- function isTestFile(filePath) {
46
- const filename = path.basename(filePath);
47
- return filename.includes('.test.') || filename.includes('.spec.');
48
- }
49
- // compile single TS file
50
- function compileFile(filePath) {
51
- try {
52
- const rel = path.relative(SRC_DIR, filePath);
53
- const outFile = path.join(DIST_DIR, rel).replace(/\.ts$/, ".js");
54
- const result = transformFileSync(filePath, {
55
- jsc: {
56
- parser: { syntax: "typescript", decorators: true },
57
- target: "es2022",
58
- transform: { decoratorMetadata: true },
59
- },
60
- module: { type: "commonjs" },
61
- sourceMaps: false,
62
- });
63
- fs.mkdirSync(path.dirname(outFile), { recursive: true });
64
- fs.writeFileSync(outFile, result.code, "utf8");
65
- //logCompile(`✓ ${rel}`);
66
- return true;
67
- }
68
- catch (error) {
69
- const errorMessage = error instanceof Error ? error.message : String(error);
70
- logError('COMPILE', `✗ ${path.relative(SRC_DIR, filePath)} - ${errorMessage}`);
71
- return false;
72
- }
73
- }
74
- // compile all TS (excluding test files)
75
- function compileAll(dir = SRC_DIR) {
76
- if (!fs.existsSync(dir)) {
77
- logError('COMPILE', `Source directory ${dir} does not exist`);
78
- return 0;
79
- }
80
- let compiled = 0;
81
- const files = fs.readdirSync(dir, { withFileTypes: true });
82
- for (const f of files) {
83
- const full = path.join(dir, f.name);
84
- if (f.isDirectory()) {
85
- compiled += compileAll(full);
86
- }
87
- else if (f.name.endsWith(".ts")) {
88
- // Skip test files
89
- if (isTestFile(full)) {
90
- // logWatch(`⏭️ Skipping test file: ${path.relative(SRC_DIR, full)}`);
91
- continue;
92
- }
93
- if (compileFile(full)) {
94
- compiled++;
95
- }
96
- }
97
- }
98
- return compiled;
99
- }
100
- // start Node with integrated output
101
- function startNode() {
102
- if (nodeProcess) {
103
- logServer("⚠️ Process already running, skipping start");
104
- return;
105
- }
106
- if (isRestarting) {
107
- // Reset the flag when actually starting
108
- isRestarting = false;
109
- }
110
- if (!fs.existsSync(ENTRY_FILE)) {
111
- logError('AVLEON', `Entry file ${ENTRY_FILE} does not exist`);
112
- return;
113
- }
114
- logServer("🚀 Starting server...");
115
- try {
116
- nodeProcess = spawn("node", [ENTRY_FILE], {
117
- stdio: ['ignore', 'pipe', 'pipe'],
118
- env: { ...process.env, FORCE_COLOR: '1' },
119
- detached: false // Ensure process stays attached
120
- });
121
- // Forward stdout with server prefix
122
- nodeProcess.stdout?.on('data', (data) => {
123
- const lines = data.toString().split('\n').filter((line) => line.trim());
124
- lines.forEach((line) => logServer(line));
125
- });
126
- // Forward stderr with server prefix
127
- nodeProcess.stderr?.on('data', (data) => {
128
- const lines = data.toString().split('\n').filter((line) => line.trim());
129
- lines.forEach((line) => logError('AVLEON', line));
130
- });
131
- nodeProcess.on("exit", (code, signal) => {
132
- const wasRestarting = isRestarting;
133
- nodeProcess = null;
134
- if (wasRestarting) {
135
- // This is expected during restart
136
- return;
137
- }
138
- if (code && code !== 0) {
139
- logError('AVLEON', `Process exited with code ${code}`);
140
- }
141
- else if (signal) {
142
- logServer(`Process terminated by signal ${signal}`);
143
- }
144
- isRestarting = false;
145
- });
146
- nodeProcess.on("error", (error) => {
147
- logError('AVLEON', `Process error: ${error.message}`);
148
- nodeProcess = null;
149
- isRestarting = false;
150
- });
151
- }
152
- catch (error) {
153
- const errorMessage = error instanceof Error ? error.message : String(error);
154
- logError('AVLEON', `Failed to start server: ${errorMessage}`);
155
- nodeProcess = null;
156
- isRestarting = false;
157
- }
158
- }
159
- // kill Node
160
- function killNode() {
161
- return new Promise((resolve) => {
162
- if (!nodeProcess)
163
- return resolve();
164
- logServer("🛑 Stopping server...");
165
- let resolved = false;
166
- const cleanup = () => {
167
- if (!resolved) {
168
- resolved = true;
169
- nodeProcess = null;
170
- logServer("✓ Server stopped");
171
- resolve();
172
- }
173
- };
174
- nodeProcess.once("exit", cleanup);
175
- nodeProcess.once("close", cleanup);
176
- // Try graceful shutdown first
177
- try {
178
- nodeProcess.kill("SIGTERM");
179
- }
180
- catch (error) {
181
- const errorMessage = error instanceof Error ? error.message : String(error);
182
- logError('AVLEON', `Error sending SIGTERM: ${errorMessage}`);
183
- }
184
- // Force kill after 1 second if still running
185
- const forceKillTimeout = setTimeout(() => {
186
- if (nodeProcess && !resolved) {
187
- logServer("⚠️ Force killing server...");
188
- try {
189
- nodeProcess.kill("SIGKILL");
190
- }
191
- catch (error) {
192
- const errorMessage = error instanceof Error ? error.message : String(error);
193
- logError('AVLEON', `Error sending SIGKILL: ${errorMessage}`);
194
- }
195
- setTimeout(cleanup, 100);
196
- }
197
- }, 1000);
198
- // Fallback timeout - always resolve within 3 seconds
199
- setTimeout(() => {
200
- clearTimeout(forceKillTimeout);
201
- if (!resolved) {
202
- logError('AVLEON', 'Force cleanup - process may still be running');
203
- nodeProcess = null;
204
- resolved = true;
205
- resolve();
206
- }
207
- }, 3000);
208
- });
209
- }
210
- // restart Node
211
- async function restartNode() {
212
- if (isRestarting) {
213
- logServer("⏳ Already restarting, skipping...");
214
- return;
215
- }
216
- isRestarting = true;
217
- logServer("🔄 Restarting server...");
218
- try {
219
- await killNode();
220
- // Add delay to ensure process is fully cleaned up
221
- await new Promise(resolve => setTimeout(resolve, 200));
222
- startNode();
223
- }
224
- catch (error) {
225
- const errorMessage = error instanceof Error ? error.message : String(error);
226
- logError('AVLEON', `Restart error: ${errorMessage}`);
227
- isRestarting = false;
228
- }
229
- }
230
- let restartTimer = null;
231
- async function debouncedRestart() {
232
- if (restartTimer)
233
- clearTimeout(restartTimer);
234
- restartTimer = setTimeout(async () => {
235
- restartTimer = null;
236
- await restartNode();
237
- }, 300); // wait 300ms after last change
238
- }
239
- // watch src
240
- function watch() {
241
- const watcher = chokidar.watch(SRC_DIR, {
242
- ignoreInitial: true,
243
- ignored: [
244
- /(^|[\/\\])\../, // ignore dotfiles
245
- /\.(test|spec)\.(ts|js)$/ // ignore test files
246
- ],
247
- persistent: true,
248
- followSymlinks: false,
249
- awaitWriteFinish: {
250
- stabilityThreshold: 100,
251
- pollInterval: 50
252
- }
253
- });
254
- watcher.on("add", (file) => {
255
- if (file.endsWith('.ts') && !isTestFile(file)) {
256
- if (compileFile(file)) {
257
- setTimeout(() => restartNode(), 100);
258
- }
259
- }
260
- });
261
- watcher.on("change", async (file) => {
262
- if (file.endsWith('.ts') && !isTestFile(file)) {
263
- if (compileFile(file)) {
264
- await debouncedRestart();
265
- }
266
- }
267
- });
268
- watcher.on("unlink", async (file) => {
269
- if (!isTestFile(file)) {
270
- const outFile = path
271
- .join(DIST_DIR, path.relative(SRC_DIR, file))
272
- .replace(/\.ts$/, ".js");
273
- if (fs.existsSync(outFile)) {
274
- fs.unlinkSync(outFile);
275
- }
276
- await restartNode();
277
- }
278
- });
279
- // Debug: log all watcher events
280
- watcher.on('all', (eventName, filePath) => {
281
- if (!['add', 'change', 'unlink'].includes(eventName)) {
282
- //logWatch(`🔍 Debug: ${eventName} -> ${filePath}`);
283
- }
284
- });
285
- watcher.on("error", (error) => {
286
- logError('WATCH', `Watcher error: ${error.message}`);
287
- });
288
- }
289
- process.on("uncaughtException", (error) => {
290
- logError('CLI', `Uncaught exception: ${error.message}`);
291
- logError('CLI', error.stack ?? "");
292
- });
293
- process.on("unhandledRejection", (reason) => {
294
- logError('CLI', `Unhandled rejection: ${reason}`);
295
- });
296
- // Graceful shutdown
297
- process.on("SIGINT", async () => {
298
- await killNode();
299
- process.exit(0);
300
- });
301
- // Main execution
302
- (async () => {
303
- console.log(`${Colors.BOLD}${Colors.CYAN}🔧 Development Server${Colors.RESET}`);
304
- console.log('━'.repeat(50));
305
- logWatch("🚀 Starting development server...");
306
- const compiled = compileAll();
307
- startNode();
308
- watch();
309
- console.log('━'.repeat(50));
310
- logWatch("✨ Ready! Press Ctrl+C to stop");
311
- })();
package/dist/service.js DELETED
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createService = createService;
7
- const fs_1 = require("fs");
8
- const path_1 = __importDefault(require("path"));
9
- const path_helper_1 = require("./helpers/path-helper");
10
- const promises_1 = __importDefault(require("node:fs/promises"));
11
- const file_helper_1 = require("./helpers/file-helper");
12
- const lodash_1 = require("lodash");
13
- function capitalize(str) {
14
- if (!str)
15
- return '';
16
- return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
17
- }
18
- function lower(str) {
19
- return str.toLowerCase();
20
- }
21
- const servicesStubs = {
22
- basic: path_helper_1.pathHelper.stubPath('services/basic-service.stub'),
23
- rest: path_helper_1.pathHelper.stubPath('services/rest-service.stub'),
24
- ormRest: path_helper_1.pathHelper.stubPath('services/orm-rest-service.stub')
25
- };
26
- async function createService(name, options = { force: false, resource: false, prefix: true, rest: false, model: null, root: null, orm: false }, p) {
27
- if (!name) {
28
- throw new Error("Service name not found. use --name or npx avleon make:service HomeService");
29
- }
30
- if ((options.rest || options.resource) && !options.model) {
31
- throw new Error("Model not found. Plese ensure you pass --model or -m to create resouce service");
32
- }
33
- // determine stub for generate
34
- let stubPath = servicesStubs.basic;
35
- if (options.rest || options.resource) {
36
- stubPath = options.orm ? servicesStubs.ormRest : servicesStubs.rest;
37
- }
38
- const rootPath = options.root ? 'src/' + options.root + '/' : 'src/services/';
39
- const outDir = path_1.default.join(rootPath, (0, file_helper_1.getFilePathWithoutName)(name));
40
- if (!(0, fs_1.existsSync)(outDir)) {
41
- await promises_1.default.mkdir(outDir, { recursive: true });
42
- }
43
- const content = await promises_1.default.readFile(stubPath, 'utf8');
44
- const names = (0, file_helper_1.resolveNames)(file_helper_1.fh.filenameFromPath(name), 'Service');
45
- const className = names.className.replace("Service", '');
46
- let replacedContent = content
47
- .replaceAll('{Service}', className)
48
- .replaceAll('{service}', names.varName);
49
- if (options.model) {
50
- replacedContent = replacedContent
51
- .replaceAll('{Model}', capitalize(options.model))
52
- .replaceAll('{model}', lower(options.model));
53
- }
54
- await promises_1.default.writeFile(path_1.default.join(outDir, (0, lodash_1.kebabCase)(className) + '.service.ts'), replacedContent, 'utf8');
55
- console.log("Service created successfully!");
56
- }
57
- async function createRestService(name, model) {
58
- let stubPath = path_helper_1.pathHelper.stubPath('services/rest-service.stub');
59
- const content = await promises_1.default.readFile(stubPath, 'utf8');
60
- let replacedContent = content
61
- .replaceAll('{Service}', name);
62
- if (model) {
63
- replacedContent = replacedContent
64
- .replaceAll('{Model}', capitalize(model))
65
- .replaceAll('{model}', lower(model));
66
- }
67
- await promises_1.default.writeFile(path_1.default.join('src/services/', (0, lodash_1.kebabCase)(name) + '.service.ts'), replacedContent, 'utf8');
68
- console.log("Service created succssessfully!");
69
- }