create-next-style-guide 0.1.4 → 0.1.5
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 +74 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -530,9 +530,10 @@ async function runPrompts(initialName) {
|
|
|
530
530
|
placeholder: "my-app",
|
|
531
531
|
initialValue: initialName ?? "my-app",
|
|
532
532
|
validate(value) {
|
|
533
|
-
|
|
533
|
+
const next = value ?? "";
|
|
534
|
+
if (!next.trim()) return "Name is required.";
|
|
534
535
|
try {
|
|
535
|
-
slugify(
|
|
536
|
+
slugify(next);
|
|
536
537
|
} catch (error) {
|
|
537
538
|
return error instanceof Error ? error.message : "Invalid name.";
|
|
538
539
|
}
|
|
@@ -626,10 +627,34 @@ async function runPrompts(initialName) {
|
|
|
626
627
|
// src/scaffold.ts
|
|
627
628
|
import fs28 from "fs-extra";
|
|
628
629
|
import path29 from "path";
|
|
630
|
+
import { execFileSync } from "child_process";
|
|
629
631
|
import * as p2 from "@clack/prompts";
|
|
630
|
-
import { execSync } from "child_process";
|
|
631
632
|
import color2 from "picocolors";
|
|
632
633
|
|
|
634
|
+
// src/helpers/run-package-install.ts
|
|
635
|
+
import { spawn } from "child_process";
|
|
636
|
+
function runPackageInstall(projectDir, pm) {
|
|
637
|
+
return new Promise((resolve, reject) => {
|
|
638
|
+
const child = spawn(pm.id, pm.installArgs, {
|
|
639
|
+
cwd: projectDir,
|
|
640
|
+
stdio: "inherit",
|
|
641
|
+
env: process.env,
|
|
642
|
+
shell: process.platform === "win32"
|
|
643
|
+
});
|
|
644
|
+
child.on("error", reject);
|
|
645
|
+
child.on("close", (code) => {
|
|
646
|
+
if (code === 0) {
|
|
647
|
+
resolve();
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
reject(new Error(`${pm.id} ${pm.installArgs.join(" ")} exited with ${code}`));
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
function yieldUi() {
|
|
655
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
656
|
+
}
|
|
657
|
+
|
|
633
658
|
// src/helpers/replace-tokens.ts
|
|
634
659
|
import fs from "fs-extra";
|
|
635
660
|
import path2 from "path";
|
|
@@ -1964,7 +1989,7 @@ var huskyInstaller = {
|
|
|
1964
1989
|
},
|
|
1965
1990
|
"devDependencies"
|
|
1966
1991
|
);
|
|
1967
|
-
await addScripts(projectDir, { prepare: "husky" });
|
|
1992
|
+
await addScripts(projectDir, { prepare: "husky || true" });
|
|
1968
1993
|
const tsHooks = [];
|
|
1969
1994
|
if (options.prettier) tsHooks.push("prettier --write");
|
|
1970
1995
|
if (options.eslint) tsHooks.push("eslint --fix");
|
|
@@ -3669,10 +3694,18 @@ var installers = [
|
|
|
3669
3694
|
appProvidersInstaller,
|
|
3670
3695
|
surfaceInstaller
|
|
3671
3696
|
];
|
|
3672
|
-
async function runInstallers(ctx) {
|
|
3697
|
+
async function runInstallers(ctx, onProgress) {
|
|
3698
|
+
const active = installers.filter(
|
|
3699
|
+
(installer) => installer.active(ctx.options)
|
|
3700
|
+
);
|
|
3673
3701
|
const ran = [];
|
|
3674
|
-
for (
|
|
3675
|
-
|
|
3702
|
+
for (let i = 0; i < active.length; i += 1) {
|
|
3703
|
+
const installer = active[i];
|
|
3704
|
+
await onProgress?.({
|
|
3705
|
+
id: installer.id,
|
|
3706
|
+
index: i + 1,
|
|
3707
|
+
total: active.length
|
|
3708
|
+
});
|
|
3676
3709
|
await installer.run(ctx);
|
|
3677
3710
|
ran.push(installer.id);
|
|
3678
3711
|
}
|
|
@@ -3693,6 +3726,7 @@ async function scaffold(options) {
|
|
|
3693
3726
|
}
|
|
3694
3727
|
const spin = p2.spinner();
|
|
3695
3728
|
spin.start("Copying template");
|
|
3729
|
+
await yieldUi();
|
|
3696
3730
|
if (!await fs28.pathExists(TEMPLATE_DIR)) {
|
|
3697
3731
|
spin.stop("Template missing");
|
|
3698
3732
|
throw new Error(`Template directory not found at ${TEMPLATE_DIR}`);
|
|
@@ -3709,30 +3743,51 @@ async function scaffold(options) {
|
|
|
3709
3743
|
await fs28.move(gitignoreSrc, gitignoreDest, { overwrite: true });
|
|
3710
3744
|
}
|
|
3711
3745
|
spin.message("Applying project tokens");
|
|
3746
|
+
await yieldUi();
|
|
3712
3747
|
await replaceTokensInTree(projectDir, {
|
|
3713
3748
|
__PROJECT_NAME__: options.name,
|
|
3714
3749
|
__PROJECT_SLUG__: options.slug,
|
|
3715
3750
|
__PACKAGE_MANAGER__: pm.id
|
|
3716
3751
|
});
|
|
3717
|
-
|
|
3718
|
-
|
|
3752
|
+
const ran = await runInstallers({ projectDir, options }, async (step) => {
|
|
3753
|
+
spin.message(`Installer (${step.index}/${step.total}): ${step.id}`);
|
|
3754
|
+
await yieldUi();
|
|
3755
|
+
});
|
|
3756
|
+
spin.stop(
|
|
3757
|
+
ran.length ? `Scaffold ready \xB7 ${ran.length} installer${ran.length === 1 ? "" : "s"}` : "Scaffold ready \xB7 base template"
|
|
3758
|
+
);
|
|
3719
3759
|
if (!options.noInstall) {
|
|
3720
|
-
|
|
3760
|
+
if (options.husky) {
|
|
3761
|
+
try {
|
|
3762
|
+
execFileSync("git", ["init"], {
|
|
3763
|
+
cwd: projectDir,
|
|
3764
|
+
stdio: "ignore"
|
|
3765
|
+
});
|
|
3766
|
+
} catch {
|
|
3767
|
+
}
|
|
3768
|
+
}
|
|
3769
|
+
p2.log.step(
|
|
3770
|
+
`Installing dependencies with ${color2.cyan(pm.id)} \u2014 live output below\u2026`
|
|
3771
|
+
);
|
|
3721
3772
|
try {
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
});
|
|
3726
|
-
} catch {
|
|
3773
|
+
await runPackageInstall(projectDir, pm);
|
|
3774
|
+
p2.log.success("Dependencies installed");
|
|
3775
|
+
} catch (error) {
|
|
3727
3776
|
if (pm.id !== "npm") {
|
|
3728
|
-
|
|
3729
|
-
|
|
3777
|
+
p2.log.warn(`${pm.id} failed \u2014 retrying with npm\u2026`);
|
|
3778
|
+
const npm = getPackageManager("npm");
|
|
3779
|
+
await runPackageInstall(projectDir, npm);
|
|
3780
|
+
p2.log.success("Dependencies installed (npm)");
|
|
3730
3781
|
} else {
|
|
3731
|
-
|
|
3782
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3783
|
+
throw new Error(`Dependency install failed: ${message}`);
|
|
3732
3784
|
}
|
|
3733
3785
|
}
|
|
3786
|
+
} else {
|
|
3787
|
+
p2.log.info(
|
|
3788
|
+
color2.dim(`Skipped install \xB7 run ${pm.id} install in the project folder`)
|
|
3789
|
+
);
|
|
3734
3790
|
}
|
|
3735
|
-
spin.stop("Project ready");
|
|
3736
3791
|
if (ran.length) {
|
|
3737
3792
|
p2.log.info(`Installers: ${ran.join(", ")}`);
|
|
3738
3793
|
} else {
|