@grove-dev/cli 0.2.10 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5,6 +5,8 @@
5
5
  *
6
6
  * V1 command surface:
7
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.
8
10
  * grove import <src> turn an awesome list into records/*.yml
9
11
  * grove validate check records, taxonomy, health, decisions
10
12
  * grove generate build data/generated/records.{full,index}.json
@@ -20,11 +22,12 @@ import { spawn } from "node:child_process";
20
22
  import { mkdir, readFile, writeFile, access } from "node:fs/promises";
21
23
  import { createRequire } from "node:module";
22
24
  import { dirname, join, resolve } from "node:path";
25
+ import { fileURLToPath } from "node:url";
23
26
  import { Command } from "commander";
24
27
  import * as p from "@clack/prompts";
25
28
  import { cleanupStale, enrichFromGithubHtml, fetchGithubMetadata, generate, blueprintKind, importAwesomeList, loadConfig, parseGithubRepoUrl, stringifyRecordYaml, validateProject, } from "@grove-dev/core";
26
29
  import { parse as parseYaml } from "yaml";
27
- import { copyTemplate, ensureDir, isFramework, listTemplates, renameProjectInTemplate, SUPPORTED_FRAMEWORKS, } from "./template-loader.js";
30
+ import { copyTemplate, ensureDir, findMonorepoRoot, isFramework, listTemplates, packageNameFromProjectName, renameProjectInTemplate, SUPPORTED_FRAMEWORKS, } from "./template-loader.js";
28
31
  /**
29
32
  * Resolve the CLI's own version. After `tsc` builds, the build script
30
33
  * copies `package.json` next to `index.js` so production usage can read
@@ -64,8 +67,6 @@ const DEPLOY_LABELS = {
64
67
  };
65
68
  const FRAMEWORK_LABELS = {
66
69
  astro: { label: "Astro", hint: "Static-first, great for content sites (V1 supported)" },
67
- nextjs: { label: "Next.js", hint: "Roadmap only — not in V1" },
68
- svelte: { label: "SvelteKit", hint: "Roadmap only — not in V1" },
69
70
  };
70
71
  const BLUEPRINT_LABELS = {
71
72
  "project-directory": { label: "project-directory", hint: "Structured projects/tools/apps" },
@@ -84,7 +85,7 @@ program
84
85
  .argument("[name]", "project directory name (current dir if omitted)")
85
86
  .description("Scaffold a new Grove project from a framework template.")
86
87
  .option("-b, --blueprint <name>", "blueprint: project-directory | resource-hub | ecosystem-map")
87
- .option("-f, --framework <name>", "framework: astro | nextjs | svelte (V1: astro)")
88
+ .option("-f, --framework <name>", "framework: astro (V1: astro only — nextjs/svelte roadmap)")
88
89
  .option("-t, --template <name>", "template name", "default")
89
90
  .option("-d, --deploy <provider>", `deploy provider: ${DEPLOY_PROVIDERS.join(" | ")}`)
90
91
  .option("-g, --github <mode>", "GitHub workflow mode: none | public (V1: none=private, public=community)")
@@ -180,7 +181,7 @@ program
180
181
  }
181
182
  else {
182
183
  const f = await p.select({
183
- message: "Pick a framework (V1 only supports astro)",
184
+ message: "Pick a framework (V1: astro only — nextjs/svelte land in v0.3.0)",
184
185
  options: SUPPORTED_FRAMEWORKS.map((f) => ({
185
186
  value: f,
186
187
  label: FRAMEWORK_LABELS[f].label,
@@ -278,7 +279,24 @@ program
278
279
  await writeIfMissing(join(root, "content", "methodology.md"), "# Methodology\n\nGrove uses repository metadata as a signal. Human curation decisions control final visibility.\n");
279
280
  // Always-on workflows (safe for both private and public projects)
280
281
  await writeIfMissing(join(root, ".github", "workflows", "validate-data.yml"), workflowValidate());
281
- await writeIfMissing(join(root, ".github", "workflows", "build.yml"), workflowBuild(framework));
282
+ // The build workflow's deploy step depends on the chosen provider.
283
+ // For `github-pages` we keep the Pages deploy inline (the original
284
+ // V1 behaviour). For `vercel` / `netlify` / `cloudflare` / `none`
285
+ // we write a thin build workflow + a separate deploy workflow (or
286
+ // skip the deploy workflow entirely for `none`).
287
+ await writeIfMissing(join(root, ".github", "workflows", "build.yml"), workflowBuild(framework, deploy));
288
+ // Provider-specific config files (vercel.json, netlify.toml, wrangler.jsonc).
289
+ // These live at the project root and are picked up automatically by
290
+ // the provider's CLI / build hook.
291
+ for (const file of deployConfigFiles(deploy, projectName)) {
292
+ await writeIfMissing(join(root, file.path), file.content);
293
+ }
294
+ // For vercel / netlify / cloudflare we also write a GitHub Actions
295
+ // workflow that triggers the provider's deploy on push to main.
296
+ // (`github-pages` deploys inline in build.yml; `none` skips this.)
297
+ if (deploy === "vercel" || deploy === "netlify" || deploy === "cloudflare") {
298
+ await writeIfMissing(join(root, ".github", "workflows", `deploy-${deploy}.yml`), workflowDeploy(deploy));
299
+ }
282
300
  // Issue templates — both modes support a basic set
283
301
  await writeIfMissing(join(root, ".github", "ISSUE_TEMPLATE", "record_submission.md"), issueTemplateSubmission(blueprint));
284
302
  await writeIfMissing(join(root, ".github", "ISSUE_TEMPLATE", "bug_report.md"), issueTemplateBug());
@@ -318,9 +336,13 @@ program
318
336
  const ghLabel = githubMode === "public"
319
337
  ? "public GitHub metadata (sync + cleanup + update workflows)"
320
338
  : "none / private (only validate + build workflows)";
339
+ const deployLabel = deploy === "none"
340
+ ? "none (no deploy workflow written)"
341
+ : `${deploy} workflow + config written`;
321
342
  p.outro(`🌳 ${projectName} is ready at ${root}\n\n` +
322
343
  `Blueprint: ${blueprint}\n` +
323
- `GitHub mode: ${ghLabel}\n\n` +
344
+ `GitHub mode: ${ghLabel}\n` +
345
+ `Deploy: ${deployLabel}\n\n` +
324
346
  `Next steps:\n` +
325
347
  ` cd ${projectDir}\n` +
326
348
  ` grove validate\n` +
@@ -328,6 +350,230 @@ program
328
350
  ` grove build\n`);
329
351
  });
330
352
  // ──────────────────────────────────────────────────────────────────────
353
+ // grove run — dev-only "pretend user" smoke test
354
+ // ──────────────────────────────────────────────────────────────────────
355
+ //
356
+ // `grove new` is the production path: it copies the framework template
357
+ // into a fresh dir, keeps its published Grove package versions, and
358
+ // (optionally) installs + inits git.
359
+ //
360
+ // `grove run` is the dev / CI-internal path. It does almost the same
361
+ // scaffolding, but with two differences that make it useful when
362
+ // iterating on the monorepo:
363
+ //
364
+ // 1. Grove dependencies in the scaffolded `package.json` are
365
+ // rewritten to direct local links, so package changes are picked
366
+ // up by the next `grove run` without a publish step.
367
+ //
368
+ // 2. The scaffold lives INSIDE the monorepo, under
369
+ // `<monorepo-root>/.grove/run/<timestamp>/`. `.grove/*` is
370
+ // registered in `pnpm-workspace.yaml`, so root-level tooling can
371
+ // discover and operate on the generated project.
372
+ //
373
+ // After scaffolding and (optionally) installing, `grove run` can launch
374
+ // the framework dev server in-process. That makes end-to-end smoke
375
+ // tests a one-liner:
376
+ //
377
+ // grove run dev # scaffold → install → astro dev
378
+ // grove run build # scaffold → install → astro build
379
+ // grove run init --no-install # just scaffold, fix deps manually
380
+ //
381
+ // V1 only supports `astro` because that's the only framework with a
382
+ // real template + peer wiring. `nextjs` and `svelte` are not exposed as
383
+ // scaffold options in V1 — they exist as skeleton packages but their
384
+ // templates have no real pages / components / layouts.
385
+ program
386
+ .command("run")
387
+ .argument("[action]", "run action: dev (default) | build | init", "dev")
388
+ .argument("[name]", "project directory name (default: grove-run-<timestamp>)")
389
+ .description("Scaffold a Grove project from the LOCAL workspace template and run it.")
390
+ .option("-f, --framework <name>", "framework: astro (V1: astro only — nextjs/svelte roadmap)", "astro")
391
+ .option("-t, --template <name>", "template name", "default")
392
+ .option("-d, --dir <name>", "project directory name (overrides positional name; relative to monorepo root)")
393
+ .option("--no-install", "skip `pnpm install` after scaffolding")
394
+ .option("--no-git", "skip `git init` after scaffolding")
395
+ .option("--port <port>", "dev server port (only used by `dev` action; passed to astro dev)", (value) => Number(value))
396
+ .action(async (action, name, opts) => {
397
+ // ── Validate action ────────────────────────────────────────────
398
+ const validActions = ["dev", "build", "init"];
399
+ if (!validActions.includes(action)) {
400
+ p.log.error(`Unknown run action: ${action}.`);
401
+ p.log.info(`Try one of: ${validActions.join(", ")}`);
402
+ process.exit(1);
403
+ }
404
+ const runAction = action;
405
+ // ── Validate framework ─────────────────────────────────────────
406
+ if (!isFramework(opts.framework)) {
407
+ p.log.error(`Unknown framework: ${opts.framework}.`);
408
+ p.log.info(`Try one of: ${SUPPORTED_FRAMEWORKS.join(", ")}`);
409
+ process.exit(1);
410
+ }
411
+ const framework = opts.framework;
412
+ if (framework !== "astro") {
413
+ // V1 only supports astro. The CLI rejects other frameworks at
414
+ // the `--framework` boundary in `grove new`; `grove run` keeps
415
+ // the same restriction by virtue of the `Framework` union
416
+ // (see template-loader.ts). This branch is therefore
417
+ // unreachable in V1; kept as a safety net for any future
418
+ // framework that slips past the type guard.
419
+ p.log.warn(`Framework "${framework}" is not supported in V1. Only astro is wired up — proceeding anyway and hoping for the best.`);
420
+ }
421
+ p.intro(`🧪 Grove run — ${runAction}`);
422
+ // ── Locate the monorepo root ───────────────────────────────────
423
+ // We need the monorepo root so we can:
424
+ // (a) decide where to put the scaffolded project (always
425
+ // inside the monorepo, under `.grove/run/<stamp>/`)
426
+ // (b) run `pnpm install --filter` from there, so the
427
+ // workspace protocol resolves `packages/*` siblings.
428
+ const cliLocation = dirname(fileURLToPath(import.meta.url));
429
+ let monorepoRoot;
430
+ try {
431
+ monorepoRoot = findMonorepoRoot(cliLocation);
432
+ }
433
+ catch (err) {
434
+ p.log.error(err.message);
435
+ process.exit(1);
436
+ }
437
+ p.log.info(`Monorepo root: ${monorepoRoot}`);
438
+ // ── Resolve target directory ───────────────────────────────────
439
+ const stamp = new Date()
440
+ .toISOString()
441
+ .replace(/[-:]/g, "")
442
+ .replace(/\..+$/, "")
443
+ .replace("T", "-");
444
+ const dirRel = opts.dir ?? name ?? `grove-run-${stamp}`;
445
+ // Always live under <monorepo-root>/.grove/run/<name>/ so the
446
+ // workspace picks it up via the `.grove/*` glob in
447
+ // `pnpm-workspace.yaml`.
448
+ const root = resolve(monorepoRoot, ".grove", "run", dirRel);
449
+ // The dir name and the package.json `name` are not the same —
450
+ // `renameProjectInTemplatePreserveDeps` slugifies the dir name
451
+ // and appends `-<framework>-<template>`. We need the package
452
+ // name to drive `pnpm --filter`, so compute it once and reuse.
453
+ const projectName = root.split("/").filter(Boolean).pop() ?? dirRel;
454
+ // ── Look up the LOCAL template via @grove-dev/<framework>'s
455
+ // `templates/<name>` directory. Inside this monorepo, that
456
+ // is a symlink straight to packages/astro/templates/default/,
457
+ // so a template change in the source tree flows through to
458
+ // the scaffolded project with no publish step. ─────────────
459
+ const templates = await listTemplates(framework);
460
+ const tpl = templates.find((t) => t.template === opts.template) ?? templates[0];
461
+ if (!tpl) {
462
+ p.log.error(`No templates found for ${framework}.`);
463
+ process.exit(1);
464
+ }
465
+ p.log.info(`Template: ${tpl.path}`);
466
+ const packageName = packageNameFromProjectName(projectName, framework, tpl.template);
467
+ p.log.info(`Project: ${projectName} (package: ${packageName}) → ${root}`);
468
+ // ── Scaffold (or reuse an existing scaffold) ──────────────────
469
+ // If the target dir already contains a package.json whose
470
+ // name matches what we would have written, treat it as a
471
+ // re-run of `grove run dev` against an already-initialised
472
+ // project and skip the copy. That makes iterative development
473
+ // a one-line affair: edit template, run `grove run dev` again.
474
+ const sentinel = join(root, "package.json");
475
+ let alreadyScaffolded = false;
476
+ try {
477
+ const existing = JSON.parse(await readFile(sentinel, "utf8"));
478
+ const expectedName = packageNameFromProjectName(projectName, framework, tpl.template);
479
+ alreadyScaffolded = existing.name === expectedName;
480
+ }
481
+ catch {
482
+ alreadyScaffolded = false;
483
+ }
484
+ const s = p.spinner();
485
+ if (alreadyScaffolded) {
486
+ s.start("Reusing existing scaffold");
487
+ s.stop("Reusing existing scaffold");
488
+ }
489
+ else {
490
+ s.start("Scaffolding");
491
+ await mkdir(root, { recursive: true });
492
+ await copyTemplate(framework, root, tpl.template);
493
+ // Use local package paths for the dev-only run path. Installing
494
+ // the generated project as a standalone package avoids pnpm's
495
+ // workspace discovery cache when a project appears mid-command.
496
+ await renameProjectInTemplate(framework, root, projectName, tpl.template, { mode: "file" });
497
+ s.stop("Scaffolded (local package deps)");
498
+ }
499
+ // ── git init ───────────────────────────────────────────────────
500
+ if (opts.git !== false) {
501
+ try {
502
+ await runExternal("git", ["init", "-b", "main"], { stdio: "ignore", cwd: root });
503
+ p.log.step("Initialized git repo on `main`");
504
+ }
505
+ catch {
506
+ p.log.warn("git not found — skipping git init");
507
+ }
508
+ }
509
+ // ── pnpm install (from monorepo root, scoped to this project) ──
510
+ if (opts.install !== false) {
511
+ const installSpinner = p.spinner();
512
+ installSpinner.start("Installing dependencies");
513
+ try {
514
+ await runExternal("pnpm", ["install", "--ignore-workspace"], {
515
+ stdio: "ignore",
516
+ cwd: root,
517
+ });
518
+ installSpinner.stop("Installed dependencies");
519
+ }
520
+ catch {
521
+ installSpinner.stop("Install failed");
522
+ p.log.warn(`Run \`pnpm install --ignore-workspace\` from ${root} to retry.`);
523
+ if (runAction !== "init") {
524
+ p.log.error("Cannot continue without a working install.");
525
+ process.exit(1);
526
+ }
527
+ }
528
+ }
529
+ // ── Run the requested action ───────────────────────────────────
530
+ if (runAction === "init") {
531
+ p.outro(`🌳 Scaffolded at ${root}\n\n` +
532
+ `Next steps:\n` +
533
+ ` cd ${root}\n` +
534
+ ` pnpm dev\n`);
535
+ return;
536
+ }
537
+ if (runAction === "build") {
538
+ // Run the template's `build` script, not `astro build` directly.
539
+ // The script chains `build:data` + `build:sitemap` + `build:llms`
540
+ // + `astro build` so the data is generated first. Skipping that
541
+ // chain gives you a half-built site with no records.
542
+ p.log.step(`Building ${packageName} via 'pnpm run build' (this can take a while)…`);
543
+ await runExternal("pnpm", ["--filter", packageName, "run", "build"], {
544
+ stdio: "inherit",
545
+ cwd: monorepoRoot,
546
+ });
547
+ p.outro(`🌳 Build done at ${root}`);
548
+ return;
549
+ }
550
+ // runAction === "dev" — start the dev server in-process.
551
+ //
552
+ // The template's `dev` script chains `build:data && astro dev`,
553
+ // which is what we want for a production user. But for a dev
554
+ // smoke test, the script's `&&` makes pnpm's `--` forwarding
555
+ // land in a tricky place: `pnpm run dev -- --port 4327` becomes
556
+ // `astro dev -- --port 4327`, where Astro treats `--port 4327`
557
+ // as positional args (port flag ignored).
558
+ //
559
+ // Cleanest workaround: run `build:data` separately (the only
560
+ // pre-step `dev` does), then `pnpm exec astro dev` directly with
561
+ // the port flag in the right place. Two `runExternal` calls is
562
+ // fine — they're both fast (`build:data` is a quick
563
+ // `grove generate`, and `astro dev` is what the user actually
564
+ // wants to see).
565
+ const port = typeof opts.port === "number" ? opts.port : 4321;
566
+ p.log.step(`Generating data via 'pnpm run build:data'…`);
567
+ try {
568
+ await runExternal("pnpm", ["--filter", packageName, "run", "build:data"], { stdio: "inherit", cwd: monorepoRoot });
569
+ }
570
+ catch {
571
+ p.log.warn(`build:data failed — starting astro dev anyway, site will be empty.`);
572
+ }
573
+ p.log.step(`Starting astro dev on port ${port} (Ctrl-C to stop)…`);
574
+ await runExternal("pnpm", ["--filter", packageName, "exec", "astro", "dev", "--port", String(port)], { stdio: "inherit", cwd: monorepoRoot });
575
+ });
576
+ // ──────────────────────────────────────────────────────────────────────
331
577
  // grove import
332
578
  // ──────────────────────────────────────────────────────────────────────
333
579
  program
@@ -485,7 +731,16 @@ program
485
731
  process.exit(1);
486
732
  }
487
733
  if (target === "contributors") {
488
- console.log("[sync contributors] contributor sync is not yet implemented in V1.");
734
+ const script = resolve(process.cwd(), "scripts", "sync-contributors.mjs");
735
+ try {
736
+ await access(script);
737
+ }
738
+ catch {
739
+ console.error(`[sync contributors] Missing ${script}. ` +
740
+ "Restore the template script or run this command from a Grove project root.");
741
+ process.exit(1);
742
+ }
743
+ await runExternal(process.execPath, [script], { stdio: "inherit", cwd: process.cwd() });
489
744
  return;
490
745
  }
491
746
  const recordsDir = resolve(process.cwd(), config.paths.recordsDir);
@@ -636,6 +891,7 @@ program
636
891
  .argument("<action>", "sync")
637
892
  .description("Sync Grove workflow templates into the current project.")
638
893
  .option("--force", "overwrite existing workflow files")
894
+ .option("-d, --deploy <provider>", `deploy provider for the build workflow + config files: ${DEPLOY_PROVIDERS.join(" | ")}`, "github-pages")
639
895
  .action(async (action, opts) => {
640
896
  if (action !== "sync") {
641
897
  console.error(`Unknown workflows action: ${action}. Use "sync".`);
@@ -647,6 +903,10 @@ program
647
903
  const githubMode = config.integrations?.github === false || config.integrations?.github === undefined
648
904
  ? "none"
649
905
  : "public";
906
+ // Validate the deploy option; default to github-pages for back-compat.
907
+ const deploy = opts.deploy && DEPLOY_PROVIDERS.includes(opts.deploy)
908
+ ? opts.deploy
909
+ : "github-pages";
650
910
  const root = process.cwd();
651
911
  // Make sure the directories exist. `ensureDir` returns a
652
912
  // promise; without `await`, the subsequent `writeFile` can race
@@ -655,8 +915,21 @@ program
655
915
  await ensureDir(join(root, ".github", "ISSUE_TEMPLATE"));
656
916
  const files = [
657
917
  { path: join(root, ".github", "workflows", "validate-data.yml"), content: workflowValidate() },
658
- { path: join(root, ".github", "workflows", "build.yml"), content: workflowBuild("astro") },
918
+ { path: join(root, ".github", "workflows", "build.yml"), content: workflowBuild("astro", deploy) },
659
919
  ];
920
+ // Provider-specific deploy workflow (vercel / netlify / cloudflare).
921
+ // GitHub Pages deploys inline in build.yml; `none` writes nothing.
922
+ if (deploy === "vercel" || deploy === "netlify" || deploy === "cloudflare") {
923
+ files.push({
924
+ path: join(root, ".github", "workflows", `deploy-${deploy}.yml`),
925
+ content: workflowDeploy(deploy),
926
+ });
927
+ }
928
+ // Provider-specific config files at the project root.
929
+ const projectName = config.site?.name ?? "Grove Directory";
930
+ for (const file of deployConfigFiles(deploy, projectName)) {
931
+ files.push({ path: join(root, file.path), content: file.content });
932
+ }
660
933
  if (githubMode === "public") {
661
934
  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() });
662
935
  }
@@ -670,7 +943,7 @@ program
670
943
  await writeFile(f.path, f.content, "utf8");
671
944
  written++;
672
945
  }
673
- console.log(`[workflows sync] ${githubMode} mode: ${written} written, ${skipped} skipped` +
946
+ console.log(`[workflows sync] ${githubMode} mode, deploy=${deploy}: ${written} written, ${skipped} skipped` +
674
947
  (opts.force ? " (--force)" : ""));
675
948
  });
676
949
  // ──────────────────────────────────────────────────────────────────────
@@ -701,36 +974,24 @@ async function detectFramework() {
701
974
  const all = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
702
975
  if (all["@grove-dev/astro"])
703
976
  return "astro";
704
- if (all["@grove-dev/nextjs"])
705
- return "nextjs";
706
- if (all["@grove-dev/svelte"])
707
- return "svelte";
708
977
  }
709
978
  catch {
710
979
  /* ignore */
711
980
  }
712
981
  console.error("Could not detect a Grove framework in the current project.");
713
- console.error("Install @grove-dev/astro first. (Next.js and SvelteKit are roadmap-only in V1.)");
982
+ console.error("Install @grove-dev/astro first. (V1 supports Astro only.)");
714
983
  process.exit(1);
715
984
  }
716
985
  function frameworkBuildCommand(fw) {
717
986
  switch (fw) {
718
987
  case "astro":
719
988
  return ["pnpm", ["exec", "astro", "build"]];
720
- case "nextjs":
721
- return ["pnpm", ["exec", "next", "build"]];
722
- case "svelte":
723
- return ["pnpm", ["exec", "vite", "build"]];
724
989
  }
725
990
  }
726
991
  function frameworkDevCommand(fw) {
727
992
  switch (fw) {
728
993
  case "astro":
729
994
  return ["pnpm", ["exec", "astro", "dev"]];
730
- case "nextjs":
731
- return ["pnpm", ["exec", "next", "dev"]];
732
- case "svelte":
733
- return ["pnpm", ["exec", "vite", "dev"]];
734
995
  }
735
996
  }
736
997
  function runExternal(bin, args, opts = {}) {
@@ -901,10 +1162,48 @@ jobs:
901
1162
  run: pnpm exec grove validate
902
1163
  `;
903
1164
  }
904
- function workflowBuild(framework) {
1165
+ function workflowBuild(framework, deploy) {
905
1166
  // The project's "build" script in package.json already chains
906
1167
  // grove generate && grove sitemap && grove llms && <framework> build
907
1168
  // via the `grove` package's own build orchestration. Keep the workflow thin.
1169
+ //
1170
+ // For `github-pages` we add a deploy-pages step at the end so the
1171
+ // build workflow is self-contained (the `pages: write` permission
1172
+ // and the `actions/configure-pages` + `actions/deploy-pages` steps
1173
+ // are the canonical Pages deploy path).
1174
+ //
1175
+ // For `vercel` / `netlify` / `cloudflare` we keep build.yml as a
1176
+ // pure build + artifact upload; the provider-specific deploy lives
1177
+ // in a separate `.github/workflows/deploy-<provider>.yml` workflow.
1178
+ // For `none` we still upload the artifact so a user can manually
1179
+ // download it, but skip the deploy step.
1180
+ const isPages = deploy === "github-pages";
1181
+ const pagesSteps = isPages
1182
+ ? ` - name: Setup Pages
1183
+ uses: actions/configure-pages@v5
1184
+
1185
+ - name: Upload Pages artifact
1186
+ uses: actions/upload-pages-artifact@v3
1187
+ with:
1188
+ path: ./dist
1189
+
1190
+ - name: Deploy to GitHub Pages
1191
+ id: deployment
1192
+ uses: actions/deploy-pages@v4
1193
+
1194
+ - name: Summary
1195
+ if: success()
1196
+ run: |
1197
+ echo "✅ Deployed to \${{ steps.deployment.outputs.page_url }}"
1198
+ `
1199
+ : "";
1200
+ const pagesPermissions = isPages
1201
+ ? ` contents: read
1202
+ pages: write
1203
+ id-token: write
1204
+ `
1205
+ : ` contents: read
1206
+ `;
908
1207
  return `name: Build site
909
1208
 
910
1209
  # Runs on every PR, every push to main, and on manual dispatch.
@@ -917,8 +1216,7 @@ on:
917
1216
  workflow_dispatch:
918
1217
 
919
1218
  permissions:
920
- contents: read
921
-
1219
+ ${pagesPermissions}
922
1220
  jobs:
923
1221
  build:
924
1222
  runs-on: ubuntu-latest
@@ -940,16 +1238,252 @@ jobs:
940
1238
  - name: Install dependencies
941
1239
  run: pnpm install --frozen-lockfile
942
1240
 
1241
+ # \`build\` chains build:data + build:sitemap + build:llms + <framework> build.
1242
+ # Site URL is overridden so sitemap/OG/canonical links resolve to
1243
+ # the deployed URL rather than the placeholder in grove.config.ts.
943
1244
  - name: Build the site
944
- run: pnpm build
1245
+ env:
1246
+ SITE_URL: \${{ vars.SITE_URL || github.pages.custom_domain || format('https://{0}.github.io/{1}', github.repository_owner, github.event.repository.name) }}
1247
+ run: pnpm run build
1248
+ ${pagesSteps}`;
1249
+ }
1250
+ /**
1251
+ * Provider-specific deploy workflow. Triggered after a successful build
1252
+ * to deploy the static site to the chosen provider via its CLI / API.
1253
+ * Used for vercel / netlify / cloudflare (GitHub Pages deploys inline
1254
+ * in build.yml, and `none` writes no deploy workflow at all).
1255
+ */
1256
+ function workflowDeploy(deploy) {
1257
+ switch (deploy) {
1258
+ case "vercel":
1259
+ return `name: Deploy to Vercel
1260
+
1261
+ # Runs after a successful build on main. Uses the Vercel CLI to deploy
1262
+ # the built \`dist/\` directory. Requires a VERCEL_TOKEN secret (and
1263
+ # optionally VERCEL_ORG_ID / VERCEL_PROJECT_ID for project linking).
1264
+ on:
1265
+ workflow_run:
1266
+ workflows: ["Build site"]
1267
+ types:
1268
+ - completed
1269
+ workflow_dispatch:
1270
+
1271
+ permissions:
1272
+ contents: read
1273
+
1274
+ jobs:
1275
+ deploy:
1276
+ if: \${{ github.event.workflow_run.conclusion == 'success' }}
1277
+ runs-on: ubuntu-latest
1278
+
1279
+ steps:
1280
+ - name: Checkout
1281
+ uses: actions/checkout@v4
1282
+
1283
+ - name: Setup pnpm
1284
+ uses: pnpm/action-setup@v4
1285
+
1286
+ - name: Setup Node
1287
+ uses: actions/setup-node@v4
1288
+ with:
1289
+ node-version: "20"
1290
+ cache: pnpm
1291
+ cache-dependency-path: "**/pnpm-lock.yaml"
1292
+
1293
+ - name: Install Vercel CLI
1294
+ run: pnpm add -g vercel@latest
1295
+
1296
+ - name: Pull Vercel project info
1297
+ id: vercel
1298
+ run: |
1299
+ echo "PROJECT_ID=\${VERCEL_PROJECT_ID}" >> $GITHUB_OUTPUT
1300
+ env:
1301
+ VERCEL_TOKEN: \${{ secrets.VERCEL_TOKEN }}
1302
+ VERCEL_ORG_ID: \${{ secrets.VERCEL_ORG_ID }}
1303
+ VERCEL_PROJECT_ID: \${{ secrets.VERCEL_PROJECT_ID }}
1304
+
1305
+ - name: Deploy to Vercel (production)
1306
+ run: vercel deploy --prod --yes --token \$VERCEL_TOKEN
1307
+ env:
1308
+ VERCEL_TOKEN: \${{ secrets.VERCEL_TOKEN }}
1309
+ `;
1310
+ case "netlify":
1311
+ return `name: Deploy to Netlify
1312
+
1313
+ # Runs after a successful build on main. Uses the Netlify CLI to deploy
1314
+ # the built \`dist/\` directory. Requires NETLIFY_AUTH_TOKEN and
1315
+ # NETLIFY_SITE_ID secrets.
1316
+ on:
1317
+ workflow_run:
1318
+ workflows: ["Build site"]
1319
+ types:
1320
+ - completed
1321
+ workflow_dispatch:
1322
+
1323
+ permissions:
1324
+ contents: read
1325
+
1326
+ jobs:
1327
+ deploy:
1328
+ if: \${{ github.event.workflow_run.conclusion == 'success' }}
1329
+ runs-on: ubuntu-latest
1330
+
1331
+ steps:
1332
+ - name: Checkout
1333
+ uses: actions/checkout@v4
1334
+
1335
+ - name: Setup pnpm
1336
+ uses: pnpm/action-setup@v4
1337
+
1338
+ - name: Setup Node
1339
+ uses: actions/setup-node@v4
1340
+ with:
1341
+ node-version: "20"
1342
+ cache: pnpm
1343
+ cache-dependency-path: "**/pnpm-lock.yaml"
945
1344
 
946
- - name: Upload build artifact
947
- uses: actions/upload-artifact@v4
1345
+ - name: Install Netlify CLI
1346
+ run: pnpm add -g netlify-cli@latest
1347
+
1348
+ - name: Deploy to Netlify (production)
1349
+ run: netlify deploy --prod --dir=dist --message "Deploy from GitHub Actions"
1350
+ env:
1351
+ NETLIFY_AUTH_TOKEN: \${{ secrets.NETLIFY_AUTH_TOKEN }}
1352
+ NETLIFY_SITE_ID: \${{ secrets.NETLIFY_SITE_ID }}
1353
+ `;
1354
+ case "cloudflare":
1355
+ return `name: Deploy to Cloudflare Pages
1356
+
1357
+ # Runs after a successful build on main. Uses wrangler to deploy the
1358
+ # built \`dist/\` directory to Cloudflare Pages. Requires
1359
+ # CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID secrets.
1360
+ on:
1361
+ workflow_run:
1362
+ workflows: ["Build site"]
1363
+ types:
1364
+ - completed
1365
+ workflow_dispatch:
1366
+
1367
+ permissions:
1368
+ contents: read
1369
+
1370
+ jobs:
1371
+ deploy:
1372
+ if: \${{ github.event.workflow_run.conclusion == 'success' }}
1373
+ runs-on: ubuntu-latest
1374
+
1375
+ steps:
1376
+ - name: Checkout
1377
+ uses: actions/checkout@v4
1378
+
1379
+ - name: Setup pnpm
1380
+ uses: pnpm/action-setup@v4
1381
+
1382
+ - name: Setup Node
1383
+ uses: actions/setup-node@v4
948
1384
  with:
949
- name: dist
950
- path: dist
951
- retention-days: 7
1385
+ node-version: "20"
1386
+ cache: pnpm
1387
+ cache-dependency-path: "**/pnpm-lock.yaml"
1388
+
1389
+ - name: Install wrangler
1390
+ run: pnpm add -g wrangler@latest
1391
+
1392
+ - name: Deploy to Cloudflare Pages
1393
+ run: wrangler pages deploy dist --project-name ${"${{ github.event.repository.name }}"} --commit-dirty=true
1394
+ env:
1395
+ CLOUDFLARE_API_TOKEN: \${{ secrets.CLOUDFLARE_API_TOKEN }}
1396
+ CLOUDFLARE_ACCOUNT_ID: \${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
952
1397
  `;
1398
+ default:
1399
+ // github-pages and none never reach this path; build.yml handles
1400
+ // github-pages, and `none` writes no deploy workflow.
1401
+ throw new Error(`workflowDeploy: unsupported deploy provider ${deploy}`);
1402
+ }
1403
+ }
1404
+ /**
1405
+ * Provider-specific config files written at the project root so the
1406
+ * provider's CLI / build hook picks them up automatically. V1 only
1407
+ * emits configs for vercel / netlify / cloudflare / github-pages.
1408
+ * `none` emits nothing.
1409
+ */
1410
+ function deployConfigFiles(deploy, projectName) {
1411
+ switch (deploy) {
1412
+ case "vercel":
1413
+ return [
1414
+ {
1415
+ path: "vercel.json",
1416
+ content: `{
1417
+ "$schema": "https://openapi.vercel.sh/vercel.json",
1418
+ "buildCommand": "pnpm run build",
1419
+ "outputDirectory": "dist",
1420
+ "framework": null,
1421
+ "cleanUrls": true,
1422
+ "trailingSlash": false
1423
+ }
1424
+ `,
1425
+ },
1426
+ ];
1427
+ case "netlify":
1428
+ return [
1429
+ {
1430
+ path: "netlify.toml",
1431
+ content: `# Netlify configuration for ${projectName}.
1432
+ # Generated by \`grove new --deploy netlify\`. See https://docs.netlify.com/configure-netlify/file-based-configuration/
1433
+
1434
+ [build]
1435
+ command = "pnpm run build"
1436
+ publish = "dist"
1437
+
1438
+ [build.environment]
1439
+ NODE_VERSION = "20"
1440
+ PNPM_VERSION = "10"
1441
+
1442
+ # Astro renders clean URLs out of the box; keep static asset caching
1443
+ # aggressive but always revalidate HTML so a fresh deploy shows up.
1444
+ [[headers]]
1445
+ for = "/*"
1446
+ [headers.values]
1447
+ X-Content-Type-Options = "nosniff"
1448
+ X-Frame-Options = "DENY"
1449
+ Referrer-Policy = "strict-origin-when-cross-origin"
1450
+
1451
+ [[headers]]
1452
+ for = "/assets/*"
1453
+ [headers.values]
1454
+ Cache-Control = "public, max-age=31536000, immutable"
1455
+ `,
1456
+ },
1457
+ ];
1458
+ case "cloudflare":
1459
+ return [
1460
+ {
1461
+ path: "wrangler.jsonc",
1462
+ content: `// Cloudflare Pages configuration for ${projectName}.
1463
+ // Generated by \`grove new --deploy cloudflare\`. See https://developers.cloudflare.com/pages/functions/wrangler-configuration/
1464
+ {
1465
+ "name": "${slugifyProjectName(projectName)}",
1466
+ "compatibility_date": "${new Date().toISOString().slice(0, 10)}",
1467
+ "pages_build_output_dir": "./dist",
1468
+ "observability": {
1469
+ "enabled": true
1470
+ }
1471
+ }
1472
+ `,
1473
+ },
1474
+ ];
1475
+ case "github-pages":
1476
+ // GitHub Pages uses repo-level Pages settings; no config file.
1477
+ return [];
1478
+ case "none":
1479
+ return [];
1480
+ }
1481
+ }
1482
+ function slugifyProjectName(name) {
1483
+ return name
1484
+ .toLowerCase()
1485
+ .replace(/[^a-z0-9-]+/g, "-")
1486
+ .replace(/^-+|-+$/g, "") || "grove-site";
953
1487
  }
954
1488
  function issueTemplateSubmission(blueprint) {
955
1489
  const labelHint = blueprint === "project-directory"