@grove-dev/cli 0.2.20 → 0.3.2

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.
Files changed (108) hide show
  1. package/README.md +8 -93
  2. package/dist/index.d.ts +1 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +99 -1937
  5. package/dist/index.js.map +1 -1
  6. package/dist/init.d.ts +11 -0
  7. package/dist/init.d.ts.map +1 -0
  8. package/dist/init.js +82 -0
  9. package/dist/init.js.map +1 -0
  10. package/dist/package.json +7 -18
  11. package/dist/site/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
  12. package/dist/site/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  13. package/dist/site/.github/ISSUE_TEMPLATE/record_submission.md +48 -0
  14. package/dist/site/.github/pull_request_template.md +27 -0
  15. package/dist/site/.github/workflows/ci.yml +21 -0
  16. package/dist/site/.github/workflows/cleanup.yml +23 -0
  17. package/dist/site/.github/workflows/deploy.yml +36 -0
  18. package/dist/site/.github/workflows/sync-contributors.yml +28 -0
  19. package/dist/site/.github/workflows/sync-github.yml +31 -0
  20. package/dist/site/astro.config.mjs +24 -0
  21. package/dist/site/content/pages/about.md +63 -0
  22. package/dist/site/content/pages/methodology.md +103 -0
  23. package/dist/site/data/health.yml +13 -0
  24. package/dist/site/data/records/.gitkeep +0 -0
  25. package/dist/site/data/records/crewai.yml +21 -0
  26. package/dist/site/data/records/dify.yml +21 -0
  27. package/dist/site/data/records/flowise.yml +21 -0
  28. package/dist/site/data/records/llamaindex.yml +21 -0
  29. package/dist/site/data/records/ollama.yml +28 -0
  30. package/dist/site/data/records/open-webui.yml +21 -0
  31. package/dist/site/data/taxonomy/categories.yml +10 -0
  32. package/dist/site/data/taxonomy/distribution-channels.yml +43 -0
  33. package/dist/site/data/taxonomy/platforms.yml +27 -0
  34. package/dist/site/data/taxonomy/stacks.yml +18 -0
  35. package/dist/site/grove.config.ts +76 -0
  36. package/dist/site/package.json +33 -0
  37. package/dist/site/public/icons/platforms/android.svg +1 -0
  38. package/dist/site/public/icons/platforms/apple-dark.svg +1 -0
  39. package/dist/site/public/icons/platforms/apple-light.svg +1 -0
  40. package/dist/site/public/icons/platforms/chrome.svg +1 -0
  41. package/dist/site/public/icons/platforms/chromeos.svg +5 -0
  42. package/dist/site/public/icons/platforms/desktop.svg +4 -0
  43. package/dist/site/public/icons/platforms/embedded.svg +5 -0
  44. package/dist/site/public/icons/platforms/ios.svg +1 -0
  45. package/dist/site/public/icons/platforms/linux.svg +1 -0
  46. package/dist/site/public/icons/platforms/macos.svg +1 -0
  47. package/dist/site/public/icons/platforms/ubuntu.svg +1 -0
  48. package/dist/site/public/icons/platforms/web.svg +5 -0
  49. package/dist/site/public/icons/platforms/windows.svg +6 -0
  50. package/dist/site/public/icons/stacks/android.svg +1 -0
  51. package/dist/site/public/icons/stacks/apple-dark.svg +1 -0
  52. package/dist/site/public/icons/stacks/apple-light.svg +1 -0
  53. package/dist/site/public/icons/stacks/bun.svg +1 -0
  54. package/dist/site/public/icons/stacks/capacitor.svg +14 -0
  55. package/dist/site/public/icons/stacks/clojure.svg +1 -0
  56. package/dist/site/public/icons/stacks/clojurescript.svg +1 -0
  57. package/dist/site/public/icons/stacks/dart.svg +1 -0
  58. package/dist/site/public/icons/stacks/deno.svg +1 -0
  59. package/dist/site/public/icons/stacks/django.svg +1 -0
  60. package/dist/site/public/icons/stacks/docker.svg +1 -0
  61. package/dist/site/public/icons/stacks/firebase.svg +1 -0
  62. package/dist/site/public/icons/stacks/flutter.svg +1 -0
  63. package/dist/site/public/icons/stacks/go.svg +1 -0
  64. package/dist/site/public/icons/stacks/graphql.svg +1 -0
  65. package/dist/site/public/icons/stacks/ionic.svg +4 -0
  66. package/dist/site/public/icons/stacks/java.svg +1 -0
  67. package/dist/site/public/icons/stacks/javascript.svg +1 -0
  68. package/dist/site/public/icons/stacks/kotlin.svg +1 -0
  69. package/dist/site/public/icons/stacks/llm.svg +1 -0
  70. package/dist/site/public/icons/stacks/mongodb.svg +1 -0
  71. package/dist/site/public/icons/stacks/node.js.svg +1 -0
  72. package/dist/site/public/icons/stacks/nodejs.svg +1 -0
  73. package/dist/site/public/icons/stacks/python.svg +1 -0
  74. package/dist/site/public/icons/stacks/rag.svg +7 -0
  75. package/dist/site/public/icons/stacks/react-native.svg +1 -0
  76. package/dist/site/public/icons/stacks/react.svg +1 -0
  77. package/dist/site/public/icons/stacks/rust.svg +1 -0
  78. package/dist/site/public/icons/stacks/solidity.svg +1 -0
  79. package/dist/site/public/icons/stacks/sveltekit.svg +1 -0
  80. package/dist/site/public/icons/stacks/swift.svg +1 -0
  81. package/dist/site/public/icons/stacks/tensorflow.svg +1 -0
  82. package/dist/site/public/icons/stacks/typescript.svg +1 -0
  83. package/dist/site/public/icons/stacks/vue.svg +1 -0
  84. package/dist/site/public/og-image.svg +48 -0
  85. package/dist/site/public/robots.txt +53 -0
  86. package/dist/site/src/pages/404.astro +64 -0
  87. package/dist/site/src/pages/[slug]/[recordSlug].astro +527 -0
  88. package/dist/site/src/pages/[slug]/index.astro +242 -0
  89. package/dist/site/src/pages/about.astro +189 -0
  90. package/dist/site/src/pages/apps/[recordSlug].astro +34 -0
  91. package/dist/site/src/pages/contributors.astro +113 -0
  92. package/dist/site/src/pages/index.astro +131 -0
  93. package/dist/site/src/pages/submit.astro +170 -0
  94. package/dist/site/src/styles/global.css +33 -0
  95. package/dist/site/tsconfig.json +13 -0
  96. package/package.json +8 -19
  97. package/dist/helpers.d.ts +0 -27
  98. package/dist/helpers.d.ts.map +0 -1
  99. package/dist/helpers.js +0 -41
  100. package/dist/helpers.js.map +0 -1
  101. package/dist/template-loader.d.ts +0 -99
  102. package/dist/template-loader.d.ts.map +0 -1
  103. package/dist/template-loader.js +0 -338
  104. package/dist/template-loader.js.map +0 -1
  105. package/dist/template-loader.test.d.ts +0 -2
  106. package/dist/template-loader.test.d.ts.map +0 -1
  107. package/dist/template-loader.test.js +0 -270
  108. package/dist/template-loader.test.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,873 +1,117 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * Grove CLI — scaffolds Grove-powered spaces and orchestrates
4
- * `@grove-dev/core` commands.
5
- *
6
- * V1 command surface:
7
- * grove new <name> scaffold a new project (asks blueprint + framework)
8
- * grove run [action] dev-internal: scaffold from LOCAL template and run it
9
- * (dev | build | init). Links local Grove packages.
10
- * grove import <src> turn an awesome list into records/*.yml
11
- * grove validate check records, taxonomy, health, decisions
12
- * grove generate build data/generated/records.{full,index}.json
13
- * grove sitemap write public/sitemap.xml
14
- * grove llms write public/llms.txt and llms-full.txt
15
- * grove sync github optional: enrich records with GitHub metadata
16
- * grove cleanup stale flag records that need human review
17
- * grove workflows sync re-emit GitHub workflow files
18
- * grove build run the framework's build command
19
- * grove dev run the framework's dev server
20
- */
21
2
  import { spawn } from "node:child_process";
22
- import { mkdir, readFile, writeFile, access, readdir } from "node:fs/promises";
23
- import { createRequire } from "node:module";
24
- import { dirname, join, resolve } from "node:path";
25
- import { fileURLToPath } from "node:url";
3
+ import { readFile, readdir, writeFile } from "node:fs/promises";
4
+ import { basename, join, resolve } from "node:path";
26
5
  import { Command } from "commander";
27
- import * as p from "@clack/prompts";
28
- import { cleanupStale, enrichFromGithubHtml, fetchGithubMetadata, generate, blueprintKind, importAwesomeList, loadConfig, parseGithubRepoUrl, stringifyRecordYaml, validateProject, } from "@grove-dev/core";
6
+ import { cleanupStale, enrichFromGithubHtml, fetchGithubMetadata, loadConfig, parseGithubRepoUrl, prepareDirectory, stringifyRecordYaml, syncContributors, validateProject, } from "@grove-dev/core";
29
7
  import { parse as parseYaml } from "yaml";
30
- import { copyTemplate, ensureDir, findMonorepoRoot, isFramework, listTemplates, packageNameFromProjectName, renameProjectInTemplate, SUPPORTED_FRAMEWORKS, } from "./template-loader.js";
31
- import { DEPLOY_PROVIDERS, parseDeployProvider } from "./helpers.js";
32
- /**
33
- * Resolve the CLI's own version. After `tsc` builds, the build script
34
- * copies `package.json` next to `index.js` so production usage can read
35
- * it via `import.meta.url`. In dev (`tsx src/index.ts`) we fall back
36
- * to a `require` of the source `package.json`.
37
- */
38
- function readOwnVersion() {
39
- // 1) Production: dist/index.js → ./package.json (alongside the built file).
40
- try {
41
- const distPkg = createRequire(import.meta.url)("./package.json");
42
- if (distPkg?.version)
43
- return String(distPkg.version);
44
- }
45
- catch {
46
- /* not built yet — fall through */
47
- }
48
- // 2) Dev: src/index.ts → ../../package.json.
49
- try {
50
- const srcPkg = createRequire(import.meta.url)("../../package.json");
51
- if (srcPkg?.version)
52
- return String(srcPkg.version);
53
- }
54
- catch {
55
- /* missing — fall through */
56
- }
57
- return "0.0.0-dev";
58
- }
59
- const CLI_VERSION = readOwnVersion();
8
+ import { initDirectory, readCliVersion } from "./init.js";
60
9
  const program = new Command();
61
- const DEPLOY_LABELS = {
62
- vercel: { label: "Vercel", hint: "Vercel — best for Next.js and SSR" },
63
- netlify: { label: "Netlify", hint: "Netlify — strong form handling and edge" },
64
- cloudflare: { label: "Cloudflare Pages", hint: "Cloudflare Pages — global edge" },
65
- "github-pages": { label: "GitHub Pages", hint: "GitHub Pages — free for public repos" },
66
- none: { label: "None", hint: "I'll bring my own deploy — no workflow" },
67
- };
68
- const FRAMEWORK_LABELS = {
69
- astro: { label: "Astro", hint: "Static-first, great for content sites (V1 supported)" },
70
- };
71
- const BLUEPRINT_LABELS = {
72
- "project-directory": { label: "project-directory", hint: "Structured projects/tools/apps" },
73
- "resource-hub": { label: "resource-hub", hint: "Guides, comparisons, resources" },
74
- "ecosystem-map": { label: "ecosystem-map", hint: "Orgs, products, communities" },
75
- };
10
+ function run(command, args, cwd = process.cwd()) {
11
+ return new Promise((resolvePromise, reject) => {
12
+ const child = spawn(command, args, { cwd, stdio: "inherit", shell: false });
13
+ child.once("error", reject);
14
+ child.once("exit", (code, signal) => {
15
+ if (code === 0)
16
+ resolvePromise();
17
+ else
18
+ reject(new Error(`${command} exited with ${signal ?? code ?? "unknown status"}`));
19
+ });
20
+ });
21
+ }
76
22
  program
77
23
  .name("grove")
78
- .description("Grove — grow a community knowledge site.")
79
- .version(CLI_VERSION);
80
- // ──────────────────────────────────────────────────────────────────────
81
- // grove new
82
- // ──────────────────────────────────────────────────────────────────────
83
- program
84
- .command("new")
85
- .argument("[name]", "project directory name (current dir if omitted)")
86
- .description("Scaffold a new Grove project from a framework template.")
87
- .option("-b, --blueprint <name>", "blueprint: project-directory | resource-hub | ecosystem-map")
88
- .option("-f, --framework <name>", "framework: astro (V1: astro only — nextjs/svelte roadmap)")
89
- .option("-t, --template <name>", "template name", "default")
90
- .option("-d, --deploy <provider>", `deploy provider: ${DEPLOY_PROVIDERS.join(" | ")}`)
91
- .option("-g, --github <mode>", "GitHub workflow mode: none | public (V1: none=private, public=community)")
92
- .option("--local", "link @grove-dev/* dependencies to the local monorepo (workspace development only)")
93
- .option("--no-git", "skip `git init` after scaffolding")
94
- .option("--no-install", "skip `pnpm install` after scaffolding")
95
- .option("-y, --yes", "accept defaults for every prompt (CI / scripted use)")
96
- .action(async (name, opts) => {
97
- p.intro("🌱 Grow a new Grove space");
98
- const projectDir = opts.yes || name ? name ?? "." : await resolveText("Where should the new space live?", ".");
99
- const projectName = opts.yes || name
100
- ? (projectDir === "." ? "Grove Directory" : projectDir)
101
- : await resolveText("What is the name of this space?", "Grove Directory");
102
- // Blueprint
103
- let blueprint;
104
- const validBlueprints = Object.keys(BLUEPRINT_LABELS);
105
- if (opts.blueprint && validBlueprints.includes(opts.blueprint)) {
106
- blueprint = opts.blueprint;
107
- }
108
- else if (opts.blueprint) {
109
- p.log.error(`Unknown blueprint: ${opts.blueprint}.`);
110
- p.log.info(`Try one of: ${validBlueprints.join(", ")}`);
111
- process.exit(1);
112
- }
113
- else if (opts.yes) {
114
- blueprint = "project-directory";
115
- }
116
- else {
117
- const b = unwrapPrompt(await p.select({
118
- message: "Pick a blueprint",
119
- options: validBlueprints.map((b) => ({
120
- value: b,
121
- label: BLUEPRINT_LABELS[b].label,
122
- hint: BLUEPRINT_LABELS[b].hint,
123
- })),
124
- initialValue: "project-directory",
125
- }));
126
- blueprint = b;
127
- }
128
- // GitHub integration
129
- // "none" — private/local mode: only validate-data.yml + build.yml
130
- // "public" — public GitHub mode: + sync + cleanup + update + issue/PR templates
131
- let githubMode;
132
- if (opts.github && (opts.github === "none" || opts.github === "public")) {
133
- githubMode = opts.github;
134
- }
135
- else if (opts.github) {
136
- p.log.error(`Unknown GitHub mode: ${opts.github}.`);
137
- p.log.info(`Try one of: none | public`);
138
- process.exit(1);
139
- }
140
- else if (opts.yes) {
141
- githubMode = "none";
142
- }
143
- else {
144
- const g = unwrapPrompt(await p.select({
145
- message: "GitHub automation mode?",
146
- options: [
147
- {
148
- value: "none",
149
- label: "none / private",
150
- hint: "Private or local — no GitHub token, only validate + build",
151
- },
152
- {
153
- value: "public",
154
- label: "public GitHub metadata",
155
- hint: "Community sites — syncs stars, contributors, stale records (token-gated)",
156
- },
157
- ],
158
- initialValue: "none",
159
- }));
160
- githubMode = g;
161
- }
162
- // Framework
163
- let framework;
164
- if (opts.framework && isFramework(opts.framework)) {
165
- framework = opts.framework;
166
- }
167
- else if (opts.framework) {
168
- p.log.error(`Unknown framework: ${opts.framework}.`);
169
- p.log.info(`Try one of: ${SUPPORTED_FRAMEWORKS.join(", ")}`);
170
- process.exit(1);
171
- }
172
- else if (opts.yes) {
173
- framework = "astro";
174
- }
175
- else {
176
- const f = unwrapPrompt(await p.select({
177
- message: "Pick a framework (V1: astro only — nextjs/svelte land in v0.3.0)",
178
- options: SUPPORTED_FRAMEWORKS.map((f) => ({
179
- value: f,
180
- label: FRAMEWORK_LABELS[f].label,
181
- hint: FRAMEWORK_LABELS[f].hint,
182
- })),
183
- initialValue: "astro",
184
- }));
185
- framework = f;
186
- }
187
- const template = opts.template;
188
- let deploy;
189
- if (opts.deploy && DEPLOY_PROVIDERS.includes(opts.deploy)) {
190
- deploy = opts.deploy;
191
- }
192
- else if (opts.deploy) {
193
- p.log.error(`Unknown deploy provider: ${opts.deploy}.`);
194
- p.log.info(`Try one of: ${DEPLOY_PROVIDERS.join(", ")}`);
195
- process.exit(1);
196
- }
197
- else if (opts.yes) {
198
- deploy = "github-pages";
199
- }
200
- else {
201
- const d = unwrapPrompt(await p.select({
202
- message: "Where will this space be deployed?",
203
- options: DEPLOY_PROVIDERS.map((d) => ({
204
- value: d,
205
- label: DEPLOY_LABELS[d].label,
206
- hint: DEPLOY_LABELS[d].hint,
207
- })),
208
- initialValue: "github-pages",
209
- }));
210
- deploy = d;
211
- }
212
- const initGit = opts.yes
213
- ? (opts.git ?? true)
214
- : unwrapPrompt(await p.confirm({
215
- message: "Initialize a git repository?",
216
- initialValue: opts.git ?? true,
217
- }));
218
- const installDeps = opts.yes
219
- ? (opts.install ?? true)
220
- : unwrapPrompt(await p.confirm({
221
- message: "Install dependencies with pnpm?",
222
- initialValue: opts.install ?? true,
223
- }));
224
- const root = resolve(projectDir);
225
- const templates = await listTemplates(framework);
226
- const tpl = templates.find((t) => t.template === template) ?? templates[0];
227
- if (!tpl) {
228
- p.log.error(`No templates found for ${framework}.`);
229
- process.exit(1);
230
- }
231
- const s = p.spinner();
232
- s.start("Scaffolding");
233
- await mkdir(root, { recursive: true });
234
- await copyTemplate(framework, root, tpl.template);
235
- const renameResult = await renameProjectInTemplate(framework, root, projectName, tpl.template, { mode: opts.local ? "file" : "published" });
236
- if (renameResult.rewrittenDeps.length > 0) {
237
- const depLabel = opts.local ? "local monorepo link" : "published version";
238
- p.log.step(`Rewrote @grove-dev/* deps to ${depLabel}: ${renameResult.rewrittenDeps.join(", ")}`);
239
- }
240
- await Promise.all([
241
- ensureDir(join(root, "data")),
242
- ensureDir(join(root, "data", "records")),
243
- ensureDir(join(root, "data", "taxonomy")),
244
- ensureDir(join(root, "data", "generated")),
245
- ensureDir(join(root, "content")),
246
- ensureDir(join(root, "content", "pages")),
247
- ensureDir(join(root, "content", "records")),
248
- ensureDir(join(root, "public")),
249
- ensureDir(join(root, ".github")),
250
- ensureDir(join(root, ".github", "ISSUE_TEMPLATE")),
251
- ensureDir(join(root, ".github", "workflows")),
252
- ]);
253
- await writeIfMissing(join(root, "grove.config.ts"), projectConfig(projectName, blueprint, githubMode));
254
- await writeIfMissing(join(root, "README.md"), projectReadme(projectName, blueprint, framework));
255
- await writeIfMissing(join(root, ".gitignore"), gitignoreTemplate());
256
- await writeIfMissing(join(root, "data", "decisions.yml"), "decisions: []\n");
257
- await writeIfMissing(join(root, "content", "methodology.md"), "# Methodology\n\nGrove uses repository metadata as a signal. Human curation decisions control final visibility.\n");
258
- // Always-on workflows (safe for both private and public projects)
259
- await writeIfMissing(join(root, ".github", "workflows", "validate-data.yml"), workflowValidate());
260
- // The build workflow's deploy step depends on the chosen provider.
261
- // For `github-pages` we keep the Pages deploy inline (the original
262
- // V1 behaviour). For `vercel` / `netlify` / `cloudflare` / `none`
263
- // we write a thin build workflow + a separate deploy workflow (or
264
- // skip the deploy workflow entirely for `none`).
265
- await writeIfMissing(join(root, ".github", "workflows", "build.yml"), workflowBuild(framework, deploy));
266
- // Provider-specific config files (vercel.json, netlify.toml, wrangler.jsonc).
267
- // These live at the project root and are picked up automatically by
268
- // the provider's CLI / build hook.
269
- for (const file of deployConfigFiles(deploy, projectName)) {
270
- await writeIfMissing(join(root, file.path), file.content);
271
- }
272
- // For vercel / netlify / cloudflare we also write a GitHub Actions
273
- // workflow that triggers the provider's deploy on push to main.
274
- // (`github-pages` deploys inline in build.yml; `none` skips this.)
275
- if (deploy === "vercel" || deploy === "netlify" || deploy === "cloudflare") {
276
- await writeIfMissing(join(root, ".github", "workflows", `deploy-${deploy}.yml`), workflowDeploy(deploy));
277
- }
278
- // Issue templates — both modes support a basic set
279
- await writeIfMissing(join(root, ".github", "ISSUE_TEMPLATE", "record_submission.md"), issueTemplateSubmission(blueprint));
280
- await writeIfMissing(join(root, ".github", "ISSUE_TEMPLATE", "bug_report.md"), issueTemplateBug());
281
- await writeIfMissing(join(root, ".github", "ISSUE_TEMPLATE", "feature_request.md"), issueTemplateFeature());
282
- // Public-GitHub-only workflows and templates
283
- if (githubMode === "public") {
284
- await writeIfMissing(join(root, ".github", "workflows", "sync-github-metadata.yml"), workflowSyncGithubMetadata());
285
- await writeIfMissing(join(root, ".github", "workflows", "sync-contributors.yml"), workflowSyncContributors());
286
- await writeIfMissing(join(root, ".github", "workflows", "cleanup-stale-records.yml"), workflowCleanupStaleRecords());
287
- await writeIfMissing(join(root, ".github", "workflows", "update-records.yml"), workflowUpdateRecords());
288
- await writeIfMissing(join(root, ".github", "ISSUE_TEMPLATE", "report-broken-record.md"), issueTemplateBrokenRecord());
289
- await writeIfMissing(join(root, ".github", "pull_request_template.md"), pullRequestTemplate());
290
- }
291
- await writeIfMissing(join(root, "LICENSE"), licenseMIT(projectName));
292
- s.stop("Scaffolded");
293
- if (initGit) {
294
- try {
295
- await runExternal("git", ["init", "-b", "main"], { stdio: "ignore", cwd: root });
296
- p.log.step("Initialized git repo on `main`");
297
- }
298
- catch {
299
- p.log.warn("git not found — skipping git init");
300
- }
301
- }
302
- if (installDeps) {
303
- const installSpinner = p.spinner();
304
- installSpinner.start("Installing dependencies");
305
- try {
306
- await runExternal("pnpm", ["install"], { stdio: "ignore", cwd: root });
307
- installSpinner.stop("Installed dependencies");
308
- }
309
- catch {
310
- installSpinner.stop("Install failed");
311
- p.log.warn(`Run \`pnpm install\` inside ${root} to retry.`);
312
- // The scaffold succeeded but the install didn't — flag the
313
- // partial-success state to the parent process. The outro
314
- // still prints so the user sees the path + next steps, but
315
- // the non-zero exit code means CI / shell wrappers can
316
- // detect the failure and stop before calling `grove build`
317
- // on a half-installed project. (Audit finding: a warning
318
- // alone is silent failure for `grove new`.)
319
- process.exitCode = 1;
320
- }
321
- }
322
- const ghLabel = githubMode === "public"
323
- ? "public GitHub metadata (sync + cleanup + update workflows)"
324
- : "none / private (only validate + build workflows)";
325
- const deployLabel = deploy === "none"
326
- ? "none (no deploy workflow written)"
327
- : `${deploy} workflow + config written`;
328
- p.outro(`🌳 ${projectName} is ready at ${root}\n\n` +
329
- `Blueprint: ${blueprint}\n` +
330
- `GitHub mode: ${ghLabel}\n` +
331
- `Deploy: ${deployLabel}\n\n` +
332
- `Next steps:\n` +
333
- ` cd ${projectDir}\n` +
334
- ` grove validate\n` +
335
- ` grove generate\n` +
336
- ` grove build\n`);
337
- });
338
- // ──────────────────────────────────────────────────────────────────────
339
- // grove run — dev-only "pretend user" smoke test
340
- // ──────────────────────────────────────────────────────────────────────
341
- //
342
- // `grove new` is the production path: it copies the framework template
343
- // into a fresh dir, keeps its published Grove package versions, and
344
- // (optionally) installs + inits git.
345
- //
346
- // `grove run` is the dev / CI-internal path. It does almost the same
347
- // scaffolding, but with two differences that make it useful when
348
- // iterating on the monorepo:
349
- //
350
- // 1. Grove dependencies in the scaffolded `package.json` are
351
- // rewritten to direct local links, so package changes are picked
352
- // up by the next `grove run` without a publish step.
353
- //
354
- // 2. The scaffold lives INSIDE the monorepo, under
355
- // `<monorepo-root>/.grove/run/<timestamp>/`. `.grove/*` is
356
- // registered in `pnpm-workspace.yaml`, so root-level tooling can
357
- // discover and operate on the generated project.
358
- //
359
- // After scaffolding and (optionally) installing, `grove run` can launch
360
- // the framework dev server in-process. That makes end-to-end smoke
361
- // tests a one-liner:
362
- //
363
- // grove run dev # scaffold → install → astro dev
364
- // grove run build # scaffold → install → astro build
365
- // grove run init --no-install # just scaffold, fix deps manually
366
- //
367
- // V1 only supports `astro` because that's the only framework with a
368
- // real template + peer wiring. `nextjs` and `svelte` are not exposed as
369
- // scaffold options in V1 — they exist as skeleton packages but their
370
- // templates have no real pages / components / layouts.
24
+ .description("Build and maintain a Grove-powered directory.")
25
+ .version(readCliVersion());
371
26
  program
372
- .command("run")
373
- .argument("[action]", "run action: dev (default) | build | init", "dev")
374
- .argument("[name]", "project directory name (default: grove-run-<timestamp>)")
375
- .description("Scaffold a Grove project from the LOCAL workspace template and run it.")
376
- .option("-f, --framework <name>", "framework: astro (V1: astro only — nextjs/svelte roadmap)", "astro")
377
- .option("-t, --template <name>", "template name", "default")
378
- .option("-d, --dir <name>", "project directory name (overrides positional name; relative to monorepo root)")
379
- .option("--no-install", "skip `pnpm install` after scaffolding")
380
- .option("--no-git", "skip `git init` after scaffolding")
381
- .option("--port <port>", "dev server port (only used by `dev` action; passed to astro dev; 1-65535)", (value) => {
382
- // Commander passes the raw string here. We accept decimal
383
- // integers, reject floats, NaN, and out-of-range values.
384
- // Throwing makes commander surface the message AND exit 1
385
- // before the action handler runs — exactly the behaviour the
386
- // audit wanted (a non-integer or out-of-range port used to
387
- // silently become `NaN`, which astro dev then printed as
388
- // `--port NaN` and refused to bind).
389
- const port = Number(value);
390
- if (!Number.isInteger(port) || port < 1 || port > 65535) {
391
- throw new Error(`Invalid --port: "${value}" is not an integer in 1..65535.`);
392
- }
393
- return port;
394
- })
395
- .action(async (action, name, opts) => {
396
- // ── Validate action ────────────────────────────────────────────
397
- const validActions = ["dev", "build", "init"];
398
- if (!validActions.includes(action)) {
399
- p.log.error(`Unknown run action: ${action}.`);
400
- p.log.info(`Try one of: ${validActions.join(", ")}`);
401
- process.exit(1);
402
- }
403
- const runAction = action;
404
- // ── Validate framework ─────────────────────────────────────────
405
- if (!isFramework(opts.framework)) {
406
- p.log.error(`Unknown framework: ${opts.framework}.`);
407
- p.log.info(`Try one of: ${SUPPORTED_FRAMEWORKS.join(", ")}`);
408
- process.exit(1);
409
- }
410
- const framework = opts.framework;
411
- const _exhaustive = framework;
412
- p.intro(`🧪 Grove run — ${runAction}`);
413
- // ── Locate the monorepo root ───────────────────────────────────
414
- // We need the monorepo root so we can:
415
- // (a) decide where to put the scaffolded project (always
416
- // inside the monorepo, under `.grove/run/<stamp>/`)
417
- // (b) run `pnpm install --filter` from there, so the
418
- // workspace protocol resolves `packages/*` siblings.
419
- const cliLocation = dirname(fileURLToPath(import.meta.url));
420
- let monorepoRoot;
421
- try {
422
- monorepoRoot = findMonorepoRoot(cliLocation);
423
- }
424
- catch (err) {
425
- p.log.error(err.message);
426
- process.exit(1);
427
- }
428
- p.log.info(`Monorepo root: ${monorepoRoot}`);
429
- // ── Resolve target directory ───────────────────────────────────
430
- // If the caller did not pin a project (no `--dir`, no positional
431
- // name), reuse an existing scaffold under `.grove/run/` so that
432
- // repeat invocations of `pnpm grove:dev` / `grove:build` don't
433
- // pile up a new timestamped folder on every run.
434
- //
435
- // Selection rules when no name is given:
436
- // - 0 existing scaffolds → fall back to a fresh timestamped name.
437
- // - 1 existing scaffold → use it.
438
- // - 2+ existing scaffolds → refuse and ask the caller to pass
439
- // `--dir <name>` so we don't pick
440
- // silently and surprise the user.
441
- const runRoot = resolve(monorepoRoot, ".grove", "run");
442
- let dirRel;
443
- if (opts.dir) {
444
- dirRel = opts.dir;
445
- }
446
- else if (name) {
447
- dirRel = name;
448
- }
449
- else {
450
- const existing = [];
451
- try {
452
- const entries = await readdir(runRoot, { withFileTypes: true });
453
- for (const entry of entries) {
454
- if (!entry.isDirectory())
455
- continue;
456
- // Only count it as a scaffold if it has a package.json —
457
- // that's the same sentinel `run` uses to detect a previous
458
- // scaffold, so we stay consistent with the "is this
459
- // reusable?" check below.
460
- try {
461
- await access(join(runRoot, entry.name, "package.json"));
462
- existing.push(entry.name);
463
- }
464
- catch {
465
- /* not a scaffold, skip */
466
- }
467
- }
468
- }
469
- catch {
470
- /* runRoot doesn't exist yet — we'll create it */
471
- }
472
- if (existing.length === 0) {
473
- const stamp = new Date()
474
- .toISOString()
475
- .replace(/[-:]/g, "")
476
- .replace(/\..+$/, "")
477
- .replace("T", "-");
478
- dirRel = `grove-run-${stamp}`;
479
- }
480
- else if (existing.length === 1) {
481
- const only = existing[0];
482
- if (only) {
483
- dirRel = only;
484
- p.log.info(`Reusing scaffold: ${dirRel} (pass --dir <name> to override)`);
485
- }
486
- else {
487
- dirRel = "grove-run-default";
488
- }
489
- }
490
- else {
491
- p.log.error(`Found ${existing.length} scaffolds under .grove/run/. ` +
492
- `Pass --dir <name> to pick one:`);
493
- for (const e of existing.sort())
494
- p.log.info(` - ${e}`);
495
- process.exit(1);
496
- }
497
- }
498
- // Always live under <monorepo-root>/.grove/run/<name>/ so the
499
- // workspace picks it up via the `.grove/*` glob in
500
- // `pnpm-workspace.yaml`.
501
- const root = resolve(monorepoRoot, ".grove", "run", dirRel);
502
- // The dir name and the package.json `name` are not the same —
503
- // `packageNameFromProjectName` slugifies the dir name and appends
504
- // `-<framework>-<template>`. We need the package name to drive
505
- // `pnpm --filter`, so compute it once and reuse.
506
- const projectName = root.split("/").filter(Boolean).pop() ?? dirRel;
507
- // ── Look up the LOCAL template via @grove-dev/<framework>'s
508
- // `templates/<name>` directory. Inside this monorepo, that
509
- // is a symlink straight to packages/astro/templates/default/,
510
- // so a template change in the source tree flows through to
511
- // the scaffolded project with no publish step. ─────────────
512
- const templates = await listTemplates(framework);
513
- const tpl = templates.find((t) => t.template === opts.template) ?? templates[0];
514
- if (!tpl) {
515
- p.log.error(`No templates found for ${framework}.`);
516
- process.exit(1);
517
- }
518
- p.log.info(`Template: ${tpl.path}`);
519
- const packageName = packageNameFromProjectName(projectName, framework, tpl.template);
520
- p.log.info(`Project: ${projectName} (package: ${packageName}) → ${root}`);
521
- // ── Scaffold (or reuse an existing scaffold) ──────────────────
522
- // If the target dir already contains the expected package, this
523
- // is a re-run. Refresh template-owned files in place so edits to
524
- // the local adapter are visible immediately; node_modules and
525
- // generated data are excluded by copyTemplate and stay reusable.
526
- const sentinel = join(root, "package.json");
527
- let alreadyScaffolded = false;
528
- try {
529
- const existing = JSON.parse(await readFile(sentinel, "utf8"));
530
- const expectedName = packageNameFromProjectName(projectName, framework, tpl.template);
531
- alreadyScaffolded = existing.name === expectedName;
532
- }
533
- catch {
534
- alreadyScaffolded = false;
535
- }
536
- const s = p.spinner();
537
- if (alreadyScaffolded) {
538
- s.start("Refreshing scaffold from local template");
539
- await copyTemplate(framework, root, tpl.template, { force: true });
540
- await renameProjectInTemplate(framework, root, projectName, tpl.template, { mode: "file" });
541
- s.stop("Refreshed scaffold (local package deps)");
542
- }
543
- else {
544
- s.start("Scaffolding");
545
- await mkdir(root, { recursive: true });
546
- await copyTemplate(framework, root, tpl.template);
547
- // Use local package paths for the dev-only run path. Installing
548
- // the generated project as a standalone package avoids pnpm's
549
- // workspace discovery cache when a project appears mid-command.
550
- await renameProjectInTemplate(framework, root, projectName, tpl.template, { mode: "file" });
551
- s.stop("Scaffolded (local package deps)");
552
- }
553
- // ── git init ───────────────────────────────────────────────────
554
- if (opts.git !== false) {
555
- try {
556
- await runExternal("git", ["init", "-b", "main"], { stdio: "ignore", cwd: root });
557
- p.log.step("Initialized git repo on `main`");
558
- }
559
- catch {
560
- p.log.warn("git not found — skipping git init");
561
- }
562
- }
563
- // ── pnpm install (from monorepo root, scoped to this project) ──
564
- if (opts.install !== false) {
565
- const installSpinner = p.spinner();
566
- installSpinner.start("Installing dependencies");
567
- try {
568
- await runExternal("pnpm", ["install", "--ignore-workspace"], {
569
- stdio: "ignore",
570
- cwd: root,
571
- });
572
- installSpinner.stop("Installed dependencies");
573
- }
574
- catch {
575
- installSpinner.stop("Install failed");
576
- p.log.warn(`Run \`pnpm install --ignore-workspace\` from ${root} to retry.`);
577
- if (runAction !== "init") {
578
- p.log.error("Cannot continue without a working install.");
579
- process.exit(1);
580
- }
581
- // For `grove run init` we still want a non-zero exit so CI
582
- // / shell wrappers can detect the partial-success state
583
- // (audit finding: warnings alone are silent failures).
584
- process.exitCode = 1;
585
- }
586
- }
587
- // ── Run the requested action ───────────────────────────────────
588
- if (runAction === "init") {
589
- p.outro(`🌳 Scaffolded at ${root}\n\n` +
590
- `Next steps:\n` +
591
- ` cd ${root}\n` +
592
- ` pnpm dev\n`);
593
- return;
594
- }
595
- if (runAction === "build") {
596
- // Run the template's `build` script, not `astro build` directly.
597
- // The script chains `build:data` + `build:sitemap` + `build:llms`
598
- // + `astro build` so the data is generated first. Skipping that
599
- // chain gives you a half-built site with no records.
600
- p.log.step(`Building ${packageName} via 'pnpm run build' (this can take a while)…`);
601
- await runExternal("pnpm", ["--filter", packageName, "run", "build"], {
602
- stdio: "inherit",
603
- cwd: monorepoRoot,
604
- });
605
- p.outro(`🌳 Build done at ${root}`);
606
- return;
607
- }
608
- // runAction === "dev" — start the dev server in-process.
609
- //
610
- // The template's `dev` script chains `build:data && astro dev`,
611
- // which is what we want for a production user. But for a dev
612
- // smoke test, the script's `&&` makes pnpm's `--` forwarding
613
- // land in a tricky place: `pnpm run dev -- --port 4327` becomes
614
- // `astro dev -- --port 4327`, where Astro treats `--port 4327`
615
- // as positional args (port flag ignored).
616
- //
617
- // Cleanest workaround: run `build:data` separately (the only
618
- // pre-step `dev` does), then `pnpm exec astro dev` directly with
619
- // the port flag in the right place. Two `runExternal` calls is
620
- // fine — they're both fast (`build:data` is a quick
621
- // `grove generate`, and `astro dev` is what the user actually
622
- // wants to see).
623
- const port = typeof opts.port === "number" ? opts.port : 4321;
624
- p.log.step(`Generating data via 'pnpm run build:data'…`);
625
- try {
626
- await runExternal("pnpm", ["--filter", packageName, "run", "build:data"], { stdio: "inherit", cwd: monorepoRoot });
627
- }
628
- catch {
629
- p.log.warn(`build:data failed — starting astro dev anyway, site will be empty.`);
630
- }
631
- p.log.step(`Starting astro dev on port ${port} (Ctrl-C to stop)…`);
632
- await runExternal("pnpm", ["--filter", packageName, "exec", "astro", "dev", "--port", String(port)], { stdio: "inherit", cwd: monorepoRoot });
633
- });
634
- // ──────────────────────────────────────────────────────────────────────
635
- // grove import
636
- // ──────────────────────────────────────────────────────────────────────
637
- program
638
- .command("import")
639
- .argument("<source>", "GitHub awesome-list URL, raw README URL, or local README.md")
640
- .description("Import Markdown links into data/records/*.yml for the current blueprint.")
641
- .action(async (source) => {
642
- const config = await loadConfig();
643
- const result = await importAwesomeList(source);
644
- const recordsDir = resolve(process.cwd(), config.paths.recordsDir);
645
- await mkdir(recordsDir, { recursive: true });
646
- const expectedKind = blueprintKind[config.blueprint];
647
- let written = 0;
648
- for (const record of result.records) {
649
- const yamlObj = {
650
- kind: expectedKind,
651
- slug: record.slug,
652
- description: record.description,
653
- category: record.category,
654
- tags: [],
655
- links: record.links,
656
- source: { type: "import" },
657
- };
658
- if (expectedKind === "project") {
659
- yamlObj.name = record.name;
660
- }
661
- else if (expectedKind === "resource") {
662
- yamlObj.title = record.name;
663
- yamlObj.type = "link";
664
- yamlObj.topic = record.category;
665
- }
666
- else if (expectedKind === "entity") {
667
- yamlObj.name = record.name;
668
- yamlObj.type = "other";
669
- }
670
- const path = join(recordsDir, `${record.slug}.yml`);
671
- await writeFile(path, stringifyRecordYaml(yamlObj), "utf8");
672
- written++;
673
- }
674
- console.log(`Imported ${written} record(s) into ${recordsDir}`);
27
+ .command("init")
28
+ .argument("[directory]", "directory to create", ".")
29
+ .description("Create a complete Grove directory from the official site.")
30
+ .option("--no-install", "skip pnpm install")
31
+ .option("--no-git", "skip git init")
32
+ .action(async (directory, options) => {
33
+ const target = resolve(process.cwd(), directory);
34
+ const result = await initDirectory(target, {
35
+ ...(directory === "." ? {} : { projectName: basename(resolve(directory)) }),
36
+ });
37
+ console.log(`Created ${result.projectName} in ${result.targetDir}`);
38
+ if (options.install)
39
+ await run("pnpm", ["install"], target);
40
+ if (options.git)
41
+ await run("git", ["init"], target);
42
+ console.log(`\nNext:\n cd ${directory}\n pnpm dev`);
675
43
  });
676
- // ──────────────────────────────────────────────────────────────────────
677
- // grove validate
678
- // ──────────────────────────────────────────────────────────────────────
679
44
  program
680
- .command("validate")
681
- .description("Validate project data files against the configured blueprint.")
682
- .option("--strict", "fail on warnings as well as errors")
683
- .action(async (opts) => {
45
+ .command("check")
46
+ .description("Validate data, generate artifacts, and run Astro checks.")
47
+ .option("--strict", "treat Grove warnings as errors")
48
+ .action(async (options) => {
684
49
  const config = await loadConfig();
685
- const result = await validateProject(config, opts.strict !== undefined ? { strict: opts.strict } : {});
686
- for (const issue of result.errors) {
687
- console.log(`✖ ${issue.code}: ${issue.message}`);
688
- }
689
- for (const issue of result.warnings) {
690
- console.log(`⚠ ${issue.code}: ${issue.message}`);
50
+ const result = await validateProject(config, {
51
+ ...(options.strict === undefined ? {} : { strict: options.strict }),
52
+ });
53
+ for (const issue of result.issues) {
54
+ const output = issue.severity === "error" ? console.error : console.warn;
55
+ output(`[${issue.severity}] ${issue.code}: ${issue.message}`);
691
56
  }
692
- if (!result.ok) {
57
+ if (!result.ok || (options.strict && result.warnings.length > 0)) {
693
58
  process.exitCode = 1;
694
- const total = result.issues.length;
695
- const errorCount = result.errors.length;
696
- const warnCount = result.warnings.length;
697
- console.log(`Validation failed with ${errorCount} error(s) and ${warnCount} warning(s) (${total} total).`);
698
59
  return;
699
60
  }
700
- if (result.warnings.length > 0) {
701
- console.log(`Validation passed with ${result.warnings.length} warning(s).`);
702
- }
703
- else {
704
- console.log("Validation passed.");
705
- }
706
- });
707
- // ──────────────────────────────────────────────────────────────────────
708
- // grove generate
709
- // ──────────────────────────────────────────────────────────────────────
710
- program
711
- .command("generate")
712
- .description("Build data/generated/records.{full,index}.json from data/records/*.yml.")
713
- .action(async () => {
714
- const result = await generate();
715
- console.log(`[generate] ${result.totalRecords} total, ${result.visibleRecords} visible\n` +
716
- ` full: ${result.fullPath}\n` +
717
- ` index: ${result.indexPath}\n` +
718
- ` alias: ${result.aliasPath}`);
719
- });
720
- // ──────────────────────────────────────────────────────────────────────
721
- // grove sitemap
722
- // ──────────────────────────────────────────────────────────────────────
723
- program
724
- .command("sitemap")
725
- .description("Generate public/sitemap.xml from data/generated/records.full.json.")
726
- .action(async () => {
727
- const config = await loadConfig();
728
- const { buildSitemap } = await import("@grove-dev/core");
729
- const recordsPath = join(process.cwd(), config.paths.generatedDir, "records.full.json");
730
- let payload;
731
- try {
732
- payload = JSON.parse(await readFile(recordsPath, "utf8"));
733
- }
734
- catch {
735
- payload = { records: [] };
736
- }
737
- const items = (payload.records ?? []);
738
- const result = await buildSitemap({
739
- generatedAt: payload.generatedAt ?? new Date().toISOString(),
740
- items,
741
- });
742
- console.log(`[sitemap] wrote ${result.urlCount} URLs → ${result.path}`);
743
- });
744
- // ──────────────────────────────────────────────────────────────────────
745
- // grove llms
746
- // ──────────────────────────────────────────────────────────────────────
747
- program
748
- .command("llms")
749
- .description("Generate public/llms.txt and public/llms-full.txt.")
750
- .action(async () => {
751
- const config = await loadConfig();
752
- const { buildLlmsFiles } = await import("@grove-dev/core");
753
- const recordsPath = join(process.cwd(), config.paths.generatedDir, "records.full.json");
754
- let payload;
755
- try {
756
- payload = JSON.parse(await readFile(recordsPath, "utf8"));
757
- }
758
- catch {
759
- payload = { records: [] };
760
- }
761
- const records = (payload.records ?? []);
762
- const result = await buildLlmsFiles({
763
- generatedAt: payload.generatedAt ?? new Date().toISOString(),
764
- records: records.map((r) => {
765
- // Build the optional fields conditionally so we never assign
766
- // `undefined` to a property typed as `string` (breaks
767
- // `exactOptionalPropertyTypes` in the consumer's types).
768
- const base = {
769
- slug: r.slug,
770
- name: r.name ?? r.title ?? r.slug,
771
- };
772
- if (r.description !== undefined)
773
- base.description = r.description;
774
- if (r.category !== undefined)
775
- base.category = r.category;
776
- if (r.stack !== undefined)
777
- base.stack = r.stack;
778
- if (r.stars !== undefined)
779
- base.stars = r.stars;
780
- if (r.visibility !== undefined)
781
- base.visibility = r.visibility;
782
- return base;
783
- }),
784
- });
785
- console.log(`[llms] ${result.indexed} indexed → ${result.txtPath} + ${result.fullPath}`);
61
+ const prepared = await prepareDirectory();
62
+ console.log(`[grove] ${prepared.generated.totalRecords} records prepared; sitemap and llms files updated.`);
63
+ await run("pnpm", ["exec", "astro", "check"]);
786
64
  });
787
- // ──────────────────────────────────────────────────────────────────────
788
- // grove sync github
789
- // ──────────────────────────────────────────────────────────────────────
790
65
  program
791
66
  .command("sync")
792
67
  .argument("<target>", "github | contributors")
793
- .description("Optional GitHub integration: enrich records with GitHub metadata.")
794
- .option("--limit <n>", "limit records to sync (rate-limit guard)", (value) => Number(value))
795
- .option("--strict", "fail on unavailable GitHub metadata")
68
+ .description("Refresh GitHub metadata owned by Grove.")
69
+ .option("--limit <count>", "limit records to sync", Number)
70
+ .option("--strict", "fail if any GitHub record cannot be refreshed")
796
71
  .action(async (target, options) => {
797
72
  const config = await loadConfig();
798
- if (target !== "github" && target !== "contributors") {
799
- console.error(`Unknown sync target: ${target}. Use "github" or "contributors".`);
800
- process.exit(1);
801
- }
802
73
  if (target === "contributors") {
803
- const script = resolve(process.cwd(), "scripts", "sync-contributors.mjs");
804
- try {
805
- await access(script);
806
- }
807
- catch {
808
- console.error(`[sync contributors] Missing ${script}. ` +
809
- "Restore the template script or run this command from a Grove project root.");
810
- process.exit(1);
811
- }
812
- await runExternal(process.execPath, [script], { stdio: "inherit", cwd: process.cwd() });
74
+ await prepareDirectory();
75
+ const result = await syncContributors({
76
+ cwd: process.cwd(),
77
+ generatedDir: config.paths.generatedDir,
78
+ ...(config.site.repoUrl ? { repoUrl: config.site.repoUrl } : {}),
79
+ });
80
+ console.log(`[sync contributors] ${result.contributors} contributors from ${result.repositories} repository → ${result.outputPath}`);
813
81
  return;
814
82
  }
815
- const recordsDir = resolve(process.cwd(), config.paths.recordsDir);
816
- const { readdir } = await import("node:fs/promises");
817
- let entries = [];
818
- try {
819
- entries = await readdir(recordsDir);
820
- }
821
- catch {
822
- console.error(`[sync github] ${recordsDir} does not exist.`);
823
- process.exit(1);
83
+ if (target !== "github") {
84
+ throw new Error(`Unknown sync target "${target}". Use github or contributors.`);
824
85
  }
825
- const files = entries.filter((f) => f.endsWith(".yml")).sort();
826
- const selected = typeof options.limit === "number" ? files.slice(0, options.limit) : files;
86
+ const recordsDir = resolve(process.cwd(), config.paths.recordsDir);
87
+ const files = (await readdir(recordsDir))
88
+ .filter((file) => file.endsWith(".yml"))
89
+ .sort();
90
+ const selected = options.limit === undefined ? files : files.slice(0, options.limit);
827
91
  let updated = 0;
828
92
  let htmlOnly = 0;
829
93
  let failed = 0;
830
94
  for (const file of selected) {
831
- const path = join(recordsDir, file);
832
- const text = await readFile(path, "utf8");
833
- const raw = (parseYaml(text) ?? {});
834
- // Canonical repo URL: `repoUrl` first (the project-directory
835
- // canonical field per the schema), then fall back to
836
- // `links.github` for sites that only use the human-facing link.
837
- // When both are present and disagree, warn loudly — a curator
838
- // who updated only `links.github` and forgot `repoUrl` would
839
- // otherwise see stale metadata with no explanation.
95
+ const filePath = join(recordsDir, file);
96
+ const raw = (parseYaml(await readFile(filePath, "utf8")) ?? {});
840
97
  const links = raw.links ?? {};
841
- const rawRepoUrl = raw.repoUrl;
842
- const linksGithub = links.github;
843
- if (rawRepoUrl &&
844
- linksGithub &&
845
- rawRepoUrl.trim() !== linksGithub.trim()) {
846
- process.stderr.write(`[sync github] ${file}: repoUrl "${rawRepoUrl}" and links.github "${linksGithub}" disagree — using repoUrl. Update repoUrl (or remove it) to silence this.\n`);
847
- }
848
- const repoUrl = rawRepoUrl ?? linksGithub ?? null;
98
+ const repoUrl = raw.repoUrl ?? links.github;
849
99
  if (!repoUrl) {
850
- process.stdout.write(`[sync github] ${file}: no repoUrl or links.github, skipping\n`);
100
+ console.log(`[sync github] ${file}: no repository, skipped`);
851
101
  continue;
852
102
  }
853
103
  const ref = parseGithubRepoUrl(repoUrl);
854
104
  if (!ref) {
855
- process.stdout.write(`[sync github] ${file}: unparseable repoUrl, skipping\n`);
105
+ console.log(`[sync github] ${file}: invalid GitHub URL, skipped`);
856
106
  continue;
857
107
  }
858
- process.stdout.write(`[sync github] ${ref.owner}/${ref.repo} ... `);
859
- // Build a github patch. We always either write a real `repository`
860
- // block (API success), a partial block from HTML (fallback), or
861
- // skip the file (both fail). The `sync` block records which
862
- // path the data came from so downstream consumers can tell
863
- // full metadata from partial.
864
- const gh = raw.github ?? {};
865
- const githubPatch = {};
866
- let syncSource = null;
108
+ const github = raw.github ?? {};
109
+ const patch = {};
110
+ let source;
867
111
  try {
868
112
  const metadata = await fetchGithubMetadata(ref);
869
113
  if (metadata) {
870
- githubPatch.repository = {
114
+ patch.repository = {
871
115
  full_name: metadata.fullName,
872
116
  stargazers_count: metadata.stars,
873
117
  forks_count: metadata.forks,
@@ -880,1141 +124,59 @@ program
880
124
  : null,
881
125
  topics: metadata.topics,
882
126
  };
883
- syncSource = "api";
127
+ source = "api";
884
128
  }
885
129
  }
886
130
  catch {
887
- // API failed — try HTML fallback below.
131
+ // The token-free HTML fallback below keeps scheduled syncs useful.
888
132
  }
889
- if (syncSource === null) {
133
+ if (!source) {
890
134
  try {
891
135
  const enriched = await enrichFromGithubHtml(repoUrl);
892
136
  if (!enriched.notFound && !enriched.rateLimited && !enriched.error) {
893
- githubPatch.html = {
137
+ patch.html = {
894
138
  license: enriched.fields.license,
895
139
  language: enriched.fields.language,
896
140
  topics: enriched.fields.topics,
897
141
  homepage: enriched.fields.homepage,
898
142
  };
899
- syncSource = "html";
900
- htmlOnly++;
143
+ source = "html";
144
+ htmlOnly += 1;
901
145
  }
902
146
  }
903
147
  catch {
904
- // both API and HTML failed
148
+ // Report the record once both metadata sources have failed.
905
149
  }
906
150
  }
907
- if (syncSource === null) {
908
- process.stdout.write("skipped (api+html error)\n");
909
- failed++;
151
+ if (!source) {
152
+ failed += 1;
153
+ console.log(`[sync github] ${file}: unavailable`);
910
154
  continue;
911
155
  }
912
- githubPatch.sync = {
913
- syncedAt: new Date().toISOString(),
914
- source: syncSource,
915
- };
916
- const next = {
917
- ...raw,
918
- github: { ...gh, ...githubPatch },
919
- };
920
- await writeFile(path, stringifyRecordYaml(next), "utf8");
921
- process.stdout.write(syncSource === "api" ? "updated\n" : "html-fallback\n");
922
- updated++;
156
+ patch.sync = { syncedAt: new Date().toISOString(), source };
157
+ await writeFile(filePath, stringifyRecordYaml({ ...raw, github: { ...github, ...patch } }), "utf8");
158
+ updated += 1;
159
+ console.log(`[sync github] ${file}: ${source}`);
923
160
  }
924
- console.log(`\n[sync github] ${updated} updated (${htmlOnly} html-only), ${failed} failed`);
925
- // In strict mode, fail the build if any record could not be synced.
926
- if (options.strict && failed > 0) {
161
+ console.log(`[sync github] ${updated} updated (${htmlOnly} HTML fallback), ${failed} failed`);
162
+ if (options.strict && failed > 0)
927
163
  process.exitCode = 1;
928
- console.error(`[sync github] --strict: ${failed} record(s) could not be synced.`);
929
- }
930
164
  });
931
- // ──────────────────────────────────────────────────────────────────────
932
- // grove cleanup stale
933
- // ──────────────────────────────────────────────────────────────────────
934
165
  program
935
166
  .command("cleanup")
936
- .argument("<target>", "stale")
937
- .description("List records that need human curation.")
938
- .option("--report", "produce a report (default behaviour in V1)")
939
- .option("--strict", "fail the run if any candidates need curation")
940
- .action(async (target, opts) => {
941
- if (target !== "stale") {
942
- console.error(`Unknown cleanup target: ${target}. Use "stale".`);
943
- process.exit(1);
944
- }
167
+ .description("Write a report of records that need human review.")
168
+ .option("--strict", "fail when review candidates exist")
169
+ .action(async (options) => {
945
170
  const { report, path } = await cleanupStale();
946
- console.log(`[cleanup stale] ${report.totalCandidates} candidate(s) → ${path}`);
947
- for (const c of report.candidates.slice(0, 10)) {
948
- console.log(` - ${c.slug} (${c.status}, ${c.stars}★)`);
171
+ console.log(`[cleanup] ${report.totalCandidates} candidate(s) → ${path}`);
172
+ for (const candidate of report.candidates.slice(0, 10)) {
173
+ console.log(` - ${candidate.slug} (${candidate.status}, ${candidate.stars}★)`);
949
174
  }
950
- if (opts.strict && report.totalCandidates > 0) {
175
+ if (options.strict && report.totalCandidates > 0)
951
176
  process.exitCode = 1;
952
- console.error(`[cleanup stale] --strict: ${report.totalCandidates} record(s) need human review.`);
953
- }
954
- });
955
- // ──────────────────────────────────────────────────────────────────────
956
- // grove workflows sync
957
- // ──────────────────────────────────────────────────────────────────────
958
- program
959
- .command("workflows")
960
- .argument("<action>", "sync")
961
- .description("Sync Grove workflow templates into the current project.")
962
- .option("--force", "overwrite existing workflow files")
963
- .option("-d, --deploy <provider>", `deploy provider for the build workflow + config files: ${DEPLOY_PROVIDERS.join(" | ")} (default: github-pages)`)
964
- .action(async (action, opts) => {
965
- if (action !== "sync") {
966
- console.error(`Unknown workflows action: ${action}. Use "sync".`);
967
- process.exit(1);
968
- }
969
- const config = await loadConfig();
970
- // config.integrations.github is the configured GitHub integration mode.
971
- // `false` → "none" (private); anything else → "public".
972
- const githubMode = config.integrations?.github === false || config.integrations?.github === undefined
973
- ? "none"
974
- : "public";
975
- // Validate the --deploy option. The previous implementation
976
- // silently fell back to "github-pages" for any value not in
977
- // DEPLOY_PROVIDERS — which is a footgun for scripted use: a
978
- // typo (e.g. `--deploy vercels`) would write a Pages deploy
979
- // workflow for a project the user explicitly targeted at
980
- // Vercel. We now fail loudly with the valid set, and default
981
- // to "github-pages" only when --deploy is omitted entirely
982
- // (commander leaves the field `undefined` for the no-flag
983
- // case). The default text moved to the help string above.
984
- const deploy = parseDeployProvider(opts.deploy);
985
- const root = process.cwd();
986
- // Make sure the directories exist. `ensureDir` returns a
987
- // promise; without `await`, the subsequent `writeFile` can race
988
- // the directory creation on cold start.
989
- await ensureDir(join(root, ".github", "workflows"));
990
- await ensureDir(join(root, ".github", "ISSUE_TEMPLATE"));
991
- const files = [
992
- { path: join(root, ".github", "workflows", "validate-data.yml"), content: workflowValidate() },
993
- { path: join(root, ".github", "workflows", "build.yml"), content: workflowBuild("astro", deploy) },
994
- ];
995
- // Provider-specific deploy workflow (vercel / netlify / cloudflare).
996
- // GitHub Pages deploys inline in build.yml; `none` writes nothing.
997
- if (deploy === "vercel" || deploy === "netlify" || deploy === "cloudflare") {
998
- files.push({
999
- path: join(root, ".github", "workflows", `deploy-${deploy}.yml`),
1000
- content: workflowDeploy(deploy),
1001
- });
1002
- }
1003
- // Provider-specific config files at the project root.
1004
- const projectName = config.site?.name ?? "Grove Directory";
1005
- for (const file of deployConfigFiles(deploy, projectName)) {
1006
- files.push({ path: join(root, file.path), content: file.content });
1007
- }
1008
- if (githubMode === "public") {
1009
- files.push({ path: join(root, ".github", "workflows", "sync-github-metadata.yml"), content: workflowSyncGithubMetadata() }, { path: join(root, ".github", "workflows", "sync-contributors.yml"), content: workflowSyncContributors() }, { path: join(root, ".github", "workflows", "cleanup-stale-records.yml"), content: workflowCleanupStaleRecords() }, { path: join(root, ".github", "workflows", "update-records.yml"), content: workflowUpdateRecords() }, { path: join(root, ".github", "ISSUE_TEMPLATE", "report-broken-record.md"), content: issueTemplateBrokenRecord() }, { path: join(root, ".github", "pull_request_template.md"), content: pullRequestTemplate() });
1010
- }
1011
- let written = 0;
1012
- let skipped = 0;
1013
- for (const f of files) {
1014
- if (!opts.force && (await existsLocal(f.path))) {
1015
- skipped++;
1016
- continue;
1017
- }
1018
- await writeFile(f.path, f.content, "utf8");
1019
- written++;
1020
- }
1021
- console.log(`[workflows sync] ${githubMode} mode, deploy=${deploy}: ${written} written, ${skipped} skipped` +
1022
- (opts.force ? " (--force)" : ""));
1023
- });
1024
- // ──────────────────────────────────────────────────────────────────────
1025
- // grove build / grove dev
1026
- // ──────────────────────────────────────────────────────────────────────
1027
- program
1028
- .command("build")
1029
- .description("Build the static site in the current project repo.")
1030
- .action(async () => {
1031
- const framework = await detectFramework();
1032
- const cmd = frameworkBuildCommand(framework);
1033
- await runExternal(cmd[0], cmd[1], { stdio: "inherit" });
1034
- });
1035
- program
1036
- .command("dev")
1037
- .description("Start the framework dev server in the current project repo.")
1038
- .action(async () => {
1039
- const framework = await detectFramework();
1040
- const cmd = frameworkDevCommand(framework);
1041
- await runExternal(cmd[0], cmd[1], { stdio: "inherit" });
1042
- });
1043
- // ──────────────────────────────────────────────────────────────────────
1044
- // Framework discovery
1045
- // ──────────────────────────────────────────────────────────────────────
1046
- async function detectFramework() {
1047
- try {
1048
- const pkg = JSON.parse(await readFile("package.json", "utf8"));
1049
- const all = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
1050
- if (all["@grove-dev/astro"])
1051
- return "astro";
1052
- }
1053
- catch {
1054
- /* ignore */
1055
- }
1056
- console.error("Could not detect a Grove framework in the current project.");
1057
- console.error("Install @grove-dev/astro first. (V1 supports Astro only.)");
1058
- process.exit(1);
1059
- }
1060
- function frameworkBuildCommand(fw) {
1061
- switch (fw) {
1062
- case "astro":
1063
- return ["pnpm", ["exec", "astro", "build"]];
1064
- }
1065
- }
1066
- function frameworkDevCommand(fw) {
1067
- switch (fw) {
1068
- case "astro":
1069
- return ["pnpm", ["exec", "astro", "dev"]];
1070
- }
1071
- }
1072
- function runExternal(bin, args, opts = {}) {
1073
- return new Promise((resolveP, rejectP) => {
1074
- const child = spawn(bin, args, {
1075
- stdio: opts.stdio ?? "inherit",
1076
- cwd: opts.cwd,
1077
- shell: process.platform === "win32",
1078
- });
1079
- child.on("exit", (code) => {
1080
- if (code === 0)
1081
- resolveP();
1082
- else
1083
- rejectP(new Error(`${bin} ${args.join(" ")} exited with code ${code}`));
1084
- });
1085
- });
1086
- }
1087
- async function existsLocal(path) {
1088
- try {
1089
- await access(path);
1090
- return true;
1091
- }
1092
- catch {
1093
- return false;
1094
- }
1095
- }
1096
- // parseDeployProvider and DEPLOY_PROVIDERS live in ./helpers.js
1097
- // so they can be unit-tested without booting the whole CLI
1098
- // program. Re-exported here for consumers that previously
1099
- // imported them from the index.
1100
- export { parseDeployProvider, DEPLOY_PROVIDERS };
1101
- // ──────────────────────────────────────────────────────────────────────
1102
- // Helper: project file templates
1103
- // ──────────────────────────────────────────────────────────────────────
1104
- /**
1105
- * Unwrap a clack prompt result, treating cancellation as a clean exit.
1106
- *
1107
- * Clack's `p.isCancel(x)` is the only blessed way to detect that the
1108
- * user pressed Ctrl-C / Escape on a prompt. The standard exit shape is
1109
- * - log the abort message via `p.cancel(...)`
1110
- * - terminate the process with exit 0 (clean exit, not an error)
1111
- *
1112
- * Seven call sites in this file used to inline that three-line dance.
1113
- * Centralising it here:
1114
- * 1. makes the abort behaviour auditable from one place,
1115
- * 2. lets the verifier grep for a single `process.exit(0)` and
1116
- * confirm there are no stragglers, and
1117
- * 3. makes future changes (e.g. switching the abort message to a
1118
- * localised string) a one-line edit.
1119
- *
1120
- * Callers should pass the raw `p.text(...)` / `p.select(...)` / etc.
1121
- * return value and a TypeScript type parameter so the narrowed return
1122
- * is correctly inferred. Example:
1123
- *
1124
- * const b = unwrapPrompt<Blueprint>(await p.select({ ... }));
1125
- */
1126
- function unwrapPrompt(value, message = "Aborted.") {
1127
- if (p.isCancel(value)) {
1128
- p.cancel(message);
1129
- process.exit(0);
1130
- }
1131
- return value;
1132
- }
1133
- async function resolveText(message, fallback, placeholder) {
1134
- // Build the options object conditionally so `placeholder` is
1135
- // omitted entirely (not set to `undefined`) — the CLI library's
1136
- // TextOptions has `placeholder: string` under
1137
- // exactOptionalPropertyTypes, so passing `undefined` is a type
1138
- // error.
1139
- const textOpts = {
1140
- message,
1141
- defaultValue: fallback,
1142
- ...(placeholder !== undefined ? { placeholder } : {}),
1143
- validate: (value) => {
1144
- if (!value || value.trim().length === 0)
1145
- return `${message} is required`;
1146
- return undefined;
1147
- },
1148
- };
1149
- const result = unwrapPrompt(await p.text(textOpts));
1150
- return result;
1151
- }
1152
- async function writeIfMissing(path, content) {
1153
- try {
1154
- await readFile(path, "utf8");
1155
- }
1156
- catch {
1157
- await mkdir(dirname(path), { recursive: true });
1158
- await writeFile(path, content, "utf8");
1159
- }
1160
- }
1161
- function projectConfig(projectName, blueprint, githubMode) {
1162
- const githubIntegrations = githubMode === "public"
1163
- ? `integrations: { github: { metadata: true, health: true } },`
1164
- : `integrations: { github: false },`;
1165
- return `import { defineConfig } from "@grove-dev/core";
1166
-
1167
- export default defineConfig({
1168
- blueprint: "${blueprint}",
1169
-
1170
- site: {
1171
- name: "${projectName}",
1172
- tagline: "A growing community knowledge site.",
1173
- },
1174
-
1175
- ${githubIntegrations}
1176
-
1177
- facets: ["category", "tags"],
1178
177
  });
1179
- `;
1180
- }
1181
- function projectReadme(projectName, blueprint, framework) {
1182
- return `# ${projectName}
1183
-
1184
- A growing community knowledge site built with [Grove](https://github.com/tortuvshin/grove).
1185
-
1186
- Blueprint: **${blueprint}** · Framework: **${framework}**
1187
-
1188
- ## What this is
1189
-
1190
- This repository is **data + branding + decisions**, not the framework.
1191
- The CLI and the renderer live in the \`grove\` repo; you consume them as
1192
- \`@grove-dev/core\`, \`@grove-dev/cli\`, and \`@grove-dev/${framework}\`.
1193
-
1194
- ## Workflow
1195
-
1196
- \`\`\`bash
1197
- grove import <awesome-list-url> # write data/records/*.yml
1198
- grove sync github # optional: enrich with GitHub metadata
1199
- grove cleanup stale # flag records that need human review
1200
- grove validate # check schemas, slugs, taxonomy
1201
- grove generate # build data/generated/records.{full,index}.json
1202
- grove sitemap # write public/sitemap.xml
1203
- grove llms # write public/llms.txt + llms-full.txt
1204
- grove build # run the framework's build command
1205
- \`\`\`
1206
-
1207
- ## Files
1208
-
1209
- - \`grove.config.ts\` — site name, blueprint, integrations, theme, paths.
1210
- - \`data/records/\` — per-record YAML (commit this).
1211
- - \`data/decisions.yml\` — human curation decisions.
1212
- - \`data/generated/\` — auto-generated JSON; do not commit.
1213
- - \`content/pages/\` — Markdown pages (\`about.md\`, \`methodology.md\`, ...).
1214
- - \`content/records/\` — optional Markdown body per record.
1215
- - \`public/\` — logo, OG image, and other static assets.
1216
- - \`.github/workflows/\` — validate + build + (optional) sync workflows.
1217
- `;
1218
- }
1219
- function gitignoreTemplate() {
1220
- return `node_modules/
1221
- dist/
1222
- .astro/
1223
- .next/
1224
- .svelte-kit/
1225
- .DS_Store
1226
- .env
1227
- .env.*
1228
- !.env.example
1229
- data/generated/
1230
- coverage/
1231
- .tmp-test/
1232
- .idea/
1233
- .vscode/
1234
- *.log
1235
- *.tsbuildinfo
1236
- `;
1237
- }
1238
- function workflowValidate() {
1239
- return `name: Validate data
1240
-
1241
- # Runs on every PR, every push to main, and on manual dispatch.
1242
- # No secrets required — safe for fork PRs.
1243
- on:
1244
- pull_request:
1245
- push:
1246
- branches:
1247
- - main
1248
- workflow_dispatch:
1249
-
1250
- permissions:
1251
- contents: read
1252
-
1253
- jobs:
1254
- validate:
1255
- runs-on: ubuntu-latest
1256
-
1257
- steps:
1258
- - name: Checkout
1259
- uses: actions/checkout@v4
1260
-
1261
- - name: Setup pnpm
1262
- uses: pnpm/action-setup@v4
1263
-
1264
- - name: Setup Node
1265
- uses: actions/setup-node@v4
1266
- with:
1267
- node-version: "20"
1268
- cache: pnpm
1269
-
1270
- - name: Install dependencies
1271
- run: pnpm install --frozen-lockfile
1272
-
1273
- - name: Validate Grove data
1274
- run: pnpm exec grove validate
1275
- `;
1276
- }
1277
- function workflowBuild(framework, deploy) {
1278
- // The project's "build" script in package.json already chains
1279
- // grove generate && grove sitemap && grove llms && <framework> build
1280
- // via the `grove` package's own build orchestration. Keep the workflow thin.
1281
- //
1282
- // For `github-pages` we add a deploy-pages step at the end so the
1283
- // build workflow is self-contained (the `pages: write` permission
1284
- // and the `actions/configure-pages` + `actions/deploy-pages` steps
1285
- // are the canonical Pages deploy path).
1286
- //
1287
- // For `vercel` / `netlify` / `cloudflare` we keep build.yml as a
1288
- // pure build + artifact upload; the provider-specific deploy lives
1289
- // in a separate `.github/workflows/deploy-<provider>.yml` workflow.
1290
- // For `none` we still upload the artifact so a user can manually
1291
- // download it, but skip the deploy step.
1292
- const isPages = deploy === "github-pages";
1293
- const pagesSteps = isPages
1294
- ? ` - name: Setup Pages
1295
- uses: actions/configure-pages@v5
1296
-
1297
- - name: Upload Pages artifact
1298
- uses: actions/upload-pages-artifact@v3
1299
- with:
1300
- path: ./dist
1301
-
1302
- - name: Deploy to GitHub Pages
1303
- id: deployment
1304
- uses: actions/deploy-pages@v4
1305
-
1306
- - name: Summary
1307
- if: success()
1308
- run: |
1309
- echo "✅ Deployed to \${{ steps.deployment.outputs.page_url }}"
1310
- `
1311
- : "";
1312
- const pagesPermissions = isPages
1313
- ? ` contents: read
1314
- pages: write
1315
- id-token: write
1316
- `
1317
- : ` contents: read
1318
- `;
1319
- return `name: Build site
1320
-
1321
- # Runs on every PR, every push to main, and on manual dispatch.
1322
- # No secrets required — safe for fork PRs.
1323
- on:
1324
- pull_request:
1325
- push:
1326
- branches:
1327
- - main
1328
- workflow_dispatch:
1329
-
1330
- permissions:
1331
- ${pagesPermissions}
1332
- jobs:
1333
- build:
1334
- runs-on: ubuntu-latest
1335
-
1336
- steps:
1337
- - name: Checkout
1338
- uses: actions/checkout@v4
1339
-
1340
- - name: Setup pnpm
1341
- uses: pnpm/action-setup@v4
1342
-
1343
- - name: Setup Node
1344
- uses: actions/setup-node@v4
1345
- with:
1346
- node-version: "20"
1347
- cache: pnpm
1348
- cache-dependency-path: "**/pnpm-lock.yaml"
1349
-
1350
- - name: Install dependencies
1351
- run: pnpm install --frozen-lockfile
1352
-
1353
- # \`build\` chains build:data + build:sitemap + build:llms + <framework> build.
1354
- # Site URL is overridden so sitemap/OG/canonical links resolve to
1355
- # the deployed URL rather than the placeholder in grove.config.ts.
1356
- - name: Build the site
1357
- env:
1358
- SITE_URL: \${{ vars.SITE_URL || github.pages.custom_domain || format('https://{0}.github.io/{1}', github.repository_owner, github.event.repository.name) }}
1359
- run: pnpm run build
1360
- ${pagesSteps}`;
1361
- }
1362
- /**
1363
- * Provider-specific deploy workflow. Triggered after a successful build
1364
- * to deploy the static site to the chosen provider via its CLI / API.
1365
- * Used for vercel / netlify / cloudflare (GitHub Pages deploys inline
1366
- * in build.yml, and `none` writes no deploy workflow at all).
1367
- */
1368
- function workflowDeploy(deploy) {
1369
- switch (deploy) {
1370
- case "vercel":
1371
- return `name: Deploy to Vercel
1372
-
1373
- # Runs after a successful build on main. Uses the Vercel CLI to deploy
1374
- # the built \`dist/\` directory. Requires a VERCEL_TOKEN secret (and
1375
- # optionally VERCEL_ORG_ID / VERCEL_PROJECT_ID for project linking).
1376
- on:
1377
- workflow_run:
1378
- workflows: ["Build site"]
1379
- types:
1380
- - completed
1381
- workflow_dispatch:
1382
-
1383
- permissions:
1384
- contents: read
1385
-
1386
- jobs:
1387
- deploy:
1388
- if: \${{ github.event.workflow_run.conclusion == 'success' }}
1389
- runs-on: ubuntu-latest
1390
-
1391
- steps:
1392
- - name: Checkout
1393
- uses: actions/checkout@v4
1394
-
1395
- - name: Setup pnpm
1396
- uses: pnpm/action-setup@v4
1397
-
1398
- - name: Setup Node
1399
- uses: actions/setup-node@v4
1400
- with:
1401
- node-version: "20"
1402
- cache: pnpm
1403
- cache-dependency-path: "**/pnpm-lock.yaml"
1404
-
1405
- - name: Install Vercel CLI
1406
- run: pnpm add -g vercel@latest
1407
-
1408
- - name: Pull Vercel project info
1409
- id: vercel
1410
- run: |
1411
- echo "PROJECT_ID=\${VERCEL_PROJECT_ID}" >> $GITHUB_OUTPUT
1412
- env:
1413
- VERCEL_TOKEN: \${{ secrets.VERCEL_TOKEN }}
1414
- VERCEL_ORG_ID: \${{ secrets.VERCEL_ORG_ID }}
1415
- VERCEL_PROJECT_ID: \${{ secrets.VERCEL_PROJECT_ID }}
1416
-
1417
- - name: Deploy to Vercel (production)
1418
- run: vercel deploy --prod --yes --token \$VERCEL_TOKEN
1419
- env:
1420
- VERCEL_TOKEN: \${{ secrets.VERCEL_TOKEN }}
1421
- `;
1422
- case "netlify":
1423
- return `name: Deploy to Netlify
1424
-
1425
- # Runs after a successful build on main. Uses the Netlify CLI to deploy
1426
- # the built \`dist/\` directory. Requires NETLIFY_AUTH_TOKEN and
1427
- # NETLIFY_SITE_ID secrets.
1428
- on:
1429
- workflow_run:
1430
- workflows: ["Build site"]
1431
- types:
1432
- - completed
1433
- workflow_dispatch:
1434
-
1435
- permissions:
1436
- contents: read
1437
-
1438
- jobs:
1439
- deploy:
1440
- if: \${{ github.event.workflow_run.conclusion == 'success' }}
1441
- runs-on: ubuntu-latest
1442
-
1443
- steps:
1444
- - name: Checkout
1445
- uses: actions/checkout@v4
1446
-
1447
- - name: Setup pnpm
1448
- uses: pnpm/action-setup@v4
1449
-
1450
- - name: Setup Node
1451
- uses: actions/setup-node@v4
1452
- with:
1453
- node-version: "20"
1454
- cache: pnpm
1455
- cache-dependency-path: "**/pnpm-lock.yaml"
1456
-
1457
- - name: Install Netlify CLI
1458
- run: pnpm add -g netlify-cli@latest
1459
-
1460
- - name: Deploy to Netlify (production)
1461
- run: netlify deploy --prod --dir=dist --message "Deploy from GitHub Actions"
1462
- env:
1463
- NETLIFY_AUTH_TOKEN: \${{ secrets.NETLIFY_AUTH_TOKEN }}
1464
- NETLIFY_SITE_ID: \${{ secrets.NETLIFY_SITE_ID }}
1465
- `;
1466
- case "cloudflare":
1467
- return `name: Deploy to Cloudflare Pages
1468
-
1469
- # Runs after a successful build on main. Uses wrangler to deploy the
1470
- # built \`dist/\` directory to Cloudflare Pages. Requires
1471
- # CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID secrets.
1472
- on:
1473
- workflow_run:
1474
- workflows: ["Build site"]
1475
- types:
1476
- - completed
1477
- workflow_dispatch:
1478
-
1479
- permissions:
1480
- contents: read
1481
-
1482
- jobs:
1483
- deploy:
1484
- if: \${{ github.event.workflow_run.conclusion == 'success' }}
1485
- runs-on: ubuntu-latest
1486
-
1487
- steps:
1488
- - name: Checkout
1489
- uses: actions/checkout@v4
1490
-
1491
- - name: Setup pnpm
1492
- uses: pnpm/action-setup@v4
1493
-
1494
- - name: Setup Node
1495
- uses: actions/setup-node@v4
1496
- with:
1497
- node-version: "20"
1498
- cache: pnpm
1499
- cache-dependency-path: "**/pnpm-lock.yaml"
1500
-
1501
- - name: Install wrangler
1502
- run: pnpm add -g wrangler@latest
1503
-
1504
- - name: Deploy to Cloudflare Pages
1505
- run: wrangler pages deploy dist --project-name ${"${{ github.event.repository.name }}"} --commit-dirty=true
1506
- env:
1507
- CLOUDFLARE_API_TOKEN: \${{ secrets.CLOUDFLARE_API_TOKEN }}
1508
- CLOUDFLARE_ACCOUNT_ID: \${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
1509
- `;
1510
- default:
1511
- // github-pages and none never reach this path; build.yml handles
1512
- // github-pages, and `none` writes no deploy workflow.
1513
- throw new Error(`workflowDeploy: unsupported deploy provider ${deploy}`);
1514
- }
1515
- }
1516
- /**
1517
- * Provider-specific config files written at the project root so the
1518
- * provider's CLI / build hook picks them up automatically. V1 only
1519
- * emits configs for vercel / netlify / cloudflare / github-pages.
1520
- * `none` emits nothing.
1521
- */
1522
- function deployConfigFiles(deploy, projectName) {
1523
- switch (deploy) {
1524
- case "vercel":
1525
- return [
1526
- {
1527
- path: "vercel.json",
1528
- content: `{
1529
- "$schema": "https://openapi.vercel.sh/vercel.json",
1530
- "buildCommand": "pnpm run build",
1531
- "outputDirectory": "dist",
1532
- "framework": null,
1533
- "cleanUrls": true,
1534
- "trailingSlash": false
1535
- }
1536
- `,
1537
- },
1538
- ];
1539
- case "netlify":
1540
- return [
1541
- {
1542
- path: "netlify.toml",
1543
- content: `# Netlify configuration for ${projectName}.
1544
- # Generated by \`grove new --deploy netlify\`. See https://docs.netlify.com/configure-netlify/file-based-configuration/
1545
-
1546
- [build]
1547
- command = "pnpm run build"
1548
- publish = "dist"
1549
-
1550
- [build.environment]
1551
- NODE_VERSION = "20"
1552
- PNPM_VERSION = "10"
1553
-
1554
- # Astro renders clean URLs out of the box; keep static asset caching
1555
- # aggressive but always revalidate HTML so a fresh deploy shows up.
1556
- [[headers]]
1557
- for = "/*"
1558
- [headers.values]
1559
- X-Content-Type-Options = "nosniff"
1560
- X-Frame-Options = "DENY"
1561
- Referrer-Policy = "strict-origin-when-cross-origin"
1562
-
1563
- [[headers]]
1564
- for = "/assets/*"
1565
- [headers.values]
1566
- Cache-Control = "public, max-age=31536000, immutable"
1567
- `,
1568
- },
1569
- ];
1570
- case "cloudflare":
1571
- return [
1572
- {
1573
- path: "wrangler.jsonc",
1574
- content: `// Cloudflare Pages configuration for ${projectName}.
1575
- // Generated by \`grove new --deploy cloudflare\`. See https://developers.cloudflare.com/pages/functions/wrangler-configuration/
1576
- {
1577
- "name": "${slugifyProjectName(projectName)}",
1578
- "compatibility_date": "${new Date().toISOString().slice(0, 10)}",
1579
- "pages_build_output_dir": "./dist",
1580
- "observability": {
1581
- "enabled": true
1582
- }
1583
- }
1584
- `,
1585
- },
1586
- ];
1587
- case "github-pages":
1588
- // GitHub Pages uses repo-level Pages settings; no config file.
1589
- return [];
1590
- case "none":
1591
- return [];
1592
- }
1593
- }
1594
- function slugifyProjectName(name) {
1595
- return name
1596
- .toLowerCase()
1597
- .replace(/[^a-z0-9-]+/g, "-")
1598
- .replace(/^-+|-+$/g, "") || "grove-site";
1599
- }
1600
- function issueTemplateSubmission(blueprint) {
1601
- const labelHint = blueprint === "project-directory"
1602
- ? `- **Repository URL** (required):
1603
- - **Name**:
1604
- - **One-line description** (≤ 120 chars):
1605
- - **Category** (e.g. tools, libraries, frameworks):`
1606
- : blueprint === "resource-hub"
1607
- ? `- **Resource URL** (required):
1608
- - **Title**:
1609
- - **Type** (guide | comparison | link | explainer | other):
1610
- - **Topic**:`
1611
- : `- **Name**:
1612
- - **Type** (company | organization | community | school | ...):
1613
- - **Category**:
1614
- - **Website URL**:`;
1615
- return `---
1616
- name: Submit a record
1617
- about: Suggest a new record to add to this Grove site
1618
- title: "[Submit] "
1619
- labels: submission
1620
- ---
1621
-
1622
- ${labelHint}
1623
-
1624
- ## Why include it?
1625
-
1626
- A few sentences on what makes this record worth listing.
1627
- `;
1628
- }
1629
- function workflowSyncGithubMetadata() {
1630
- return `name: Sync GitHub metadata
1631
-
1632
- # Refreshes GitHub repository metadata (stars, forks, last commit, license, …)
1633
- # for records that link to public GitHub repos. Runs nightly and on demand.
1634
- # Uses GROVE_GITHUB_TOKEN if set, else falls back to GITHUB_TOKEN.
1635
- #
1636
- # This workflow DOES mutate data/records/*.yml: 'grove sync github' writes
1637
- # a 'github.repository' block back into the owning record file. The PR
1638
- # below is the human review point for that diff.
1639
- on:
1640
- schedule:
1641
- - cron: "0 2 * * *"
1642
- workflow_dispatch:
1643
-
1644
- permissions:
1645
- contents: write
1646
- pull-requests: write
1647
-
1648
- jobs:
1649
- sync:
1650
- runs-on: ubuntu-latest
1651
-
1652
- steps:
1653
- - name: Checkout
1654
- uses: actions/checkout@v4
1655
-
1656
- - name: Setup pnpm
1657
- uses: pnpm/action-setup@v4
1658
-
1659
- - name: Setup Node
1660
- uses: actions/setup-node@v4
1661
- with:
1662
- node-version: "20"
1663
- cache: pnpm
1664
- cache-dependency-path: "**/pnpm-lock.yaml"
1665
-
1666
- - name: Install dependencies
1667
- run: pnpm install --frozen-lockfile
1668
-
1669
- - name: Sync GitHub metadata
1670
- run: pnpm exec grove sync github
1671
- env:
1672
- GITHUB_TOKEN: \${{ secrets.GROVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
1673
-
1674
- - name: Regenerate Grove data
1675
- run: pnpm exec grove generate
1676
-
1677
- - name: Open PR with metadata refresh
1678
- uses: peter-evans/create-pull-request@v6
1679
- with:
1680
- branch: chore/grove-sync-github-metadata
1681
- title: "chore: sync GitHub metadata"
1682
- commit-message: "chore: sync GitHub metadata"
1683
- body: |
1684
- Automated metadata refresh by Grove.
1685
-
1686
- - Updated GitHub stars, forks, last commit, license, etc.
1687
- - Each touched record YAML now carries a \`github.sync\` block
1688
- with the \`syncedAt\` timestamp and the \`source\` ("api" or
1689
- "html" fallback).
1690
- - Triggered by: \${{ github.event_name }}
1691
- add-paths: |
1692
- data/records/*.yml
1693
- data/generated/*.json
1694
- `;
1695
- }
1696
- function workflowSyncContributors() {
1697
- return `name: Sync contributors
1698
-
1699
- # Refreshes contributor data (avatars, recent activity, top contributors)
1700
- # for records that have a public GitHub repository. Runs weekly and on demand.
1701
- # Uses GROVE_GITHUB_TOKEN if set, else falls back to GITHUB_TOKEN.
1702
- on:
1703
- schedule:
1704
- - cron: "0 3 * * 1"
1705
- workflow_dispatch:
1706
-
1707
- permissions:
1708
- contents: write
1709
- pull-requests: write
1710
-
1711
- jobs:
1712
- sync:
1713
- runs-on: ubuntu-latest
1714
-
1715
- steps:
1716
- - name: Checkout
1717
- uses: actions/checkout@v4
1718
-
1719
- - name: Setup pnpm
1720
- uses: pnpm/action-setup@v4
1721
-
1722
- - name: Setup Node
1723
- uses: actions/setup-node@v4
1724
- with:
1725
- node-version: "20"
1726
- cache: pnpm
1727
- cache-dependency-path: "**/pnpm-lock.yaml"
1728
-
1729
- - name: Install dependencies
1730
- run: pnpm install --frozen-lockfile
1731
-
1732
- - name: Sync contributors
1733
- run: pnpm exec grove sync contributors
1734
- env:
1735
- GITHUB_TOKEN: \${{ secrets.GROVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
1736
-
1737
- - name: Open PR with contributor refresh
1738
- uses: peter-evans/create-pull-request@v6
1739
- with:
1740
- branch: chore/grove-sync-contributors
1741
- title: "chore: sync contributors"
1742
- commit-message: "chore: sync contributors"
1743
- body: |
1744
- Automated contributor refresh by Grove.
1745
-
1746
- - Updated contributor lists, avatars, and recent activity.
1747
- - Triggered by: \${{ github.event_name }}
1748
- add-paths: |
1749
- data/generated/contributors.json
1750
- .grove/cache/contributors.json
1751
- `;
1752
- }
1753
- function workflowCleanupStaleRecords() {
1754
- return `name: Cleanup stale records
1755
-
1756
- # Reports records that may be outdated, archived, or no longer useful.
1757
- # V1 behaviour is REPORT-ONLY — does not delete records. Use --strict in
1758
- # the CLI to fail the run if any candidates are flagged.
1759
- on:
1760
- schedule:
1761
- - cron: "0 4 * * 0"
1762
- workflow_dispatch:
1763
-
1764
- permissions:
1765
- contents: write
1766
- pull-requests: write
1767
- issues: write
1768
-
1769
- jobs:
1770
- cleanup:
1771
- runs-on: ubuntu-latest
1772
-
1773
- steps:
1774
- - name: Checkout
1775
- uses: actions/checkout@v4
1776
-
1777
- - name: Setup pnpm
1778
- uses: pnpm/action-setup@v4
1779
-
1780
- - name: Setup Node
1781
- uses: actions/setup-node@v4
1782
- with:
1783
- node-version: "20"
1784
- cache: pnpm
1785
- cache-dependency-path: "**/pnpm-lock.yaml"
1786
-
1787
- - name: Install dependencies
1788
- run: pnpm install --frozen-lockfile
1789
-
1790
- - name: Generate stale-record report
1791
- run: pnpm exec grove cleanup stale
1792
- env:
1793
- GITHUB_TOKEN: \${{ secrets.GROVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
1794
-
1795
- - name: Open PR with stale-record report
1796
- uses: peter-evans/create-pull-request@v6
1797
- with:
1798
- branch: chore/grove-stale-record-report
1799
- title: "chore: update stale record report"
1800
- commit-message: "chore: update stale record report"
1801
- body: |
1802
- Automated stale record report by Grove.
1803
-
1804
- - Records flagged for human review (archived, inactive, broken links, …).
1805
- - Triggered by: \${{ github.event_name }}
1806
- add-paths: |
1807
- data/generated/stale-records.json
1808
- docs/generated/stale-records.md
1809
- `;
1810
- }
1811
- function workflowUpdateRecords() {
1812
- return `name: Update Grove records
1813
-
1814
- # Full maintenance cycle: validate + sync GitHub metadata + sync contributors
1815
- # + cleanup stale records + regenerate. Run on demand, or weekly if your
1816
- # project needs hands-off maintenance.
1817
- on:
1818
- workflow_dispatch:
1819
- schedule:
1820
- - cron: "0 5 * * 1"
1821
-
1822
- permissions:
1823
- contents: write
1824
- pull-requests: write
1825
- issues: write
1826
-
1827
- jobs:
1828
- update:
1829
- runs-on: ubuntu-latest
1830
-
1831
- steps:
1832
- - name: Checkout
1833
- uses: actions/checkout@v4
1834
-
1835
- - name: Setup pnpm
1836
- uses: pnpm/action-setup@v4
1837
-
1838
- - name: Setup Node
1839
- uses: actions/setup-node@v4
1840
- with:
1841
- node-version: "20"
1842
- cache: pnpm
1843
- cache-dependency-path: "**/pnpm-lock.yaml"
1844
-
1845
- - name: Install dependencies
1846
- run: pnpm install --frozen-lockfile
1847
-
1848
- - name: Validate records
1849
- run: pnpm exec grove validate
1850
-
1851
- - name: Sync GitHub metadata
1852
- run: pnpm exec grove sync github
1853
- env:
1854
- GITHUB_TOKEN: \${{ secrets.GROVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
1855
-
1856
- - name: Sync contributors
1857
- run: pnpm exec grove sync contributors
1858
- env:
1859
- GITHUB_TOKEN: \${{ secrets.GROVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
1860
-
1861
- - name: Cleanup stale records
1862
- run: pnpm exec grove cleanup stale
1863
- env:
1864
- GITHUB_TOKEN: \${{ secrets.GROVE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
1865
-
1866
- - name: Regenerate
1867
- run: pnpm exec grove generate
1868
-
1869
- - name: Open PR with maintenance update
1870
- uses: peter-evans/create-pull-request@v6
1871
- with:
1872
- branch: chore/grove-update-records
1873
- title: "chore: update Grove records"
1874
- commit-message: "chore: update Grove records"
1875
- body: |
1876
- Automated Grove maintenance update.
1877
-
1878
- - Validated records
1879
- - Synced GitHub metadata
1880
- - Synced contributors
1881
- - Flagged stale records (report only)
1882
- - Regenerated indexes
1883
-
1884
- Triggered by: \${{ github.event_name }}
1885
- `;
1886
- }
1887
- function issueTemplateBrokenRecord() {
1888
- return `---
1889
- name: Report broken record
1890
- about: Report a broken link, dead project, wrong category, or duplicate record
1891
- title: "[Broken] "
1892
- labels: broken-record
1893
- ---
1894
-
1895
- ## Which record is broken?
1896
-
1897
- Record slug (e.g. \`zod\`) or full URL of the record page:
1898
-
1899
- ## What is wrong?
1900
-
1901
- - [ ] Broken link (404, dead site, repo not found)
1902
- - [ ] Dead / abandoned / archived project
1903
- - [ ] Wrong category or tags
1904
- - [ ] Duplicate of an existing record
1905
- - [ ] Security concern
1906
- - [ ] Outdated metadata (stars, last commit, etc.)
1907
- - [ ] Incorrect description
1908
- - [ ] Other (describe below)
1909
-
1910
- ## Details
1911
-
1912
- A short description of the issue, with evidence if possible (link to a working
1913
- alternative, archive.org snapshot, or commit history).
1914
-
1915
- ## Suggested fix (optional)
1916
-
1917
- If you know what should change, describe it here.
1918
- `;
1919
- }
1920
- function pullRequestTemplate() {
1921
- return `## What did you add or change?
1922
-
1923
- <!-- A short summary of your change. -->
1924
-
1925
- ## Is this a new record?
1926
-
1927
- - [ ] Yes — adds a new record under \`data/records/\`
1928
- - [ ] No — updates an existing record, fixes a bug, or changes infrastructure
1929
-
1930
- ## Checklist
1931
-
1932
- - [ ] I added or updated records under \`data/records/\`
1933
- - [ ] The record has a clear, accurate description
1934
- - [ ] The category and tags are appropriate
1935
- - [ ] I ran \`pnpm exec grove validate\` and it passed
1936
- - [ ] I did not add generated files manually unless required
1937
- - [ ] I included the official / source link where available
1938
- - [ ] This PR is safe to publish (no private or sensitive data)
1939
- `;
1940
- }
1941
- function issueTemplateBug() {
1942
- return `---
1943
- name: Bug report
1944
- about: Something is broken or wrong
1945
- title: "[Bug] "
1946
- labels: bug
1947
- ---
1948
-
1949
- ## What happened
1950
-
1951
- A clear description of the bug.
1952
-
1953
- ## How to reproduce
1954
-
1955
- Steps to reproduce the behaviour.
1956
-
1957
- ## Expected
1958
-
1959
- What you expected to happen.
1960
- `;
1961
- }
1962
- function issueTemplateFeature() {
1963
- return `---
1964
- name: Feature request
1965
- about: Suggest a new feature
1966
- title: "[Feature] "
1967
- labels: enhancement
1968
- ---
1969
-
1970
- ## What
1971
-
1972
- A clear description of the feature.
1973
-
1974
- ## Why
1975
-
1976
- What problem does this solve?
1977
- `;
1978
- }
1979
- function licenseMIT(projectName) {
1980
- const year = new Date().getFullYear();
1981
- return `MIT License
1982
-
1983
- Copyright (c) ${year} ${projectName}
1984
-
1985
- Permission is hereby granted, free of charge, to any person obtaining a copy
1986
- of this software and associated documentation files (the "Software"), to deal
1987
- in the Software without restriction, including without limitation the rights
1988
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1989
- copies of the Software, and to permit persons to whom the Software is
1990
- furnished to do so, subject to the following conditions:
1991
-
1992
- The above copyright notice and this permission notice shall be included in all
1993
- copies or substantial portions of the Software.
1994
-
1995
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1996
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1997
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1998
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1999
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2000
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2001
- SOFTWARE.
2002
- `;
2003
- }
2004
178
  program.parseAsync().catch((error) => {
2005
- // Prefer the full stack trace so the user can see where in their
2006
- // .ts file the throw originated. `error.stack` is always present
2007
- // for Error subclasses; `error.message` is the fallback when
2008
- // something non-Error was thrown (e.g. a bare string).
2009
- if (error instanceof Error && error.stack) {
2010
- console.error(error.stack);
2011
- }
2012
- else if (error instanceof Error) {
2013
- console.error(error.message);
2014
- }
2015
- else {
2016
- console.error(String(error));
2017
- }
2018
- process.exit(1);
179
+ console.error(error instanceof Error ? error.message : String(error));
180
+ process.exitCode = 1;
2019
181
  });
2020
182
  //# sourceMappingURL=index.js.map