create-sprint 0.0.56 → 0.0.60
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/generators.js +16 -32
- package/dist/index.js +6 -6
- package/package.json +1 -1
- package/src/generators.ts +16 -32
- package/src/index.ts +6 -7
package/dist/generators.js
CHANGED
|
@@ -117,35 +117,13 @@ export default defineConfig({
|
|
|
117
117
|
export function getMainFile(language) {
|
|
118
118
|
if (language === "typescript") {
|
|
119
119
|
return `import Sprint from "sprint-es";
|
|
120
|
-
import homeRouter from "./routes/home";
|
|
121
|
-
import adminRouter from "./routes/admin";
|
|
122
|
-
import authInternalMiddleware from "./middlewares/auth.internal";
|
|
123
|
-
import authUserMiddleware from "./middlewares/auth.user";
|
|
124
120
|
|
|
125
121
|
const app = new Sprint();
|
|
126
|
-
|
|
127
|
-
app.use(authUserMiddleware);
|
|
128
|
-
app.use(authInternalMiddleware);
|
|
129
|
-
app.route("/", homeRouter);
|
|
130
|
-
app.route("/admin", adminRouter);
|
|
131
|
-
|
|
132
|
-
app.listen();
|
|
133
122
|
`;
|
|
134
123
|
}
|
|
135
124
|
return `import Sprint from "sprint-es";
|
|
136
|
-
import homeRouter from "./routes/home.js";
|
|
137
|
-
import adminRouter from "./routes/admin.js";
|
|
138
|
-
import authInternalMiddleware from "./middlewares/auth.internal.js";
|
|
139
|
-
import authUserMiddleware from "./middlewares/auth.user.js";
|
|
140
125
|
|
|
141
126
|
const app = new Sprint();
|
|
142
|
-
|
|
143
|
-
app.use(authUserMiddleware);
|
|
144
|
-
app.use(authInternalMiddleware);
|
|
145
|
-
app.route("/", homeRouter);
|
|
146
|
-
app.route("/admin", adminRouter);
|
|
147
|
-
|
|
148
|
-
app.listen();
|
|
149
127
|
`;
|
|
150
128
|
}
|
|
151
129
|
export function getHomeRoute(language) {
|
|
@@ -255,11 +233,12 @@ export const adminUsersController: Handler = (req: SprintRequest, res: SprintRes
|
|
|
255
233
|
});
|
|
256
234
|
};
|
|
257
235
|
|
|
236
|
+
const { privateKey, encryptionSecret } = getJwtFromEnv();
|
|
237
|
+
|
|
258
238
|
export const jwtGenerateController: Handler = (req: SprintRequest, res: SprintResponse) => {
|
|
259
239
|
const { userId, role } = req.body || {};
|
|
260
240
|
|
|
261
241
|
try {
|
|
262
|
-
const { privateKey, encryptionSecret } = getJwtFromEnv();
|
|
263
242
|
const payload = { userId, role: role || "user" };
|
|
264
243
|
const token = signEncrypted(payload, privateKey, encryptionSecret, { expiresIn: "1h" });
|
|
265
244
|
res.json({ token });
|
|
@@ -289,11 +268,12 @@ export const adminUsersController = (req: SprintRequest, res: SprintResponse) =>
|
|
|
289
268
|
});
|
|
290
269
|
};
|
|
291
270
|
|
|
271
|
+
const { privateKey, encryptionSecret } = getJwtFromEnv();
|
|
272
|
+
|
|
292
273
|
export const jwtGenerateController = (req: SprintRequest, res: SprintResponse) => {
|
|
293
274
|
const { userId, role } = req.body || {};
|
|
294
275
|
|
|
295
276
|
try {
|
|
296
|
-
const { privateKey, encryptionSecret } = getJwtFromEnv();
|
|
297
277
|
const payload = { userId, role: role || "user" };
|
|
298
278
|
const token = signEncrypted(payload, privateKey, encryptionSecret, { expiresIn: "1h" });
|
|
299
279
|
res.json({ token });
|
|
@@ -360,13 +340,13 @@ export const jwtGenerateSchema = defineRouteSchema({
|
|
|
360
340
|
}
|
|
361
341
|
export function getInternalAuthMiddleware(language) {
|
|
362
342
|
if (language === "typescript") {
|
|
363
|
-
return `import { defineMiddleware } from "sprint-es";
|
|
343
|
+
return `import { defineMiddleware, SprintRequest, SprintResponse, NextFunction } from "sprint-es";
|
|
364
344
|
|
|
365
345
|
export default defineMiddleware({
|
|
366
346
|
name: "adminAuth",
|
|
367
347
|
priority: 10,
|
|
368
348
|
include: "/admin/**",
|
|
369
|
-
handler: (req, res, next) => {
|
|
349
|
+
handler: (req: SprintRequest, res: SprintResponse, next: NextFunction) => {
|
|
370
350
|
const auth = req.sprint.getAuthorization();
|
|
371
351
|
if (!auth) return res.status(401).json({ error: "No authorization header" });
|
|
372
352
|
|
|
@@ -400,7 +380,7 @@ export default defineMiddleware({
|
|
|
400
380
|
}
|
|
401
381
|
export function getUserAuthMiddleware(language) {
|
|
402
382
|
if (language === "typescript") {
|
|
403
|
-
return `import { defineMiddleware } from "sprint-es";
|
|
383
|
+
return `import { defineMiddleware, SprintRequest, SprintResponse, NextFunction } from "sprint-es";
|
|
404
384
|
import { verifyEncrypted, getJwtFromEnv } from "sprint-es/jwt";
|
|
405
385
|
|
|
406
386
|
const { publicKey, encryptionSecret } = getJwtFromEnv();
|
|
@@ -410,7 +390,7 @@ export default defineMiddleware({
|
|
|
410
390
|
priority: 10,
|
|
411
391
|
include: "/**",
|
|
412
392
|
exclude: "/admin/**",
|
|
413
|
-
handler: (req, res, next) => {
|
|
393
|
+
handler: (req: SprintRequest, res: SprintResponse, next: NextFunction) => {
|
|
414
394
|
const auth = req.sprint.getAuthorization();
|
|
415
395
|
if (!auth) return res.status(401).json({ error: "No authorization header" });
|
|
416
396
|
|
|
@@ -625,19 +605,23 @@ initTelemetry({
|
|
|
625
605
|
export function getEnvExample(telemetry) {
|
|
626
606
|
let env = `PORT=5000
|
|
627
607
|
|
|
608
|
+
JWT_PUBLIC_KEY=""
|
|
609
|
+
JWT_PRIVATE_KEY=""
|
|
610
|
+
JWT_ENCRYPTION_SECRET=""
|
|
611
|
+
|
|
628
612
|
# Development: npm run dev (NODE_ENV=development)
|
|
629
613
|
# Production: npm start (NODE_ENV=production)
|
|
630
614
|
`;
|
|
631
615
|
if (telemetry === "sentry" || telemetry === "glitchtip") {
|
|
632
616
|
env += `
|
|
633
617
|
# Sentry / GlitchTip (use GlitchTip DSN for self-hosted)
|
|
634
|
-
SENTRY_DSN=
|
|
618
|
+
SENTRY_DSN=""
|
|
635
619
|
`;
|
|
636
620
|
}
|
|
637
621
|
else if (telemetry === "discord") {
|
|
638
622
|
env += `
|
|
639
623
|
# Discord Webhook URL for error notifications
|
|
640
|
-
DISCORD_TELEMETRY_WEBHOOK_URL=
|
|
624
|
+
DISCORD_TELEMETRY_WEBHOOK_URL=""
|
|
641
625
|
`;
|
|
642
626
|
}
|
|
643
627
|
return env;
|
|
@@ -656,13 +640,13 @@ JWT_ENCRYPTION_SECRET='${crypto.randomBytes(32).toString("hex")}'
|
|
|
656
640
|
if (telemetry === "sentry" || telemetry === "glitchtip") {
|
|
657
641
|
env += `
|
|
658
642
|
# Sentry / GlitchTip
|
|
659
|
-
SENTRY_DSN=
|
|
643
|
+
SENTRY_DSN=""
|
|
660
644
|
`;
|
|
661
645
|
}
|
|
662
646
|
else if (telemetry === "discord") {
|
|
663
647
|
env += `
|
|
664
648
|
# Discord Webhook URL
|
|
665
|
-
DISCORD_TELEMETRY_WEBHOOK_URL=
|
|
649
|
+
DISCORD_TELEMETRY_WEBHOOK_URL=""
|
|
666
650
|
`;
|
|
667
651
|
}
|
|
668
652
|
return env;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { join } from "path";
|
|
|
5
5
|
import color from "picocolors";
|
|
6
6
|
import * as p from "@clack/prompts";
|
|
7
7
|
import { validateProjectName } from "./validators.js";
|
|
8
|
-
import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getViteConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob } from "./generators.js";
|
|
8
|
+
import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getViteConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getEnvExample, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob } from "./generators.js";
|
|
9
9
|
export async function writeFile(path, content, options) {
|
|
10
10
|
if (typeof content === "string")
|
|
11
11
|
content = content.trimEnd();
|
|
@@ -68,15 +68,15 @@ export async function runCLI(args) {
|
|
|
68
68
|
else if (!options.skipPrompts) {
|
|
69
69
|
installDeps = await p.confirm({ message: "Install dependencies now?", initialValue: true });
|
|
70
70
|
}
|
|
71
|
-
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
72
71
|
if (installDeps) {
|
|
73
72
|
const s2 = p.spinner();
|
|
74
73
|
s2.start("Installing dependencies");
|
|
75
74
|
try {
|
|
76
75
|
await new Promise((resolve, reject) => {
|
|
77
|
-
const child = spawn(
|
|
76
|
+
const child = spawn("npm", ["install"], {
|
|
78
77
|
cwd: targetDir,
|
|
79
|
-
stdio: "inherit"
|
|
78
|
+
stdio: "inherit",
|
|
79
|
+
shell: true
|
|
80
80
|
});
|
|
81
81
|
child.on("close", (code) => {
|
|
82
82
|
if (code === 0)
|
|
@@ -184,8 +184,8 @@ async function createProject(projectName, language, telemetry, useDocker) {
|
|
|
184
184
|
await writeFile(join(srcDir, "schemas", "home." + (language === "typescript" ? "ts" : "js")), getHomeSchema(language));
|
|
185
185
|
await writeFile(join(srcDir, "schemas", "admin." + (language === "typescript" ? "ts" : "js")), getAdminSchema(language));
|
|
186
186
|
await writeFile(join(srcDir, "cronjobs", "example." + (language === "typescript" ? "ts" : "js")), getExampleCronJob(language));
|
|
187
|
-
await writeFile(join(targetDir, ".env.development.example"),
|
|
188
|
-
await writeFile(join(targetDir, ".env.production.example"),
|
|
187
|
+
await writeFile(join(targetDir, ".env.development.example"), getEnvExample(telemetry));
|
|
188
|
+
await writeFile(join(targetDir, ".env.production.example"), getEnvExample(telemetry));
|
|
189
189
|
await writeFile(join(targetDir, ".env.development"), getEnvDevelopment(telemetry));
|
|
190
190
|
await writeFile(join(targetDir, ".env.production"), getEnvProduction(telemetry));
|
|
191
191
|
await writeFile(join(targetDir, ".gitignore"), getGitignore());
|
package/package.json
CHANGED
package/src/generators.ts
CHANGED
|
@@ -131,36 +131,14 @@ export default defineConfig({
|
|
|
131
131
|
export function getMainFile(language: string) {
|
|
132
132
|
if (language === "typescript") {
|
|
133
133
|
return `import Sprint from "sprint-es";
|
|
134
|
-
import homeRouter from "./routes/home";
|
|
135
|
-
import adminRouter from "./routes/admin";
|
|
136
|
-
import authInternalMiddleware from "./middlewares/auth.internal";
|
|
137
|
-
import authUserMiddleware from "./middlewares/auth.user";
|
|
138
134
|
|
|
139
135
|
const app = new Sprint();
|
|
140
|
-
|
|
141
|
-
app.use(authUserMiddleware);
|
|
142
|
-
app.use(authInternalMiddleware);
|
|
143
|
-
app.route("/", homeRouter);
|
|
144
|
-
app.route("/admin", adminRouter);
|
|
145
|
-
|
|
146
|
-
app.listen();
|
|
147
136
|
`;
|
|
148
137
|
}
|
|
149
138
|
|
|
150
139
|
return `import Sprint from "sprint-es";
|
|
151
|
-
import homeRouter from "./routes/home.js";
|
|
152
|
-
import adminRouter from "./routes/admin.js";
|
|
153
|
-
import authInternalMiddleware from "./middlewares/auth.internal.js";
|
|
154
|
-
import authUserMiddleware from "./middlewares/auth.user.js";
|
|
155
140
|
|
|
156
141
|
const app = new Sprint();
|
|
157
|
-
|
|
158
|
-
app.use(authUserMiddleware);
|
|
159
|
-
app.use(authInternalMiddleware);
|
|
160
|
-
app.route("/", homeRouter);
|
|
161
|
-
app.route("/admin", adminRouter);
|
|
162
|
-
|
|
163
|
-
app.listen();
|
|
164
142
|
`;
|
|
165
143
|
}
|
|
166
144
|
|
|
@@ -274,11 +252,12 @@ export const adminUsersController: Handler = (req: SprintRequest, res: SprintRes
|
|
|
274
252
|
});
|
|
275
253
|
};
|
|
276
254
|
|
|
255
|
+
const { privateKey, encryptionSecret } = getJwtFromEnv();
|
|
256
|
+
|
|
277
257
|
export const jwtGenerateController: Handler = (req: SprintRequest, res: SprintResponse) => {
|
|
278
258
|
const { userId, role } = req.body || {};
|
|
279
259
|
|
|
280
260
|
try {
|
|
281
|
-
const { privateKey, encryptionSecret } = getJwtFromEnv();
|
|
282
261
|
const payload = { userId, role: role || "user" };
|
|
283
262
|
const token = signEncrypted(payload, privateKey, encryptionSecret, { expiresIn: "1h" });
|
|
284
263
|
res.json({ token });
|
|
@@ -307,11 +286,12 @@ export const adminUsersController = (req: SprintRequest, res: SprintResponse) =>
|
|
|
307
286
|
});
|
|
308
287
|
};
|
|
309
288
|
|
|
289
|
+
const { privateKey, encryptionSecret } = getJwtFromEnv();
|
|
290
|
+
|
|
310
291
|
export const jwtGenerateController = (req: SprintRequest, res: SprintResponse) => {
|
|
311
292
|
const { userId, role } = req.body || {};
|
|
312
293
|
|
|
313
294
|
try {
|
|
314
|
-
const { privateKey, encryptionSecret } = getJwtFromEnv();
|
|
315
295
|
const payload = { userId, role: role || "user" };
|
|
316
296
|
const token = signEncrypted(payload, privateKey, encryptionSecret, { expiresIn: "1h" });
|
|
317
297
|
res.json({ token });
|
|
@@ -381,13 +361,13 @@ export const jwtGenerateSchema = defineRouteSchema({
|
|
|
381
361
|
|
|
382
362
|
export function getInternalAuthMiddleware(language: string) {
|
|
383
363
|
if (language === "typescript") {
|
|
384
|
-
return `import { defineMiddleware } from "sprint-es";
|
|
364
|
+
return `import { defineMiddleware, SprintRequest, SprintResponse, NextFunction } from "sprint-es";
|
|
385
365
|
|
|
386
366
|
export default defineMiddleware({
|
|
387
367
|
name: "adminAuth",
|
|
388
368
|
priority: 10,
|
|
389
369
|
include: "/admin/**",
|
|
390
|
-
handler: (req, res, next) => {
|
|
370
|
+
handler: (req: SprintRequest, res: SprintResponse, next: NextFunction) => {
|
|
391
371
|
const auth = req.sprint.getAuthorization();
|
|
392
372
|
if (!auth) return res.status(401).json({ error: "No authorization header" });
|
|
393
373
|
|
|
@@ -422,7 +402,7 @@ export default defineMiddleware({
|
|
|
422
402
|
|
|
423
403
|
export function getUserAuthMiddleware(language: string) {
|
|
424
404
|
if (language === "typescript") {
|
|
425
|
-
return `import { defineMiddleware } from "sprint-es";
|
|
405
|
+
return `import { defineMiddleware, SprintRequest, SprintResponse, NextFunction } from "sprint-es";
|
|
426
406
|
import { verifyEncrypted, getJwtFromEnv } from "sprint-es/jwt";
|
|
427
407
|
|
|
428
408
|
const { publicKey, encryptionSecret } = getJwtFromEnv();
|
|
@@ -432,7 +412,7 @@ export default defineMiddleware({
|
|
|
432
412
|
priority: 10,
|
|
433
413
|
include: "/**",
|
|
434
414
|
exclude: "/admin/**",
|
|
435
|
-
handler: (req, res, next) => {
|
|
415
|
+
handler: (req: SprintRequest, res: SprintResponse, next: NextFunction) => {
|
|
436
416
|
const auth = req.sprint.getAuthorization();
|
|
437
417
|
if (!auth) return res.status(401).json({ error: "No authorization header" });
|
|
438
418
|
|
|
@@ -656,6 +636,10 @@ initTelemetry({
|
|
|
656
636
|
export function getEnvExample(telemetry: string) {
|
|
657
637
|
let env = `PORT=5000
|
|
658
638
|
|
|
639
|
+
JWT_PUBLIC_KEY=""
|
|
640
|
+
JWT_PRIVATE_KEY=""
|
|
641
|
+
JWT_ENCRYPTION_SECRET=""
|
|
642
|
+
|
|
659
643
|
# Development: npm run dev (NODE_ENV=development)
|
|
660
644
|
# Production: npm start (NODE_ENV=production)
|
|
661
645
|
`;
|
|
@@ -663,12 +647,12 @@ export function getEnvExample(telemetry: string) {
|
|
|
663
647
|
if (telemetry === "sentry" || telemetry === "glitchtip") {
|
|
664
648
|
env += `
|
|
665
649
|
# Sentry / GlitchTip (use GlitchTip DSN for self-hosted)
|
|
666
|
-
SENTRY_DSN=
|
|
650
|
+
SENTRY_DSN=""
|
|
667
651
|
`;
|
|
668
652
|
} else if (telemetry === "discord") {
|
|
669
653
|
env += `
|
|
670
654
|
# Discord Webhook URL for error notifications
|
|
671
|
-
DISCORD_TELEMETRY_WEBHOOK_URL=
|
|
655
|
+
DISCORD_TELEMETRY_WEBHOOK_URL=""
|
|
672
656
|
`;
|
|
673
657
|
}
|
|
674
658
|
|
|
@@ -691,12 +675,12 @@ JWT_ENCRYPTION_SECRET='${crypto.randomBytes(32).toString("hex")}'
|
|
|
691
675
|
if (telemetry === "sentry" || telemetry === "glitchtip") {
|
|
692
676
|
env += `
|
|
693
677
|
# Sentry / GlitchTip
|
|
694
|
-
SENTRY_DSN=
|
|
678
|
+
SENTRY_DSN=""
|
|
695
679
|
`;
|
|
696
680
|
} else if (telemetry === "discord") {
|
|
697
681
|
env += `
|
|
698
682
|
# Discord Webhook URL
|
|
699
|
-
DISCORD_TELEMETRY_WEBHOOK_URL=
|
|
683
|
+
DISCORD_TELEMETRY_WEBHOOK_URL=""
|
|
700
684
|
`;
|
|
701
685
|
}
|
|
702
686
|
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { join } from "path";
|
|
|
5
5
|
import color from "picocolors";
|
|
6
6
|
import * as p from "@clack/prompts";
|
|
7
7
|
import { validateProjectName } from "./validators.js";
|
|
8
|
-
import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getViteConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob } from "./generators.js";
|
|
8
|
+
import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getViteConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getEnvExample, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob } from "./generators.js";
|
|
9
9
|
|
|
10
10
|
export interface CLIOptions {
|
|
11
11
|
projectName?: string;
|
|
@@ -103,16 +103,15 @@ export async function runCLI(args: string[]) {
|
|
|
103
103
|
installDeps = await p.confirm({ message: "Install dependencies now?", initialValue: true }) as boolean;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
107
|
-
|
|
108
106
|
if (installDeps) {
|
|
109
107
|
const s2 = p.spinner();
|
|
110
108
|
s2.start("Installing dependencies");
|
|
111
109
|
try {
|
|
112
110
|
await new Promise<void>((resolve, reject) => {
|
|
113
|
-
const child = spawn(
|
|
111
|
+
const child = spawn("npm", ["install"], {
|
|
114
112
|
cwd: targetDir,
|
|
115
|
-
stdio: "inherit"
|
|
113
|
+
stdio: "inherit",
|
|
114
|
+
shell: true
|
|
116
115
|
});
|
|
117
116
|
child.on("close", (code) => {
|
|
118
117
|
if (code === 0) resolve();
|
|
@@ -236,8 +235,8 @@ async function createProject(
|
|
|
236
235
|
|
|
237
236
|
await writeFile(join(srcDir, "cronjobs", "example." + (language === "typescript" ? "ts" : "js")), getExampleCronJob(language));
|
|
238
237
|
|
|
239
|
-
await writeFile(join(targetDir, ".env.development.example"),
|
|
240
|
-
await writeFile(join(targetDir, ".env.production.example"),
|
|
238
|
+
await writeFile(join(targetDir, ".env.development.example"), getEnvExample(telemetry));
|
|
239
|
+
await writeFile(join(targetDir, ".env.production.example"), getEnvExample(telemetry));
|
|
241
240
|
|
|
242
241
|
await writeFile(join(targetDir, ".env.development"), getEnvDevelopment(telemetry));
|
|
243
242
|
await writeFile(join(targetDir, ".env.production"), getEnvProduction(telemetry));
|