sprint-es 0.0.91 ā 0.0.93
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 +14 -7
- package/dist/esm/cli.js +18 -8
- package/dist/esm/index.js +14 -7
- 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", "sprint.config.ts"] : ["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,21 +271,25 @@ class Sprint {
|
|
|
271
271
|
}
|
|
272
272
|
async init() {
|
|
273
273
|
const callerDir = process.cwd();
|
|
274
|
+
const basePath = isProd ? "dist" : "src";
|
|
275
|
+
path.join(callerDir, basePath, "middlewares");
|
|
276
|
+
path.join(callerDir, basePath, "routes");
|
|
277
|
+
path.join(callerDir, basePath, "cronjobs");
|
|
274
278
|
try {
|
|
275
|
-
const middlewaresCandidate = path.isAbsolute(this.middlewaresPath) ? this.middlewaresPath : path.join(callerDir, this.middlewaresPath);
|
|
279
|
+
const middlewaresCandidate = path.isAbsolute(this.middlewaresPath) ? this.middlewaresPath : path.join(callerDir, this.middlewaresPath.replace("./src/", `./${basePath}/`).replace("./dist/", `./${basePath}/`));
|
|
276
280
|
if (fs.existsSync(middlewaresCandidate) && fs.statSync(middlewaresCandidate).isDirectory()) await this.loadMiddlewares(middlewaresCandidate);
|
|
277
281
|
else if (isVerbose) console.log(`[Sprint] Middlewares folder not found at: ${middlewaresCandidate}, skipping.`);
|
|
278
282
|
} catch (err) {
|
|
279
283
|
console.error("[Sprint] Failed to load middlewares:", err);
|
|
280
284
|
}
|
|
281
285
|
try {
|
|
282
|
-
const routesCandidate = path.isAbsolute(this.routesPath) ? this.routesPath : path.join(callerDir, this.routesPath);
|
|
286
|
+
const routesCandidate = path.isAbsolute(this.routesPath) ? this.routesPath : path.join(callerDir, this.routesPath.replace("./src/", `./${basePath}/`).replace("./dist/", `./${basePath}/`));
|
|
283
287
|
if (fs.existsSync(routesCandidate) && fs.statSync(routesCandidate).isDirectory()) await this.loadRoutes(routesCandidate);
|
|
284
288
|
} catch (err) {
|
|
285
289
|
console.error("[Sprint] Failed to load routes:", err);
|
|
286
290
|
}
|
|
287
291
|
try {
|
|
288
|
-
const cronjobsCandidate = path.isAbsolute(this.cronjobsPath) ? this.cronjobsPath : path.join(callerDir, this.cronjobsPath);
|
|
292
|
+
const cronjobsCandidate = path.isAbsolute(this.cronjobsPath) ? this.cronjobsPath : path.join(callerDir, this.cronjobsPath.replace("./src/", `./${basePath}/`).replace("./dist/", `./${basePath}/`));
|
|
289
293
|
if (fs.existsSync(cronjobsCandidate) && fs.statSync(cronjobsCandidate).isDirectory()) await this.loadCronJobs(cronjobsCandidate);
|
|
290
294
|
else if (isVerbose) console.log(`[Sprint] Cronjobs folder not found at: ${cronjobsCandidate}, skipping.`);
|
|
291
295
|
} catch (err) {
|
|
@@ -360,11 +364,12 @@ class Sprint {
|
|
|
360
364
|
* Load all middleware files from the middlewares folder
|
|
361
365
|
*/
|
|
362
366
|
async loadMiddlewares(middlewaresPath) {
|
|
367
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
363
368
|
const files = await fs.promises.readdir(middlewaresPath);
|
|
364
369
|
for (const file of files) {
|
|
365
370
|
const filePath = path.join(middlewaresPath, file);
|
|
366
371
|
const stat = await fs.promises.stat(filePath);
|
|
367
|
-
if (stat.isFile() &&
|
|
372
|
+
if (stat.isFile() && file.endsWith(fileExt)) {
|
|
368
373
|
try {
|
|
369
374
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
370
375
|
const module2 = await import(moduleUrl);
|
|
@@ -398,13 +403,14 @@ class Sprint {
|
|
|
398
403
|
});
|
|
399
404
|
}
|
|
400
405
|
async loadRoutes(routesPath) {
|
|
406
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
401
407
|
const walkDir = async (dir) => {
|
|
402
408
|
const files = await fs.promises.readdir(dir);
|
|
403
409
|
for (const file of files) {
|
|
404
410
|
const filePath = path.join(dir, file);
|
|
405
411
|
const stat = await fs.promises.stat(filePath);
|
|
406
412
|
if (stat.isDirectory()) await walkDir(filePath);
|
|
407
|
-
else if (stat.isFile() &&
|
|
413
|
+
else if (stat.isFile() && file.endsWith(fileExt)) {
|
|
408
414
|
try {
|
|
409
415
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
410
416
|
const module2 = await import(moduleUrl);
|
|
@@ -456,11 +462,12 @@ class Sprint {
|
|
|
456
462
|
await walkDir(routesPath);
|
|
457
463
|
}
|
|
458
464
|
async loadCronJobs(cronjobsPath) {
|
|
465
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
459
466
|
const files = await fs.promises.readdir(cronjobsPath);
|
|
460
467
|
for (const file of files) {
|
|
461
468
|
const filePath = path.join(cronjobsPath, file);
|
|
462
469
|
const stat = await fs.promises.stat(filePath);
|
|
463
|
-
if (stat.isFile() &&
|
|
470
|
+
if (stat.isFile() && file.endsWith(fileExt)) {
|
|
464
471
|
try {
|
|
465
472
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
466
473
|
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", "sprint.config.ts"] : ["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,21 +246,25 @@ class Sprint {
|
|
|
246
246
|
}
|
|
247
247
|
async init() {
|
|
248
248
|
const callerDir = process.cwd();
|
|
249
|
+
const basePath = isProd ? "dist" : "src";
|
|
250
|
+
path.join(callerDir, basePath, "middlewares");
|
|
251
|
+
path.join(callerDir, basePath, "routes");
|
|
252
|
+
path.join(callerDir, basePath, "cronjobs");
|
|
249
253
|
try {
|
|
250
|
-
const middlewaresCandidate = path.isAbsolute(this.middlewaresPath) ? this.middlewaresPath : path.join(callerDir, this.middlewaresPath);
|
|
254
|
+
const middlewaresCandidate = path.isAbsolute(this.middlewaresPath) ? this.middlewaresPath : path.join(callerDir, this.middlewaresPath.replace("./src/", `./${basePath}/`).replace("./dist/", `./${basePath}/`));
|
|
251
255
|
if (fs.existsSync(middlewaresCandidate) && fs.statSync(middlewaresCandidate).isDirectory()) await this.loadMiddlewares(middlewaresCandidate);
|
|
252
256
|
else if (isVerbose) console.log(`[Sprint] Middlewares folder not found at: ${middlewaresCandidate}, skipping.`);
|
|
253
257
|
} catch (err) {
|
|
254
258
|
console.error("[Sprint] Failed to load middlewares:", err);
|
|
255
259
|
}
|
|
256
260
|
try {
|
|
257
|
-
const routesCandidate = path.isAbsolute(this.routesPath) ? this.routesPath : path.join(callerDir, this.routesPath);
|
|
261
|
+
const routesCandidate = path.isAbsolute(this.routesPath) ? this.routesPath : path.join(callerDir, this.routesPath.replace("./src/", `./${basePath}/`).replace("./dist/", `./${basePath}/`));
|
|
258
262
|
if (fs.existsSync(routesCandidate) && fs.statSync(routesCandidate).isDirectory()) await this.loadRoutes(routesCandidate);
|
|
259
263
|
} catch (err) {
|
|
260
264
|
console.error("[Sprint] Failed to load routes:", err);
|
|
261
265
|
}
|
|
262
266
|
try {
|
|
263
|
-
const cronjobsCandidate = path.isAbsolute(this.cronjobsPath) ? this.cronjobsPath : path.join(callerDir, this.cronjobsPath);
|
|
267
|
+
const cronjobsCandidate = path.isAbsolute(this.cronjobsPath) ? this.cronjobsPath : path.join(callerDir, this.cronjobsPath.replace("./src/", `./${basePath}/`).replace("./dist/", `./${basePath}/`));
|
|
264
268
|
if (fs.existsSync(cronjobsCandidate) && fs.statSync(cronjobsCandidate).isDirectory()) await this.loadCronJobs(cronjobsCandidate);
|
|
265
269
|
else if (isVerbose) console.log(`[Sprint] Cronjobs folder not found at: ${cronjobsCandidate}, skipping.`);
|
|
266
270
|
} catch (err) {
|
|
@@ -335,11 +339,12 @@ class Sprint {
|
|
|
335
339
|
* Load all middleware files from the middlewares folder
|
|
336
340
|
*/
|
|
337
341
|
async loadMiddlewares(middlewaresPath) {
|
|
342
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
338
343
|
const files = await fs.promises.readdir(middlewaresPath);
|
|
339
344
|
for (const file of files) {
|
|
340
345
|
const filePath = path.join(middlewaresPath, file);
|
|
341
346
|
const stat = await fs.promises.stat(filePath);
|
|
342
|
-
if (stat.isFile() &&
|
|
347
|
+
if (stat.isFile() && file.endsWith(fileExt)) {
|
|
343
348
|
try {
|
|
344
349
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
345
350
|
const module = await import(moduleUrl);
|
|
@@ -373,13 +378,14 @@ class Sprint {
|
|
|
373
378
|
});
|
|
374
379
|
}
|
|
375
380
|
async loadRoutes(routesPath) {
|
|
381
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
376
382
|
const walkDir = async (dir) => {
|
|
377
383
|
const files = await fs.promises.readdir(dir);
|
|
378
384
|
for (const file of files) {
|
|
379
385
|
const filePath = path.join(dir, file);
|
|
380
386
|
const stat = await fs.promises.stat(filePath);
|
|
381
387
|
if (stat.isDirectory()) await walkDir(filePath);
|
|
382
|
-
else if (stat.isFile() &&
|
|
388
|
+
else if (stat.isFile() && file.endsWith(fileExt)) {
|
|
383
389
|
try {
|
|
384
390
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
385
391
|
const module = await import(moduleUrl);
|
|
@@ -431,11 +437,12 @@ class Sprint {
|
|
|
431
437
|
await walkDir(routesPath);
|
|
432
438
|
}
|
|
433
439
|
async loadCronJobs(cronjobsPath) {
|
|
440
|
+
const fileExt = isProd ? ".js" : ".ts";
|
|
434
441
|
const files = await fs.promises.readdir(cronjobsPath);
|
|
435
442
|
for (const file of files) {
|
|
436
443
|
const filePath = path.join(cronjobsPath, file);
|
|
437
444
|
const stat = await fs.promises.stat(filePath);
|
|
438
|
-
if (stat.isFile() &&
|
|
445
|
+
if (stat.isFile() && file.endsWith(fileExt)) {
|
|
439
446
|
try {
|
|
440
447
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
441
448
|
await import(moduleUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sprint.d.ts","sourceRoot":"","sources":["../../src/sprint.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAA+B,gBAAgB,EAAoB,MAAM,SAAS,CAAC;AACnG,OAAO,OAAO,EAAE,EAAE,WAAW,EAAoD,MAAM,SAAS,CAAC;AAejG,eAAO,MAAM,aAAa,SAAQ,CAAC;AACnC,eAAO,MAAM,YAAY,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"sprint.d.ts","sourceRoot":"","sources":["../../src/sprint.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAA+B,gBAAgB,EAAoB,MAAM,SAAS,CAAC;AACnG,OAAO,OAAO,EAAE,EAAE,WAAW,EAAoD,MAAM,SAAS,CAAC;AAejG,eAAO,MAAM,aAAa,SAAQ,CAAC;AACnC,eAAO,MAAM,YAAY,SAAS,CAAC;AAoDnC,qBAAa,MAAM;IACR,GAAG,EAAE,WAAW,CAAC;IACxB,OAAO,CAAC,IAAI,CAAwD;IACpE,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,YAAY,CAAwB;IAC5C,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,OAAO,CAcb;IACF,OAAO,CAAC,OAAO,CAcb;IACF,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,gBAAgB,CAIhB;;YAsJM,IAAI;IAyClB,OAAO,CAAC,YAAY;IAiDpB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA4B9B;;OAEG;YACW,eAAe;IAiC7B,OAAO,CAAC,eAAe;YAiBT,UAAU;YAkFV,YAAY;IAoB1B,OAAO,CAAC,YAAY;IAgCpB,+BAA+B;IAC/B,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,mBAAmB;IA+K3B,OAAO,CAAC,kBAAkB;IAqC1B,OAAO,CAAC,kBAAkB;IA8B1B,OAAO,CAAC,mBAAmB;IA+BpB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAClC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACnC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAClC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACrC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACpC,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,GAAG,gBAAgB,EAAE,YAAY,CAAC,EAAE,OAAO;IAY9E,gBAAgB,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI;IAIvC,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;CA8DzC"}
|