create-rigg 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/dist/index.mjs +56 -18
- package/package.json +6 -5
- package/template/test/index.test.ts +5 -0
- package/template/vitest.config.ts +7 -0
package/dist/index.mjs
CHANGED
|
@@ -26,6 +26,12 @@ const FRAMEWORKS = [
|
|
|
26
26
|
label: "Express"
|
|
27
27
|
}
|
|
28
28
|
];
|
|
29
|
+
const FRAMEWORK_LABELS = {
|
|
30
|
+
none: "None",
|
|
31
|
+
hono: "Hono",
|
|
32
|
+
fastify: "Fastify",
|
|
33
|
+
express: "Express"
|
|
34
|
+
};
|
|
29
35
|
const FRAMEWORK_DEPS = {
|
|
30
36
|
none: {
|
|
31
37
|
deps: [],
|
|
@@ -79,8 +85,15 @@ app.listen(3000, () => {
|
|
|
79
85
|
`
|
|
80
86
|
};
|
|
81
87
|
//#endregion
|
|
88
|
+
//#region src/pkg-managers.ts
|
|
89
|
+
const PKG_MANAGERS = [
|
|
90
|
+
"npm",
|
|
91
|
+
"pnpm",
|
|
92
|
+
"yarn",
|
|
93
|
+
"bun"
|
|
94
|
+
];
|
|
95
|
+
//#endregion
|
|
82
96
|
//#region src/index.ts
|
|
83
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
84
97
|
/** Creates a colored gradient text effect */
|
|
85
98
|
function gradient(text, stops, whiteRange) {
|
|
86
99
|
const chars = [...text];
|
|
@@ -97,9 +110,7 @@ function gradient(text, stops, whiteRange) {
|
|
|
97
110
|
/** Detects the package manager used to invoke the CLI via npm_config_user_agent. */
|
|
98
111
|
function detectPkgManager() {
|
|
99
112
|
const ua = process.env.npm_config_user_agent ?? "";
|
|
100
|
-
if (ua.startsWith(
|
|
101
|
-
if (ua.startsWith("bun")) return "bun";
|
|
102
|
-
if (ua.startsWith("yarn")) return "yarn";
|
|
113
|
+
for (const pm of PKG_MANAGERS) if (ua.startsWith(pm)) return pm;
|
|
103
114
|
return "npm";
|
|
104
115
|
}
|
|
105
116
|
/** Builds the install/add command args for the given package manager. */
|
|
@@ -119,7 +130,7 @@ function addArgs(pkgManager, packages, dev) {
|
|
|
119
130
|
/** Runs a command synchronously, exiting the process if it fails. */
|
|
120
131
|
function run(cmd, args, opts) {
|
|
121
132
|
const result = spawn.sync(cmd, args, {
|
|
122
|
-
stdio: "
|
|
133
|
+
stdio: "ignore",
|
|
123
134
|
...opts
|
|
124
135
|
});
|
|
125
136
|
if (result.status != null && result.status !== 0) process.exit(result.status);
|
|
@@ -174,7 +185,10 @@ async function promptFramework(argv) {
|
|
|
174
185
|
/** Asks the user to confirm before wiping a non-empty target directory. */
|
|
175
186
|
async function confirmOverwrite(projectName, targetDir) {
|
|
176
187
|
if (isEmpty(targetDir)) return;
|
|
177
|
-
const overwrite = await p.confirm({
|
|
188
|
+
const overwrite = await p.confirm({
|
|
189
|
+
message: `${pc.white(projectName)} is not empty. Remove existing files and continue?`,
|
|
190
|
+
initialValue: false
|
|
191
|
+
});
|
|
178
192
|
if (p.isCancel(overwrite) || !overwrite) {
|
|
179
193
|
p.cancel("Cancelled");
|
|
180
194
|
process.exit(0);
|
|
@@ -186,7 +200,8 @@ async function confirmOverwrite(projectName, targetDir) {
|
|
|
186
200
|
}
|
|
187
201
|
/** Copies the base template, sets the package name, and writes the framework starter code. */
|
|
188
202
|
function scaffoldFiles(projectName, framework, targetDir) {
|
|
189
|
-
|
|
203
|
+
const directory = path.dirname(fileURLToPath(import.meta.url));
|
|
204
|
+
copyDir(path.join(directory, "..", "template"), targetDir);
|
|
190
205
|
const pkgJsonPath = path.join(targetDir, "package.json");
|
|
191
206
|
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
|
|
192
207
|
pkg.name = projectName;
|
|
@@ -196,7 +211,15 @@ function scaffoldFiles(projectName, framework, targetDir) {
|
|
|
196
211
|
}
|
|
197
212
|
/** Installs shared dev dependencies and any framework-specific packages. */
|
|
198
213
|
function installDependencies(pkgManager, framework, targetDir) {
|
|
199
|
-
p.log.step(`Installing dependencies with ${pkgManager
|
|
214
|
+
p.log.step(`Installing dependencies with ${gradient(pkgManager, [[
|
|
215
|
+
168,
|
|
216
|
+
85,
|
|
217
|
+
247
|
|
218
|
+
], [
|
|
219
|
+
99,
|
|
220
|
+
102,
|
|
221
|
+
241
|
|
222
|
+
]])}...`);
|
|
200
223
|
run(pkgManager, addArgs(pkgManager, [
|
|
201
224
|
"@types/node",
|
|
202
225
|
"oxfmt",
|
|
@@ -208,7 +231,15 @@ function installDependencies(pkgManager, framework, targetDir) {
|
|
|
208
231
|
], true), { cwd: targetDir });
|
|
209
232
|
/** Install framework dependencies */
|
|
210
233
|
if (framework !== "none") {
|
|
211
|
-
p.log.step(`Installing ${framework
|
|
234
|
+
p.log.step(`Installing ${gradient(FRAMEWORK_LABELS[framework], [[
|
|
235
|
+
168,
|
|
236
|
+
85,
|
|
237
|
+
247
|
|
238
|
+
], [
|
|
239
|
+
99,
|
|
240
|
+
102,
|
|
241
|
+
241
|
|
242
|
+
]])}...`);
|
|
212
243
|
const frameworkDeps = FRAMEWORK_DEPS[framework];
|
|
213
244
|
if (frameworkDeps.deps.length > 0) run(pkgManager, addArgs(pkgManager, frameworkDeps.deps, false), { cwd: targetDir });
|
|
214
245
|
if (frameworkDeps.devDeps.length > 0) run(pkgManager, addArgs(pkgManager, frameworkDeps.devDeps, true), { cwd: targetDir });
|
|
@@ -216,7 +247,7 @@ function installDependencies(pkgManager, framework, targetDir) {
|
|
|
216
247
|
}
|
|
217
248
|
/** Prints the gradient outro with next steps. */
|
|
218
249
|
function showOutro(projectName, framework, pkgManager) {
|
|
219
|
-
const frameworkLabel =
|
|
250
|
+
const frameworkLabel = FRAMEWORK_LABELS[framework];
|
|
220
251
|
const outroStops = [[
|
|
221
252
|
168,
|
|
222
253
|
85,
|
|
@@ -234,7 +265,7 @@ function showOutro(projectName, framework, pkgManager) {
|
|
|
234
265
|
}
|
|
235
266
|
async function main() {
|
|
236
267
|
const argv = mri(process.argv.slice(2), {
|
|
237
|
-
string: ["template"],
|
|
268
|
+
string: ["template", "pm"],
|
|
238
269
|
alias: { t: "template" }
|
|
239
270
|
});
|
|
240
271
|
p.intro(pc.bold(gradient("rigg - The Unified Toolchain Starter for Node.js", [
|
|
@@ -255,10 +286,10 @@ async function main() {
|
|
|
255
286
|
]
|
|
256
287
|
], [0, 6])));
|
|
257
288
|
const projectName = await promptProjectName(argv);
|
|
258
|
-
const framework = await promptFramework(argv);
|
|
259
289
|
const targetDir = path.resolve(process.cwd(), projectName);
|
|
260
|
-
const pkgManager = detectPkgManager();
|
|
290
|
+
const pkgManager = argv.pm ?? detectPkgManager();
|
|
261
291
|
await confirmOverwrite(projectName, targetDir);
|
|
292
|
+
const framework = await promptFramework(argv);
|
|
262
293
|
scaffoldFiles(projectName, framework, targetDir);
|
|
263
294
|
run("git", [
|
|
264
295
|
"init",
|
|
@@ -271,25 +302,32 @@ async function main() {
|
|
|
271
302
|
p.log.step("Initializing git repository");
|
|
272
303
|
installDependencies(pkgManager, framework, targetDir);
|
|
273
304
|
p.log.step("Formatting code");
|
|
305
|
+
const execCmd = pkgManager === "bun" ? "x" : "exec";
|
|
306
|
+
const sep = pkgManager === "npm" || pkgManager === "yarn" ? ["--"] : [];
|
|
274
307
|
run(pkgManager, [
|
|
275
|
-
|
|
308
|
+
execCmd,
|
|
276
309
|
"oxlint",
|
|
277
|
-
|
|
310
|
+
...sep,
|
|
278
311
|
"--init"
|
|
279
312
|
], {
|
|
280
313
|
cwd: targetDir,
|
|
281
314
|
stdio: "ignore"
|
|
282
315
|
});
|
|
283
316
|
run(pkgManager, [
|
|
284
|
-
|
|
317
|
+
execCmd,
|
|
285
318
|
"oxfmt",
|
|
286
|
-
|
|
319
|
+
...sep,
|
|
287
320
|
"--init"
|
|
288
321
|
], {
|
|
289
322
|
cwd: targetDir,
|
|
290
323
|
stdio: "ignore"
|
|
291
324
|
});
|
|
292
|
-
run(pkgManager, [
|
|
325
|
+
run(pkgManager, [
|
|
326
|
+
execCmd,
|
|
327
|
+
"oxfmt",
|
|
328
|
+
...sep,
|
|
329
|
+
"."
|
|
330
|
+
], {
|
|
293
331
|
cwd: targetDir,
|
|
294
332
|
stdio: "ignore"
|
|
295
333
|
});
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-rigg",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "The Unified Toolchain Starter for Node.js backend and non-web projects
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "The Unified Toolchain Starter for Node.js backend and non-web projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"backend",
|
|
7
|
-
"node",
|
|
8
|
-
"nodejs",
|
|
9
7
|
"create-rigg",
|
|
10
8
|
"express",
|
|
11
9
|
"fastify",
|
|
12
10
|
"framework",
|
|
13
11
|
"hono",
|
|
12
|
+
"node",
|
|
13
|
+
"nodejs",
|
|
14
14
|
"oxfmt",
|
|
15
15
|
"oxlint",
|
|
16
16
|
"rigg",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"fmt:check": "oxfmt --check",
|
|
43
43
|
"check": "oxlint && oxfmt --check && tsc --noEmit",
|
|
44
44
|
"dev": "tsx src/index.ts",
|
|
45
|
-
"build": "tsdown src/index.ts"
|
|
45
|
+
"build": "tsdown src/index.ts",
|
|
46
|
+
"prepublishOnly": "oxlint && oxfmt && tsc --noEmit && vitest run && pnpm build"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"@clack/prompts": "^1.1.0",
|