@grove-dev/cli 0.2.10 → 0.2.14

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
@@ -17,14 +19,15 @@
17
19
  * grove dev run the framework's dev server
18
20
  */
19
21
  import { spawn } from "node:child_process";
20
- import { mkdir, readFile, writeFile, access } from "node:fs/promises";
22
+ import { mkdir, readFile, writeFile, access, readdir } 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,286 @@ 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
+ // If the caller did not pin a project (no `--dir`, no positional
440
+ // name), reuse an existing scaffold under `.grove/run/` so that
441
+ // repeat invocations of `pnpm grove:dev` / `grove:build` don't
442
+ // pile up a new timestamped folder on every run.
443
+ //
444
+ // Selection rules when no name is given:
445
+ // - 0 existing scaffolds → fall back to a fresh timestamped name.
446
+ // - 1 existing scaffold → use it.
447
+ // - 2+ existing scaffolds → refuse and ask the caller to pass
448
+ // `--dir <name>` so we don't pick
449
+ // silently and surprise the user.
450
+ const runRoot = resolve(monorepoRoot, ".grove", "run");
451
+ let dirRel;
452
+ if (opts.dir) {
453
+ dirRel = opts.dir;
454
+ }
455
+ else if (name) {
456
+ dirRel = name;
457
+ }
458
+ else {
459
+ const existing = [];
460
+ try {
461
+ const entries = await readdir(runRoot, { withFileTypes: true });
462
+ for (const entry of entries) {
463
+ if (!entry.isDirectory())
464
+ continue;
465
+ // Only count it as a scaffold if it has a package.json —
466
+ // that's the same sentinel `run` uses to detect a previous
467
+ // scaffold, so we stay consistent with the "is this
468
+ // reusable?" check below.
469
+ try {
470
+ await access(join(runRoot, entry.name, "package.json"));
471
+ existing.push(entry.name);
472
+ }
473
+ catch {
474
+ /* not a scaffold, skip */
475
+ }
476
+ }
477
+ }
478
+ catch {
479
+ /* runRoot doesn't exist yet — we'll create it */
480
+ }
481
+ if (existing.length === 0) {
482
+ const stamp = new Date()
483
+ .toISOString()
484
+ .replace(/[-:]/g, "")
485
+ .replace(/\..+$/, "")
486
+ .replace("T", "-");
487
+ dirRel = `grove-run-${stamp}`;
488
+ }
489
+ else if (existing.length === 1) {
490
+ dirRel = existing[0];
491
+ p.log.info(`Reusing scaffold: ${dirRel} (pass --dir <name> to override)`);
492
+ }
493
+ else {
494
+ p.log.error(`Found ${existing.length} scaffolds under .grove/run/. ` +
495
+ `Pass --dir <name> to pick one:`);
496
+ for (const e of existing.sort())
497
+ p.log.info(` - ${e}`);
498
+ process.exit(1);
499
+ }
500
+ }
501
+ // Always live under <monorepo-root>/.grove/run/<name>/ so the
502
+ // workspace picks it up via the `.grove/*` glob in
503
+ // `pnpm-workspace.yaml`.
504
+ const root = resolve(monorepoRoot, ".grove", "run", dirRel);
505
+ // The dir name and the package.json `name` are not the same —
506
+ // `renameProjectInTemplatePreserveDeps` slugifies the dir name
507
+ // and appends `-<framework>-<template>`. We need the package
508
+ // name to drive `pnpm --filter`, so compute it once and reuse.
509
+ const projectName = root.split("/").filter(Boolean).pop() ?? dirRel;
510
+ // ── Look up the LOCAL template via @grove-dev/<framework>'s
511
+ // `templates/<name>` directory. Inside this monorepo, that
512
+ // is a symlink straight to packages/astro/templates/default/,
513
+ // so a template change in the source tree flows through to
514
+ // the scaffolded project with no publish step. ─────────────
515
+ const templates = await listTemplates(framework);
516
+ const tpl = templates.find((t) => t.template === opts.template) ?? templates[0];
517
+ if (!tpl) {
518
+ p.log.error(`No templates found for ${framework}.`);
519
+ process.exit(1);
520
+ }
521
+ p.log.info(`Template: ${tpl.path}`);
522
+ const packageName = packageNameFromProjectName(projectName, framework, tpl.template);
523
+ p.log.info(`Project: ${projectName} (package: ${packageName}) → ${root}`);
524
+ // ── Scaffold (or reuse an existing scaffold) ──────────────────
525
+ // If the target dir already contains a package.json whose
526
+ // name matches what we would have written, treat it as a
527
+ // re-run of `grove run dev` against an already-initialised
528
+ // project and skip the copy. That makes iterative development
529
+ // a one-line affair: edit template, run `grove run dev` again.
530
+ const sentinel = join(root, "package.json");
531
+ let alreadyScaffolded = false;
532
+ try {
533
+ const existing = JSON.parse(await readFile(sentinel, "utf8"));
534
+ const expectedName = packageNameFromProjectName(projectName, framework, tpl.template);
535
+ alreadyScaffolded = existing.name === expectedName;
536
+ }
537
+ catch {
538
+ alreadyScaffolded = false;
539
+ }
540
+ const s = p.spinner();
541
+ if (alreadyScaffolded) {
542
+ s.start("Reusing existing scaffold");
543
+ s.stop("Reusing existing scaffold");
544
+ }
545
+ else {
546
+ s.start("Scaffolding");
547
+ await mkdir(root, { recursive: true });
548
+ await copyTemplate(framework, root, tpl.template);
549
+ // Use local package paths for the dev-only run path. Installing
550
+ // the generated project as a standalone package avoids pnpm's
551
+ // workspace discovery cache when a project appears mid-command.
552
+ await renameProjectInTemplate(framework, root, projectName, tpl.template, { mode: "file" });
553
+ s.stop("Scaffolded (local package deps)");
554
+ }
555
+ // ── git init ───────────────────────────────────────────────────
556
+ if (opts.git !== false) {
557
+ try {
558
+ await runExternal("git", ["init", "-b", "main"], { stdio: "ignore", cwd: root });
559
+ p.log.step("Initialized git repo on `main`");
560
+ }
561
+ catch {
562
+ p.log.warn("git not found — skipping git init");
563
+ }
564
+ }
565
+ // ── pnpm install (from monorepo root, scoped to this project) ──
566
+ if (opts.install !== false) {
567
+ const installSpinner = p.spinner();
568
+ installSpinner.start("Installing dependencies");
569
+ try {
570
+ await runExternal("pnpm", ["install", "--ignore-workspace"], {
571
+ stdio: "ignore",
572
+ cwd: root,
573
+ });
574
+ installSpinner.stop("Installed dependencies");
575
+ }
576
+ catch {
577
+ installSpinner.stop("Install failed");
578
+ p.log.warn(`Run \`pnpm install --ignore-workspace\` from ${root} to retry.`);
579
+ if (runAction !== "init") {
580
+ p.log.error("Cannot continue without a working install.");
581
+ process.exit(1);
582
+ }
583
+ }
584
+ }
585
+ // ── Run the requested action ───────────────────────────────────
586
+ if (runAction === "init") {
587
+ p.outro(`🌳 Scaffolded at ${root}\n\n` +
588
+ `Next steps:\n` +
589
+ ` cd ${root}\n` +
590
+ ` pnpm dev\n`);
591
+ return;
592
+ }
593
+ if (runAction === "build") {
594
+ // Run the template's `build` script, not `astro build` directly.
595
+ // The script chains `build:data` + `build:sitemap` + `build:llms`
596
+ // + `astro build` so the data is generated first. Skipping that
597
+ // chain gives you a half-built site with no records.
598
+ p.log.step(`Building ${packageName} via 'pnpm run build' (this can take a while)…`);
599
+ await runExternal("pnpm", ["--filter", packageName, "run", "build"], {
600
+ stdio: "inherit",
601
+ cwd: monorepoRoot,
602
+ });
603
+ p.outro(`🌳 Build done at ${root}`);
604
+ return;
605
+ }
606
+ // runAction === "dev" — start the dev server in-process.
607
+ //
608
+ // The template's `dev` script chains `build:data && astro dev`,
609
+ // which is what we want for a production user. But for a dev
610
+ // smoke test, the script's `&&` makes pnpm's `--` forwarding
611
+ // land in a tricky place: `pnpm run dev -- --port 4327` becomes
612
+ // `astro dev -- --port 4327`, where Astro treats `--port 4327`
613
+ // as positional args (port flag ignored).
614
+ //
615
+ // Cleanest workaround: run `build:data` separately (the only
616
+ // pre-step `dev` does), then `pnpm exec astro dev` directly with
617
+ // the port flag in the right place. Two `runExternal` calls is
618
+ // fine — they're both fast (`build:data` is a quick
619
+ // `grove generate`, and `astro dev` is what the user actually
620
+ // wants to see).
621
+ const port = typeof opts.port === "number" ? opts.port : 4321;
622
+ p.log.step(`Generating data via 'pnpm run build:data'…`);
623
+ try {
624
+ await runExternal("pnpm", ["--filter", packageName, "run", "build:data"], { stdio: "inherit", cwd: monorepoRoot });
625
+ }
626
+ catch {
627
+ p.log.warn(`build:data failed — starting astro dev anyway, site will be empty.`);
628
+ }
629
+ p.log.step(`Starting astro dev on port ${port} (Ctrl-C to stop)…`);
630
+ await runExternal("pnpm", ["--filter", packageName, "exec", "astro", "dev", "--port", String(port)], { stdio: "inherit", cwd: monorepoRoot });
631
+ });
632
+ // ──────────────────────────────────────────────────────────────────────
331
633
  // grove import
332
634
  // ──────────────────────────────────────────────────────────────────────
333
635
  program
@@ -485,7 +787,16 @@ program
485
787
  process.exit(1);
486
788
  }
487
789
  if (target === "contributors") {
488
- console.log("[sync contributors] contributor sync is not yet implemented in V1.");
790
+ const script = resolve(process.cwd(), "scripts", "sync-contributors.mjs");
791
+ try {
792
+ await access(script);
793
+ }
794
+ catch {
795
+ console.error(`[sync contributors] Missing ${script}. ` +
796
+ "Restore the template script or run this command from a Grove project root.");
797
+ process.exit(1);
798
+ }
799
+ await runExternal(process.execPath, [script], { stdio: "inherit", cwd: process.cwd() });
489
800
  return;
490
801
  }
491
802
  const recordsDir = resolve(process.cwd(), config.paths.recordsDir);
@@ -636,6 +947,7 @@ program
636
947
  .argument("<action>", "sync")
637
948
  .description("Sync Grove workflow templates into the current project.")
638
949
  .option("--force", "overwrite existing workflow files")
950
+ .option("-d, --deploy <provider>", `deploy provider for the build workflow + config files: ${DEPLOY_PROVIDERS.join(" | ")}`, "github-pages")
639
951
  .action(async (action, opts) => {
640
952
  if (action !== "sync") {
641
953
  console.error(`Unknown workflows action: ${action}. Use "sync".`);
@@ -647,6 +959,10 @@ program
647
959
  const githubMode = config.integrations?.github === false || config.integrations?.github === undefined
648
960
  ? "none"
649
961
  : "public";
962
+ // Validate the deploy option; default to github-pages for back-compat.
963
+ const deploy = opts.deploy && DEPLOY_PROVIDERS.includes(opts.deploy)
964
+ ? opts.deploy
965
+ : "github-pages";
650
966
  const root = process.cwd();
651
967
  // Make sure the directories exist. `ensureDir` returns a
652
968
  // promise; without `await`, the subsequent `writeFile` can race
@@ -655,8 +971,21 @@ program
655
971
  await ensureDir(join(root, ".github", "ISSUE_TEMPLATE"));
656
972
  const files = [
657
973
  { path: join(root, ".github", "workflows", "validate-data.yml"), content: workflowValidate() },
658
- { path: join(root, ".github", "workflows", "build.yml"), content: workflowBuild("astro") },
974
+ { path: join(root, ".github", "workflows", "build.yml"), content: workflowBuild("astro", deploy) },
659
975
  ];
976
+ // Provider-specific deploy workflow (vercel / netlify / cloudflare).
977
+ // GitHub Pages deploys inline in build.yml; `none` writes nothing.
978
+ if (deploy === "vercel" || deploy === "netlify" || deploy === "cloudflare") {
979
+ files.push({
980
+ path: join(root, ".github", "workflows", `deploy-${deploy}.yml`),
981
+ content: workflowDeploy(deploy),
982
+ });
983
+ }
984
+ // Provider-specific config files at the project root.
985
+ const projectName = config.site?.name ?? "Grove Directory";
986
+ for (const file of deployConfigFiles(deploy, projectName)) {
987
+ files.push({ path: join(root, file.path), content: file.content });
988
+ }
660
989
  if (githubMode === "public") {
661
990
  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
991
  }
@@ -670,7 +999,7 @@ program
670
999
  await writeFile(f.path, f.content, "utf8");
671
1000
  written++;
672
1001
  }
673
- console.log(`[workflows sync] ${githubMode} mode: ${written} written, ${skipped} skipped` +
1002
+ console.log(`[workflows sync] ${githubMode} mode, deploy=${deploy}: ${written} written, ${skipped} skipped` +
674
1003
  (opts.force ? " (--force)" : ""));
675
1004
  });
676
1005
  // ──────────────────────────────────────────────────────────────────────
@@ -701,36 +1030,24 @@ async function detectFramework() {
701
1030
  const all = { ...(pkg.dependencies ?? {}), ...(pkg.devDependencies ?? {}) };
702
1031
  if (all["@grove-dev/astro"])
703
1032
  return "astro";
704
- if (all["@grove-dev/nextjs"])
705
- return "nextjs";
706
- if (all["@grove-dev/svelte"])
707
- return "svelte";
708
1033
  }
709
1034
  catch {
710
1035
  /* ignore */
711
1036
  }
712
1037
  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.)");
1038
+ console.error("Install @grove-dev/astro first. (V1 supports Astro only.)");
714
1039
  process.exit(1);
715
1040
  }
716
1041
  function frameworkBuildCommand(fw) {
717
1042
  switch (fw) {
718
1043
  case "astro":
719
1044
  return ["pnpm", ["exec", "astro", "build"]];
720
- case "nextjs":
721
- return ["pnpm", ["exec", "next", "build"]];
722
- case "svelte":
723
- return ["pnpm", ["exec", "vite", "build"]];
724
1045
  }
725
1046
  }
726
1047
  function frameworkDevCommand(fw) {
727
1048
  switch (fw) {
728
1049
  case "astro":
729
1050
  return ["pnpm", ["exec", "astro", "dev"]];
730
- case "nextjs":
731
- return ["pnpm", ["exec", "next", "dev"]];
732
- case "svelte":
733
- return ["pnpm", ["exec", "vite", "dev"]];
734
1051
  }
735
1052
  }
736
1053
  function runExternal(bin, args, opts = {}) {
@@ -901,10 +1218,48 @@ jobs:
901
1218
  run: pnpm exec grove validate
902
1219
  `;
903
1220
  }
904
- function workflowBuild(framework) {
1221
+ function workflowBuild(framework, deploy) {
905
1222
  // The project's "build" script in package.json already chains
906
1223
  // grove generate && grove sitemap && grove llms && <framework> build
907
1224
  // via the `grove` package's own build orchestration. Keep the workflow thin.
1225
+ //
1226
+ // For `github-pages` we add a deploy-pages step at the end so the
1227
+ // build workflow is self-contained (the `pages: write` permission
1228
+ // and the `actions/configure-pages` + `actions/deploy-pages` steps
1229
+ // are the canonical Pages deploy path).
1230
+ //
1231
+ // For `vercel` / `netlify` / `cloudflare` we keep build.yml as a
1232
+ // pure build + artifact upload; the provider-specific deploy lives
1233
+ // in a separate `.github/workflows/deploy-<provider>.yml` workflow.
1234
+ // For `none` we still upload the artifact so a user can manually
1235
+ // download it, but skip the deploy step.
1236
+ const isPages = deploy === "github-pages";
1237
+ const pagesSteps = isPages
1238
+ ? ` - name: Setup Pages
1239
+ uses: actions/configure-pages@v5
1240
+
1241
+ - name: Upload Pages artifact
1242
+ uses: actions/upload-pages-artifact@v3
1243
+ with:
1244
+ path: ./dist
1245
+
1246
+ - name: Deploy to GitHub Pages
1247
+ id: deployment
1248
+ uses: actions/deploy-pages@v4
1249
+
1250
+ - name: Summary
1251
+ if: success()
1252
+ run: |
1253
+ echo "✅ Deployed to \${{ steps.deployment.outputs.page_url }}"
1254
+ `
1255
+ : "";
1256
+ const pagesPermissions = isPages
1257
+ ? ` contents: read
1258
+ pages: write
1259
+ id-token: write
1260
+ `
1261
+ : ` contents: read
1262
+ `;
908
1263
  return `name: Build site
909
1264
 
910
1265
  # Runs on every PR, every push to main, and on manual dispatch.
@@ -917,8 +1272,7 @@ on:
917
1272
  workflow_dispatch:
918
1273
 
919
1274
  permissions:
920
- contents: read
921
-
1275
+ ${pagesPermissions}
922
1276
  jobs:
923
1277
  build:
924
1278
  runs-on: ubuntu-latest
@@ -940,16 +1294,252 @@ jobs:
940
1294
  - name: Install dependencies
941
1295
  run: pnpm install --frozen-lockfile
942
1296
 
1297
+ # \`build\` chains build:data + build:sitemap + build:llms + <framework> build.
1298
+ # Site URL is overridden so sitemap/OG/canonical links resolve to
1299
+ # the deployed URL rather than the placeholder in grove.config.ts.
943
1300
  - name: Build the site
944
- run: pnpm build
1301
+ env:
1302
+ SITE_URL: \${{ vars.SITE_URL || github.pages.custom_domain || format('https://{0}.github.io/{1}', github.repository_owner, github.event.repository.name) }}
1303
+ run: pnpm run build
1304
+ ${pagesSteps}`;
1305
+ }
1306
+ /**
1307
+ * Provider-specific deploy workflow. Triggered after a successful build
1308
+ * to deploy the static site to the chosen provider via its CLI / API.
1309
+ * Used for vercel / netlify / cloudflare (GitHub Pages deploys inline
1310
+ * in build.yml, and `none` writes no deploy workflow at all).
1311
+ */
1312
+ function workflowDeploy(deploy) {
1313
+ switch (deploy) {
1314
+ case "vercel":
1315
+ return `name: Deploy to Vercel
1316
+
1317
+ # Runs after a successful build on main. Uses the Vercel CLI to deploy
1318
+ # the built \`dist/\` directory. Requires a VERCEL_TOKEN secret (and
1319
+ # optionally VERCEL_ORG_ID / VERCEL_PROJECT_ID for project linking).
1320
+ on:
1321
+ workflow_run:
1322
+ workflows: ["Build site"]
1323
+ types:
1324
+ - completed
1325
+ workflow_dispatch:
945
1326
 
946
- - name: Upload build artifact
947
- uses: actions/upload-artifact@v4
1327
+ permissions:
1328
+ contents: read
1329
+
1330
+ jobs:
1331
+ deploy:
1332
+ if: \${{ github.event.workflow_run.conclusion == 'success' }}
1333
+ runs-on: ubuntu-latest
1334
+
1335
+ steps:
1336
+ - name: Checkout
1337
+ uses: actions/checkout@v4
1338
+
1339
+ - name: Setup pnpm
1340
+ uses: pnpm/action-setup@v4
1341
+
1342
+ - name: Setup Node
1343
+ uses: actions/setup-node@v4
948
1344
  with:
949
- name: dist
950
- path: dist
951
- retention-days: 7
1345
+ node-version: "20"
1346
+ cache: pnpm
1347
+ cache-dependency-path: "**/pnpm-lock.yaml"
1348
+
1349
+ - name: Install Vercel CLI
1350
+ run: pnpm add -g vercel@latest
1351
+
1352
+ - name: Pull Vercel project info
1353
+ id: vercel
1354
+ run: |
1355
+ echo "PROJECT_ID=\${VERCEL_PROJECT_ID}" >> $GITHUB_OUTPUT
1356
+ env:
1357
+ VERCEL_TOKEN: \${{ secrets.VERCEL_TOKEN }}
1358
+ VERCEL_ORG_ID: \${{ secrets.VERCEL_ORG_ID }}
1359
+ VERCEL_PROJECT_ID: \${{ secrets.VERCEL_PROJECT_ID }}
1360
+
1361
+ - name: Deploy to Vercel (production)
1362
+ run: vercel deploy --prod --yes --token \$VERCEL_TOKEN
1363
+ env:
1364
+ VERCEL_TOKEN: \${{ secrets.VERCEL_TOKEN }}
952
1365
  `;
1366
+ case "netlify":
1367
+ return `name: Deploy to Netlify
1368
+
1369
+ # Runs after a successful build on main. Uses the Netlify CLI to deploy
1370
+ # the built \`dist/\` directory. Requires NETLIFY_AUTH_TOKEN and
1371
+ # NETLIFY_SITE_ID secrets.
1372
+ on:
1373
+ workflow_run:
1374
+ workflows: ["Build site"]
1375
+ types:
1376
+ - completed
1377
+ workflow_dispatch:
1378
+
1379
+ permissions:
1380
+ contents: read
1381
+
1382
+ jobs:
1383
+ deploy:
1384
+ if: \${{ github.event.workflow_run.conclusion == 'success' }}
1385
+ runs-on: ubuntu-latest
1386
+
1387
+ steps:
1388
+ - name: Checkout
1389
+ uses: actions/checkout@v4
1390
+
1391
+ - name: Setup pnpm
1392
+ uses: pnpm/action-setup@v4
1393
+
1394
+ - name: Setup Node
1395
+ uses: actions/setup-node@v4
1396
+ with:
1397
+ node-version: "20"
1398
+ cache: pnpm
1399
+ cache-dependency-path: "**/pnpm-lock.yaml"
1400
+
1401
+ - name: Install Netlify CLI
1402
+ run: pnpm add -g netlify-cli@latest
1403
+
1404
+ - name: Deploy to Netlify (production)
1405
+ run: netlify deploy --prod --dir=dist --message "Deploy from GitHub Actions"
1406
+ env:
1407
+ NETLIFY_AUTH_TOKEN: \${{ secrets.NETLIFY_AUTH_TOKEN }}
1408
+ NETLIFY_SITE_ID: \${{ secrets.NETLIFY_SITE_ID }}
1409
+ `;
1410
+ case "cloudflare":
1411
+ return `name: Deploy to Cloudflare Pages
1412
+
1413
+ # Runs after a successful build on main. Uses wrangler to deploy the
1414
+ # built \`dist/\` directory to Cloudflare Pages. Requires
1415
+ # CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID secrets.
1416
+ on:
1417
+ workflow_run:
1418
+ workflows: ["Build site"]
1419
+ types:
1420
+ - completed
1421
+ workflow_dispatch:
1422
+
1423
+ permissions:
1424
+ contents: read
1425
+
1426
+ jobs:
1427
+ deploy:
1428
+ if: \${{ github.event.workflow_run.conclusion == 'success' }}
1429
+ runs-on: ubuntu-latest
1430
+
1431
+ steps:
1432
+ - name: Checkout
1433
+ uses: actions/checkout@v4
1434
+
1435
+ - name: Setup pnpm
1436
+ uses: pnpm/action-setup@v4
1437
+
1438
+ - name: Setup Node
1439
+ uses: actions/setup-node@v4
1440
+ with:
1441
+ node-version: "20"
1442
+ cache: pnpm
1443
+ cache-dependency-path: "**/pnpm-lock.yaml"
1444
+
1445
+ - name: Install wrangler
1446
+ run: pnpm add -g wrangler@latest
1447
+
1448
+ - name: Deploy to Cloudflare Pages
1449
+ run: wrangler pages deploy dist --project-name ${"${{ github.event.repository.name }}"} --commit-dirty=true
1450
+ env:
1451
+ CLOUDFLARE_API_TOKEN: \${{ secrets.CLOUDFLARE_API_TOKEN }}
1452
+ CLOUDFLARE_ACCOUNT_ID: \${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
1453
+ `;
1454
+ default:
1455
+ // github-pages and none never reach this path; build.yml handles
1456
+ // github-pages, and `none` writes no deploy workflow.
1457
+ throw new Error(`workflowDeploy: unsupported deploy provider ${deploy}`);
1458
+ }
1459
+ }
1460
+ /**
1461
+ * Provider-specific config files written at the project root so the
1462
+ * provider's CLI / build hook picks them up automatically. V1 only
1463
+ * emits configs for vercel / netlify / cloudflare / github-pages.
1464
+ * `none` emits nothing.
1465
+ */
1466
+ function deployConfigFiles(deploy, projectName) {
1467
+ switch (deploy) {
1468
+ case "vercel":
1469
+ return [
1470
+ {
1471
+ path: "vercel.json",
1472
+ content: `{
1473
+ "$schema": "https://openapi.vercel.sh/vercel.json",
1474
+ "buildCommand": "pnpm run build",
1475
+ "outputDirectory": "dist",
1476
+ "framework": null,
1477
+ "cleanUrls": true,
1478
+ "trailingSlash": false
1479
+ }
1480
+ `,
1481
+ },
1482
+ ];
1483
+ case "netlify":
1484
+ return [
1485
+ {
1486
+ path: "netlify.toml",
1487
+ content: `# Netlify configuration for ${projectName}.
1488
+ # Generated by \`grove new --deploy netlify\`. See https://docs.netlify.com/configure-netlify/file-based-configuration/
1489
+
1490
+ [build]
1491
+ command = "pnpm run build"
1492
+ publish = "dist"
1493
+
1494
+ [build.environment]
1495
+ NODE_VERSION = "20"
1496
+ PNPM_VERSION = "10"
1497
+
1498
+ # Astro renders clean URLs out of the box; keep static asset caching
1499
+ # aggressive but always revalidate HTML so a fresh deploy shows up.
1500
+ [[headers]]
1501
+ for = "/*"
1502
+ [headers.values]
1503
+ X-Content-Type-Options = "nosniff"
1504
+ X-Frame-Options = "DENY"
1505
+ Referrer-Policy = "strict-origin-when-cross-origin"
1506
+
1507
+ [[headers]]
1508
+ for = "/assets/*"
1509
+ [headers.values]
1510
+ Cache-Control = "public, max-age=31536000, immutable"
1511
+ `,
1512
+ },
1513
+ ];
1514
+ case "cloudflare":
1515
+ return [
1516
+ {
1517
+ path: "wrangler.jsonc",
1518
+ content: `// Cloudflare Pages configuration for ${projectName}.
1519
+ // Generated by \`grove new --deploy cloudflare\`. See https://developers.cloudflare.com/pages/functions/wrangler-configuration/
1520
+ {
1521
+ "name": "${slugifyProjectName(projectName)}",
1522
+ "compatibility_date": "${new Date().toISOString().slice(0, 10)}",
1523
+ "pages_build_output_dir": "./dist",
1524
+ "observability": {
1525
+ "enabled": true
1526
+ }
1527
+ }
1528
+ `,
1529
+ },
1530
+ ];
1531
+ case "github-pages":
1532
+ // GitHub Pages uses repo-level Pages settings; no config file.
1533
+ return [];
1534
+ case "none":
1535
+ return [];
1536
+ }
1537
+ }
1538
+ function slugifyProjectName(name) {
1539
+ return name
1540
+ .toLowerCase()
1541
+ .replace(/[^a-z0-9-]+/g, "-")
1542
+ .replace(/^-+|-+$/g, "") || "grove-site";
953
1543
  }
954
1544
  function issueTemplateSubmission(blueprint) {
955
1545
  const labelHint = blueprint === "project-directory"