@mochi-css/tsuki 2.0.1 → 2.1.0
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.js +46 -16
- package/package.json +1 -2
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ async function runInstall(title, command, args, packages) {
|
|
|
103
103
|
throw err;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
async function installPackages(packages) {
|
|
106
|
+
async function installPackages(packages, autoInstall = false) {
|
|
107
107
|
if (packages.length === 0) return;
|
|
108
108
|
const packageManager = await (0, package_manager_detector.detect)({ strategies: [
|
|
109
109
|
"packageManager-field",
|
|
@@ -117,10 +117,12 @@ async function installPackages(packages) {
|
|
|
117
117
|
const devPackages = packages.filter((pkg) => pkg.dev !== false).map((pkg) => pkg.name);
|
|
118
118
|
const prodPackages = packages.filter((pkg) => pkg.dev === false).map((pkg) => pkg.name);
|
|
119
119
|
const packageList = [...devPackages.map((name) => `${name} (dev)`), ...prodPackages.map((name) => name)].join(", ");
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
__clack_prompts.
|
|
123
|
-
|
|
120
|
+
if (!autoInstall) {
|
|
121
|
+
const confirmed = await __clack_prompts.confirm({ message: `Install the following packages: ${packageList}?` });
|
|
122
|
+
if (__clack_prompts.isCancel(confirmed) || !confirmed) {
|
|
123
|
+
__clack_prompts.log.info("Skipping package installation");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
124
126
|
}
|
|
125
127
|
if (devPackages.length > 0) {
|
|
126
128
|
const cmd = (0, package_manager_detector.resolveCommand)(agent, "add", [devFlag, ...devPackages]);
|
|
@@ -143,7 +145,8 @@ var ModuleRunner = class {
|
|
|
143
145
|
this.modules.push(module$1);
|
|
144
146
|
return this;
|
|
145
147
|
}
|
|
146
|
-
async run() {
|
|
148
|
+
async run(options = {}) {
|
|
149
|
+
const { nonInteractive = false, autoInstall = false, moduleOptions = {} } = options;
|
|
147
150
|
const ctx = {
|
|
148
151
|
requirePackage: (name, dev = true) => {
|
|
149
152
|
this.packages.push({
|
|
@@ -156,10 +159,12 @@ var ModuleRunner = class {
|
|
|
156
159
|
name: pkg.name,
|
|
157
160
|
dev: pkg.dev ?? true
|
|
158
161
|
});
|
|
159
|
-
}
|
|
162
|
+
},
|
|
163
|
+
nonInteractive,
|
|
164
|
+
moduleOptions
|
|
160
165
|
};
|
|
161
166
|
for (const module$1 of this.modules) await module$1.run(ctx);
|
|
162
|
-
if (this.packages.length > 0) await installPackages(this.packages);
|
|
167
|
+
if (this.packages.length > 0) await installPackages(this.packages, autoInstall);
|
|
163
168
|
}
|
|
164
169
|
};
|
|
165
170
|
|
|
@@ -304,7 +309,10 @@ function createPostcssModule(options = {}) {
|
|
|
304
309
|
name: "PostCSS",
|
|
305
310
|
async run(ctx) {
|
|
306
311
|
let configPath;
|
|
307
|
-
|
|
312
|
+
const { postcss: cliOption } = ctx.moduleOptions;
|
|
313
|
+
if (cliOption !== void 0) configPath = typeof cliOption === "string" ? cliOption : findPostcssConfig() ?? "postcss.config.mts";
|
|
314
|
+
else if (options.auto) configPath = findPostcssConfig() ?? "postcss.config.mts";
|
|
315
|
+
else if (ctx.nonInteractive) return;
|
|
308
316
|
else {
|
|
309
317
|
const usePostcss = await __clack_prompts.confirm({ message: "Do you use PostCSS?" });
|
|
310
318
|
if (__clack_prompts.isCancel(usePostcss) || !usePostcss) return;
|
|
@@ -428,8 +436,12 @@ const viteModule = {
|
|
|
428
436
|
name: "Vite",
|
|
429
437
|
async run(ctx) {
|
|
430
438
|
const existingConfig = findViteConfig();
|
|
439
|
+
const { vite: cliOption } = ctx.moduleOptions;
|
|
431
440
|
let configPath;
|
|
432
|
-
if (
|
|
441
|
+
if (cliOption !== void 0) configPath = typeof cliOption === "string" ? cliOption : existingConfig ?? "vite.config.ts";
|
|
442
|
+
else if (existingConfig) configPath = existingConfig;
|
|
443
|
+
else if (ctx.nonInteractive) configPath = "vite.config.ts";
|
|
444
|
+
else {
|
|
433
445
|
const selected = await __clack_prompts.text({
|
|
434
446
|
message: "Path to Vite config",
|
|
435
447
|
placeholder: "vite.config.ts",
|
|
@@ -437,7 +449,7 @@ const viteModule = {
|
|
|
437
449
|
});
|
|
438
450
|
if (__clack_prompts.isCancel(selected)) return;
|
|
439
451
|
configPath = selected;
|
|
440
|
-
}
|
|
452
|
+
}
|
|
441
453
|
if (!fs_extra.default.existsSync(configPath)) {
|
|
442
454
|
await fs_promises.default.writeFile(configPath, defaultViteConfig);
|
|
443
455
|
__clack_prompts.log.success("Created vite config with mochi plugin");
|
|
@@ -503,8 +515,12 @@ const nextModule = {
|
|
|
503
515
|
name: "Next.js",
|
|
504
516
|
async run(ctx) {
|
|
505
517
|
const existingConfig = findNextConfig();
|
|
518
|
+
const { next: cliOption } = ctx.moduleOptions;
|
|
506
519
|
let configPath;
|
|
507
|
-
if (
|
|
520
|
+
if (cliOption !== void 0) configPath = typeof cliOption === "string" ? cliOption : existingConfig ?? "next.config.ts";
|
|
521
|
+
else if (existingConfig) configPath = existingConfig;
|
|
522
|
+
else if (ctx.nonInteractive) configPath = "next.config.ts";
|
|
523
|
+
else {
|
|
508
524
|
const selected = await __clack_prompts.text({
|
|
509
525
|
message: "Path to Next.js config",
|
|
510
526
|
placeholder: "next.config.ts",
|
|
@@ -512,7 +528,7 @@ const nextModule = {
|
|
|
512
528
|
});
|
|
513
529
|
if (__clack_prompts.isCancel(selected)) return;
|
|
514
530
|
configPath = selected;
|
|
515
|
-
}
|
|
531
|
+
}
|
|
516
532
|
if (!fs_extra.default.existsSync(configPath)) {
|
|
517
533
|
await fs_promises.default.writeFile(configPath, defaultNextConfig);
|
|
518
534
|
__clack_prompts.log.success("Created next config with mochi");
|
|
@@ -548,16 +564,21 @@ const presets = {
|
|
|
548
564
|
|
|
549
565
|
//#endregion
|
|
550
566
|
//#region src/index.ts
|
|
551
|
-
commander.program.name("tsuki").description("Add mochi-css to your project").version("2.0
|
|
567
|
+
commander.program.name("tsuki").description("Add mochi-css to your project").version("2.1.0").addOption(new commander.Option("-p, --preset <preset>", "Preset to use").choices([
|
|
552
568
|
"vite",
|
|
553
569
|
"nextjs",
|
|
554
570
|
"lib"
|
|
555
|
-
])).action(async (options) => {
|
|
571
|
+
])).option("-n, --no-interactive", "Non-interactive mode: skip all prompts (treat as cancelled)").option("--install", "Auto-accept package installation without prompting").option("--postcss [path]", "Enable PostCSS module; optionally specify config path").option("--vite [path]", "Use the given Vite config path instead of prompting").option("--next [path]", "Use the given Next.js config path instead of prompting").action(async (options) => {
|
|
556
572
|
__clack_prompts.intro(picocolors.default.cyan("Installing Mochi-CSS..."));
|
|
557
573
|
try {
|
|
558
574
|
const runner = new ModuleRunner();
|
|
575
|
+
const nonInteractive = options.interactive === false;
|
|
559
576
|
let presetId = options.preset;
|
|
560
577
|
if (presetId === void 0) {
|
|
578
|
+
if (nonInteractive) {
|
|
579
|
+
__clack_prompts.outro(picocolors.default.red("Cancelled"));
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
561
582
|
const selected = await __clack_prompts.select({
|
|
562
583
|
message: "Which framework are you using?",
|
|
563
584
|
options: Object.values(presets).map((preset$1) => ({
|
|
@@ -574,7 +595,16 @@ commander.program.name("tsuki").description("Add mochi-css to your project").ver
|
|
|
574
595
|
const preset = presets[presetId];
|
|
575
596
|
if (!preset) throw new Error(`Unknown preset: ${presetId}`);
|
|
576
597
|
preset.setup(runner);
|
|
577
|
-
|
|
598
|
+
const moduleOptions = {};
|
|
599
|
+
if (options.postcss !== void 0) moduleOptions.postcss = options.postcss;
|
|
600
|
+
else if (presetId === "nextjs") moduleOptions.postcss = true;
|
|
601
|
+
if (options.vite !== void 0) moduleOptions.vite = options.vite;
|
|
602
|
+
if (options.next !== void 0) moduleOptions.next = options.next;
|
|
603
|
+
await runner.run({
|
|
604
|
+
nonInteractive,
|
|
605
|
+
autoInstall: options.install ?? false,
|
|
606
|
+
moduleOptions
|
|
607
|
+
});
|
|
578
608
|
__clack_prompts.outro(picocolors.default.green("Done!"));
|
|
579
609
|
} catch (e) {
|
|
580
610
|
if (e instanceof Error) __clack_prompts.outro(picocolors.default.red(e.message));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mochi-css/tsuki",
|
|
3
3
|
"repository": "git@github.com:Niikelion/mochi-css.git",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": "./dist/index.js",
|
|
7
7
|
"files": [
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"build": "tsc --noEmit && tsdown",
|
|
12
12
|
"test": "vitest",
|
|
13
13
|
"coverage": "vitest run --coverage",
|
|
14
|
-
"smoke": "jiti scripts/smoke.ts",
|
|
15
14
|
"manual": "jiti scripts/manual.ts",
|
|
16
15
|
"lint": "eslint src",
|
|
17
16
|
"lint:fix": "eslint src --fix",
|