create-taserjs 0.0.2 → 0.0.4
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/README.md +2 -0
- package/dist/cjs/addons/arktype/index.cjs.map +1 -1
- package/dist/cjs/addons/drizzle/index.cjs.map +1 -1
- package/dist/cjs/addons/kysely/index.cjs.map +1 -1
- package/dist/cjs/addons/pino/index.cjs.map +1 -1
- package/dist/cjs/addons/prisma/index.cjs +84 -24
- package/dist/cjs/addons/prisma/index.cjs.map +1 -1
- package/dist/cjs/addons/registry.cjs +1 -1
- package/dist/cjs/addons/registry.cjs.map +1 -1
- package/dist/cjs/addons/types.d.cts +1 -1
- package/dist/cjs/addons/valibot/index.cjs.map +1 -1
- package/dist/cjs/addons/validators.cjs.map +1 -1
- package/dist/cjs/addons/winston/index.cjs.map +1 -1
- package/dist/cjs/addons/zod/index.cjs.map +1 -1
- package/dist/cjs/cli.cjs +5 -0
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/commands/create.cjs +44 -11
- package/dist/cjs/commands/create.cjs.map +1 -1
- package/dist/cjs/commands/create.d.cts +1 -0
- package/dist/cjs/core/json-output.cjs.map +1 -1
- package/dist/cjs/core/package-manager.cjs.map +1 -1
- package/dist/cjs/core/package-manager.d.cts +1 -1
- package/dist/cjs/core/parse-options.cjs +7 -7
- package/dist/cjs/core/parse-options.cjs.map +1 -1
- package/dist/cjs/core/parse-options.d.cts +3 -3
- package/dist/cjs/core/project-config.cjs +1 -1
- package/dist/cjs/core/project-config.cjs.map +1 -1
- package/dist/cjs/core/resolve-packages.cjs +41 -7
- package/dist/cjs/core/resolve-packages.cjs.map +1 -1
- package/dist/cjs/core/resolve-packages.d.cts +2 -2
- package/dist/cjs/core/scaffold-engine.cjs +33 -6
- package/dist/cjs/core/scaffold-engine.cjs.map +1 -1
- package/dist/cjs/core/types.cjs +11 -3
- package/dist/cjs/core/types.cjs.map +1 -1
- package/dist/cjs/core/types.d.cts +8 -8
- package/dist/cjs/core/validate-project-name.cjs.map +1 -1
- package/dist/cjs/frameworks/index.cjs +138 -17
- package/dist/cjs/frameworks/index.cjs.map +1 -1
- package/dist/cjs/frameworks/index.d.cts +3 -3
- package/dist/cjs/scaffold.d.cts +1 -1
- package/dist/cjs/templates/base.cjs +6 -6
- package/dist/cjs/templates/base.cjs.map +1 -1
- package/dist/cjs/types.d.cts +1 -1
- package/dist/esm/addons/arktype/index.js.map +1 -1
- package/dist/esm/addons/drizzle/index.js.map +1 -1
- package/dist/esm/addons/kysely/index.js.map +1 -1
- package/dist/esm/addons/pino/index.js.map +1 -1
- package/dist/esm/addons/prisma/index.js +84 -24
- package/dist/esm/addons/prisma/index.js.map +1 -1
- package/dist/esm/addons/registry.js +2 -2
- package/dist/esm/addons/registry.js.map +1 -1
- package/dist/esm/addons/types.d.ts +1 -1
- package/dist/esm/addons/valibot/index.js.map +1 -1
- package/dist/esm/addons/validators.js.map +1 -1
- package/dist/esm/addons/winston/index.js.map +1 -1
- package/dist/esm/addons/zod/index.js.map +1 -1
- package/dist/esm/cli.js +5 -0
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/commands/create.d.ts +1 -0
- package/dist/esm/commands/create.js +46 -13
- package/dist/esm/commands/create.js.map +1 -1
- package/dist/esm/core/json-output.js.map +1 -1
- package/dist/esm/core/package-manager.d.ts +1 -1
- package/dist/esm/core/package-manager.js.map +1 -1
- package/dist/esm/core/parse-options.d.ts +3 -3
- package/dist/esm/core/parse-options.js +8 -8
- package/dist/esm/core/parse-options.js.map +1 -1
- package/dist/esm/core/project-config.js +1 -1
- package/dist/esm/core/project-config.js.map +1 -1
- package/dist/esm/core/resolve-packages.d.ts +2 -2
- package/dist/esm/core/resolve-packages.js +41 -7
- package/dist/esm/core/resolve-packages.js.map +1 -1
- package/dist/esm/core/scaffold-engine.js +34 -7
- package/dist/esm/core/scaffold-engine.js.map +1 -1
- package/dist/esm/core/types.d.ts +8 -8
- package/dist/esm/core/types.js +11 -3
- package/dist/esm/core/types.js.map +1 -1
- package/dist/esm/core/validate-project-name.js.map +1 -1
- package/dist/esm/frameworks/index.d.ts +3 -3
- package/dist/esm/frameworks/index.js +138 -17
- package/dist/esm/frameworks/index.js.map +1 -1
- package/dist/esm/scaffold.d.ts +1 -1
- package/dist/esm/templates/base.js +6 -6
- package/dist/esm/templates/base.js.map +1 -1
- package/dist/esm/types.d.ts +1 -1
- package/package.json +13 -13
- package/src/addons/arktype/index.ts +2 -2
- package/src/addons/drizzle/index.ts +53 -53
- package/src/addons/kysely/index.ts +42 -42
- package/src/addons/pino/index.ts +12 -12
- package/src/addons/prisma/index.ts +128 -55
- package/src/addons/registry.ts +37 -37
- package/src/addons/types.ts +14 -14
- package/src/addons/valibot/index.ts +2 -2
- package/src/addons/validators.ts +9 -9
- package/src/addons/winston/index.ts +12 -12
- package/src/addons/zod/index.ts +2 -2
- package/src/cli.ts +27 -26
- package/src/commands/create.ts +181 -152
- package/src/core/json-output.ts +4 -4
- package/src/core/package-manager.ts +38 -31
- package/src/core/parse-options.ts +50 -48
- package/src/core/project-config.ts +10 -14
- package/src/core/resolve-packages.ts +79 -41
- package/src/core/scaffold-engine.ts +106 -36
- package/src/core/types.ts +61 -36
- package/src/core/validate-project-name.ts +40 -40
- package/src/frameworks/index.ts +164 -29
- package/src/scaffold.ts +3 -3
- package/src/templates/base.ts +57 -51
- package/src/types.ts +5 -4
package/src/commands/create.ts
CHANGED
|
@@ -1,234 +1,258 @@
|
|
|
1
|
-
import path from
|
|
1
|
+
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import * as p from
|
|
4
|
-
import color from
|
|
3
|
+
import * as p from "@clack/prompts";
|
|
4
|
+
import color from "picocolors";
|
|
5
5
|
|
|
6
|
-
import { getCapabilitiesCatalog } from
|
|
7
|
-
import {
|
|
6
|
+
import { getCapabilitiesCatalog } from "../addons/registry.js";
|
|
7
|
+
import {
|
|
8
|
+
printCapabilitiesCatalog,
|
|
9
|
+
printJsonError,
|
|
10
|
+
printScaffoldResult,
|
|
11
|
+
} from "../core/json-output.js";
|
|
8
12
|
import {
|
|
9
13
|
parseDbFlag,
|
|
10
|
-
parseFrameworkFlag,
|
|
11
14
|
parseLoggerFlag,
|
|
15
|
+
parseTypeFlag,
|
|
12
16
|
parseValidatorFlag,
|
|
13
17
|
type ParsedCreateArgs,
|
|
14
18
|
resolveScaffoldDefaults,
|
|
15
|
-
} from
|
|
16
|
-
import { scaffoldProject } from
|
|
17
|
-
import type {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
} from "../core/parse-options.js";
|
|
20
|
+
import { scaffoldProject } from "../core/scaffold-engine.js";
|
|
21
|
+
import type {
|
|
22
|
+
DbDriver,
|
|
23
|
+
DbOdm,
|
|
24
|
+
LoggerId,
|
|
25
|
+
ProjectType,
|
|
26
|
+
ScaffoldResult,
|
|
27
|
+
ValidatorId,
|
|
28
|
+
} from "../core/types.js";
|
|
29
|
+
import { DB_DRIVERS, DB_ODMS, LOGGERS, PROJECT_TYPES, VALIDATORS } from "../core/types.js";
|
|
30
|
+
import { validateProjectName } from "../core/validate-project-name.js";
|
|
31
|
+
import { resolveUserAgent, runScript } from "../core/package-manager.js";
|
|
32
|
+
|
|
33
|
+
function isProjectType(value: unknown): value is ProjectType {
|
|
34
|
+
return typeof value === "string" && (PROJECT_TYPES as readonly string[]).includes(value);
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
function isDbOdm(value: unknown): value is DbOdm {
|
|
27
|
-
return typeof value ===
|
|
38
|
+
return typeof value === "string" && (DB_ODMS as readonly string[]).includes(value);
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
function isDbDriver(value: unknown): value is DbDriver {
|
|
31
|
-
return typeof value ===
|
|
42
|
+
return typeof value === "string" && (DB_DRIVERS as readonly string[]).includes(value);
|
|
32
43
|
}
|
|
33
44
|
|
|
34
45
|
function isLoggerId(value: unknown): value is LoggerId {
|
|
35
|
-
return typeof value ===
|
|
46
|
+
return typeof value === "string" && (LOGGERS as readonly string[]).includes(value);
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
function isValidatorId(value: unknown): value is ValidatorId {
|
|
39
|
-
return typeof value ===
|
|
50
|
+
return typeof value === "string" && (VALIDATORS as readonly string[]).includes(value);
|
|
40
51
|
}
|
|
41
52
|
|
|
42
|
-
async function promptInteractiveOptions(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
defaultValue: 'my-taser-app',
|
|
53
|
+
async function promptInteractiveOptions(args: ParsedCreateArgs): Promise<ParsedCreateArgs> {
|
|
54
|
+
const projectName =
|
|
55
|
+
args.projectName ??
|
|
56
|
+
(await p.text({
|
|
57
|
+
message: "Project name",
|
|
58
|
+
placeholder: "my-taser-app",
|
|
59
|
+
defaultValue: "my-taser-app",
|
|
50
60
|
validate(value) {
|
|
51
|
-
return validateProjectName(value)
|
|
61
|
+
return validateProjectName(value);
|
|
52
62
|
},
|
|
53
|
-
})
|
|
63
|
+
}));
|
|
54
64
|
|
|
55
65
|
if (p.isCancel(projectName)) {
|
|
56
|
-
p.cancel(
|
|
57
|
-
process.exit(0)
|
|
66
|
+
p.cancel("Scaffold cancelled.");
|
|
67
|
+
process.exit(0);
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
const
|
|
61
|
-
??
|
|
62
|
-
|
|
70
|
+
const type =
|
|
71
|
+
args.type ??
|
|
72
|
+
(await p.select({
|
|
73
|
+
message: "Project type (runtime / framework)",
|
|
63
74
|
options: [
|
|
64
|
-
{ value:
|
|
65
|
-
{ value:
|
|
66
|
-
{ value:
|
|
67
|
-
{ value:
|
|
75
|
+
{ value: "node", label: "Node.js", hint: "default" },
|
|
76
|
+
{ value: "express", label: "Express" },
|
|
77
|
+
{ value: "fastify", label: "Fastify" },
|
|
78
|
+
{ value: "hono", label: "Hono" },
|
|
79
|
+
{ value: "bun", label: "Bun" },
|
|
80
|
+
{ value: "deno", label: "Deno" },
|
|
81
|
+
{ value: "aws-lambda", label: "AWS Lambda" },
|
|
82
|
+
{ value: "cloudflare-workers", label: "Cloudflare Workers" },
|
|
83
|
+
{ value: "netlify", label: "Netlify" },
|
|
84
|
+
{ value: "vercel", label: "Vercel" },
|
|
85
|
+
{ value: "azure-functions", label: "Azure Functions" },
|
|
86
|
+
{ value: "google-cloud-run", label: "Google Cloud Run" },
|
|
68
87
|
],
|
|
69
|
-
initialValue:
|
|
70
|
-
})
|
|
88
|
+
initialValue: "node",
|
|
89
|
+
}));
|
|
71
90
|
|
|
72
|
-
if (p.isCancel(
|
|
73
|
-
p.cancel(
|
|
74
|
-
process.exit(0)
|
|
91
|
+
if (p.isCancel(type) || !isProjectType(type)) {
|
|
92
|
+
p.cancel("Scaffold cancelled.");
|
|
93
|
+
process.exit(0);
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
const dbChoice =
|
|
78
|
-
??
|
|
79
|
-
|
|
96
|
+
const dbChoice =
|
|
97
|
+
args.db ??
|
|
98
|
+
(await p.select({
|
|
99
|
+
message: "Database",
|
|
80
100
|
options: [
|
|
81
|
-
{ value:
|
|
82
|
-
{ value:
|
|
83
|
-
{ value:
|
|
84
|
-
{ value:
|
|
101
|
+
{ value: "none", label: "None", hint: "default" },
|
|
102
|
+
{ value: "drizzle", label: "Drizzle" },
|
|
103
|
+
{ value: "prisma", label: "Prisma" },
|
|
104
|
+
{ value: "kysely", label: "Kysely" },
|
|
85
105
|
],
|
|
86
|
-
initialValue:
|
|
87
|
-
})
|
|
106
|
+
initialValue: "none",
|
|
107
|
+
}));
|
|
88
108
|
|
|
89
109
|
if (p.isCancel(dbChoice)) {
|
|
90
|
-
p.cancel(
|
|
91
|
-
process.exit(0)
|
|
110
|
+
p.cancel("Scaffold cancelled.");
|
|
111
|
+
process.exit(0);
|
|
92
112
|
}
|
|
93
113
|
|
|
94
|
-
let db: DbOdm | undefined
|
|
95
|
-
let driver: DbDriver | undefined
|
|
114
|
+
let db: DbOdm | undefined;
|
|
115
|
+
let driver: DbDriver | undefined;
|
|
96
116
|
|
|
97
|
-
if (dbChoice !==
|
|
98
|
-
db = dbChoice
|
|
99
|
-
const driverChoice =
|
|
100
|
-
??
|
|
101
|
-
|
|
117
|
+
if (dbChoice !== "none" && isDbOdm(dbChoice)) {
|
|
118
|
+
db = dbChoice;
|
|
119
|
+
const driverChoice =
|
|
120
|
+
args.driver ??
|
|
121
|
+
(await p.select({
|
|
122
|
+
message: "Database driver",
|
|
102
123
|
options: [
|
|
103
|
-
{ value:
|
|
104
|
-
{ value:
|
|
105
|
-
{ value:
|
|
124
|
+
{ value: "sqlite", label: "SQLite", hint: "default" },
|
|
125
|
+
{ value: "postgres", label: "PostgreSQL" },
|
|
126
|
+
{ value: "mysql", label: "MySQL" },
|
|
106
127
|
],
|
|
107
|
-
initialValue:
|
|
108
|
-
})
|
|
128
|
+
initialValue: "sqlite",
|
|
129
|
+
}));
|
|
109
130
|
|
|
110
131
|
if (p.isCancel(driverChoice) || !isDbDriver(driverChoice)) {
|
|
111
|
-
p.cancel(
|
|
112
|
-
process.exit(0)
|
|
132
|
+
p.cancel("Scaffold cancelled.");
|
|
133
|
+
process.exit(0);
|
|
113
134
|
}
|
|
114
|
-
driver = driverChoice
|
|
135
|
+
driver = driverChoice;
|
|
115
136
|
}
|
|
116
137
|
|
|
117
|
-
const loggerChoice =
|
|
118
|
-
??
|
|
119
|
-
|
|
138
|
+
const loggerChoice =
|
|
139
|
+
args.logger ??
|
|
140
|
+
(await p.select({
|
|
141
|
+
message: "Logger",
|
|
120
142
|
options: [
|
|
121
|
-
{ value:
|
|
122
|
-
{ value:
|
|
123
|
-
{ value:
|
|
143
|
+
{ value: "none", label: "None", hint: "default" },
|
|
144
|
+
{ value: "pino", label: "Pino" },
|
|
145
|
+
{ value: "winston", label: "Winston" },
|
|
124
146
|
],
|
|
125
|
-
initialValue:
|
|
126
|
-
})
|
|
147
|
+
initialValue: "none",
|
|
148
|
+
}));
|
|
127
149
|
|
|
128
150
|
if (p.isCancel(loggerChoice)) {
|
|
129
|
-
p.cancel(
|
|
130
|
-
process.exit(0)
|
|
151
|
+
p.cancel("Scaffold cancelled.");
|
|
152
|
+
process.exit(0);
|
|
131
153
|
}
|
|
132
154
|
|
|
133
|
-
const logger =
|
|
155
|
+
const logger =
|
|
156
|
+
loggerChoice === "none" ? undefined : isLoggerId(loggerChoice) ? loggerChoice : undefined;
|
|
134
157
|
|
|
135
|
-
const validatorChoice =
|
|
136
|
-
??
|
|
137
|
-
|
|
158
|
+
const validatorChoice =
|
|
159
|
+
args.validator ??
|
|
160
|
+
(await p.select({
|
|
161
|
+
message: "Validator",
|
|
138
162
|
options: [
|
|
139
|
-
{ value:
|
|
140
|
-
{ value:
|
|
141
|
-
{ value:
|
|
142
|
-
{ value:
|
|
163
|
+
{ value: "none", label: "None", hint: "default" },
|
|
164
|
+
{ value: "zod", label: "Zod" },
|
|
165
|
+
{ value: "arktype", label: "Arktype" },
|
|
166
|
+
{ value: "valibot", label: "Valibot" },
|
|
143
167
|
],
|
|
144
|
-
initialValue:
|
|
145
|
-
})
|
|
168
|
+
initialValue: "none",
|
|
169
|
+
}));
|
|
146
170
|
|
|
147
171
|
if (p.isCancel(validatorChoice)) {
|
|
148
|
-
p.cancel(
|
|
149
|
-
process.exit(0)
|
|
172
|
+
p.cancel("Scaffold cancelled.");
|
|
173
|
+
process.exit(0);
|
|
150
174
|
}
|
|
151
175
|
|
|
152
|
-
const validator =
|
|
176
|
+
const validator =
|
|
177
|
+
validatorChoice === "none"
|
|
178
|
+
? undefined
|
|
179
|
+
: isValidatorId(validatorChoice)
|
|
180
|
+
? validatorChoice
|
|
181
|
+
: undefined;
|
|
153
182
|
|
|
154
183
|
return {
|
|
155
184
|
projectName: String(projectName).trim(),
|
|
156
|
-
|
|
185
|
+
type,
|
|
157
186
|
yes: args.yes,
|
|
158
187
|
noInstall: args.noInstall,
|
|
159
188
|
json: args.json,
|
|
160
189
|
...(db ? { db, driver: driver! } : {}),
|
|
161
190
|
...(logger ? { logger } : {}),
|
|
162
191
|
...(validator ? { validator } : {}),
|
|
163
|
-
}
|
|
192
|
+
};
|
|
164
193
|
}
|
|
165
194
|
|
|
166
|
-
export async function runCreateCommand(
|
|
195
|
+
export async function runCreateCommand(
|
|
196
|
+
args: ParsedCreateArgs,
|
|
197
|
+
): Promise<ScaffoldResult | undefined> {
|
|
167
198
|
if (args.json && !args.projectName) {
|
|
168
|
-
printCapabilitiesCatalog(getCapabilitiesCatalog())
|
|
169
|
-
return undefined
|
|
199
|
+
printCapabilitiesCatalog(getCapabilitiesCatalog());
|
|
200
|
+
return undefined;
|
|
170
201
|
}
|
|
171
202
|
|
|
172
|
-
const cwd = process.cwd()
|
|
173
|
-
const interactive = !args.yes
|
|
203
|
+
const cwd = process.cwd();
|
|
204
|
+
const interactive = !args.yes;
|
|
174
205
|
const resolved = interactive
|
|
175
206
|
? await promptInteractiveOptions(args)
|
|
176
207
|
: {
|
|
177
208
|
...args,
|
|
178
209
|
projectName: args.projectName?.trim(),
|
|
179
|
-
|
|
180
|
-
}
|
|
210
|
+
type: args.type ?? "node",
|
|
211
|
+
};
|
|
181
212
|
|
|
182
213
|
if (!resolved.projectName) {
|
|
183
|
-
const message =
|
|
214
|
+
const message = "Project name is required";
|
|
184
215
|
if (args.json) {
|
|
185
|
-
printJsonError(message)
|
|
186
|
-
process.exit(1)
|
|
216
|
+
printJsonError(message);
|
|
217
|
+
process.exit(1);
|
|
187
218
|
}
|
|
188
|
-
throw new Error(message)
|
|
219
|
+
throw new Error(message);
|
|
189
220
|
}
|
|
190
221
|
|
|
191
|
-
const nameError = validateProjectName(resolved.projectName, cwd)
|
|
222
|
+
const nameError = validateProjectName(resolved.projectName, cwd);
|
|
192
223
|
if (nameError) {
|
|
193
224
|
if (args.json) {
|
|
194
|
-
printJsonError(nameError)
|
|
195
|
-
process.exit(1)
|
|
225
|
+
printJsonError(nameError);
|
|
226
|
+
process.exit(1);
|
|
196
227
|
}
|
|
197
|
-
throw new Error(nameError)
|
|
228
|
+
throw new Error(nameError);
|
|
198
229
|
}
|
|
199
230
|
|
|
200
|
-
const targetDir = path.resolve(cwd, resolved.projectName)
|
|
231
|
+
const targetDir = path.resolve(cwd, resolved.projectName);
|
|
201
232
|
const scaffoldCtx = resolveScaffoldDefaults({
|
|
202
233
|
...resolved,
|
|
203
234
|
projectName: resolved.projectName,
|
|
204
|
-
})
|
|
205
|
-
scaffoldCtx.targetDir = targetDir
|
|
235
|
+
});
|
|
236
|
+
scaffoldCtx.targetDir = targetDir;
|
|
206
237
|
|
|
207
238
|
if (!args.json) {
|
|
208
|
-
const spinner = p.spinner()
|
|
209
|
-
spinner.start(
|
|
239
|
+
const spinner = p.spinner();
|
|
240
|
+
spinner.start("Scaffolding project");
|
|
210
241
|
try {
|
|
211
242
|
const result = await scaffoldProject({
|
|
212
243
|
...scaffoldCtx,
|
|
213
244
|
targetDir,
|
|
214
245
|
skipInstall: args.noInstall,
|
|
215
246
|
agent: resolveUserAgent(),
|
|
216
|
-
})
|
|
217
|
-
spinner.stop(
|
|
218
|
-
const cdPath = path.relative(cwd, targetDir) ||
|
|
219
|
-
p.note(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
)
|
|
226
|
-
p.outro(color.green('Done.'))
|
|
227
|
-
return result
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
spinner.stop('Scaffold failed')
|
|
231
|
-
throw error
|
|
247
|
+
});
|
|
248
|
+
spinner.stop("Project created");
|
|
249
|
+
const cdPath = path.relative(cwd, targetDir) || ".";
|
|
250
|
+
p.note([`cd ${cdPath}`, runScript(resolveUserAgent(), "dev")].join("\n"), "Next steps");
|
|
251
|
+
p.outro(color.green("Done."));
|
|
252
|
+
return result;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
spinner.stop("Scaffold failed");
|
|
255
|
+
throw error;
|
|
232
256
|
}
|
|
233
257
|
}
|
|
234
258
|
|
|
@@ -237,47 +261,52 @@ export async function runCreateCommand(args: ParsedCreateArgs): Promise<Scaffold
|
|
|
237
261
|
targetDir,
|
|
238
262
|
skipInstall: args.noInstall,
|
|
239
263
|
agent: resolveUserAgent(),
|
|
240
|
-
})
|
|
241
|
-
printScaffoldResult(result)
|
|
242
|
-
return result
|
|
264
|
+
});
|
|
265
|
+
printScaffoldResult(result);
|
|
266
|
+
return result;
|
|
243
267
|
}
|
|
244
268
|
|
|
245
|
-
export function buildParsedArgsFromCli(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
269
|
+
export function buildParsedArgsFromCli(
|
|
270
|
+
values: {
|
|
271
|
+
type?: string;
|
|
272
|
+
framework?: string;
|
|
273
|
+
db?: string;
|
|
274
|
+
logger?: string;
|
|
275
|
+
validator?: string;
|
|
276
|
+
y?: boolean;
|
|
277
|
+
noInstall?: boolean;
|
|
278
|
+
json?: boolean;
|
|
279
|
+
},
|
|
280
|
+
positionals: string[],
|
|
281
|
+
): ParsedCreateArgs {
|
|
254
282
|
const args: ParsedCreateArgs = {
|
|
255
283
|
yes: values.y ?? false,
|
|
256
284
|
noInstall: values.noInstall ?? false,
|
|
257
285
|
json: values.json ?? false,
|
|
258
|
-
}
|
|
286
|
+
};
|
|
259
287
|
|
|
260
288
|
if (positionals[0]) {
|
|
261
|
-
args.projectName = positionals[0]
|
|
289
|
+
args.projectName = positionals[0];
|
|
262
290
|
}
|
|
263
291
|
|
|
264
|
-
|
|
265
|
-
|
|
292
|
+
const typeFlag = values.type ?? values.framework;
|
|
293
|
+
if (typeFlag) {
|
|
294
|
+
args.type = parseTypeFlag(typeFlag);
|
|
266
295
|
}
|
|
267
296
|
|
|
268
297
|
if (values.db) {
|
|
269
|
-
const parsed = parseDbFlag(values.db)
|
|
270
|
-
args.db = parsed.db
|
|
271
|
-
args.driver = parsed.driver
|
|
298
|
+
const parsed = parseDbFlag(values.db);
|
|
299
|
+
args.db = parsed.db;
|
|
300
|
+
args.driver = parsed.driver;
|
|
272
301
|
}
|
|
273
302
|
|
|
274
303
|
if (values.logger) {
|
|
275
|
-
args.logger = parseLoggerFlag(values.logger)
|
|
304
|
+
args.logger = parseLoggerFlag(values.logger);
|
|
276
305
|
}
|
|
277
306
|
|
|
278
307
|
if (values.validator) {
|
|
279
|
-
args.validator = parseValidatorFlag(values.validator)
|
|
308
|
+
args.validator = parseValidatorFlag(values.validator);
|
|
280
309
|
}
|
|
281
310
|
|
|
282
|
-
return args
|
|
311
|
+
return args;
|
|
283
312
|
}
|
package/src/core/json-output.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { CapabilitiesCatalog, ScaffoldResult } from
|
|
1
|
+
import type { CapabilitiesCatalog, ScaffoldResult } from "./types.js";
|
|
2
2
|
|
|
3
3
|
export function printCapabilitiesCatalog(catalog: CapabilitiesCatalog): void {
|
|
4
|
-
console.log(JSON.stringify(catalog, null, 2))
|
|
4
|
+
console.log(JSON.stringify(catalog, null, 2));
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export function printScaffoldResult(result: ScaffoldResult): void {
|
|
8
|
-
console.log(JSON.stringify(result, null, 2))
|
|
8
|
+
console.log(JSON.stringify(result, null, 2));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function printJsonError(message: string): void {
|
|
12
|
-
console.error(JSON.stringify({ error: message }))
|
|
12
|
+
console.error(JSON.stringify({ error: message }));
|
|
13
13
|
}
|
|
@@ -1,65 +1,72 @@
|
|
|
1
|
-
import { spawn } from
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
2
|
|
|
3
|
-
import type { Agent, ResolvedCommand } from
|
|
4
|
-
import { resolveCommand } from
|
|
5
|
-
import { getUserAgent } from
|
|
3
|
+
import type { Agent, ResolvedCommand } from "package-manager-detector";
|
|
4
|
+
import { resolveCommand } from "package-manager-detector/commands";
|
|
5
|
+
import { getUserAgent } from "package-manager-detector/detect";
|
|
6
6
|
|
|
7
7
|
export function resolveUserAgent(): Agent {
|
|
8
|
-
return getUserAgent() ||
|
|
8
|
+
return getUserAgent() || "npm";
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function runCommand(command: string, args: string[], cwd: string): Promise<void> {
|
|
12
12
|
return new Promise((resolve, reject) => {
|
|
13
13
|
const child = spawn(command, args, {
|
|
14
14
|
cwd,
|
|
15
|
-
stdio:
|
|
15
|
+
stdio: "inherit",
|
|
16
16
|
shell: false,
|
|
17
17
|
env: process.env,
|
|
18
|
-
})
|
|
19
|
-
child.on(
|
|
20
|
-
child.on(
|
|
18
|
+
});
|
|
19
|
+
child.on("error", reject);
|
|
20
|
+
child.on("close", (code) => {
|
|
21
21
|
if (code === 0) {
|
|
22
|
-
resolve()
|
|
23
|
-
return
|
|
22
|
+
resolve();
|
|
23
|
+
return;
|
|
24
24
|
}
|
|
25
|
-
reject(new Error(`${command} ${args.join(
|
|
26
|
-
})
|
|
27
|
-
})
|
|
25
|
+
reject(new Error(`${command} ${args.join(" ")} exited with code ${code}`));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export function resolveInstallCommand(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
export function resolveInstallCommand(
|
|
31
|
+
agent: Agent,
|
|
32
|
+
packages: string[],
|
|
33
|
+
dev: boolean,
|
|
34
|
+
): ResolvedCommand {
|
|
35
|
+
const args = dev ? ["-D", ...packages] : packages;
|
|
36
|
+
const command = resolveCommand(agent, "add", args);
|
|
37
|
+
if (command) return command;
|
|
34
38
|
|
|
35
39
|
return {
|
|
36
|
-
command:
|
|
37
|
-
args: [
|
|
38
|
-
}
|
|
40
|
+
command: "npm",
|
|
41
|
+
args: ["install", ...args],
|
|
42
|
+
};
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
export async function installPackages(
|
|
42
46
|
agent: Agent,
|
|
43
47
|
cwd: string,
|
|
44
|
-
{
|
|
45
|
-
dependencies
|
|
46
|
-
devDependencies
|
|
48
|
+
{
|
|
49
|
+
dependencies,
|
|
50
|
+
devDependencies,
|
|
51
|
+
}: {
|
|
52
|
+
dependencies: string[];
|
|
53
|
+
devDependencies: string[];
|
|
47
54
|
},
|
|
48
55
|
): Promise<void> {
|
|
49
56
|
if (dependencies.length > 0) {
|
|
50
|
-
const { command, args } = resolveInstallCommand(agent, dependencies, false)
|
|
51
|
-
await runCommand(command, args, cwd)
|
|
57
|
+
const { command, args } = resolveInstallCommand(agent, dependencies, false);
|
|
58
|
+
await runCommand(command, args, cwd);
|
|
52
59
|
}
|
|
53
60
|
if (devDependencies.length > 0) {
|
|
54
|
-
const { command, args } = resolveInstallCommand(agent, devDependencies, true)
|
|
55
|
-
await runCommand(command, args, cwd)
|
|
61
|
+
const { command, args } = resolveInstallCommand(agent, devDependencies, true);
|
|
62
|
+
await runCommand(command, args, cwd);
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
export function runScript(agent: Agent, script: string): string {
|
|
60
|
-
const resolved = resolveCommand(agent,
|
|
67
|
+
const resolved = resolveCommand(agent, "run", [script]);
|
|
61
68
|
if (!resolved) {
|
|
62
|
-
throw new Error(`Unable to resolve run command for ${agent}`)
|
|
69
|
+
throw new Error(`Unable to resolve run command for ${agent}`);
|
|
63
70
|
}
|
|
64
|
-
return `${resolved.command} ${resolved.args.join(
|
|
71
|
+
return `${resolved.command} ${resolved.args.join(" ")}`;
|
|
65
72
|
}
|