sprint-es 0.0.91 ā 0.0.94
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/dist/cjs/cli.cjs +18 -8
- package/dist/cjs/index.cjs +24 -12
- package/dist/esm/cli.js +18 -8
- package/dist/esm/index.js +24 -12
- package/dist/types/sprint.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -296,23 +296,32 @@ async function runDoctor() {
|
|
|
296
296
|
logger.break();
|
|
297
297
|
}
|
|
298
298
|
switch (command) {
|
|
299
|
-
case "dev":
|
|
299
|
+
case "dev": {
|
|
300
300
|
console.log("š Starting development server with hot reload...");
|
|
301
|
-
const
|
|
302
|
-
|
|
301
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
302
|
+
const srcFile = isTS ? fs.existsSync(path.join(projectRoot, "src/app.ts")) ? "src/app.ts" : "src/index.ts" : fs.existsSync(path.join(projectRoot, "src/app.js")) ? "src/app.js" : "src/index.js";
|
|
303
|
+
const devCmd = isTS ? `tsx --watch ${srcFile}` : `node --watch ${srcFile}`;
|
|
304
|
+
runCommand(devCmd, { NODE_ENV: "development" });
|
|
303
305
|
break;
|
|
304
|
-
|
|
306
|
+
}
|
|
307
|
+
case "build": {
|
|
305
308
|
console.log("š Building for production...");
|
|
306
|
-
|
|
309
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
310
|
+
const buildCmd = isTS ? "tsc && tsc-alias" : "echo 'No build step needed for JS projects'";
|
|
311
|
+
runCommand(buildCmd, { NODE_ENV: "production" });
|
|
307
312
|
break;
|
|
308
|
-
|
|
313
|
+
}
|
|
314
|
+
case "start": {
|
|
309
315
|
console.log("š Starting production server...");
|
|
310
|
-
|
|
316
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
317
|
+
const entryFile = isTS ? fs.existsSync(path.join(projectRoot, "dist/app.js")) ? "dist/app.js" : "dist/index.js" : fs.existsSync(path.join(projectRoot, "src/app.js")) ? "src/app.js" : "src/index.js";
|
|
318
|
+
runCommand(`node ${entryFile}`, { NODE_ENV: "production" });
|
|
311
319
|
break;
|
|
320
|
+
}
|
|
312
321
|
case "doctor":
|
|
313
322
|
runDoctor();
|
|
314
323
|
break;
|
|
315
|
-
case "generate-keys":
|
|
324
|
+
case "generate-keys": {
|
|
316
325
|
const { publicKey, privateKey } = crypto__namespace.generateKeyPairSync("rsa", {
|
|
317
326
|
modulusLength: 2048,
|
|
318
327
|
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
@@ -325,6 +334,7 @@ switch (command) {
|
|
|
325
334
|
console.log("\nš Add these to your .env file (use single quotes for multiline values):\n");
|
|
326
335
|
process.exit(0);
|
|
327
336
|
break;
|
|
337
|
+
}
|
|
328
338
|
default:
|
|
329
339
|
console.error(`Unknown command: ${command}`);
|
|
330
340
|
console.log("Use --help for usage information");
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -103,7 +103,7 @@ async function loadSprintConfig() {
|
|
|
103
103
|
const callerDir = process.cwd();
|
|
104
104
|
const projectRoot = await findProjectRoot(callerDir);
|
|
105
105
|
if (!projectRoot) return null;
|
|
106
|
-
const configFiles = ["sprint.config.ts", "sprint.config.js"];
|
|
106
|
+
const configFiles = isProd ? ["sprint.config.js", "dist/sprint.config.js"] : ["sprint.config.ts", "sprint.config.js"];
|
|
107
107
|
for (const configFile of configFiles) {
|
|
108
108
|
const configPath = path.join(projectRoot, configFile);
|
|
109
109
|
if (!fs.existsSync(configPath)) continue;
|
|
@@ -271,23 +271,32 @@ class Sprint {
|
|
|
271
271
|
}
|
|
272
272
|
async init() {
|
|
273
273
|
const callerDir = process.cwd();
|
|
274
|
+
const normalizePath = (p) => {
|
|
275
|
+
if (path.isAbsolute(p)) return p;
|
|
276
|
+
return isProd ? p.replace(/\bsrc\b/, "dist") : p.replace(/\bdist\b/, "src");
|
|
277
|
+
};
|
|
278
|
+
const middlewaresCandidate = normalizePath(this.middlewaresPath);
|
|
279
|
+
const routesCandidate = normalizePath(this.routesPath);
|
|
280
|
+
const cronjobsCandidate = normalizePath(this.cronjobsPath);
|
|
281
|
+
const resolve = (p) => path.isAbsolute(p) ? p : path.join(callerDir, p);
|
|
274
282
|
try {
|
|
275
|
-
const
|
|
276
|
-
if (fs.existsSync(
|
|
277
|
-
else if (isVerbose) console.log(`[Sprint] Middlewares folder not found at: ${
|
|
283
|
+
const fullPath = resolve(middlewaresCandidate);
|
|
284
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) await this.loadMiddlewares(fullPath);
|
|
285
|
+
else if (isVerbose) console.log(`[Sprint] Middlewares folder not found at: ${fullPath}, skipping.`);
|
|
278
286
|
} catch (err) {
|
|
279
287
|
console.error("[Sprint] Failed to load middlewares:", err);
|
|
280
288
|
}
|
|
281
289
|
try {
|
|
282
|
-
const
|
|
283
|
-
if (fs.existsSync(
|
|
290
|
+
const fullPath = resolve(routesCandidate);
|
|
291
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) await this.loadRoutes(fullPath);
|
|
292
|
+
else console.warn(`[Sprint] Routes folder not found at: ${fullPath}`);
|
|
284
293
|
} catch (err) {
|
|
285
294
|
console.error("[Sprint] Failed to load routes:", err);
|
|
286
295
|
}
|
|
287
296
|
try {
|
|
288
|
-
const
|
|
289
|
-
if (fs.existsSync(
|
|
290
|
-
else if (isVerbose) console.log(`[Sprint] Cronjobs folder not found at: ${
|
|
297
|
+
const fullPath = resolve(cronjobsCandidate);
|
|
298
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) await this.loadCronJobs(fullPath);
|
|
299
|
+
else if (isVerbose) console.log(`[Sprint] Cronjobs folder not found at: ${fullPath}, skipping.`);
|
|
291
300
|
} catch (err) {
|
|
292
301
|
console.error("[Sprint] Failed to load cronjobs:", err);
|
|
293
302
|
}
|
|
@@ -360,11 +369,12 @@ class Sprint {
|
|
|
360
369
|
* Load all middleware files from the middlewares folder
|
|
361
370
|
*/
|
|
362
371
|
async loadMiddlewares(middlewaresPath) {
|
|
372
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
363
373
|
const files = await fs.promises.readdir(middlewaresPath);
|
|
364
374
|
for (const file of files) {
|
|
365
375
|
const filePath = path.join(middlewaresPath, file);
|
|
366
376
|
const stat = await fs.promises.stat(filePath);
|
|
367
|
-
if (stat.isFile() &&
|
|
377
|
+
if (stat.isFile() && file.endsWith(fileExt)) {
|
|
368
378
|
try {
|
|
369
379
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
370
380
|
const module2 = await import(moduleUrl);
|
|
@@ -398,13 +408,14 @@ class Sprint {
|
|
|
398
408
|
});
|
|
399
409
|
}
|
|
400
410
|
async loadRoutes(routesPath) {
|
|
411
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
401
412
|
const walkDir = async (dir) => {
|
|
402
413
|
const files = await fs.promises.readdir(dir);
|
|
403
414
|
for (const file of files) {
|
|
404
415
|
const filePath = path.join(dir, file);
|
|
405
416
|
const stat = await fs.promises.stat(filePath);
|
|
406
417
|
if (stat.isDirectory()) await walkDir(filePath);
|
|
407
|
-
else if (stat.isFile() &&
|
|
418
|
+
else if (stat.isFile() && file.endsWith(fileExt)) {
|
|
408
419
|
try {
|
|
409
420
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
410
421
|
const module2 = await import(moduleUrl);
|
|
@@ -456,11 +467,12 @@ class Sprint {
|
|
|
456
467
|
await walkDir(routesPath);
|
|
457
468
|
}
|
|
458
469
|
async loadCronJobs(cronjobsPath) {
|
|
470
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
459
471
|
const files = await fs.promises.readdir(cronjobsPath);
|
|
460
472
|
for (const file of files) {
|
|
461
473
|
const filePath = path.join(cronjobsPath, file);
|
|
462
474
|
const stat = await fs.promises.stat(filePath);
|
|
463
|
-
if (stat.isFile() &&
|
|
475
|
+
if (stat.isFile() && file.endsWith(fileExt)) {
|
|
464
476
|
try {
|
|
465
477
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
466
478
|
await import(moduleUrl);
|
package/dist/esm/cli.js
CHANGED
|
@@ -278,23 +278,32 @@ async function runDoctor() {
|
|
|
278
278
|
logger.break();
|
|
279
279
|
}
|
|
280
280
|
switch (command) {
|
|
281
|
-
case "dev":
|
|
281
|
+
case "dev": {
|
|
282
282
|
console.log("š Starting development server with hot reload...");
|
|
283
|
-
const
|
|
284
|
-
|
|
283
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
284
|
+
const srcFile = isTS ? existsSync(join(projectRoot, "src/app.ts")) ? "src/app.ts" : "src/index.ts" : existsSync(join(projectRoot, "src/app.js")) ? "src/app.js" : "src/index.js";
|
|
285
|
+
const devCmd = isTS ? `tsx --watch ${srcFile}` : `node --watch ${srcFile}`;
|
|
286
|
+
runCommand(devCmd, { NODE_ENV: "development" });
|
|
285
287
|
break;
|
|
286
|
-
|
|
288
|
+
}
|
|
289
|
+
case "build": {
|
|
287
290
|
console.log("š Building for production...");
|
|
288
|
-
|
|
291
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
292
|
+
const buildCmd = isTS ? "tsc && tsc-alias" : "echo 'No build step needed for JS projects'";
|
|
293
|
+
runCommand(buildCmd, { NODE_ENV: "production" });
|
|
289
294
|
break;
|
|
290
|
-
|
|
295
|
+
}
|
|
296
|
+
case "start": {
|
|
291
297
|
console.log("š Starting production server...");
|
|
292
|
-
|
|
298
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
299
|
+
const entryFile = isTS ? existsSync(join(projectRoot, "dist/app.js")) ? "dist/app.js" : "dist/index.js" : existsSync(join(projectRoot, "src/app.js")) ? "src/app.js" : "src/index.js";
|
|
300
|
+
runCommand(`node ${entryFile}`, { NODE_ENV: "production" });
|
|
293
301
|
break;
|
|
302
|
+
}
|
|
294
303
|
case "doctor":
|
|
295
304
|
runDoctor();
|
|
296
305
|
break;
|
|
297
|
-
case "generate-keys":
|
|
306
|
+
case "generate-keys": {
|
|
298
307
|
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
|
|
299
308
|
modulusLength: 2048,
|
|
300
309
|
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
@@ -307,6 +316,7 @@ switch (command) {
|
|
|
307
316
|
console.log("\nš Add these to your .env file (use single quotes for multiline values):\n");
|
|
308
317
|
process.exit(0);
|
|
309
318
|
break;
|
|
319
|
+
}
|
|
310
320
|
default:
|
|
311
321
|
console.error(`Unknown command: ${command}`);
|
|
312
322
|
console.log("Use --help for usage information");
|
package/dist/esm/index.js
CHANGED
|
@@ -78,7 +78,7 @@ async function loadSprintConfig() {
|
|
|
78
78
|
const callerDir = process.cwd();
|
|
79
79
|
const projectRoot = await findProjectRoot(callerDir);
|
|
80
80
|
if (!projectRoot) return null;
|
|
81
|
-
const configFiles = ["sprint.config.ts", "sprint.config.js"];
|
|
81
|
+
const configFiles = isProd ? ["sprint.config.js", "dist/sprint.config.js"] : ["sprint.config.ts", "sprint.config.js"];
|
|
82
82
|
for (const configFile of configFiles) {
|
|
83
83
|
const configPath = path.join(projectRoot, configFile);
|
|
84
84
|
if (!fs.existsSync(configPath)) continue;
|
|
@@ -246,23 +246,32 @@ class Sprint {
|
|
|
246
246
|
}
|
|
247
247
|
async init() {
|
|
248
248
|
const callerDir = process.cwd();
|
|
249
|
+
const normalizePath = (p) => {
|
|
250
|
+
if (path.isAbsolute(p)) return p;
|
|
251
|
+
return isProd ? p.replace(/\bsrc\b/, "dist") : p.replace(/\bdist\b/, "src");
|
|
252
|
+
};
|
|
253
|
+
const middlewaresCandidate = normalizePath(this.middlewaresPath);
|
|
254
|
+
const routesCandidate = normalizePath(this.routesPath);
|
|
255
|
+
const cronjobsCandidate = normalizePath(this.cronjobsPath);
|
|
256
|
+
const resolve = (p) => path.isAbsolute(p) ? p : path.join(callerDir, p);
|
|
249
257
|
try {
|
|
250
|
-
const
|
|
251
|
-
if (fs.existsSync(
|
|
252
|
-
else if (isVerbose) console.log(`[Sprint] Middlewares folder not found at: ${
|
|
258
|
+
const fullPath = resolve(middlewaresCandidate);
|
|
259
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) await this.loadMiddlewares(fullPath);
|
|
260
|
+
else if (isVerbose) console.log(`[Sprint] Middlewares folder not found at: ${fullPath}, skipping.`);
|
|
253
261
|
} catch (err) {
|
|
254
262
|
console.error("[Sprint] Failed to load middlewares:", err);
|
|
255
263
|
}
|
|
256
264
|
try {
|
|
257
|
-
const
|
|
258
|
-
if (fs.existsSync(
|
|
265
|
+
const fullPath = resolve(routesCandidate);
|
|
266
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) await this.loadRoutes(fullPath);
|
|
267
|
+
else console.warn(`[Sprint] Routes folder not found at: ${fullPath}`);
|
|
259
268
|
} catch (err) {
|
|
260
269
|
console.error("[Sprint] Failed to load routes:", err);
|
|
261
270
|
}
|
|
262
271
|
try {
|
|
263
|
-
const
|
|
264
|
-
if (fs.existsSync(
|
|
265
|
-
else if (isVerbose) console.log(`[Sprint] Cronjobs folder not found at: ${
|
|
272
|
+
const fullPath = resolve(cronjobsCandidate);
|
|
273
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) await this.loadCronJobs(fullPath);
|
|
274
|
+
else if (isVerbose) console.log(`[Sprint] Cronjobs folder not found at: ${fullPath}, skipping.`);
|
|
266
275
|
} catch (err) {
|
|
267
276
|
console.error("[Sprint] Failed to load cronjobs:", err);
|
|
268
277
|
}
|
|
@@ -335,11 +344,12 @@ class Sprint {
|
|
|
335
344
|
* Load all middleware files from the middlewares folder
|
|
336
345
|
*/
|
|
337
346
|
async loadMiddlewares(middlewaresPath) {
|
|
347
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
338
348
|
const files = await fs.promises.readdir(middlewaresPath);
|
|
339
349
|
for (const file of files) {
|
|
340
350
|
const filePath = path.join(middlewaresPath, file);
|
|
341
351
|
const stat = await fs.promises.stat(filePath);
|
|
342
|
-
if (stat.isFile() &&
|
|
352
|
+
if (stat.isFile() && file.endsWith(fileExt)) {
|
|
343
353
|
try {
|
|
344
354
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
345
355
|
const module = await import(moduleUrl);
|
|
@@ -373,13 +383,14 @@ class Sprint {
|
|
|
373
383
|
});
|
|
374
384
|
}
|
|
375
385
|
async loadRoutes(routesPath) {
|
|
386
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
376
387
|
const walkDir = async (dir) => {
|
|
377
388
|
const files = await fs.promises.readdir(dir);
|
|
378
389
|
for (const file of files) {
|
|
379
390
|
const filePath = path.join(dir, file);
|
|
380
391
|
const stat = await fs.promises.stat(filePath);
|
|
381
392
|
if (stat.isDirectory()) await walkDir(filePath);
|
|
382
|
-
else if (stat.isFile() &&
|
|
393
|
+
else if (stat.isFile() && file.endsWith(fileExt)) {
|
|
383
394
|
try {
|
|
384
395
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
385
396
|
const module = await import(moduleUrl);
|
|
@@ -431,11 +442,12 @@ class Sprint {
|
|
|
431
442
|
await walkDir(routesPath);
|
|
432
443
|
}
|
|
433
444
|
async loadCronJobs(cronjobsPath) {
|
|
445
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
434
446
|
const files = await fs.promises.readdir(cronjobsPath);
|
|
435
447
|
for (const file of files) {
|
|
436
448
|
const filePath = path.join(cronjobsPath, file);
|
|
437
449
|
const stat = await fs.promises.stat(filePath);
|
|
438
|
-
if (stat.isFile() &&
|
|
450
|
+
if (stat.isFile() && file.endsWith(fileExt)) {
|
|
439
451
|
try {
|
|
440
452
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
441
453
|
await import(moduleUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sprint.d.ts","sourceRoot":"","sources":["../../src/sprint.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO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