sprint-es 0.0.102 ā 0.0.105
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 +80 -68
- package/dist/esm/cli.js +81 -69
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -162,14 +162,20 @@ 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 {
|
|
175
|
+
console.error(`Command failed with exit code ${code}`);
|
|
176
|
+
process.exit(code);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
173
179
|
});
|
|
174
180
|
}
|
|
175
181
|
function generateJWTSecret() {
|
|
@@ -384,66 +390,72 @@ async function runDoctor() {
|
|
|
384
390
|
}
|
|
385
391
|
logger.break();
|
|
386
392
|
}
|
|
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
|
-
|
|
393
|
+
async function main() {
|
|
394
|
+
switch (command) {
|
|
395
|
+
case "dev": {
|
|
396
|
+
console.log("š Starting development server with hot reload...");
|
|
397
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
398
|
+
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";
|
|
399
|
+
const devCmd = isTS ? `tsx --watch ${srcFile}` : `node --watch ${srcFile}`;
|
|
400
|
+
await runCommand(devCmd, { NODE_ENV: "development" });
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
case "build": {
|
|
404
|
+
console.log("š Building for production...");
|
|
405
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
406
|
+
const buildCmd = "tsc && tsc-esm-fix --src=dist --ext=.js && tsc-alias";
|
|
407
|
+
if (isTS) {
|
|
408
|
+
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
409
|
+
const tsconfig = JSON.parse(stripJsonComments(fs.readFileSync(tsconfigPath, "utf-8")));
|
|
410
|
+
const originalInclude = tsconfig.include ?? [];
|
|
411
|
+
const patched = originalInclude.filter((p) => !p.includes("sprint.config"));
|
|
412
|
+
if (patched.length !== originalInclude.length) {
|
|
413
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify({ ...tsconfig, include: patched }, null, 4));
|
|
414
|
+
try {
|
|
415
|
+
await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
416
|
+
} finally {
|
|
417
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
|
|
418
|
+
}
|
|
419
|
+
} else await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
420
|
+
await runCommand(
|
|
421
|
+
"esbuild sprint.config.ts --outfile=dist/sprint.config.js --platform=node --format=esm --bundle=false",
|
|
422
|
+
{ NODE_ENV: "production" }
|
|
423
|
+
);
|
|
424
|
+
} else await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
case "start": {
|
|
428
|
+
console.log("š Starting production server...");
|
|
429
|
+
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
430
|
+
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";
|
|
431
|
+
await runCommand(`node ${entryFile}`, { NODE_ENV: "production" });
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
case "doctor":
|
|
435
|
+
runDoctor();
|
|
436
|
+
break;
|
|
437
|
+
case "generate-keys": {
|
|
438
|
+
const { publicKey, privateKey } = crypto__namespace.generateKeyPairSync("rsa", {
|
|
439
|
+
modulusLength: 2048,
|
|
440
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
441
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" }
|
|
442
|
+
});
|
|
443
|
+
console.log("\nš Generating JWT keys...\n");
|
|
444
|
+
console.log("JWT_PUBLIC_KEY='" + publicKey + "'");
|
|
445
|
+
console.log("\nJWT_PRIVATE_KEY='" + privateKey + "'");
|
|
446
|
+
console.log("\nJWT_ENCRYPTION_SECRET=" + generateJWTSecret());
|
|
447
|
+
console.log("\nš Add these to your .env file (use single quotes for multiline values):\n");
|
|
448
|
+
process.exit(0);
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
default:
|
|
452
|
+
console.error(`Unknown command: ${command}`);
|
|
453
|
+
console.log("Use --help for usage information");
|
|
454
|
+
process.exit(1);
|
|
443
455
|
}
|
|
444
|
-
default:
|
|
445
|
-
console.error(`Unknown command: ${command}`);
|
|
446
|
-
console.log("Use --help for usage information");
|
|
447
|
-
process.exit(1);
|
|
448
456
|
}
|
|
457
|
+
main().then(() => process.exit(0)).catch((err) => {
|
|
458
|
+
console.error(err);
|
|
459
|
+
process.exit(1);
|
|
460
|
+
});
|
|
449
461
|
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,20 @@ 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 {
|
|
156
|
+
console.error(`Command failed with exit code ${code}`);
|
|
157
|
+
process.exit(code);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
154
160
|
});
|
|
155
161
|
}
|
|
156
162
|
function generateJWTSecret() {
|
|
@@ -365,68 +371,74 @@ async function runDoctor() {
|
|
|
365
371
|
}
|
|
366
372
|
logger.break();
|
|
367
373
|
}
|
|
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
|
-
|
|
374
|
+
async function main() {
|
|
375
|
+
switch (command) {
|
|
376
|
+
case "dev": {
|
|
377
|
+
console.log("š Starting development server with hot reload...");
|
|
378
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
379
|
+
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";
|
|
380
|
+
const devCmd = isTS ? `tsx --watch ${srcFile}` : `node --watch ${srcFile}`;
|
|
381
|
+
await runCommand(devCmd, { NODE_ENV: "development" });
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
case "build": {
|
|
385
|
+
console.log("š Building for production...");
|
|
386
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
387
|
+
const buildCmd = "tsc && tsc-esm-fix --src=dist --ext=.js && tsc-alias";
|
|
388
|
+
if (isTS) {
|
|
389
|
+
const tsconfigPath = join(projectRoot, "tsconfig.json");
|
|
390
|
+
const tsconfig = JSON.parse(stripJsonComments(readFileSync(tsconfigPath, "utf-8")));
|
|
391
|
+
const originalInclude = tsconfig.include ?? [];
|
|
392
|
+
const patched = originalInclude.filter((p) => !p.includes("sprint.config"));
|
|
393
|
+
if (patched.length !== originalInclude.length) {
|
|
394
|
+
writeFileSync(tsconfigPath, JSON.stringify({ ...tsconfig, include: patched }, null, 4));
|
|
395
|
+
try {
|
|
396
|
+
await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
397
|
+
} finally {
|
|
398
|
+
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
|
|
399
|
+
}
|
|
400
|
+
} else await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
401
|
+
await runCommand(
|
|
402
|
+
"esbuild sprint.config.ts --outfile=dist/sprint.config.js --platform=node --format=esm --bundle=false",
|
|
403
|
+
{ NODE_ENV: "production" }
|
|
404
|
+
);
|
|
405
|
+
} else await runCommand(buildCmd, { NODE_ENV: "production" });
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
case "start": {
|
|
409
|
+
console.log("š Starting production server...");
|
|
410
|
+
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
411
|
+
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";
|
|
412
|
+
await runCommand(`node ${entryFile}`, { NODE_ENV: "production" });
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
case "doctor":
|
|
416
|
+
runDoctor();
|
|
417
|
+
break;
|
|
418
|
+
case "generate-keys": {
|
|
419
|
+
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
|
|
420
|
+
modulusLength: 2048,
|
|
421
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
422
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" }
|
|
423
|
+
});
|
|
424
|
+
console.log("\nš Generating JWT keys...\n");
|
|
425
|
+
console.log("JWT_PUBLIC_KEY='" + publicKey + "'");
|
|
426
|
+
console.log("\nJWT_PRIVATE_KEY='" + privateKey + "'");
|
|
427
|
+
console.log("\nJWT_ENCRYPTION_SECRET=" + generateJWTSecret());
|
|
428
|
+
console.log("\nš Add these to your .env file (use single quotes for multiline values):\n");
|
|
429
|
+
process.exit(0);
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
default:
|
|
433
|
+
console.error(`Unknown command: ${command}`);
|
|
434
|
+
console.log("Use --help for usage information");
|
|
435
|
+
process.exit(1);
|
|
424
436
|
}
|
|
425
|
-
default:
|
|
426
|
-
console.error(`Unknown command: ${command}`);
|
|
427
|
-
console.log("Use --help for usage information");
|
|
428
|
-
process.exit(1);
|
|
429
437
|
}
|
|
438
|
+
main().then(() => process.exit(0)).catch((err) => {
|
|
439
|
+
console.error(err);
|
|
440
|
+
process.exit(1);
|
|
441
|
+
});
|
|
430
442
|
export {
|
|
431
443
|
stripJsonComments as default
|
|
432
444
|
};
|