@farming-labs/docs 0.0.2-beta.29 → 0.0.2-beta.30
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/cli/index.mjs +41 -12
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1496,25 +1496,52 @@ async function init(options = {}) {
|
|
|
1496
1496
|
p.log.error(`Invalid ${pc.cyan("--template")}. Use one of: ${VALID_TEMPLATES.map((t) => pc.cyan(t)).join(", ")}`);
|
|
1497
1497
|
process.exit(1);
|
|
1498
1498
|
}
|
|
1499
|
+
let projectName = options.name?.trim();
|
|
1500
|
+
if (!projectName) {
|
|
1501
|
+
const nameAnswer = await p.text({
|
|
1502
|
+
message: "Project name? (we'll create this folder and bootstrap the app here)",
|
|
1503
|
+
placeholder: "my-docs",
|
|
1504
|
+
defaultValue: "my-docs",
|
|
1505
|
+
validate: (value) => {
|
|
1506
|
+
const v = (value ?? "").trim();
|
|
1507
|
+
if (!v) return "Project name is required";
|
|
1508
|
+
if (v.includes("/") || v.includes("\\")) return "Project name cannot contain path separators";
|
|
1509
|
+
if (v.includes(" ")) return "Project name cannot contain spaces";
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
if (p.isCancel(nameAnswer)) {
|
|
1513
|
+
p.outro(pc.red("Init cancelled."));
|
|
1514
|
+
process.exit(0);
|
|
1515
|
+
}
|
|
1516
|
+
projectName = nameAnswer.trim();
|
|
1517
|
+
}
|
|
1499
1518
|
const templateLabel = template === "next" ? "Next.js" : template === "nuxt" ? "Nuxt" : template === "sveltekit" ? "SvelteKit" : "Astro";
|
|
1500
|
-
|
|
1519
|
+
const targetDir = path.join(cwd, projectName);
|
|
1520
|
+
const fs = await import("node:fs");
|
|
1521
|
+
if (fs.existsSync(targetDir)) {
|
|
1522
|
+
p.log.error(`Directory ${pc.cyan(projectName)} already exists. Choose a different ${pc.cyan("--name")} or remove it.`);
|
|
1523
|
+
process.exit(1);
|
|
1524
|
+
}
|
|
1525
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
1526
|
+
p.log.step(`Bootstrapping project with ${pc.cyan(`'${projectName}'`)} (${templateLabel})...`);
|
|
1501
1527
|
try {
|
|
1502
|
-
exec(`npx degit ${EXAMPLES_REPO}/examples/${template} . --force`,
|
|
1528
|
+
exec(`npx degit ${EXAMPLES_REPO}/examples/${template} . --force`, targetDir);
|
|
1503
1529
|
} catch (err) {
|
|
1504
|
-
p.log.error("Failed to
|
|
1530
|
+
p.log.error("Failed to bootstrap. Check your connection and that the repo exists.");
|
|
1505
1531
|
process.exit(1);
|
|
1506
1532
|
}
|
|
1507
|
-
p.log.success(`
|
|
1508
|
-
const pm = detectPackageManager(
|
|
1533
|
+
p.log.success(`Bootstrapped ${pc.cyan(`'${projectName}'`)}. Installing dependencies...`);
|
|
1534
|
+
const pm = detectPackageManager(targetDir);
|
|
1509
1535
|
try {
|
|
1510
|
-
if (pm === "pnpm") exec("pnpm install",
|
|
1511
|
-
else if (pm === "yarn") exec("yarn install",
|
|
1512
|
-
else if (pm === "bun") exec("bun install",
|
|
1513
|
-
else exec("npm install",
|
|
1536
|
+
if (pm === "pnpm") exec("pnpm install", targetDir);
|
|
1537
|
+
else if (pm === "yarn") exec("yarn install", targetDir);
|
|
1538
|
+
else if (pm === "bun") exec("bun install", targetDir);
|
|
1539
|
+
else exec("npm install", targetDir);
|
|
1514
1540
|
} catch {
|
|
1515
1541
|
p.log.warn("Dependency install failed. Run your package manager install command manually.");
|
|
1516
1542
|
}
|
|
1517
|
-
|
|
1543
|
+
const devCmd = pm === "yarn" ? "yarn dev" : pm === "bun" ? "bun dev" : `${pm} run dev`;
|
|
1544
|
+
p.outro(pc.green(`Done! Run ${pc.cyan(`cd ${projectName} && ${devCmd}`)} to start the dev server.`));
|
|
1518
1545
|
process.exit(0);
|
|
1519
1546
|
}
|
|
1520
1547
|
let framework = detectFramework(cwd);
|
|
@@ -1930,7 +1957,7 @@ function scaffoldNuxt(cwd, cfg, globalCssRelPath, write, skipped, written) {
|
|
|
1930
1957
|
//#region src/cli/index.ts
|
|
1931
1958
|
const args = process.argv.slice(2);
|
|
1932
1959
|
const command = args[0];
|
|
1933
|
-
/** Parse flags like --template next, --theme darksharp, --entry docs */
|
|
1960
|
+
/** Parse flags like --template next, --name my-docs, --theme darksharp, --entry docs */
|
|
1934
1961
|
function parseFlags(argv) {
|
|
1935
1962
|
const flags = {};
|
|
1936
1963
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -1949,6 +1976,7 @@ async function main() {
|
|
|
1949
1976
|
const flags = parseFlags(args);
|
|
1950
1977
|
const initOptions = {
|
|
1951
1978
|
template: flags.template,
|
|
1979
|
+
name: flags.name,
|
|
1952
1980
|
theme: flags.theme,
|
|
1953
1981
|
entry: flags.entry
|
|
1954
1982
|
};
|
|
@@ -1976,7 +2004,8 @@ ${pc.dim("Supported frameworks:")}
|
|
|
1976
2004
|
Next.js, SvelteKit, Astro, Nuxt
|
|
1977
2005
|
|
|
1978
2006
|
${pc.dim("Options for init:")}
|
|
1979
|
-
${pc.cyan("--template <name>")}
|
|
2007
|
+
${pc.cyan("--template <name>")} Bootstrap a project (${pc.dim("next")}, ${pc.dim("nuxt")}, ${pc.dim("sveltekit")}, ${pc.dim("astro")}); use with ${pc.cyan("--name")}
|
|
2008
|
+
${pc.cyan("--name <project>")} Project folder name when using ${pc.cyan("--template")}; prompt if omitted (e.g. ${pc.dim("my-docs")})
|
|
1980
2009
|
${pc.cyan("--theme <name>")} Skip theme prompt (e.g. ${pc.dim("darksharp")}, ${pc.dim("greentree")})
|
|
1981
2010
|
${pc.cyan("--entry <path>")} Skip entry path prompt (e.g. ${pc.dim("docs")})
|
|
1982
2011
|
${pc.cyan("-h, --help")} Show this help message
|