@farming-labs/docs 0.0.4 → 0.0.5-beta.1
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 +95 -2
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1948,11 +1948,93 @@ function scaffoldNuxt(cwd, cfg, globalCssRelPath, write, skipped, written) {
|
|
|
1948
1948
|
write(`${cfg.entry}/quickstart/page.md`, nuxtQuickstartPageTemplate(cfg));
|
|
1949
1949
|
}
|
|
1950
1950
|
|
|
1951
|
+
//#endregion
|
|
1952
|
+
//#region src/cli/upgrade.ts
|
|
1953
|
+
/**
|
|
1954
|
+
* Upgrade @farming-labs/* packages to latest.
|
|
1955
|
+
* Detects framework from package.json by default, or use --framework (next, nuxt, sveltekit, astro).
|
|
1956
|
+
*/
|
|
1957
|
+
const PRESETS = [
|
|
1958
|
+
"next",
|
|
1959
|
+
"nuxt",
|
|
1960
|
+
"sveltekit",
|
|
1961
|
+
"astro"
|
|
1962
|
+
];
|
|
1963
|
+
const PACKAGES_BY_FRAMEWORK = {
|
|
1964
|
+
nextjs: [
|
|
1965
|
+
"@farming-labs/docs",
|
|
1966
|
+
"@farming-labs/theme",
|
|
1967
|
+
"@farming-labs/next"
|
|
1968
|
+
],
|
|
1969
|
+
nuxt: [
|
|
1970
|
+
"@farming-labs/docs",
|
|
1971
|
+
"@farming-labs/nuxt",
|
|
1972
|
+
"@farming-labs/nuxt-theme"
|
|
1973
|
+
],
|
|
1974
|
+
sveltekit: [
|
|
1975
|
+
"@farming-labs/docs",
|
|
1976
|
+
"@farming-labs/svelte",
|
|
1977
|
+
"@farming-labs/svelte-theme"
|
|
1978
|
+
],
|
|
1979
|
+
astro: [
|
|
1980
|
+
"@farming-labs/docs",
|
|
1981
|
+
"@farming-labs/astro",
|
|
1982
|
+
"@farming-labs/astro-theme"
|
|
1983
|
+
]
|
|
1984
|
+
};
|
|
1985
|
+
function presetFromFramework(fw) {
|
|
1986
|
+
return fw === "nextjs" ? "next" : fw;
|
|
1987
|
+
}
|
|
1988
|
+
function frameworkFromPreset(preset) {
|
|
1989
|
+
return preset === "next" ? "nextjs" : preset;
|
|
1990
|
+
}
|
|
1991
|
+
async function upgrade(options = {}) {
|
|
1992
|
+
const cwd = process.cwd();
|
|
1993
|
+
const tag = options.tag ?? "latest";
|
|
1994
|
+
p.intro(pc.bgCyan(pc.black(" @farming-labs/docs upgrade ")));
|
|
1995
|
+
if (!fileExists(path.join(cwd, "package.json"))) {
|
|
1996
|
+
p.log.error("No package.json found in the current directory. Run this from your project root.");
|
|
1997
|
+
process.exit(1);
|
|
1998
|
+
}
|
|
1999
|
+
let framework = null;
|
|
2000
|
+
let preset;
|
|
2001
|
+
if (options.framework) {
|
|
2002
|
+
const raw = options.framework.toLowerCase().trim();
|
|
2003
|
+
const normalized = raw === "nextjs" ? "next" : raw;
|
|
2004
|
+
if (!PRESETS.includes(normalized)) {
|
|
2005
|
+
p.log.error(`Invalid framework ${pc.cyan(options.framework)}. Use one of: ${PRESETS.map((t) => pc.cyan(t)).join(", ")}`);
|
|
2006
|
+
process.exit(1);
|
|
2007
|
+
}
|
|
2008
|
+
preset = normalized;
|
|
2009
|
+
framework = frameworkFromPreset(preset);
|
|
2010
|
+
} else {
|
|
2011
|
+
framework = detectFramework(cwd);
|
|
2012
|
+
if (!framework) {
|
|
2013
|
+
p.log.error("Could not detect a supported framework (Next.js, Nuxt, SvelteKit, Astro). Use " + pc.cyan("--framework <next|nuxt|sveltekit|astro>") + " to specify.");
|
|
2014
|
+
process.exit(1);
|
|
2015
|
+
}
|
|
2016
|
+
preset = presetFromFramework(framework);
|
|
2017
|
+
}
|
|
2018
|
+
const packages = PACKAGES_BY_FRAMEWORK[framework];
|
|
2019
|
+
const packagesWithTag = packages.map((name) => `${name}@${tag}`);
|
|
2020
|
+
const cmd = `${installCommand(detectPackageManager(cwd))} ${packagesWithTag.join(" ")}`;
|
|
2021
|
+
p.log.step(`Upgrading ${preset} docs packages to ${tag}...`);
|
|
2022
|
+
p.log.message(pc.dim(packages.join(", ")));
|
|
2023
|
+
try {
|
|
2024
|
+
exec(cmd, cwd);
|
|
2025
|
+
p.log.success(`Packages upgraded to ${tag}.`);
|
|
2026
|
+
p.outro(pc.green("Done. Run your dev server to confirm everything works."));
|
|
2027
|
+
} catch {
|
|
2028
|
+
p.log.error("Upgrade failed. Try running manually:\n " + pc.cyan(cmd));
|
|
2029
|
+
process.exit(1);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
|
|
1951
2033
|
//#endregion
|
|
1952
2034
|
//#region src/cli/index.ts
|
|
1953
2035
|
const args = process.argv.slice(2);
|
|
1954
2036
|
const command = args[0];
|
|
1955
|
-
/** Parse flags like --template next, --name my-docs, --theme darksharp, --entry docs */
|
|
2037
|
+
/** Parse flags like --template next, --name my-docs, --theme darksharp, --entry docs, --framework astro */
|
|
1956
2038
|
function parseFlags(argv) {
|
|
1957
2039
|
const flags = {};
|
|
1958
2040
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -1976,6 +2058,10 @@ async function main() {
|
|
|
1976
2058
|
entry: flags.entry
|
|
1977
2059
|
};
|
|
1978
2060
|
if (!command || command === "init") await init(initOptions);
|
|
2061
|
+
else if (command === "upgrade") await upgrade({
|
|
2062
|
+
framework: flags.framework ?? (args[1] && !args[1].startsWith("--") ? args[1] : void 0),
|
|
2063
|
+
tag: args.includes("--beta") ? "beta" : "latest"
|
|
2064
|
+
});
|
|
1979
2065
|
else if (command === "--help" || command === "-h") printHelp();
|
|
1980
2066
|
else if (command === "--version" || command === "-v") printVersion();
|
|
1981
2067
|
else {
|
|
@@ -1993,7 +2079,8 @@ ${pc.dim("Usage:")}
|
|
|
1993
2079
|
npx @farming-labs/docs@latest ${pc.cyan("<command>")}
|
|
1994
2080
|
|
|
1995
2081
|
${pc.dim("Commands:")}
|
|
1996
|
-
${pc.cyan("init")}
|
|
2082
|
+
${pc.cyan("init")} Scaffold docs in your project (default)
|
|
2083
|
+
${pc.cyan("upgrade")} Upgrade @farming-labs/* packages to latest (auto-detect or use --framework)
|
|
1997
2084
|
|
|
1998
2085
|
${pc.dim("Supported frameworks:")}
|
|
1999
2086
|
Next.js, SvelteKit, Astro, Nuxt
|
|
@@ -2003,6 +2090,12 @@ ${pc.dim("Options for init:")}
|
|
|
2003
2090
|
${pc.cyan("--name <project>")} Project folder name when using ${pc.cyan("--template")}; prompt if omitted (e.g. ${pc.dim("my-docs")})
|
|
2004
2091
|
${pc.cyan("--theme <name>")} Skip theme prompt (e.g. ${pc.dim("darksharp")}, ${pc.dim("greentree")})
|
|
2005
2092
|
${pc.cyan("--entry <path>")} Skip entry path prompt (e.g. ${pc.dim("docs")})
|
|
2093
|
+
|
|
2094
|
+
${pc.dim("Options for upgrade:")}
|
|
2095
|
+
${pc.cyan("--framework <name>")} Explicit framework (${pc.dim("next")}, ${pc.dim("nuxt")}, ${pc.dim("sveltekit")}, ${pc.dim("astro")}); omit to auto-detect
|
|
2096
|
+
${pc.cyan("--latest")} Install latest stable (default)
|
|
2097
|
+
${pc.cyan("--beta")} Install beta versions
|
|
2098
|
+
|
|
2006
2099
|
${pc.cyan("-h, --help")} Show this help message
|
|
2007
2100
|
${pc.cyan("-v, --version")} Show version
|
|
2008
2101
|
`);
|