@mayrlabs/setup-project 0.1.4 → 0.1.6
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/CHANGELOG.md +12 -0
- package/dist/index.js +681 -405
- package/dist/index.mjs +749 -418
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -33,12 +33,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
));
|
|
34
34
|
|
|
35
35
|
// src/index.ts
|
|
36
|
-
var
|
|
37
|
-
var
|
|
36
|
+
var import_prompts12 = require("@clack/prompts");
|
|
37
|
+
var import_picocolors11 = __toESM(require("picocolors"));
|
|
38
38
|
var import_commander = require("commander");
|
|
39
39
|
|
|
40
40
|
// src/services/husky.ts
|
|
41
|
-
var
|
|
41
|
+
var import_prompts2 = require("@clack/prompts");
|
|
42
42
|
|
|
43
43
|
// src/utils/pm.ts
|
|
44
44
|
var import_execa = require("execa");
|
|
@@ -73,30 +73,137 @@ async function installPackages(packages, dev = false) {
|
|
|
73
73
|
// src/services/husky.ts
|
|
74
74
|
var import_execa2 = require("execa");
|
|
75
75
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
76
|
+
var import_picocolors = __toESM(require("picocolors"));
|
|
77
|
+
|
|
78
|
+
// src/constants/options.ts
|
|
79
|
+
var TOOL_OPTIONS = [
|
|
80
|
+
{ value: "husky", label: "Husky" },
|
|
81
|
+
{ value: "formatter", label: "Formatter (Prettier/Oxfmt)" },
|
|
82
|
+
{ value: "linter", label: "Linter (Eslint/Oxlint)" },
|
|
83
|
+
{ value: "lint-staged", label: "Lint-staged" },
|
|
84
|
+
{ value: "env", label: "Env Validation (@t3-oss/env)" },
|
|
85
|
+
{ value: "test", label: "Test Runner (Vitest/Jest)" },
|
|
86
|
+
{ value: "editorConfig", label: "EditorConfig" },
|
|
87
|
+
{ value: "license", label: "License" }
|
|
88
|
+
];
|
|
89
|
+
var HUSKY_HOOK_OPTIONS = [
|
|
90
|
+
{ value: "lint-staged", label: "lint-staged" },
|
|
91
|
+
{ value: "custom", label: "Custom script" },
|
|
92
|
+
{ value: "none", label: "None" }
|
|
93
|
+
];
|
|
94
|
+
var FORMATTER_OPTIONS = [
|
|
95
|
+
{ value: "prettier", label: "Prettier" },
|
|
96
|
+
{ value: "oxfmt", label: "Oxfmt" }
|
|
97
|
+
];
|
|
98
|
+
var LINTER_OPTIONS = [
|
|
99
|
+
{ value: "eslint", label: "ESLint" },
|
|
100
|
+
{ value: "oxlint", label: "Oxlint" }
|
|
101
|
+
];
|
|
102
|
+
var LINT_STAGED_EXTENSIONS = [
|
|
103
|
+
{ value: "js", label: "js" },
|
|
104
|
+
{ value: "ts", label: "ts" },
|
|
105
|
+
{ value: "jsx", label: "jsx" },
|
|
106
|
+
{ value: "tsx", label: "tsx" },
|
|
107
|
+
{ value: "html", label: "html" },
|
|
108
|
+
{ value: "vue", label: "vue" },
|
|
109
|
+
{ value: "svelte", label: "svelte" },
|
|
110
|
+
{ value: "css", label: "css" },
|
|
111
|
+
{ value: "scss", label: "scss" },
|
|
112
|
+
{ value: "json", label: "json" },
|
|
113
|
+
{ value: "yaml", label: "yaml" },
|
|
114
|
+
{ value: "md", label: "md" }
|
|
115
|
+
];
|
|
116
|
+
var ENV_VARIANT_OPTIONS = [
|
|
117
|
+
{ value: "@t3-oss/env-nextjs", label: "Next.js" },
|
|
118
|
+
{ value: "@t3-oss/env-nuxt", label: "Nuxt" },
|
|
119
|
+
{ value: "@t3-oss/env-core", label: "Core" }
|
|
120
|
+
];
|
|
121
|
+
var ENV_VALIDATOR_OPTIONS = [
|
|
122
|
+
{ value: "zod", label: "Zod" },
|
|
123
|
+
{ value: "valibot", label: "Valibot" },
|
|
124
|
+
{ value: "arktype", label: "Arktype" }
|
|
125
|
+
];
|
|
126
|
+
var ENV_PRESET_OPTIONS = [
|
|
127
|
+
{ value: "netlify", label: "Netlify" },
|
|
128
|
+
{ value: "vercel", label: "Vercel" },
|
|
129
|
+
{ value: "neonVercel", label: "Neon (Vercel)" },
|
|
130
|
+
{ value: "supabaseVercel", label: "Supabase (Vercel)" },
|
|
131
|
+
{ value: "uploadThing", label: "UploadThing" },
|
|
132
|
+
{ value: "render", label: "Render" },
|
|
133
|
+
{ value: "railway", label: "Railway" },
|
|
134
|
+
{ value: "fly.io", label: "Fly.io" },
|
|
135
|
+
{ value: "upstashRedis", label: "Upstash Redis" },
|
|
136
|
+
{ value: "coolify", label: "Coolify" },
|
|
137
|
+
{ value: "vite", label: "Vite" },
|
|
138
|
+
{ value: "wxt", label: "WXT" }
|
|
139
|
+
];
|
|
140
|
+
var ENV_SPLIT_OPTIONS = [
|
|
141
|
+
{ value: "split", label: "Split (env/server.ts, env/client.ts)" },
|
|
142
|
+
{ value: "joined", label: "Joined (env.ts)" }
|
|
143
|
+
];
|
|
144
|
+
var TEST_RUNNER_OPTIONS = [
|
|
145
|
+
{ value: "vitest", label: "Vitest" },
|
|
146
|
+
{ value: "jest", label: "Jest" }
|
|
147
|
+
];
|
|
148
|
+
var EDITOR_CONFIG_OPTIONS = [
|
|
149
|
+
{ value: "default", label: "Default (Spaces 2)" },
|
|
150
|
+
{ value: "spaces4", label: "Spaces 4" },
|
|
151
|
+
{ value: "tabs", label: "Tabs" }
|
|
152
|
+
];
|
|
153
|
+
var LICENSE_TYPE_OPTIONS = [
|
|
154
|
+
{ value: "MIT", label: "MIT" },
|
|
155
|
+
{ value: "ISC", label: "ISC" },
|
|
156
|
+
{ value: "Apache-2.0", label: "Apache 2.0" },
|
|
157
|
+
{ value: "UNLICENSED", label: "UNLICENSED" }
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
// src/utils/handle-cancel.ts
|
|
161
|
+
var import_prompts = require("@clack/prompts");
|
|
162
|
+
async function withCancelHandling(promptFn, cancelMessage = "Operation cancelled.") {
|
|
163
|
+
while (true) {
|
|
164
|
+
const response = await promptFn();
|
|
165
|
+
if ((0, import_prompts.isCancel)(response)) {
|
|
166
|
+
const shouldCancel = await (0, import_prompts.confirm)({
|
|
167
|
+
message: "Do you really want to cancel options selection?"
|
|
168
|
+
});
|
|
169
|
+
if ((0, import_prompts.isCancel)(shouldCancel) || shouldCancel) {
|
|
170
|
+
(0, import_prompts.cancel)(cancelMessage);
|
|
171
|
+
process.exit(0);
|
|
172
|
+
}
|
|
173
|
+
continue;
|
|
174
|
+
} else {
|
|
175
|
+
return response;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/services/husky.ts
|
|
181
|
+
async function promptHusky(config2) {
|
|
182
|
+
import_prompts2.log.message(import_picocolors.default.bgMagenta(import_picocolors.default.black(" Husky Configuration ")));
|
|
183
|
+
const hookType = await withCancelHandling(
|
|
184
|
+
async () => (0, import_prompts2.select)({
|
|
185
|
+
message: "What pre-commit hook would you like to use?",
|
|
186
|
+
options: HUSKY_HOOK_OPTIONS
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
const huskyConfig = config2.get("husky");
|
|
190
|
+
huskyConfig.options = { hookType };
|
|
86
191
|
if (hookType === "lint-staged") {
|
|
87
|
-
|
|
192
|
+
config2.enableTool("lintStaged");
|
|
88
193
|
} else if (hookType === "custom") {
|
|
89
|
-
const script = await (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
194
|
+
const script = await withCancelHandling(
|
|
195
|
+
async () => (0, import_prompts2.text)({
|
|
196
|
+
message: "Enter your custom pre-commit script:",
|
|
197
|
+
placeholder: huskyConfig.options.customScript,
|
|
198
|
+
validate(value) {
|
|
199
|
+
if (value.length === 0) return "Value is required!";
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
huskyConfig.options.customScript = script;
|
|
97
204
|
}
|
|
98
205
|
}
|
|
99
|
-
async function installHusky(
|
|
206
|
+
async function installHusky(config2) {
|
|
100
207
|
await installPackages(["husky"], true);
|
|
101
208
|
try {
|
|
102
209
|
await (0, import_execa2.execa)("npx", ["husky", "init"]);
|
|
@@ -104,12 +211,15 @@ async function installHusky(config) {
|
|
|
104
211
|
await (0, import_execa2.execa)("npm", ["pkg", "set", "scripts.prepare=husky"]);
|
|
105
212
|
await (0, import_execa2.execa)("npm", ["run", "prepare"]);
|
|
106
213
|
}
|
|
107
|
-
|
|
214
|
+
const husky = config2.get("husky");
|
|
215
|
+
const hookType = husky.options.hookType;
|
|
216
|
+
const customScript = husky.options.customScript;
|
|
217
|
+
if (hookType === "lint-staged") {
|
|
108
218
|
await import_fs_extra.default.outputFile(".husky/pre-commit", "npx lint-staged\n", {
|
|
109
219
|
mode: 493
|
|
110
220
|
});
|
|
111
|
-
} else if (
|
|
112
|
-
await import_fs_extra.default.outputFile(".husky/pre-commit", `${
|
|
221
|
+
} else if (hookType === "custom" && customScript) {
|
|
222
|
+
await import_fs_extra.default.outputFile(".husky/pre-commit", `${customScript}
|
|
113
223
|
`, {
|
|
114
224
|
mode: 493
|
|
115
225
|
});
|
|
@@ -117,22 +227,24 @@ async function installHusky(config) {
|
|
|
117
227
|
}
|
|
118
228
|
|
|
119
229
|
// src/services/formatter.ts
|
|
120
|
-
var
|
|
230
|
+
var import_prompts3 = require("@clack/prompts");
|
|
121
231
|
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
232
|
+
var import_picocolors2 = __toESM(require("picocolors"));
|
|
233
|
+
async function promptFormatter(config2) {
|
|
234
|
+
const formatterConfig = config2.get("formatter");
|
|
235
|
+
import_prompts3.log.message(import_picocolors2.default.bgBlue(import_picocolors2.default.black(" Formatter Configuration ")));
|
|
236
|
+
const formatter = await withCancelHandling(
|
|
237
|
+
async () => (0, import_prompts3.select)({
|
|
125
238
|
message: "Select a formatter:",
|
|
126
|
-
options:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
config.formatterChoice = formatter;
|
|
132
|
-
}
|
|
239
|
+
options: FORMATTER_OPTIONS,
|
|
240
|
+
initialValue: formatterConfig.options.choice
|
|
241
|
+
})
|
|
242
|
+
);
|
|
243
|
+
formatterConfig.options = { choice: formatter };
|
|
133
244
|
}
|
|
134
|
-
async function installFormatter(
|
|
135
|
-
|
|
245
|
+
async function installFormatter(config2) {
|
|
246
|
+
const choice = config2.get("formatter").options.choice;
|
|
247
|
+
if (choice === "prettier") {
|
|
136
248
|
await installPackages(["prettier"], true);
|
|
137
249
|
const configContent = {
|
|
138
250
|
semi: true,
|
|
@@ -142,28 +254,30 @@ async function installFormatter(config) {
|
|
|
142
254
|
tabWidth: 2
|
|
143
255
|
};
|
|
144
256
|
await import_fs_extra2.default.writeJson(".prettierrc", configContent, { spaces: 2 });
|
|
145
|
-
} else if (
|
|
257
|
+
} else if (choice === "oxfmt") {
|
|
146
258
|
await installPackages(["oxfmt"], true);
|
|
147
259
|
}
|
|
148
260
|
}
|
|
149
261
|
|
|
150
262
|
// src/services/linter.ts
|
|
151
|
-
var
|
|
263
|
+
var import_prompts4 = require("@clack/prompts");
|
|
152
264
|
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
265
|
+
var import_picocolors3 = __toESM(require("picocolors"));
|
|
266
|
+
async function promptLinter(config2) {
|
|
267
|
+
const linterConfig = config2.get("linter");
|
|
268
|
+
import_prompts4.log.message(import_picocolors3.default.bgYellow(import_picocolors3.default.black(" Linter Configuration ")));
|
|
269
|
+
const linter = await withCancelHandling(
|
|
270
|
+
async () => (0, import_prompts4.select)({
|
|
156
271
|
message: "Select a linter:",
|
|
157
|
-
options:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
config.linterChoice = linter;
|
|
163
|
-
}
|
|
272
|
+
options: LINTER_OPTIONS,
|
|
273
|
+
initialValue: linterConfig.options.choice
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
linterConfig.options = { choice: linter };
|
|
164
277
|
}
|
|
165
|
-
async function installLinter(
|
|
166
|
-
|
|
278
|
+
async function installLinter(config2) {
|
|
279
|
+
const choice = config2.get("linter").options.choice;
|
|
280
|
+
if (choice === "eslint") {
|
|
167
281
|
await installPackages(["eslint"], true);
|
|
168
282
|
const configContent = {
|
|
169
283
|
extends: ["eslint:recommended"],
|
|
@@ -177,75 +291,63 @@ async function installLinter(config) {
|
|
|
177
291
|
}
|
|
178
292
|
};
|
|
179
293
|
await import_fs_extra3.default.writeJson(".eslintrc.json", configContent, { spaces: 2 });
|
|
180
|
-
} else if (
|
|
294
|
+
} else if (choice === "oxlint") {
|
|
181
295
|
await installPackages(["oxlint"], true);
|
|
182
296
|
}
|
|
183
297
|
}
|
|
184
298
|
|
|
185
299
|
// src/services/lint-staged.ts
|
|
186
|
-
var
|
|
300
|
+
var import_prompts5 = require("@clack/prompts");
|
|
187
301
|
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
{ value: "svelte", label: "svelte" }
|
|
217
|
-
],
|
|
218
|
-
required: false
|
|
219
|
-
});
|
|
220
|
-
config.lintStagedLintExtensions = lintExtensions;
|
|
221
|
-
config.lintStagedFormatExtensions = formatExtensions;
|
|
222
|
-
if (lintExtensions.length > 0 && !config.linterChoice) {
|
|
223
|
-
await promptLinter(config);
|
|
224
|
-
config.linter = true;
|
|
225
|
-
}
|
|
226
|
-
if (formatExtensions.length > 0 && !config.formatterChoice) {
|
|
227
|
-
await promptFormatter(config);
|
|
228
|
-
config.formatter = true;
|
|
302
|
+
var import_picocolors4 = __toESM(require("picocolors"));
|
|
303
|
+
async function promptLintStaged(config2) {
|
|
304
|
+
import_prompts5.log.message(import_picocolors4.default.bgGreen(import_picocolors4.default.black(" Lint-staged Configuration ")));
|
|
305
|
+
const lintExtensions = await withCancelHandling(
|
|
306
|
+
async () => (0, import_prompts5.multiselect)({
|
|
307
|
+
message: "Select extensions to lint:",
|
|
308
|
+
options: LINT_STAGED_EXTENSIONS,
|
|
309
|
+
required: false
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
const formatExtensions = await withCancelHandling(
|
|
313
|
+
async () => (0, import_prompts5.multiselect)({
|
|
314
|
+
message: "Select extensions to format:",
|
|
315
|
+
options: LINT_STAGED_EXTENSIONS,
|
|
316
|
+
required: false
|
|
317
|
+
})
|
|
318
|
+
);
|
|
319
|
+
config2.get("lintStaged").options = {
|
|
320
|
+
lintExtensions,
|
|
321
|
+
formatExtensions
|
|
322
|
+
};
|
|
323
|
+
if (lintExtensions.length > 0 && !config2.get("linter").selected) {
|
|
324
|
+
await promptLinter(config2);
|
|
325
|
+
config2.enableTool("linter");
|
|
326
|
+
}
|
|
327
|
+
if (formatExtensions.length > 0 && !config2.get("formatter").selected) {
|
|
328
|
+
await promptFormatter(config2);
|
|
329
|
+
config2.enableTool("formatter");
|
|
229
330
|
}
|
|
230
331
|
}
|
|
231
|
-
async function installLintStaged(
|
|
332
|
+
async function installLintStaged(config2) {
|
|
232
333
|
await installPackages(["lint-staged"], true);
|
|
233
334
|
const lintStagedConfig = {};
|
|
234
|
-
const
|
|
235
|
-
const
|
|
335
|
+
const lintStagedOptions = config2.get("lintStaged").options;
|
|
336
|
+
const lintExts = lintStagedOptions?.lintExtensions || [];
|
|
337
|
+
const formatExts = lintStagedOptions?.formatExtensions || [];
|
|
236
338
|
if (lintExts.length > 0) {
|
|
237
|
-
await installLinter(
|
|
339
|
+
await installLinter(config2);
|
|
238
340
|
const glob = `*.{${lintExts.join(",")}}`;
|
|
239
|
-
if (
|
|
341
|
+
if (config2.get("linter").options.choice === "oxlint") {
|
|
240
342
|
lintStagedConfig[glob] = ["npx oxlint --fix"];
|
|
241
343
|
} else {
|
|
242
344
|
lintStagedConfig[glob] = ["eslint --fix"];
|
|
243
345
|
}
|
|
244
346
|
}
|
|
245
347
|
if (formatExts.length > 0) {
|
|
246
|
-
await installFormatter(
|
|
348
|
+
await installFormatter(config2);
|
|
247
349
|
const glob = `*.{${formatExts.join(",")}}`;
|
|
248
|
-
if (
|
|
350
|
+
if (config2.get("formatter").options.choice === "oxfmt") {
|
|
249
351
|
lintStagedConfig[glob] = ["npx oxfmt"];
|
|
250
352
|
} else {
|
|
251
353
|
lintStagedConfig[glob] = ["prettier --write"];
|
|
@@ -255,85 +357,75 @@ async function installLintStaged(config) {
|
|
|
255
357
|
}
|
|
256
358
|
|
|
257
359
|
// src/services/env.ts
|
|
258
|
-
var
|
|
360
|
+
var import_prompts6 = require("@clack/prompts");
|
|
259
361
|
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
260
362
|
var import_path = __toESM(require("path"));
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
});
|
|
283
|
-
config.envInstallPresets = installPresets;
|
|
363
|
+
var import_picocolors5 = __toESM(require("picocolors"));
|
|
364
|
+
async function promptEnv(config2) {
|
|
365
|
+
import_prompts6.log.message(import_picocolors5.default.bgCyan(import_picocolors5.default.black(" Env Validation Configuration ")));
|
|
366
|
+
const variant = await withCancelHandling(
|
|
367
|
+
async () => (0, import_prompts6.select)({
|
|
368
|
+
message: "Which @t3-oss/env variant?",
|
|
369
|
+
options: ENV_VARIANT_OPTIONS
|
|
370
|
+
})
|
|
371
|
+
);
|
|
372
|
+
const validator = await withCancelHandling(
|
|
373
|
+
async () => (0, import_prompts6.select)({
|
|
374
|
+
message: "Which validator?",
|
|
375
|
+
options: ENV_VALIDATOR_OPTIONS
|
|
376
|
+
})
|
|
377
|
+
);
|
|
378
|
+
const installPresets = await withCancelHandling(
|
|
379
|
+
async () => (0, import_prompts6.confirm)({
|
|
380
|
+
message: "Install presets?"
|
|
381
|
+
})
|
|
382
|
+
);
|
|
383
|
+
let presets;
|
|
284
384
|
if (installPresets) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
]
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
message: "Where should the environment files be created?",
|
|
315
|
-
initialValue: "src/lib",
|
|
316
|
-
placeholder: "src/lib"
|
|
317
|
-
});
|
|
318
|
-
config.envLocation = location;
|
|
385
|
+
presets = await withCancelHandling(
|
|
386
|
+
async () => (0, import_prompts6.multiselect)({
|
|
387
|
+
message: "Select preset to extend:",
|
|
388
|
+
options: ENV_PRESET_OPTIONS,
|
|
389
|
+
required: false
|
|
390
|
+
})
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
const split = await withCancelHandling(
|
|
394
|
+
async () => (0, import_prompts6.select)({
|
|
395
|
+
message: "Split or Joined env files?",
|
|
396
|
+
options: ENV_SPLIT_OPTIONS
|
|
397
|
+
})
|
|
398
|
+
);
|
|
399
|
+
const location = await withCancelHandling(
|
|
400
|
+
async () => (0, import_prompts6.text)({
|
|
401
|
+
message: "Where should the environment files be created?",
|
|
402
|
+
initialValue: config2.get("env").options.location || "src/lib",
|
|
403
|
+
placeholder: "src/lib"
|
|
404
|
+
})
|
|
405
|
+
);
|
|
406
|
+
config2.get("env").options = {
|
|
407
|
+
variant,
|
|
408
|
+
validator,
|
|
409
|
+
installPresets,
|
|
410
|
+
presets: presets || [],
|
|
411
|
+
split,
|
|
412
|
+
location
|
|
413
|
+
};
|
|
319
414
|
}
|
|
320
|
-
async function installEnv(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
const targetDir = config.envLocation;
|
|
327
|
-
await import_fs_extra5.default.ensureDir(targetDir);
|
|
328
|
-
const presetImport = config.envPresets && config.envPresets.length > 0 ? `// Presets: ${config.envPresets.join(", ")}
|
|
415
|
+
async function installEnv(config2) {
|
|
416
|
+
const envOptions = config2.get("env").options;
|
|
417
|
+
const { variant, validator, location, presets, split } = envOptions;
|
|
418
|
+
await installPackages([variant, validator], true);
|
|
419
|
+
await import_fs_extra5.default.ensureDir(location);
|
|
420
|
+
const presetImport = presets && presets.length > 0 ? `// Presets: ${presets.join(", ")}
|
|
329
421
|
` : "";
|
|
330
|
-
const content = `import { createEnv } from "${
|
|
331
|
-
import { ${
|
|
422
|
+
const content = `import { createEnv } from "${variant}";
|
|
423
|
+
import { ${validator} } from "${validator}";
|
|
332
424
|
|
|
333
425
|
${presetImport}`;
|
|
334
|
-
if (
|
|
426
|
+
if (split === "split") {
|
|
335
427
|
await import_fs_extra5.default.outputFile(
|
|
336
|
-
import_path.default.join(
|
|
428
|
+
import_path.default.join(location, "env/server.ts"),
|
|
337
429
|
`${content}
|
|
338
430
|
// Server env definition
|
|
339
431
|
export const env = createEnv({
|
|
@@ -344,7 +436,7 @@ export const env = createEnv({
|
|
|
344
436
|
});`
|
|
345
437
|
);
|
|
346
438
|
await import_fs_extra5.default.outputFile(
|
|
347
|
-
import_path.default.join(
|
|
439
|
+
import_path.default.join(location, "env/client.ts"),
|
|
348
440
|
`${content}
|
|
349
441
|
// Client env definition
|
|
350
442
|
export const env = createEnv({
|
|
@@ -358,7 +450,7 @@ export const env = createEnv({
|
|
|
358
450
|
);
|
|
359
451
|
} else {
|
|
360
452
|
await import_fs_extra5.default.outputFile(
|
|
361
|
-
import_path.default.join(
|
|
453
|
+
import_path.default.join(location, "env.ts"),
|
|
362
454
|
`${content}
|
|
363
455
|
// Joined env definition
|
|
364
456
|
export const env = createEnv({
|
|
@@ -377,20 +469,22 @@ export const env = createEnv({
|
|
|
377
469
|
}
|
|
378
470
|
|
|
379
471
|
// src/services/test.ts
|
|
380
|
-
var
|
|
472
|
+
var import_prompts7 = require("@clack/prompts");
|
|
381
473
|
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
474
|
+
var import_picocolors6 = __toESM(require("picocolors"));
|
|
475
|
+
async function promptTest(config2) {
|
|
476
|
+
import_prompts7.log.message(import_picocolors6.default.bgRed(import_picocolors6.default.black(" Test Runner Configuration ")));
|
|
477
|
+
const runner = await withCancelHandling(
|
|
478
|
+
async () => (0, import_prompts7.select)({
|
|
479
|
+
message: "Select a test runner:",
|
|
480
|
+
options: TEST_RUNNER_OPTIONS
|
|
481
|
+
})
|
|
482
|
+
);
|
|
483
|
+
config2.get("test").options = { runner };
|
|
391
484
|
}
|
|
392
|
-
async function installTest(
|
|
393
|
-
|
|
485
|
+
async function installTest(config2) {
|
|
486
|
+
const runner = config2.get("test").options.runner;
|
|
487
|
+
if (runner === "vitest") {
|
|
394
488
|
await installPackages(["vitest"], true);
|
|
395
489
|
const configFile = "vitest.config.ts";
|
|
396
490
|
if (!await import_fs_extra6.default.pathExists(configFile)) {
|
|
@@ -406,7 +500,7 @@ export default defineConfig({
|
|
|
406
500
|
`
|
|
407
501
|
);
|
|
408
502
|
}
|
|
409
|
-
} else if (
|
|
503
|
+
} else if (runner === "jest") {
|
|
410
504
|
await installPackages(["jest", "ts-jest", "@types/jest"], true);
|
|
411
505
|
const configFile = "jest.config.js";
|
|
412
506
|
if (!await import_fs_extra6.default.pathExists(configFile)) {
|
|
@@ -424,97 +518,278 @@ module.exports = {
|
|
|
424
518
|
}
|
|
425
519
|
|
|
426
520
|
// src/services/editor-config.ts
|
|
427
|
-
var
|
|
521
|
+
var import_prompts8 = require("@clack/prompts");
|
|
428
522
|
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
523
|
+
var import_picocolors7 = __toESM(require("picocolors"));
|
|
524
|
+
async function promptEditorConfig(config2) {
|
|
525
|
+
import_prompts8.log.message(import_picocolors7.default.bgWhite(import_picocolors7.default.black(" EditorConfig Configuration ")));
|
|
526
|
+
const currentPreset = config2.get("editorConfig").options.preset;
|
|
527
|
+
const preset = await withCancelHandling(
|
|
528
|
+
async () => (0, import_prompts8.select)({
|
|
529
|
+
message: "Select EditorConfig preset:",
|
|
530
|
+
options: EDITOR_CONFIG_OPTIONS,
|
|
531
|
+
initialValue: currentPreset
|
|
532
|
+
})
|
|
533
|
+
);
|
|
534
|
+
config2.get("editorConfig").options = { preset };
|
|
439
535
|
}
|
|
440
|
-
async function installEditorConfig(
|
|
536
|
+
async function installEditorConfig(config2) {
|
|
441
537
|
let content = "root = true\n\n[*]\ncharset = utf-8\nend_of_line = lf\ninsert_final_newline = true\ntrim_trailing_whitespace = true\n";
|
|
442
|
-
|
|
538
|
+
const preset = config2.get("editorConfig").options.preset;
|
|
539
|
+
if (preset === "default") {
|
|
443
540
|
content += "indent_style = space\nindent_size = 2\n";
|
|
444
|
-
} else if (
|
|
541
|
+
} else if (preset === "spaces4") {
|
|
445
542
|
content += "indent_style = space\nindent_size = 4\n";
|
|
446
|
-
} else if (
|
|
543
|
+
} else if (preset === "tabs") {
|
|
447
544
|
content += "indent_style = tab\n";
|
|
448
545
|
}
|
|
449
546
|
await import_fs_extra7.default.outputFile(".editorconfig", content);
|
|
450
547
|
}
|
|
451
548
|
|
|
452
549
|
// src/services/license.ts
|
|
453
|
-
var
|
|
550
|
+
var import_prompts9 = require("@clack/prompts");
|
|
454
551
|
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
455
552
|
var import_path2 = __toESM(require("path"));
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
553
|
+
var import_picocolors8 = __toESM(require("picocolors"));
|
|
554
|
+
async function promptLicense(config2) {
|
|
555
|
+
import_prompts9.log.message(import_picocolors8.default.bgGreen(import_picocolors8.default.black(" License Configuration ")));
|
|
556
|
+
const licenseOptions = config2.get("license").options;
|
|
557
|
+
licenseOptions.name = await withCancelHandling(
|
|
558
|
+
async () => (0, import_prompts9.text)({
|
|
559
|
+
message: "License Holder Name:",
|
|
560
|
+
placeholder: "John Doe",
|
|
561
|
+
initialValue: licenseOptions.name
|
|
562
|
+
})
|
|
563
|
+
);
|
|
564
|
+
licenseOptions.email = await withCancelHandling(
|
|
565
|
+
async () => (0, import_prompts9.text)({
|
|
566
|
+
message: "License Holder Email:",
|
|
567
|
+
placeholder: "john@example.com",
|
|
568
|
+
initialValue: licenseOptions.email
|
|
569
|
+
})
|
|
570
|
+
);
|
|
571
|
+
licenseOptions.website = await withCancelHandling(
|
|
572
|
+
async () => (0, import_prompts9.text)({
|
|
573
|
+
message: "License Holder Website:",
|
|
574
|
+
placeholder: "https://example.com",
|
|
575
|
+
initialValue: licenseOptions.website
|
|
576
|
+
})
|
|
577
|
+
);
|
|
578
|
+
licenseOptions.type = await withCancelHandling(
|
|
579
|
+
async () => (0, import_prompts9.select)({
|
|
580
|
+
message: "Select License Type:",
|
|
581
|
+
options: LICENSE_TYPE_OPTIONS
|
|
582
|
+
})
|
|
583
|
+
);
|
|
483
584
|
}
|
|
484
|
-
async function installLicense(
|
|
485
|
-
|
|
585
|
+
async function installLicense(config2) {
|
|
586
|
+
const licenseOptions = config2.get("license").options;
|
|
587
|
+
const { type, name, email, website } = licenseOptions;
|
|
588
|
+
if (type !== "UNLICENSED") {
|
|
486
589
|
const year = (/* @__PURE__ */ new Date()).getFullYear().toString();
|
|
487
|
-
const templatePath = import_path2.default.join(
|
|
488
|
-
__dirname,
|
|
489
|
-
"licenses",
|
|
490
|
-
`${config.licenseType}.txt`
|
|
491
|
-
);
|
|
590
|
+
const templatePath = import_path2.default.join(__dirname, "licenses", `${type}.txt`);
|
|
492
591
|
if (await import_fs_extra8.default.pathExists(templatePath)) {
|
|
493
592
|
let licenseContent = await import_fs_extra8.default.readFile(templatePath, "utf-8");
|
|
494
593
|
licenseContent = licenseContent.replace(/{YEAR}/g, year);
|
|
495
|
-
licenseContent = licenseContent.replace(/{HOLDER}/g,
|
|
496
|
-
licenseContent = licenseContent.replace(/{EMAIL}/g,
|
|
497
|
-
licenseContent = licenseContent.replace(
|
|
498
|
-
/{WEBSITE}/g,
|
|
499
|
-
config.licenseWebsite
|
|
500
|
-
);
|
|
594
|
+
licenseContent = licenseContent.replace(/{HOLDER}/g, name || "");
|
|
595
|
+
licenseContent = licenseContent.replace(/{EMAIL}/g, email || "");
|
|
596
|
+
licenseContent = licenseContent.replace(/{WEBSITE}/g, website || "");
|
|
501
597
|
await import_fs_extra8.default.outputFile("LICENSE", licenseContent);
|
|
502
598
|
} else {
|
|
503
|
-
const simpleContent = `Copyright (c) ${year} ${
|
|
504
|
-
Licensed under ${
|
|
599
|
+
const simpleContent = `Copyright (c) ${year} ${name}
|
|
600
|
+
Licensed under ${type}`;
|
|
505
601
|
await import_fs_extra8.default.outputFile("LICENSE", simpleContent);
|
|
506
602
|
}
|
|
507
603
|
}
|
|
508
604
|
if (await import_fs_extra8.default.pathExists("package.json")) {
|
|
509
605
|
const pkg = await import_fs_extra8.default.readJson("package.json");
|
|
510
|
-
pkg.license =
|
|
511
|
-
if (
|
|
512
|
-
pkg.author =
|
|
606
|
+
pkg.license = type;
|
|
607
|
+
if (name) {
|
|
608
|
+
pkg.author = { name, email, url: website };
|
|
513
609
|
}
|
|
514
610
|
await import_fs_extra8.default.writeJson("package.json", pkg, { spaces: 2 });
|
|
515
611
|
}
|
|
516
612
|
}
|
|
517
613
|
|
|
614
|
+
// src/config/config.ts
|
|
615
|
+
var import_picocolors9 = __toESM(require("picocolors"));
|
|
616
|
+
var Config = class {
|
|
617
|
+
data;
|
|
618
|
+
constructor() {
|
|
619
|
+
this.data = {
|
|
620
|
+
husky: {
|
|
621
|
+
selected: false,
|
|
622
|
+
options: { hookType: "none", customScript: "npm run test" }
|
|
623
|
+
},
|
|
624
|
+
formatter: {
|
|
625
|
+
selected: false,
|
|
626
|
+
options: { choice: "prettier" }
|
|
627
|
+
},
|
|
628
|
+
linter: {
|
|
629
|
+
selected: false,
|
|
630
|
+
options: { choice: "eslint" }
|
|
631
|
+
},
|
|
632
|
+
lintStaged: {
|
|
633
|
+
selected: false,
|
|
634
|
+
options: { lintExtensions: [], formatExtensions: [] }
|
|
635
|
+
},
|
|
636
|
+
env: {
|
|
637
|
+
selected: false,
|
|
638
|
+
options: {
|
|
639
|
+
variant: "@t3-oss/env-nextjs",
|
|
640
|
+
validator: "zod",
|
|
641
|
+
installPresets: false,
|
|
642
|
+
presets: [],
|
|
643
|
+
split: "split",
|
|
644
|
+
location: "src/env"
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
test: {
|
|
648
|
+
selected: false,
|
|
649
|
+
options: { runner: "vitest" }
|
|
650
|
+
},
|
|
651
|
+
editorConfig: {
|
|
652
|
+
selected: false,
|
|
653
|
+
options: { preset: "default" }
|
|
654
|
+
},
|
|
655
|
+
license: {
|
|
656
|
+
selected: false,
|
|
657
|
+
options: { name: "", email: "", website: "", type: "MIT" }
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
get(tool) {
|
|
662
|
+
return this.data[tool];
|
|
663
|
+
}
|
|
664
|
+
enableTool(tool) {
|
|
665
|
+
this.data[tool].selected = true;
|
|
666
|
+
}
|
|
667
|
+
get summary() {
|
|
668
|
+
const lines = [];
|
|
669
|
+
lines.push(import_picocolors9.default.bold("The following actions will be performed:"));
|
|
670
|
+
lines.push("");
|
|
671
|
+
if (this.data.husky.selected) {
|
|
672
|
+
lines.push(import_picocolors9.default.magenta(`\u2022 Install and configure Husky`));
|
|
673
|
+
if (this.data.husky.options.hookType === "custom") {
|
|
674
|
+
lines.push(import_picocolors9.default.dim(` - Custom hook script`));
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (this.data.formatter.selected) {
|
|
678
|
+
const choice = this.data.formatter.options.choice;
|
|
679
|
+
lines.push(import_picocolors9.default.blue(`\u2022 Install and configure ${choice || "Formatter"}`));
|
|
680
|
+
}
|
|
681
|
+
if (this.data.linter.selected) {
|
|
682
|
+
const choice = this.data.linter.options.choice;
|
|
683
|
+
lines.push(import_picocolors9.default.yellow(`\u2022 Install and configure ${choice || "Linter"}`));
|
|
684
|
+
}
|
|
685
|
+
if (this.data.lintStaged.selected) {
|
|
686
|
+
lines.push(import_picocolors9.default.green(`\u2022 Install and configure Lint-staged`));
|
|
687
|
+
const lintExts = this.data.lintStaged.options.lintExtensions.join(", ");
|
|
688
|
+
const formatExts = this.data.lintStaged.options.formatExtensions.join(", ");
|
|
689
|
+
if (lintExts) lines.push(import_picocolors9.default.dim(` - Lint: ${lintExts}`));
|
|
690
|
+
if (formatExts) lines.push(import_picocolors9.default.dim(` - Format: ${formatExts}`));
|
|
691
|
+
}
|
|
692
|
+
if (this.data.env.selected) {
|
|
693
|
+
lines.push(import_picocolors9.default.cyan(`\u2022 Install and configure Env Validation`));
|
|
694
|
+
lines.push(import_picocolors9.default.dim(` - Variant: ${this.data.env.options.variant}`));
|
|
695
|
+
lines.push(import_picocolors9.default.dim(` - Validator: ${this.data.env.options.validator}`));
|
|
696
|
+
}
|
|
697
|
+
if (this.data.test.selected) {
|
|
698
|
+
const runner = this.data.test.options.runner;
|
|
699
|
+
lines.push(import_picocolors9.default.red(`\u2022 Install and configure Test Runner (${runner})`));
|
|
700
|
+
}
|
|
701
|
+
if (this.data.editorConfig.selected) {
|
|
702
|
+
const preset = this.data.editorConfig.options.preset;
|
|
703
|
+
lines.push(import_picocolors9.default.white(`\u2022 Create .editorconfig (${preset})`));
|
|
704
|
+
}
|
|
705
|
+
if (this.data.license.selected) {
|
|
706
|
+
const type = this.data.license.options.type;
|
|
707
|
+
const name = this.data.license.options.name;
|
|
708
|
+
lines.push(import_picocolors9.default.green(`\u2022 Create LICENSE (${type})`));
|
|
709
|
+
lines.push(import_picocolors9.default.dim(` - Holder: ${name}`));
|
|
710
|
+
}
|
|
711
|
+
return lines.join("\n");
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
var config = new Config();
|
|
715
|
+
|
|
716
|
+
// src/steps/execution.ts
|
|
717
|
+
var import_prompts10 = require("@clack/prompts");
|
|
718
|
+
async function execution(config2) {
|
|
719
|
+
const s = (0, import_prompts10.spinner)();
|
|
720
|
+
if (config2.get("husky").selected) {
|
|
721
|
+
s.start("Setting up Husky...");
|
|
722
|
+
await installHusky(config2);
|
|
723
|
+
s.stop("Husky setup complete.");
|
|
724
|
+
}
|
|
725
|
+
if (config2.get("formatter").selected) {
|
|
726
|
+
const choice = config2.get("formatter").options.choice;
|
|
727
|
+
s.start(`Setting up ${choice}...`);
|
|
728
|
+
await installFormatter(config2);
|
|
729
|
+
s.stop(`${choice} setup complete.`);
|
|
730
|
+
}
|
|
731
|
+
if (config2.get("linter").selected) {
|
|
732
|
+
const choice = config2.get("linter").options.choice;
|
|
733
|
+
s.start(`Setting up ${choice}...`);
|
|
734
|
+
await installLinter(config2);
|
|
735
|
+
s.stop(`${choice} setup complete.`);
|
|
736
|
+
}
|
|
737
|
+
if (config2.get("lintStaged").selected) {
|
|
738
|
+
s.start("Setting up Lint-staged...");
|
|
739
|
+
await installLintStaged(config2);
|
|
740
|
+
s.stop("Lint-staged setup complete.");
|
|
741
|
+
}
|
|
742
|
+
if (config2.get("env").selected) {
|
|
743
|
+
s.start("Setting up Env Validation...");
|
|
744
|
+
await installEnv(config2);
|
|
745
|
+
s.stop("Env Validation setup complete.");
|
|
746
|
+
}
|
|
747
|
+
if (config2.get("test").selected) {
|
|
748
|
+
const runner = config2.get("test").options.runner;
|
|
749
|
+
s.start(`Setting up ${runner}...`);
|
|
750
|
+
await installTest(config2);
|
|
751
|
+
s.stop(`${runner} setup complete.`);
|
|
752
|
+
}
|
|
753
|
+
if (config2.get("editorConfig").selected) {
|
|
754
|
+
s.start("Creating .editorconfig...");
|
|
755
|
+
await installEditorConfig(config2);
|
|
756
|
+
s.stop(".editorconfig created.");
|
|
757
|
+
}
|
|
758
|
+
if (config2.get("license").selected) {
|
|
759
|
+
s.start("Creating LICENSE...");
|
|
760
|
+
await installLicense(config2);
|
|
761
|
+
s.stop("LICENSE created.");
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/utils/logger.ts
|
|
766
|
+
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
767
|
+
var import_path3 = __toESM(require("path"));
|
|
768
|
+
var LOG_DIR = ".mayrlabs/setup-project";
|
|
769
|
+
var ERRORS_DIR = import_path3.default.join(LOG_DIR, "errors");
|
|
770
|
+
async function logError(error) {
|
|
771
|
+
try {
|
|
772
|
+
await import_fs_extra9.default.ensureDir(ERRORS_DIR);
|
|
773
|
+
const gitignorePath = import_path3.default.join(LOG_DIR, ".gitignore");
|
|
774
|
+
if (!await import_fs_extra9.default.pathExists(gitignorePath)) {
|
|
775
|
+
await import_fs_extra9.default.outputFile(gitignorePath, "*\n");
|
|
776
|
+
}
|
|
777
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
778
|
+
const logFile = import_path3.default.join(ERRORS_DIR, `log-${timestamp}.txt`);
|
|
779
|
+
const errorMessage = error instanceof Error ? error.stack || error.message : String(error);
|
|
780
|
+
const logContent = `Timestamp: ${(/* @__PURE__ */ new Date()).toISOString()}
|
|
781
|
+
|
|
782
|
+
Error:
|
|
783
|
+
${errorMessage}
|
|
784
|
+
`;
|
|
785
|
+
await import_fs_extra9.default.outputFile(logFile, logContent);
|
|
786
|
+
return logFile;
|
|
787
|
+
} catch (e) {
|
|
788
|
+
console.error("Failed to log error:", e);
|
|
789
|
+
return "";
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
518
793
|
// src/utils/git.ts
|
|
519
794
|
var import_execa3 = require("execa");
|
|
520
795
|
async function isGitRepository() {
|
|
@@ -538,10 +813,41 @@ async function commitChanges(message) {
|
|
|
538
813
|
await (0, import_execa3.execa)("git", ["commit", "-m", message]);
|
|
539
814
|
}
|
|
540
815
|
|
|
816
|
+
// src/steps/git-check.ts
|
|
817
|
+
var import_prompts11 = require("@clack/prompts");
|
|
818
|
+
async function gitCheck() {
|
|
819
|
+
if (await isGitRepository()) {
|
|
820
|
+
if (await isGitDirty()) {
|
|
821
|
+
const shouldCommit = await (0, import_prompts11.confirm)({
|
|
822
|
+
message: "Your working directory is dirty. Would you like to commit changes before proceeding?"
|
|
823
|
+
});
|
|
824
|
+
if (shouldCommit) {
|
|
825
|
+
const message = await (0, import_prompts11.text)({
|
|
826
|
+
message: "Enter commit message:",
|
|
827
|
+
placeholder: "wip: pre-setup commit",
|
|
828
|
+
validate(value) {
|
|
829
|
+
if (value.length === 0) return "Commit message is required";
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
if (typeof message === "string") {
|
|
833
|
+
const s = (0, import_prompts11.spinner)();
|
|
834
|
+
s.start("Committing changes...");
|
|
835
|
+
await commitChanges(message);
|
|
836
|
+
s.stop("Changes committed.");
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// src/utils/display.ts
|
|
844
|
+
var import_picocolors10 = __toESM(require("picocolors"));
|
|
845
|
+
var import_figlet = __toESM(require("figlet"));
|
|
846
|
+
|
|
541
847
|
// package.json
|
|
542
848
|
var package_default = {
|
|
543
849
|
name: "@mayrlabs/setup-project",
|
|
544
|
-
version: "0.1.
|
|
850
|
+
version: "0.1.6",
|
|
545
851
|
description: "Interactive CLI to setup project tools",
|
|
546
852
|
private: false,
|
|
547
853
|
publishConfig: {
|
|
@@ -590,186 +896,156 @@ var package_default = {
|
|
|
590
896
|
"@clack/prompts": "^0.7.0",
|
|
591
897
|
commander: "^11.1.0",
|
|
592
898
|
execa: "^8.0.1",
|
|
899
|
+
figlet: "^1.10.0",
|
|
593
900
|
"fs-extra": "^11.2.0",
|
|
594
901
|
picocolors: "^1.0.0",
|
|
595
902
|
zod: "^3.22.4"
|
|
596
903
|
},
|
|
597
904
|
devDependencies: {
|
|
905
|
+
"@types/figlet": "^1.7.0",
|
|
598
906
|
"@types/fs-extra": "^11.0.4",
|
|
599
907
|
"@types/node": "^20.11.16",
|
|
600
908
|
tsup: "^8.5.1",
|
|
909
|
+
tsx: "^4.21.0",
|
|
601
910
|
typescript: "^5.3.3"
|
|
602
911
|
}
|
|
603
912
|
};
|
|
604
913
|
|
|
605
|
-
// src/utils/
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
914
|
+
// src/utils/display.ts
|
|
915
|
+
function introScreen() {
|
|
916
|
+
console.log();
|
|
917
|
+
console.log(
|
|
918
|
+
import_picocolors10.default.cyan(
|
|
919
|
+
import_figlet.default.textSync("MayR\nLabs", {
|
|
920
|
+
font: "Graceful",
|
|
921
|
+
horizontalLayout: "default",
|
|
922
|
+
verticalLayout: "default",
|
|
923
|
+
width: 80,
|
|
924
|
+
whitespaceBreak: true
|
|
925
|
+
})
|
|
926
|
+
)
|
|
927
|
+
);
|
|
928
|
+
console.log(import_picocolors10.default.cyan(`@mayrlabs/setup-project v${package_default.version}`));
|
|
929
|
+
console.log();
|
|
930
|
+
}
|
|
931
|
+
function showAbout() {
|
|
932
|
+
introScreen();
|
|
933
|
+
console.log(import_picocolors10.default.bold("About:"));
|
|
934
|
+
console.log(
|
|
935
|
+
" Interactive CLI to setup project tools like Husky, Prettier, ESLint, etc."
|
|
936
|
+
);
|
|
937
|
+
console.log("");
|
|
938
|
+
console.log(import_picocolors10.default.bold("How to use:"));
|
|
939
|
+
console.log(
|
|
940
|
+
" Run 'npx @mayrlabs/setup-project' and follow the interactive prompts."
|
|
941
|
+
);
|
|
942
|
+
console.log("");
|
|
943
|
+
}
|
|
944
|
+
function showVisit() {
|
|
945
|
+
console.log(import_picocolors10.default.bold("Project Homepage:"));
|
|
946
|
+
console.log(import_picocolors10.default.underline(import_picocolors10.default.cyan(package_default.homepage)));
|
|
947
|
+
console.log("");
|
|
948
|
+
}
|
|
949
|
+
function showManual() {
|
|
950
|
+
introScreen();
|
|
951
|
+
console.log(import_picocolors10.default.bold("Usage:"));
|
|
952
|
+
console.log(" npx @mayrlabs/setup-project [command] [options]");
|
|
953
|
+
console.log("");
|
|
954
|
+
console.log(import_picocolors10.default.bold("Commands:"));
|
|
955
|
+
console.log(" about Show project details");
|
|
956
|
+
console.log(" version Show version information");
|
|
957
|
+
console.log(" visit Visit project homepage");
|
|
958
|
+
console.log(" help Show this help message");
|
|
959
|
+
console.log("");
|
|
960
|
+
console.log(import_picocolors10.default.bold("Options:"));
|
|
961
|
+
console.log(" -a, --about Show project details");
|
|
962
|
+
console.log(" -v, --version Show version information");
|
|
963
|
+
console.log(" -V, --visit Visit project homepage");
|
|
964
|
+
console.log(" -h, --help Show this help message");
|
|
965
|
+
console.log("");
|
|
631
966
|
}
|
|
632
967
|
|
|
633
968
|
// src/index.ts
|
|
634
969
|
async function main() {
|
|
635
970
|
try {
|
|
636
|
-
(
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
{ value: "formatter", label: "Formatter (Prettier/Oxfmt)" },
|
|
666
|
-
{ value: "linter", label: "Linter (Eslint/Oxlint)" },
|
|
667
|
-
{ value: "lint-staged", label: "Lint-staged" },
|
|
668
|
-
{ value: "env", label: "Env Validation (@t3-oss/env)" },
|
|
669
|
-
{ value: "test", label: "Test Runner (Vitest/Jest)" },
|
|
670
|
-
{ value: "editorConfig", label: "EditorConfig" },
|
|
671
|
-
{ value: "license", label: "License" }
|
|
672
|
-
],
|
|
673
|
-
required: false
|
|
674
|
-
});
|
|
675
|
-
if ((0, import_prompts9.isCancel)(tools)) {
|
|
676
|
-
(0, import_prompts9.cancel)("Operation cancelled.");
|
|
677
|
-
process.exit(0);
|
|
678
|
-
}
|
|
679
|
-
const selectedTools = tools;
|
|
680
|
-
const config = {
|
|
681
|
-
husky: selectedTools.includes("husky"),
|
|
682
|
-
formatter: selectedTools.includes("formatter"),
|
|
683
|
-
linter: selectedTools.includes("linter"),
|
|
684
|
-
lintStaged: selectedTools.includes("lint-staged"),
|
|
685
|
-
env: selectedTools.includes("env"),
|
|
686
|
-
test: selectedTools.includes("test"),
|
|
687
|
-
editorConfig: selectedTools.includes("editorConfig"),
|
|
688
|
-
license: selectedTools.includes("license")
|
|
689
|
-
};
|
|
690
|
-
if (config.husky) await promptHusky(config);
|
|
691
|
-
if (config.formatter) await promptFormatter(config);
|
|
692
|
-
if (config.linter) await promptLinter(config);
|
|
693
|
-
if (config.lintStaged) await promptLintStaged(config);
|
|
694
|
-
if (config.env) await promptEnv(config);
|
|
695
|
-
if (config.test) await promptTest(config);
|
|
696
|
-
if (config.editorConfig) await promptEditorConfig(config);
|
|
697
|
-
if (config.license) await promptLicense(config);
|
|
698
|
-
let summary = "The following actions will be performed:\n\n";
|
|
699
|
-
if (config.husky) summary += "- Install and configure Husky\n";
|
|
700
|
-
if (config.formatter)
|
|
701
|
-
summary += `- Install and configure ${config.formatterChoice}
|
|
702
|
-
`;
|
|
703
|
-
if (config.linter)
|
|
704
|
-
summary += `- Install and configure ${config.linterChoice}
|
|
705
|
-
`;
|
|
706
|
-
if (config.lintStaged) summary += "- Install and configure Lint-staged\n";
|
|
707
|
-
if (config.env) summary += "- Install and configure @t3-oss/env\n";
|
|
708
|
-
if (config.test)
|
|
709
|
-
summary += `- Install and configure ${config.testRunner}
|
|
710
|
-
`;
|
|
711
|
-
if (config.editorConfig) summary += "- Create .editorconfig\n";
|
|
712
|
-
if (config.license) summary += `- Create LICENSE (${config.licenseType})
|
|
713
|
-
`;
|
|
714
|
-
(0, import_prompts9.note)(summary, "Configuration Summary");
|
|
715
|
-
const proceed = await (0, import_prompts9.confirm)({
|
|
716
|
-
message: "Do you want to proceed with the installation?"
|
|
717
|
-
});
|
|
718
|
-
if (!proceed || (0, import_prompts9.isCancel)(proceed)) {
|
|
719
|
-
(0, import_prompts9.cancel)("Installation cancelled. Configuration saved.");
|
|
971
|
+
introScreen();
|
|
972
|
+
(0, import_prompts12.intro)(
|
|
973
|
+
import_picocolors11.default.inverse(import_picocolors11.default.bold(import_picocolors11.default.cyan(" Welcome to the Project Setup Wizard ")))
|
|
974
|
+
);
|
|
975
|
+
await gitCheck();
|
|
976
|
+
const tools = await withCancelHandling(
|
|
977
|
+
async () => (0, import_prompts12.multiselect)({
|
|
978
|
+
message: "Select tools to configure:",
|
|
979
|
+
options: TOOL_OPTIONS,
|
|
980
|
+
required: false
|
|
981
|
+
})
|
|
982
|
+
);
|
|
983
|
+
tools.forEach((tool) => config.enableTool(tool));
|
|
984
|
+
if (config.get("husky").selected) await promptHusky(config);
|
|
985
|
+
if (config.get("formatter").selected) await promptFormatter(config);
|
|
986
|
+
if (config.get("linter").selected) await promptLinter(config);
|
|
987
|
+
if (config.get("lintStaged").selected) await promptLintStaged(config);
|
|
988
|
+
if (config.get("env").selected) await promptEnv(config);
|
|
989
|
+
if (config.get("test").selected) await promptTest(config);
|
|
990
|
+
if (config.get("editorConfig").selected) await promptEditorConfig(config);
|
|
991
|
+
if (config.get("license").selected) await promptLicense(config);
|
|
992
|
+
(0, import_prompts12.note)(config.summary, "Configuration Summary");
|
|
993
|
+
const proceed = await withCancelHandling(
|
|
994
|
+
async () => (0, import_prompts12.confirm)({
|
|
995
|
+
message: "Do you want to proceed with the installation?"
|
|
996
|
+
})
|
|
997
|
+
);
|
|
998
|
+
if (!proceed) {
|
|
999
|
+
(0, import_prompts12.outro)(import_picocolors11.default.yellow("Installation cancelled."));
|
|
720
1000
|
process.exit(0);
|
|
721
1001
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
s.start("Setting up Husky...");
|
|
725
|
-
await installHusky(config);
|
|
726
|
-
s.stop("Husky setup complete.");
|
|
727
|
-
}
|
|
728
|
-
if (config.formatter) {
|
|
729
|
-
s.start(`Setting up ${config.formatterChoice}...`);
|
|
730
|
-
await installFormatter(config);
|
|
731
|
-
s.stop(`${config.formatterChoice} setup complete.`);
|
|
732
|
-
}
|
|
733
|
-
if (config.linter) {
|
|
734
|
-
s.start(`Setting up ${config.linterChoice}...`);
|
|
735
|
-
await installLinter(config);
|
|
736
|
-
s.stop(`${config.linterChoice} setup complete.`);
|
|
737
|
-
}
|
|
738
|
-
if (config.lintStaged) {
|
|
739
|
-
s.start("Setting up Lint-staged...");
|
|
740
|
-
await installLintStaged(config);
|
|
741
|
-
s.stop("Lint-staged setup complete.");
|
|
742
|
-
}
|
|
743
|
-
if (config.env) {
|
|
744
|
-
s.start("Setting up Env Validation...");
|
|
745
|
-
await installEnv(config);
|
|
746
|
-
s.stop("Env Validation setup complete.");
|
|
747
|
-
}
|
|
748
|
-
if (config.test) {
|
|
749
|
-
s.start(`Setting up ${config.testRunner}...`);
|
|
750
|
-
await installTest(config);
|
|
751
|
-
s.stop(`${config.testRunner} setup complete.`);
|
|
752
|
-
}
|
|
753
|
-
if (config.editorConfig) {
|
|
754
|
-
s.start("Creating .editorconfig...");
|
|
755
|
-
await installEditorConfig(config);
|
|
756
|
-
s.stop(".editorconfig created.");
|
|
757
|
-
}
|
|
758
|
-
if (config.license) {
|
|
759
|
-
s.start("Creating LICENSE...");
|
|
760
|
-
await installLicense(config);
|
|
761
|
-
s.stop("LICENSE created.");
|
|
762
|
-
}
|
|
763
|
-
(0, import_prompts9.outro)(import_picocolors.default.green("Setup complete!"));
|
|
1002
|
+
await execution(config);
|
|
1003
|
+
(0, import_prompts12.outro)(import_picocolors11.default.green("Setup complete!"));
|
|
764
1004
|
} catch (error) {
|
|
765
1005
|
const logPath = await logError(error);
|
|
766
|
-
(0,
|
|
1006
|
+
(0, import_prompts12.outro)(import_picocolors11.default.red(`
|
|
767
1007
|
Something went wrong!
|
|
768
1008
|
Error log saved to: ${logPath}`));
|
|
769
1009
|
process.exit(1);
|
|
770
1010
|
}
|
|
771
1011
|
}
|
|
772
|
-
import_commander.program.
|
|
1012
|
+
import_commander.program.helpOption(false);
|
|
1013
|
+
import_commander.program.name("setup-project").description("Interactive setup for common project tools").option("-a, --about", "Show project details").option("-v, --version", "Show version info").option("-V, --visit", "Visit project homepage").option("-h, --help", "Show help");
|
|
1014
|
+
import_commander.program.command("about").action(() => {
|
|
1015
|
+
showAbout();
|
|
1016
|
+
process.exit(0);
|
|
1017
|
+
});
|
|
1018
|
+
import_commander.program.command("version").action(() => {
|
|
1019
|
+
introScreen();
|
|
1020
|
+
process.exit(0);
|
|
1021
|
+
});
|
|
1022
|
+
import_commander.program.command("visit").action(() => {
|
|
1023
|
+
showVisit();
|
|
1024
|
+
process.exit(0);
|
|
1025
|
+
});
|
|
1026
|
+
import_commander.program.command("help").action(() => {
|
|
1027
|
+
showManual();
|
|
1028
|
+
process.exit(0);
|
|
1029
|
+
});
|
|
1030
|
+
import_commander.program.action(async (options) => {
|
|
1031
|
+
if (options.about) {
|
|
1032
|
+
showAbout();
|
|
1033
|
+
process.exit(0);
|
|
1034
|
+
}
|
|
1035
|
+
if (options.version) {
|
|
1036
|
+
introScreen();
|
|
1037
|
+
process.exit(0);
|
|
1038
|
+
}
|
|
1039
|
+
if (options.visit) {
|
|
1040
|
+
showVisit();
|
|
1041
|
+
process.exit(0);
|
|
1042
|
+
}
|
|
1043
|
+
if (options.help) {
|
|
1044
|
+
showManual();
|
|
1045
|
+
process.exit(0);
|
|
1046
|
+
}
|
|
1047
|
+
await main();
|
|
1048
|
+
});
|
|
773
1049
|
import_commander.program.parse();
|
|
774
1050
|
|
|
775
1051
|
/**
|