@veloxts/cli 0.6.31 → 0.6.52
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/CHANGELOG.md +252 -0
- package/dist/cli.js +2 -0
- package/dist/commands/schedule.d.ts +14 -0
- package/dist/commands/schedule.js +324 -0
- package/dist/generators/generators/event.d.ts +35 -0
- package/dist/generators/generators/event.js +99 -0
- package/dist/generators/generators/index.d.ts +5 -0
- package/dist/generators/generators/index.js +15 -0
- package/dist/generators/generators/job.d.ts +36 -0
- package/dist/generators/generators/job.js +98 -0
- package/dist/generators/generators/mail.d.ts +36 -0
- package/dist/generators/generators/mail.js +90 -0
- package/dist/generators/generators/storage.d.ts +35 -0
- package/dist/generators/generators/storage.js +104 -0
- package/dist/generators/generators/task.d.ts +36 -0
- package/dist/generators/generators/task.js +99 -0
- package/dist/generators/templates/event.d.ts +21 -0
- package/dist/generators/templates/event.js +410 -0
- package/dist/generators/templates/job.d.ts +23 -0
- package/dist/generators/templates/job.js +352 -0
- package/dist/generators/templates/mail.d.ts +21 -0
- package/dist/generators/templates/mail.js +411 -0
- package/dist/generators/templates/storage.d.ts +23 -0
- package/dist/generators/templates/storage.js +556 -0
- package/dist/generators/templates/task.d.ts +33 -0
- package/dist/generators/templates/task.js +189 -0
- package/package.json +8 -6
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Template
|
|
3
|
+
*
|
|
4
|
+
* Template for generating scheduled task files.
|
|
5
|
+
*/
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Path Helpers
|
|
8
|
+
// ============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Get the output path for a task file
|
|
11
|
+
*/
|
|
12
|
+
export function getTaskPath(entityName, _project) {
|
|
13
|
+
return `src/tasks/${entityName}.ts`;
|
|
14
|
+
}
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Templates
|
|
17
|
+
// ============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Generate a scheduled task file
|
|
20
|
+
*/
|
|
21
|
+
export function taskTemplate(context) {
|
|
22
|
+
const { entity, options } = context;
|
|
23
|
+
const className = entity.pascal;
|
|
24
|
+
const callbacksCode = options.callbacks
|
|
25
|
+
? `
|
|
26
|
+
.onSuccess((ctx, duration) => {
|
|
27
|
+
console.log(\`[${className}] Completed in \${duration}ms\`);
|
|
28
|
+
})
|
|
29
|
+
.onFailure((ctx, error) => {
|
|
30
|
+
console.error(\`[${className}] Failed:\`, error.message);
|
|
31
|
+
})`
|
|
32
|
+
: '';
|
|
33
|
+
const constraintsCode = options.constraints
|
|
34
|
+
? `
|
|
35
|
+
.weekdays() // Only run on Mon-Fri
|
|
36
|
+
.between('09:00', '17:00') // Only during business hours`
|
|
37
|
+
: '';
|
|
38
|
+
const noOverlapCode = options.noOverlap
|
|
39
|
+
? `
|
|
40
|
+
.withoutOverlapping()`
|
|
41
|
+
: '';
|
|
42
|
+
return `/**
|
|
43
|
+
* ${className} Task
|
|
44
|
+
*
|
|
45
|
+
* A scheduled task that runs on a cron-like schedule.
|
|
46
|
+
*
|
|
47
|
+
* @example Add to your schedule file:
|
|
48
|
+
* \`\`\`typescript
|
|
49
|
+
* import { ${className}Task } from './tasks/${entity.kebab}';
|
|
50
|
+
*
|
|
51
|
+
* export const schedule = defineSchedule([
|
|
52
|
+
* ${className}Task,
|
|
53
|
+
* // ... other tasks
|
|
54
|
+
* ]);
|
|
55
|
+
* \`\`\`
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
import { task } from '@veloxts/scheduler';
|
|
59
|
+
// import { db } from '../db';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* ${className} scheduled task
|
|
63
|
+
*
|
|
64
|
+
* Runs daily at 2:00 AM by default.
|
|
65
|
+
* Modify the schedule chain to adjust timing.
|
|
66
|
+
*/
|
|
67
|
+
export const ${className}Task = task('${entity.kebab}', async (ctx) => {
|
|
68
|
+
console.log(\`[${className}] Starting at \${ctx.startedAt.toISOString()}\`);
|
|
69
|
+
|
|
70
|
+
// TODO: Add your task logic here
|
|
71
|
+
// Example:
|
|
72
|
+
// const deleted = await db.expiredToken.deleteMany({
|
|
73
|
+
// where: { expiresAt: { lt: new Date() } }
|
|
74
|
+
// });
|
|
75
|
+
// console.log(\`[${className}] Cleaned up \${deleted.count} expired tokens\`);
|
|
76
|
+
|
|
77
|
+
console.log(\`[${className}] Completed\`);
|
|
78
|
+
})
|
|
79
|
+
.description('${className} scheduled task')
|
|
80
|
+
.daily()
|
|
81
|
+
.at('02:00')
|
|
82
|
+
.timezone('UTC')${noOverlapCode}${constraintsCode}${callbacksCode}
|
|
83
|
+
.build();
|
|
84
|
+
`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Generate a schedule file that imports and exports all tasks
|
|
88
|
+
*/
|
|
89
|
+
export function scheduleFileTemplate(taskNames) {
|
|
90
|
+
const imports = taskNames
|
|
91
|
+
.map((name) => {
|
|
92
|
+
const className = name
|
|
93
|
+
.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase())
|
|
94
|
+
.charAt(0)
|
|
95
|
+
.toUpperCase() + name.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase()).slice(1);
|
|
96
|
+
return `import { ${className}Task } from './tasks/${name}';`;
|
|
97
|
+
})
|
|
98
|
+
.join('\n');
|
|
99
|
+
const taskList = taskNames
|
|
100
|
+
.map((name) => {
|
|
101
|
+
const className = name
|
|
102
|
+
.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase())
|
|
103
|
+
.charAt(0)
|
|
104
|
+
.toUpperCase() + name.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase()).slice(1);
|
|
105
|
+
return ` ${className}Task,`;
|
|
106
|
+
})
|
|
107
|
+
.join('\n');
|
|
108
|
+
return `/**
|
|
109
|
+
* Application Schedule
|
|
110
|
+
*
|
|
111
|
+
* Define all scheduled tasks for your application here.
|
|
112
|
+
*
|
|
113
|
+
* Tasks are run via the scheduler:
|
|
114
|
+
* - velox schedule:work # Start the scheduler daemon
|
|
115
|
+
* - velox schedule:run # Run due tasks (call from system cron)
|
|
116
|
+
* - velox schedule:list # List all scheduled tasks
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
import { defineSchedule } from '@veloxts/scheduler';
|
|
120
|
+
|
|
121
|
+
${imports}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Application schedule definition
|
|
125
|
+
*
|
|
126
|
+
* Add to your app.ts:
|
|
127
|
+
* \`\`\`typescript
|
|
128
|
+
* import { schedulerPlugin } from '@veloxts/scheduler';
|
|
129
|
+
* import { schedule } from './schedule';
|
|
130
|
+
*
|
|
131
|
+
* app.register(schedulerPlugin, {
|
|
132
|
+
* tasks: schedule,
|
|
133
|
+
* autoStart: true,
|
|
134
|
+
* });
|
|
135
|
+
* \`\`\`
|
|
136
|
+
*/
|
|
137
|
+
export const schedule = defineSchedule([
|
|
138
|
+
${taskList}
|
|
139
|
+
]);
|
|
140
|
+
`;
|
|
141
|
+
}
|
|
142
|
+
// ============================================================================
|
|
143
|
+
// Post-generation Instructions
|
|
144
|
+
// ============================================================================
|
|
145
|
+
/**
|
|
146
|
+
* Get instructions to display after generating a task
|
|
147
|
+
*/
|
|
148
|
+
export function getTaskInstructions(entityName, options) {
|
|
149
|
+
const lines = [
|
|
150
|
+
`Task file created at src/tasks/${entityName}.ts`,
|
|
151
|
+
'',
|
|
152
|
+
'Next steps:',
|
|
153
|
+
'1. Implement your task logic in the handler function',
|
|
154
|
+
'2. Add the task to your schedule:',
|
|
155
|
+
'',
|
|
156
|
+
' // src/schedule.ts',
|
|
157
|
+
` import { ${toPascalCase(entityName)}Task } from './tasks/${entityName}';`,
|
|
158
|
+
'',
|
|
159
|
+
' export const schedule = defineSchedule([',
|
|
160
|
+
` ${toPascalCase(entityName)}Task,`,
|
|
161
|
+
' ]);',
|
|
162
|
+
'',
|
|
163
|
+
'3. Register the scheduler plugin in your app:',
|
|
164
|
+
'',
|
|
165
|
+
' // app.ts',
|
|
166
|
+
" import { schedulerPlugin } from '@veloxts/scheduler';",
|
|
167
|
+
" import { schedule } from './schedule';",
|
|
168
|
+
'',
|
|
169
|
+
' app.register(schedulerPlugin, {',
|
|
170
|
+
' tasks: schedule,',
|
|
171
|
+
' autoStart: true,',
|
|
172
|
+
' });',
|
|
173
|
+
];
|
|
174
|
+
if (options.callbacks) {
|
|
175
|
+
lines.push('', '4. Customize the onSuccess/onFailure callbacks as needed');
|
|
176
|
+
}
|
|
177
|
+
if (options.constraints) {
|
|
178
|
+
lines.push('', '4. Adjust the weekdays() and between() constraints as needed');
|
|
179
|
+
}
|
|
180
|
+
return lines.join('\n');
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Convert kebab-case or snake_case to PascalCase
|
|
184
|
+
*/
|
|
185
|
+
function toPascalCase(str) {
|
|
186
|
+
return str
|
|
187
|
+
.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase())
|
|
188
|
+
.replace(/^[a-z]/, (c) => c.toUpperCase());
|
|
189
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veloxts/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.52",
|
|
4
4
|
"description": "Developer tooling and CLI commands for VeloxTS framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"picocolors": "1.1.1",
|
|
41
41
|
"pluralize": "8.0.0",
|
|
42
42
|
"tsx": "4.21.0",
|
|
43
|
-
"@veloxts/
|
|
44
|
-
"@veloxts/
|
|
45
|
-
"@veloxts/orm": "0.6.
|
|
46
|
-
"@veloxts/
|
|
47
|
-
"@veloxts/
|
|
43
|
+
"@veloxts/core": "0.6.52",
|
|
44
|
+
"@veloxts/auth": "0.6.52",
|
|
45
|
+
"@veloxts/orm": "0.6.52",
|
|
46
|
+
"@veloxts/router": "0.6.52",
|
|
47
|
+
"@veloxts/validation": "0.6.52"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@prisma/client": ">=7.0.0"
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"@types/node": "25.0.3",
|
|
55
55
|
"@types/pg": "8.15.4",
|
|
56
56
|
"@types/pluralize": "0.0.33",
|
|
57
|
+
"@vitest/coverage-v8": "4.0.16",
|
|
57
58
|
"tsd": "0.33.0",
|
|
58
59
|
"typescript": "5.9.3",
|
|
59
60
|
"vitest": "4.0.16"
|
|
@@ -84,6 +85,7 @@
|
|
|
84
85
|
"type-check": "tsc --noEmit",
|
|
85
86
|
"test": "vitest run",
|
|
86
87
|
"test:watch": "vitest",
|
|
88
|
+
"test:coverage": "vitest run --coverage",
|
|
87
89
|
"test:types": "tsd",
|
|
88
90
|
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
89
91
|
}
|