@farming-labs/docs 0.0.16 → 0.0.18
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 +80 -25
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1699,21 +1699,75 @@ const VALID_TEMPLATES = [
|
|
|
1699
1699
|
async function init(options = {}) {
|
|
1700
1700
|
const cwd = process.cwd();
|
|
1701
1701
|
p.intro(pc.bgCyan(pc.black(" @farming-labs/docs ")));
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1702
|
+
let projectType = "existing";
|
|
1703
|
+
if (!options.template) {
|
|
1704
|
+
const projectTypeAnswer = await p.select({
|
|
1705
|
+
message: "Are you adding docs to an existing project or starting fresh?",
|
|
1706
|
+
options: [{
|
|
1707
|
+
value: "existing",
|
|
1708
|
+
label: "Existing project",
|
|
1709
|
+
hint: "Add docs to the current app in this directory"
|
|
1710
|
+
}, {
|
|
1711
|
+
value: "fresh",
|
|
1712
|
+
label: "Fresh project",
|
|
1713
|
+
hint: "Bootstrap a new app from a template (Next, Nuxt, SvelteKit, Astro)"
|
|
1714
|
+
}]
|
|
1715
|
+
});
|
|
1716
|
+
if (p.isCancel(projectTypeAnswer)) {
|
|
1717
|
+
p.outro(pc.red("Init cancelled."));
|
|
1718
|
+
process.exit(0);
|
|
1719
|
+
}
|
|
1720
|
+
projectType = projectTypeAnswer;
|
|
1721
|
+
}
|
|
1722
|
+
if (projectType === "fresh" || options.template) {
|
|
1723
|
+
let template;
|
|
1724
|
+
if (options.template) {
|
|
1725
|
+
template = options.template.toLowerCase();
|
|
1726
|
+
if (!VALID_TEMPLATES.includes(template)) {
|
|
1727
|
+
p.log.error(`Invalid ${pc.cyan("--template")}. Use one of: ${VALID_TEMPLATES.map((t) => pc.cyan(t)).join(", ")}`);
|
|
1728
|
+
process.exit(1);
|
|
1729
|
+
}
|
|
1730
|
+
} else {
|
|
1731
|
+
const templateAnswer = await p.select({
|
|
1732
|
+
message: "Which framework would you like to use?",
|
|
1733
|
+
options: [
|
|
1734
|
+
{
|
|
1735
|
+
value: "next",
|
|
1736
|
+
label: "Next.js",
|
|
1737
|
+
hint: "React with App Router"
|
|
1738
|
+
},
|
|
1739
|
+
{
|
|
1740
|
+
value: "nuxt",
|
|
1741
|
+
label: "Nuxt",
|
|
1742
|
+
hint: "Vue 3 with file-based routing"
|
|
1743
|
+
},
|
|
1744
|
+
{
|
|
1745
|
+
value: "sveltekit",
|
|
1746
|
+
label: "SvelteKit",
|
|
1747
|
+
hint: "Svelte with file-based routing"
|
|
1748
|
+
},
|
|
1749
|
+
{
|
|
1750
|
+
value: "astro",
|
|
1751
|
+
label: "Astro",
|
|
1752
|
+
hint: "Content-focused with islands"
|
|
1753
|
+
}
|
|
1754
|
+
]
|
|
1755
|
+
});
|
|
1756
|
+
if (p.isCancel(templateAnswer)) {
|
|
1757
|
+
p.outro(pc.red("Init cancelled."));
|
|
1758
|
+
process.exit(0);
|
|
1759
|
+
}
|
|
1760
|
+
template = templateAnswer;
|
|
1707
1761
|
}
|
|
1762
|
+
const defaultProjectName = "my-docs";
|
|
1708
1763
|
let projectName = options.name?.trim();
|
|
1709
1764
|
if (!projectName) {
|
|
1710
1765
|
const nameAnswer = await p.text({
|
|
1711
1766
|
message: "Project name? (we'll create this folder and bootstrap the app here)",
|
|
1712
|
-
placeholder:
|
|
1713
|
-
defaultValue:
|
|
1767
|
+
placeholder: defaultProjectName,
|
|
1768
|
+
defaultValue: defaultProjectName,
|
|
1714
1769
|
validate: (value) => {
|
|
1715
1770
|
const v = (value ?? "").trim();
|
|
1716
|
-
if (!v) return "Project name is required";
|
|
1717
1771
|
if (v.includes("/") || v.includes("\\")) return "Project name cannot contain path separators";
|
|
1718
1772
|
if (v.includes(" ")) return "Project name cannot contain spaces";
|
|
1719
1773
|
}
|
|
@@ -1722,7 +1776,7 @@ async function init(options = {}) {
|
|
|
1722
1776
|
p.outro(pc.red("Init cancelled."));
|
|
1723
1777
|
process.exit(0);
|
|
1724
1778
|
}
|
|
1725
|
-
projectName = nameAnswer.trim();
|
|
1779
|
+
projectName = nameAnswer.trim() || defaultProjectName;
|
|
1726
1780
|
}
|
|
1727
1781
|
const templateLabel = template === "next" ? "Next.js" : template === "nuxt" ? "Nuxt" : template === "sveltekit" ? "SvelteKit" : "Astro";
|
|
1728
1782
|
const targetDir = path.join(cwd, projectName);
|
|
@@ -1834,25 +1888,25 @@ async function init(options = {}) {
|
|
|
1834
1888
|
p.outro(pc.red("Init cancelled."));
|
|
1835
1889
|
process.exit(0);
|
|
1836
1890
|
}
|
|
1891
|
+
const defaultThemeName = "my-theme";
|
|
1837
1892
|
let customThemeName;
|
|
1838
1893
|
if (theme === "custom") {
|
|
1839
1894
|
const nameAnswer = await p.text({
|
|
1840
1895
|
message: "Theme name? (we'll create themes/<name>.ts and themes/<name>.css)",
|
|
1841
|
-
placeholder:
|
|
1842
|
-
defaultValue:
|
|
1896
|
+
placeholder: defaultThemeName,
|
|
1897
|
+
defaultValue: defaultThemeName,
|
|
1843
1898
|
validate: (value) => {
|
|
1844
1899
|
const v = (value ?? "").trim().replace(/\.(ts|css)$/i, "");
|
|
1845
|
-
if (!v) return "Theme name is required";
|
|
1846
1900
|
if (v.includes("/") || v.includes("\\")) return "Theme name cannot contain path separators";
|
|
1847
1901
|
if (v.includes(" ")) return "Theme name cannot contain spaces";
|
|
1848
|
-
if (!/^[a-z0-9_-]+$/i.test(v)) return "Use only letters, numbers, hyphens, and underscores";
|
|
1902
|
+
if (v && !/^[a-z0-9_-]+$/i.test(v)) return "Use only letters, numbers, hyphens, and underscores";
|
|
1849
1903
|
}
|
|
1850
1904
|
});
|
|
1851
1905
|
if (p.isCancel(nameAnswer)) {
|
|
1852
1906
|
p.outro(pc.red("Init cancelled."));
|
|
1853
1907
|
process.exit(0);
|
|
1854
1908
|
}
|
|
1855
|
-
customThemeName = nameAnswer.trim().replace(/\.(ts|css)$/i, "");
|
|
1909
|
+
customThemeName = nameAnswer.trim().replace(/\.(ts|css)$/i, "") || defaultThemeName;
|
|
1856
1910
|
}
|
|
1857
1911
|
const aliasHint = framework === "nextjs" ? `Uses ${pc.cyan("@/")} prefix (requires tsconfig paths)` : framework === "sveltekit" ? `Uses ${pc.cyan("$lib/")} prefix (SvelteKit built-in)` : framework === "nuxt" ? `Uses ${pc.cyan("~/")} prefix (Nuxt built-in)` : `Uses ${pc.cyan("@/")} prefix (requires tsconfig paths)`;
|
|
1858
1912
|
const useAlias = await p.confirm({
|
|
@@ -1894,21 +1948,22 @@ async function init(options = {}) {
|
|
|
1894
1948
|
}
|
|
1895
1949
|
astroAdapter = adapter;
|
|
1896
1950
|
}
|
|
1951
|
+
const defaultEntry = "docs";
|
|
1897
1952
|
const entry = await p.text({
|
|
1898
1953
|
message: "Where should your docs live?",
|
|
1899
|
-
placeholder:
|
|
1900
|
-
defaultValue:
|
|
1954
|
+
placeholder: defaultEntry,
|
|
1955
|
+
defaultValue: defaultEntry,
|
|
1901
1956
|
validate: (value) => {
|
|
1902
|
-
|
|
1903
|
-
if (
|
|
1904
|
-
if (
|
|
1957
|
+
const v = (value ?? "").trim();
|
|
1958
|
+
if (v.startsWith("/")) return "Use a relative path (no leading /)";
|
|
1959
|
+
if (v.includes(" ")) return "Path cannot contain spaces";
|
|
1905
1960
|
}
|
|
1906
1961
|
});
|
|
1907
1962
|
if (p.isCancel(entry)) {
|
|
1908
1963
|
p.outro(pc.red("Init cancelled."));
|
|
1909
1964
|
process.exit(0);
|
|
1910
1965
|
}
|
|
1911
|
-
const entryPath = entry;
|
|
1966
|
+
const entryPath = entry.trim() || defaultEntry;
|
|
1912
1967
|
const detectedCssFiles = detectGlobalCssFiles(cwd);
|
|
1913
1968
|
let globalCssRelPath;
|
|
1914
1969
|
const defaultCssPath = framework === "sveltekit" ? "src/app.css" : framework === "astro" ? "src/styles/global.css" : framework === "nuxt" ? "assets/css/main.css" : "app/globals.css";
|
|
@@ -1929,20 +1984,20 @@ async function init(options = {}) {
|
|
|
1929
1984
|
}
|
|
1930
1985
|
globalCssRelPath = picked;
|
|
1931
1986
|
} else {
|
|
1932
|
-
const
|
|
1987
|
+
const cssPathAnswer = await p.text({
|
|
1933
1988
|
message: "Where is your global CSS file?",
|
|
1934
1989
|
placeholder: defaultCssPath,
|
|
1935
1990
|
defaultValue: defaultCssPath,
|
|
1936
1991
|
validate: (value) => {
|
|
1937
|
-
|
|
1938
|
-
if (!
|
|
1992
|
+
const v = (value ?? "").trim();
|
|
1993
|
+
if (v && !v.endsWith(".css")) return "Path must end with .css";
|
|
1939
1994
|
}
|
|
1940
1995
|
});
|
|
1941
|
-
if (p.isCancel(
|
|
1996
|
+
if (p.isCancel(cssPathAnswer)) {
|
|
1942
1997
|
p.outro(pc.red("Init cancelled."));
|
|
1943
1998
|
process.exit(0);
|
|
1944
1999
|
}
|
|
1945
|
-
globalCssRelPath =
|
|
2000
|
+
globalCssRelPath = cssPathAnswer.trim() || defaultCssPath;
|
|
1946
2001
|
}
|
|
1947
2002
|
const pkgJsonContent = readFileSafe(path.join(cwd, "package.json"));
|
|
1948
2003
|
const pkgJson = pkgJsonContent ? JSON.parse(pkgJsonContent) : { name: "my-project" };
|