sprint-es 0.0.101 ā 0.0.104
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 +77 -68
- package/dist/esm/cli.js +78 -69
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -162,14 +162,17 @@ function getProjectRoot() {
|
|
|
162
162
|
}
|
|
163
163
|
const projectRoot = getProjectRoot();
|
|
164
164
|
function runCommand(cmd, envVars) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
165
|
+
return new Promise((resolve2, reject) => {
|
|
166
|
+
const child = child_process.spawn(cmd, [], {
|
|
167
|
+
cwd: projectRoot,
|
|
168
|
+
stdio: "inherit",
|
|
169
|
+
shell: true,
|
|
170
|
+
env: { ...process.env, ...envVars }
|
|
171
|
+
});
|
|
172
|
+
child.on("exit", (code) => {
|
|
173
|
+
if (code === 0 || code === null) resolve2();
|
|
174
|
+
else reject(new Error(`Command failed with exit code ${code}`));
|
|
175
|
+
});
|
|
173
176
|
});
|
|
174
177
|
}
|
|
175
178
|
function generateJWTSecret() {
|
|
@@ -384,66 +387,72 @@ async function runDoctor() {
|
|
|
384
387
|
}
|
|
385
388
|
logger.break();
|
|
386
389
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
390
|
+
async function main() {
|
|
391
|
+
switch (command) {
|
|
392
|
+
case "dev": {
|
|
393
|
+
console.log("š Starting development server with hot reload...");
|
|
394
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
395
|
+
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";
|
|
396
|
+
const devCmd = isTS ? `tsx --watch ${srcFile}` : `node --watch ${srcFile}`;
|
|
397
|
+
await runCommand(devCmd, { NODE_ENV: "development" });
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case "build": {
|
|
401
|
+
console.log("š Building for production...");
|
|
402
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
403
|
+
const buildCmd = "tsc && tsc-esm-fix --src=dist --ext=.js && tsc-alias";
|
|
404
|
+
if (isTS) {
|
|
405
|
+
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
406
|
+
const tsconfig = JSON.parse(stripJsonComments(fs.readFileSync(tsconfigPath, "utf-8")));
|
|
407
|
+
const originalInclude = tsconfig.include ?? [];
|
|
408
|
+
const patched = originalInclude.filter((p) => !p.includes("sprint.config"));
|
|
409
|
+
if (patched.length !== originalInclude.length) {
|
|
410
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify({ ...tsconfig, include: patched }, null, 4));
|
|
411
|
+
try {
|
|
412
|
+
await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
413
|
+
} finally {
|
|
414
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
|
|
415
|
+
}
|
|
416
|
+
} else await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
417
|
+
await runCommand(
|
|
418
|
+
"esbuild sprint.config.ts --outfile=dist/sprint.config.js --platform=node --format=esm --bundle=false",
|
|
419
|
+
{ NODE_ENV: "production" }
|
|
420
|
+
);
|
|
421
|
+
} else await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
case "start": {
|
|
425
|
+
console.log("š Starting production server...");
|
|
426
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
427
|
+
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";
|
|
428
|
+
await runCommand(`node ${entryFile}`, { NODE_ENV: "production" });
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
case "doctor":
|
|
432
|
+
runDoctor();
|
|
433
|
+
break;
|
|
434
|
+
case "generate-keys": {
|
|
435
|
+
const { publicKey, privateKey } = crypto__namespace.generateKeyPairSync("rsa", {
|
|
436
|
+
modulusLength: 2048,
|
|
437
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
438
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" }
|
|
439
|
+
});
|
|
440
|
+
console.log("\nš Generating JWT keys...\n");
|
|
441
|
+
console.log("JWT_PUBLIC_KEY='" + publicKey + "'");
|
|
442
|
+
console.log("\nJWT_PRIVATE_KEY='" + privateKey + "'");
|
|
443
|
+
console.log("\nJWT_ENCRYPTION_SECRET=" + generateJWTSecret());
|
|
444
|
+
console.log("\nš Add these to your .env file (use single quotes for multiline values):\n");
|
|
445
|
+
process.exit(0);
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
default:
|
|
449
|
+
console.error(`Unknown command: ${command}`);
|
|
450
|
+
console.log("Use --help for usage information");
|
|
451
|
+
process.exit(1);
|
|
443
452
|
}
|
|
444
|
-
default:
|
|
445
|
-
console.error(`Unknown command: ${command}`);
|
|
446
|
-
console.log("Use --help for usage information");
|
|
447
|
-
process.exit(1);
|
|
448
453
|
}
|
|
454
|
+
main().catch((err) => {
|
|
455
|
+
console.error(err);
|
|
456
|
+
process.exit(1);
|
|
457
|
+
});
|
|
449
458
|
exports.default = stripJsonComments;
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync, writeFileSync, readdirSync, statSync } from "fs";
|
|
3
3
|
import * as crypto from "crypto";
|
|
4
|
-
import {
|
|
4
|
+
import { resolve, join } from "path";
|
|
5
5
|
import { spawn } from "child_process";
|
|
6
6
|
const args = process.argv.slice(2);
|
|
7
7
|
const command = args[0];
|
|
@@ -143,14 +143,17 @@ function getProjectRoot() {
|
|
|
143
143
|
}
|
|
144
144
|
const projectRoot = getProjectRoot();
|
|
145
145
|
function runCommand(cmd, envVars) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
return new Promise((resolve2, reject) => {
|
|
147
|
+
const child = spawn(cmd, [], {
|
|
148
|
+
cwd: projectRoot,
|
|
149
|
+
stdio: "inherit",
|
|
150
|
+
shell: true,
|
|
151
|
+
env: { ...process.env, ...envVars }
|
|
152
|
+
});
|
|
153
|
+
child.on("exit", (code) => {
|
|
154
|
+
if (code === 0 || code === null) resolve2();
|
|
155
|
+
else reject(new Error(`Command failed with exit code ${code}`));
|
|
156
|
+
});
|
|
154
157
|
});
|
|
155
158
|
}
|
|
156
159
|
function generateJWTSecret() {
|
|
@@ -365,68 +368,74 @@ async function runDoctor() {
|
|
|
365
368
|
}
|
|
366
369
|
logger.break();
|
|
367
370
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
371
|
+
async function main() {
|
|
372
|
+
switch (command) {
|
|
373
|
+
case "dev": {
|
|
374
|
+
console.log("š Starting development server with hot reload...");
|
|
375
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
376
|
+
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";
|
|
377
|
+
const devCmd = isTS ? `tsx --watch ${srcFile}` : `node --watch ${srcFile}`;
|
|
378
|
+
await runCommand(devCmd, { NODE_ENV: "development" });
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
case "build": {
|
|
382
|
+
console.log("š Building for production...");
|
|
383
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
384
|
+
const buildCmd = "tsc && tsc-esm-fix --src=dist --ext=.js && tsc-alias";
|
|
385
|
+
if (isTS) {
|
|
386
|
+
const tsconfigPath = join(projectRoot, "tsconfig.json");
|
|
387
|
+
const tsconfig = JSON.parse(stripJsonComments(readFileSync(tsconfigPath, "utf-8")));
|
|
388
|
+
const originalInclude = tsconfig.include ?? [];
|
|
389
|
+
const patched = originalInclude.filter((p) => !p.includes("sprint.config"));
|
|
390
|
+
if (patched.length !== originalInclude.length) {
|
|
391
|
+
writeFileSync(tsconfigPath, JSON.stringify({ ...tsconfig, include: patched }, null, 4));
|
|
392
|
+
try {
|
|
393
|
+
await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
394
|
+
} finally {
|
|
395
|
+
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
|
|
396
|
+
}
|
|
397
|
+
} else await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
398
|
+
await runCommand(
|
|
399
|
+
"esbuild sprint.config.ts --outfile=dist/sprint.config.js --platform=node --format=esm --bundle=false",
|
|
400
|
+
{ NODE_ENV: "production" }
|
|
401
|
+
);
|
|
402
|
+
} else await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
case "start": {
|
|
406
|
+
console.log("š Starting production server...");
|
|
407
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
408
|
+
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";
|
|
409
|
+
await runCommand(`node ${entryFile}`, { NODE_ENV: "production" });
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
case "doctor":
|
|
413
|
+
runDoctor();
|
|
414
|
+
break;
|
|
415
|
+
case "generate-keys": {
|
|
416
|
+
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
|
|
417
|
+
modulusLength: 2048,
|
|
418
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
419
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" }
|
|
420
|
+
});
|
|
421
|
+
console.log("\nš Generating JWT keys...\n");
|
|
422
|
+
console.log("JWT_PUBLIC_KEY='" + publicKey + "'");
|
|
423
|
+
console.log("\nJWT_PRIVATE_KEY='" + privateKey + "'");
|
|
424
|
+
console.log("\nJWT_ENCRYPTION_SECRET=" + generateJWTSecret());
|
|
425
|
+
console.log("\nš Add these to your .env file (use single quotes for multiline values):\n");
|
|
426
|
+
process.exit(0);
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
default:
|
|
430
|
+
console.error(`Unknown command: ${command}`);
|
|
431
|
+
console.log("Use --help for usage information");
|
|
432
|
+
process.exit(1);
|
|
424
433
|
}
|
|
425
|
-
default:
|
|
426
|
-
console.error(`Unknown command: ${command}`);
|
|
427
|
-
console.log("Use --help for usage information");
|
|
428
|
-
process.exit(1);
|
|
429
434
|
}
|
|
435
|
+
main().catch((err) => {
|
|
436
|
+
console.error(err);
|
|
437
|
+
process.exit(1);
|
|
438
|
+
});
|
|
430
439
|
export {
|
|
431
440
|
stripJsonComments as default
|
|
432
441
|
};
|