create-sprint 0.0.100 → 0.0.108

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.
@@ -32,20 +32,17 @@ import { resolve } from "path";
32
32
 
33
33
  export default defineConfig({
34
34
  build: {
35
- lib: {
36
- entry: "src/app.ts",
37
- formats: ["es"],
38
- fileName: "app"
39
- },
40
35
  outDir: "dist",
36
+ emptyOutDir: true,
41
37
  rollupOptions: {
42
- external: ["sprint-es", "express", "cors", "morgan", "serve-favicon", "dotenv"]
38
+ input: resolve(__dirname, "src/app.ts"),
39
+ external: ["sprint-es", "express", "cors", "morgan", "serve-favicon", "dotenv", "graphql", "graphql-http", "ruru"]
43
40
  },
44
41
  target: "ES2020"
45
42
  },
46
43
  resolve: {
47
44
  alias: {
48
- "@": "src"
45
+ "@": resolve(__dirname, "src")
49
46
  }
50
47
  }
51
48
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sprint",
3
- "version": "0.0.100",
3
+ "version": "0.0.108",
4
4
  "description": "Create a new Sprint API project",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -5,12 +5,14 @@ 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, getEnvExample, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob, getGraphQLFiles } from "./generators.js";
8
+ import { getTypeScriptPackageJson, getJavaScriptPackageJson, getTsConfig, getMainFile, getHomeRoute, getAdminRoute, getHomeController, getAdminController, getEnvExample, getInternalAuthMiddleware, getUserAuthMiddleware, getHomeSchema, getAdminSchema, getDockerfile, getDockerCompose, getGitignore, getDockerIgnore, getSprintConfigFile, getEnvDevelopment, getEnvProduction, getExampleCronJob, getGraphQLFiles } from "./generators.js";
9
+
10
+ type TelemetryProviders = "none" | "sentry" | "glitchtip" | "discord" | "open-telemetry" | "telegram" | "nodemailer";
9
11
 
10
12
  export interface CLIOptions {
11
13
  projectName?: string;
12
14
  language?: "typescript" | "javascript";
13
- telemetry?: "none" | "sentry" | "glitchtip" | "discord";
15
+ telemetry?: TelemetryProviders;
14
16
  swagger?: boolean;
15
17
  graphql?: boolean;
16
18
  docker?: boolean;
@@ -33,7 +35,7 @@ export async function runCLI(args: string[]) {
33
35
  let config: {
34
36
  projectName: string;
35
37
  language: "typescript" | "javascript";
36
- telemetry: string;
38
+ telemetry: TelemetryProviders;
37
39
  swagger: boolean;
38
40
  graphql: boolean;
39
41
  docker: boolean;
@@ -43,7 +45,7 @@ export async function runCLI(args: string[]) {
43
45
  config = {
44
46
  projectName: options.projectName || "sprint-app",
45
47
  language: options.language || "typescript",
46
- telemetry: options.telemetry || "none",
48
+ telemetry: options.telemetry ?? "none",
47
49
  swagger: options.swagger ?? true,
48
50
  graphql: options.graphql ?? false,
49
51
  docker: options.docker || false,
@@ -55,7 +57,7 @@ export async function runCLI(args: string[]) {
55
57
  p.text({
56
58
  message: "Project name:",
57
59
  placeholder: "my-api",
58
- validate: (v) => validateProjectName(v) || undefined,
60
+ validate: (v) => validateProjectName(v || "sprint-app") || undefined,
59
61
  }),
60
62
 
61
63
  language: () =>
@@ -167,7 +169,10 @@ function parseArgs(args: string[]): CLIOptions {
167
169
  else if (hasJs) options.language = "javascript";
168
170
  } else options.language = "typescript";
169
171
 
170
- if (hasName !== -1 && args[hasName + 1]) options.projectName = args[hasName + 1];
172
+ if (hasName !== -1) {
173
+ const value = args[hasName + 1];
174
+ if (typeof value === "string") options.projectName = value;
175
+ }
171
176
 
172
177
  if (args.includes("--current")) options.projectName = ".";
173
178
 
@@ -181,7 +186,9 @@ function parseArgs(args: string[]): CLIOptions {
181
186
 
182
187
  if (args.includes("--no-install")) options.skipInstall = true;
183
188
 
184
- if (telemetryArg && ["sentry", "glitchtip", "discord", "none"].includes(telemetryArg)) options.telemetry = telemetryArg as CLIOptions["telemetry"];
189
+ if (telemetryArg && ["sentry", "glitchtip", "discord", "none"].includes(telemetryArg)) {
190
+ if (typeof telemetryArg === "string" && ["sentry", "glitchtip", "discord", "none"].includes(telemetryArg)) options.telemetry = telemetryArg as TelemetryProviders;
191
+ }
185
192
 
186
193
  return options;
187
194
  };
@@ -189,7 +196,7 @@ function parseArgs(args: string[]): CLIOptions {
189
196
  async function createProject(
190
197
  projectName: string,
191
198
  language: "typescript" | "javascript",
192
- telemetry: string,
199
+ telemetry: TelemetryProviders,
193
200
  swagger: boolean,
194
201
  graphql: boolean,
195
202
  useDocker: boolean
@@ -212,7 +219,6 @@ async function createProject(
212
219
 
213
220
  if (language === "typescript") {
214
221
  await writeFile(join(targetDir, "tsconfig.json"), getTsConfig());
215
- await writeFile(join(targetDir, "vite.config.ts"), getViteConfig());
216
222
  await writeFile(join(targetDir, "sprint.config.ts"), getSprintConfigFile(language, telemetry, swagger, graphql));
217
223
  } else await writeFile(join(targetDir, "sprint.config.js"), getSprintConfigFile(language, telemetry, swagger, graphql));
218
224
 
@@ -1,55 +1,58 @@
1
1
  export function getTsConfig() {
2
- return JSON.stringify({
3
- compilerOptions: {
4
- target: "ES2022",
5
- module: "NodeNext",
6
- moduleResolution: "NodeNext",
7
- lib: ["ES2022"],
8
- types: ["node"],
9
- outDir: "./dist",
10
- rootDir: "./src",
11
- strict: true,
12
- esModuleInterop: true,
13
- skipLibCheck: true,
14
- forceConsistentCasingInFileNames: true,
15
- resolveJsonModule: true,
16
- declaration: true,
17
- declarationMap: true,
18
- sourceMap: true,
19
- baseUrl: ".",
20
- paths: {
21
- "@/*": ["./src/*"]
22
- }
23
- },
24
- include: ["src/**/*"],
25
- exclude: ["node_modules", "dist"],
26
- }, null, 2);
27
- };
28
-
29
- export function getViteConfig() {
30
- return `import { defineConfig } from "vite";
31
- import { resolve } from "path";
32
-
33
- export default defineConfig({
34
- build: {
35
- lib: {
36
- entry: "src/app.ts",
37
- formats: ["es"],
38
- fileName: "app"
39
- },
40
- outDir: "dist",
41
- rollupOptions: {
42
- external: ["sprint-es", "express", "cors", "morgan", "serve-favicon", "dotenv"]
43
- },
44
- target: "ES2020"
45
- },
46
- resolve: {
47
- alias: {
48
- "@": "src"
49
- }
2
+ return `
3
+ {
4
+ "compilerOptions": {
5
+ /* Target */
6
+ "ignoreDeprecations": "6.0",
7
+ "target": "ES2022",
8
+ "module": "NodeNext",
9
+ "moduleResolution": "NodeNext",
10
+ "lib": [
11
+ "ES2022"
12
+ ],
13
+ "types": [
14
+ "node"
15
+ ],
16
+ /* Output */
17
+ "outDir": "./dist",
18
+ "rootDir": "./src",
19
+ "declaration": true,
20
+ "declarationMap": true,
21
+ "sourceMap": true,
22
+ /* Strict */
23
+ "strict": true,
24
+ "noUncheckedIndexedAccess": true,
25
+ "noImplicitOverride": true,
26
+ "noUnusedLocals": true,
27
+ "noUnusedParameters": true,
28
+ "exactOptionalPropertyTypes": true,
29
+ "noFallthroughCasesInSwitch": true,
30
+ /* Interop */
31
+ "esModuleInterop": true,
32
+ "forceConsistentCasingInFileNames": true,
33
+ "resolveJsonModule": true,
34
+ "isolatedModules": true,
35
+ /* Performance */
36
+ "incremental": true,
37
+ "skipLibCheck": true,
38
+ "baseUrl": ".",
39
+ "paths": {
40
+ "@/*": [
41
+ "./src/*"
42
+ ]
50
43
  }
51
- });
52
- `;
44
+ },
45
+ "include": [
46
+ "src/**/*"
47
+ ],
48
+ "exclude": [
49
+ "node_modules",
50
+ "dist",
51
+ "**/*.test.ts",
52
+ "**/*.spec.ts"
53
+ ]
54
+ }
55
+ `;
53
56
  };
54
57
 
55
58
  export function getSprintConfigFile(language: string, telemetry: string, swagger: boolean, graphql: boolean) {
@@ -1,6 +1,6 @@
1
1
  export function getDockerfile(language: string) {
2
2
  if (language === "typescript") {
3
- return `FROM node:20-alpine
3
+ return `FROM node:20-alpine AS builder
4
4
 
5
5
  WORKDIR /app
6
6
 
@@ -12,6 +12,17 @@ COPY . .
12
12
 
13
13
  RUN npm run build
14
14
 
15
+
16
+ FROM node:20-alpine
17
+
18
+ WORKDIR /app
19
+
20
+ COPY package*.json ./
21
+
22
+ RUN npm ci --omit=dev
23
+
24
+ COPY --from=builder /app/dist ./dist
25
+
15
26
  EXPOSE 5000
16
27
 
17
28
  CMD ["npm", "start"]
@@ -33,7 +44,7 @@ CMD ["npm", "start"]
33
44
  `;
34
45
  };
35
46
 
36
- export function getDockerCompose(language: string) {
47
+ export function getDockerCompose(_language: string) {
37
48
  return `
38
49
  services:
39
50
  app:
@@ -1,6 +1,5 @@
1
1
  export function getGraphQLFiles(language: string) {
2
2
  const isTs = language === "typescript";
3
- const ext = isTs ? "" : ".js";
4
3
 
5
4
  const tsTypes = `import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLNonNull } from "graphql";
6
5
 
@@ -1,8 +1,8 @@
1
1
  // Package JSON
2
2
  export { generateJWTKeys, getTypeScriptPackageJson, getJavaScriptPackageJson } from "./packageJson.js";
3
3
 
4
- // Config Files (tsconfig, vite.config, sprint.config)
5
- export { getTsConfig, getViteConfig, getSprintConfigFile } from "./configFiles.js";
4
+ // Config Files (tsconfig, sprint.config)
5
+ export { getTsConfig, getSprintConfigFile } from "./configFiles.js";
6
6
 
7
7
  // Environment Files
8
8
  export { getEnvExample, getEnvDevelopment, getEnvProduction } from "./env.js";
@@ -16,15 +16,14 @@ export function generateJWTKeys(): JWTKeys {
16
16
 
17
17
  export function getTypeScriptPackageJson(name: string, telemetry: string, swagger: boolean, graphql: boolean) {
18
18
  const deps: Record<string, string> = {
19
- "sprint-es": "^0.0.90"
19
+ "sprint-es": "^0.0.135"
20
20
  };
21
21
 
22
22
  const devDeps: Record<string, string> = {
23
23
  "@types/node": "^22.0.0",
24
24
  "tsx": "^4.19.0",
25
25
  typescript: "^5.6.0",
26
- vite: "^6.4.1",
27
- "vite-plugin-dts": "^4.5.4"
26
+ tsup: "^8.5.1"
28
27
  };
29
28
 
30
29
  if (telemetry === "sentry" || telemetry === "glitchtip") deps["@sentry/node"] = "^8.0.0";
@@ -43,7 +42,8 @@ export function getTypeScriptPackageJson(name: string, telemetry: string, swagge
43
42
  name: name === "." ? "sprint-app" : name,
44
43
  version: "0.0.1",
45
44
  description: "Sprint API",
46
- main: "dist/index.js",
45
+ main: "dist/app.js",
46
+ type: "module",
47
47
  scripts: {
48
48
  build: "sprint-es build",
49
49
  start: "sprint-es start",
@@ -52,13 +52,28 @@ export function getTypeScriptPackageJson(name: string, telemetry: string, swagge
52
52
  "generate:keys": "sprint-es generate-keys"
53
53
  },
54
54
  dependencies: deps,
55
- devDependencies: devDeps
55
+ devDependencies: devDeps,
56
+ tsup: {
57
+ entry: [
58
+ "src/**/*.ts"
59
+ ],
60
+ outDir: "dist",
61
+ format: [
62
+ "esm"
63
+ ],
64
+ target: "es2020",
65
+ sourcemap: true,
66
+ clean: true,
67
+ dts: true,
68
+ splitting: false,
69
+ skipNodeModulesBundle: true
70
+ }
56
71
  };
57
72
  };
58
73
 
59
74
  export function getJavaScriptPackageJson(name: string, telemetry: string, swagger: boolean, graphql: boolean) {
60
75
  const deps: Record<string, string> = {
61
- "sprint-es": "^0.0.90"
76
+ "sprint-es": "^0.0.135"
62
77
  };
63
78
 
64
79
  if (telemetry === "sentry" || telemetry === "glitchtip") deps["@sentry/node"] = "^8.0.0";
@@ -76,7 +91,7 @@ export function getJavaScriptPackageJson(name: string, telemetry: string, swagge
76
91
  name: name === "." ? "sprint-app" : name,
77
92
  version: "0.0.1",
78
93
  description: "Sprint API",
79
- main: "src/index.js",
94
+ main: "src/app.js",
80
95
  type: "module",
81
96
  scripts: {
82
97
  build: "sprint-es build",
@@ -1,6 +1,5 @@
1
1
  export function getMainFile(language: string, graphql: boolean = false) {
2
2
  const isTs = language === "typescript";
3
- const ext = isTs ? "" : ".js";
4
3
 
5
4
  if (isTs) {
6
5
  if (graphql) {