@milesroxas/design-hub 0.4.0 → 0.4.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.
@@ -11,7 +11,7 @@ import { join } from 'node:path';
11
11
  import { harnessPort, readEnv, writeEnv } from '../server/env.js';
12
12
  import { ROOT, TEMPLATES } from '../server/paths.js';
13
13
  import { CliError } from './lib/cli.js';
14
- import { gitConnected } from './lib/deploy.js';
14
+ import { gitConnected, restoreGitignore, upstashTerms } from './lib/deploy.js';
15
15
  import { holderOf, pickPort, readClaims, writeClaim } from './lib/ports.js';
16
16
  import { ENVIRONMENTS, envNames, linkedOrg, linkedProject, projectInfo, STORE_ENV, setEnv, vercel, whoami, } from './lib/vercel.js';
17
17
  export const spec = {
@@ -178,7 +178,12 @@ function link(project, team, warnings) {
178
178
  warnings.push(`.vercel/project.json pointed at ${current}; relinked to ${project}.`);
179
179
  // A new project is created in the scope given; without one the CLI's current team wins, which
180
180
  // is whichever team the user last switched to, not necessarily where this project belongs.
181
+ const gitignore = join(ROOT, '.gitignore');
182
+ const before = existsSync(gitignore) ? readFileSync(gitignore, 'utf8') : '';
181
183
  cli(['link', '--yes', '--project', project, ...(team ? ['--scope', team] : [])]);
184
+ const kept = restoreGitignore(before, existsSync(gitignore) ? readFileSync(gitignore, 'utf8') : '');
185
+ if (kept !== null)
186
+ writeFileSync(gitignore, kept);
182
187
  return 'ran';
183
188
  }
184
189
  /** The `origin` remote, or null when the project has none. */
@@ -281,11 +286,14 @@ function provisionReview(project, team, warnings) {
281
286
  // Unlike env and deploy, this command ignores the project link and takes the CLI's current team.
282
287
  ...scopeArgs(team),
283
288
  ]);
284
- if (out?.status !== 0)
285
- throw new CliError('Could not add the Upstash for Redis store.', {
289
+ if (out?.status !== 0) {
290
+ const terms = upstashTerms(out?.stderr ?? '', team);
291
+ throw new CliError('Could not add the Upstash for Redis store; most often the team has not accepted the Upstash terms yet.', {
286
292
  stderr: out?.stderr.trim().slice(-600),
287
- fix: `The Marketplace terms need accepting once per team: send the user https://vercel.com/marketplace/upstash to choose Install and accept for this team, then run this again.`,
293
+ terms: terms.url,
294
+ fix: `Tell the user, word for word: "${terms.say}" Then run this again.`,
288
295
  });
296
+ }
289
297
  store = 'created';
290
298
  }
291
299
  // The local commands (design-hub people, design-hub comments) read the same store.
@@ -74,3 +74,19 @@ export type Next = {
74
74
  };
75
75
  /** One look at the deployment Vercel started for a pushed commit: done, keep waiting, or stop. */
76
76
  export declare function nextStep(seen: Seen, sha: string, waitedMs: number): Next;
77
+ /**
78
+ * Where the user accepts the Upstash Marketplace terms for one team: the link the
79
+ * CLI printed when it has one, else that team's accept-terms page, else the
80
+ * product page. The page can list several Upstash products; the store is the one
81
+ * named here, and the rerun creates it, so nothing is created in the browser.
82
+ */
83
+ export declare function upstashTerms(stderr: string, team: string | undefined): {
84
+ url: string;
85
+ say: string;
86
+ };
87
+ /**
88
+ * `vercel link` appends `.vercel` and `.env*` to .gitignore. The template already
89
+ * ignores both, and `.env*` would hide `.env.example` and leave the tree dirty, so
90
+ * the file goes back as it was, adding only `.vercel/` when it was missing.
91
+ */
92
+ export declare function restoreGitignore(before: string, after: string): string | null;
@@ -92,3 +92,34 @@ export function nextStep(seen, sha, waitedMs) {
92
92
  };
93
93
  return { wait: true };
94
94
  }
95
+ /**
96
+ * Where the user accepts the Upstash Marketplace terms for one team: the link the
97
+ * CLI printed when it has one, else that team's accept-terms page, else the
98
+ * product page. The page can list several Upstash products; the store is the one
99
+ * named here, and the rerun creates it, so nothing is created in the browser.
100
+ */
101
+ export function upstashTerms(stderr, team) {
102
+ const printed = stderr.match(/https:\/\/vercel\.com\/\S*accept-terms\S*/)?.[0];
103
+ const url = printed ??
104
+ (team
105
+ ? `https://vercel.com/${team}/~/integrations/accept-terms/upstash?source=cli`
106
+ : 'https://vercel.com/marketplace/upstash');
107
+ return {
108
+ url,
109
+ say: `Open ${url}${team ? ` for the ${team} team` : ''} and accept the Upstash terms. ` +
110
+ 'If it lists Upstash products, choose Install on Upstash for Redis (Redis Compatible Database), the only one Design Hub uses. ' +
111
+ 'Stop once the terms are accepted: close any step that offers to create a database, because the rerun creates the store and connects it to this project.',
112
+ };
113
+ }
114
+ /**
115
+ * `vercel link` appends `.vercel` and `.env*` to .gitignore. The template already
116
+ * ignores both, and `.env*` would hide `.env.example` and leave the tree dirty, so
117
+ * the file goes back as it was, adding only `.vercel/` when it was missing.
118
+ */
119
+ export function restoreGitignore(before, after) {
120
+ if (after === before)
121
+ return null;
122
+ if (/^\/?\.vercel\/?$/m.test(before))
123
+ return before;
124
+ return `${before}${before.endsWith('\n') || !before ? '' : '\n'}.vercel/\n`;
125
+ }
@@ -2,12 +2,19 @@
2
2
  import type { Args } from './lib/cli.ts';
3
3
  export declare const spec: {
4
4
  readonly name: 'skills';
5
- readonly summary: "Install or update the project's miles-* skills from this package into .claude/skills/.";
5
+ readonly summary: "Install or update the project's miles-* skills from this package into .claude/skills/, and add any package.json script they call that the project lacks.";
6
6
  readonly flags: {};
7
- readonly output: '{ ok, installed: [name], into }';
7
+ readonly output: '{ ok, installed: [name], into, scripts: { added: [name] } }';
8
8
  };
9
9
  export declare function installSkills(from?: string, into?: string): string[];
10
+ /** The scripts a project's package.json carries, as the template writes them. The skills call them by these names. */
11
+ export declare const SCRIPTS: Record<string, string>;
12
+ /** Adds each missing script to the project's package.json; a script the project already has is never changed. */
13
+ export declare function addScripts(file?: string): string[];
10
14
  export declare function main(_args: Args<typeof spec>): {
11
15
  installed: string[];
12
16
  into: string;
17
+ scripts: {
18
+ added: string[];
19
+ };
13
20
  };
@@ -4,15 +4,17 @@
4
4
  // into the project's .claude/skills/, replacing what is there. The skills
5
5
  // ship with the package so a version bump updates them; a project never
6
6
  // edits its copies. `miles-design-hub` stays out: it starts a project from
7
- // outside one and is installed globally.
8
- import { cpSync, existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs';
7
+ // outside one and is installed globally. It also adds the package.json
8
+ // scripts a newer version's skills call, since an upgrade never touches the
9
+ // project's own files and a skill that runs `pnpm share` needs the script.
10
+ import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
9
11
  import { join } from 'node:path';
10
- import { PACKAGE_SKILLS, SKILLS } from '../server/paths.js';
12
+ import { PACKAGE_SKILLS, ROOT, SKILLS } from '../server/paths.js';
11
13
  export const spec = {
12
14
  name: 'skills',
13
- summary: "Install or update the project's miles-* skills from this package into .claude/skills/.",
15
+ summary: "Install or update the project's miles-* skills from this package into .claude/skills/, and add any package.json script they call that the project lacks.",
14
16
  flags: {},
15
- output: '{ ok, installed: [name], into }',
17
+ output: '{ ok, installed: [name], into, scripts: { added: [name] } }',
16
18
  };
17
19
  const GLOBAL_ONLY = new Set(['miles-design-hub']);
18
20
  /** Skills the package no longer ships, removed from a project on update. miles-conductor became miles-worktrees in 0.2.0. */
@@ -33,6 +35,46 @@ export function installSkills(from = PACKAGE_SKILLS, into = SKILLS) {
33
35
  }
34
36
  return names;
35
37
  }
38
+ /** The scripts a project's package.json carries, as the template writes them. The skills call them by these names. */
39
+ export const SCRIPTS = {
40
+ dev: 'design-hub dev',
41
+ build: 'design-hub build',
42
+ preview: 'design-hub preview',
43
+ export: 'design-hub export',
44
+ bootstrap: 'design-hub bootstrap',
45
+ new: 'design-hub new',
46
+ tracks: 'design-hub tracks',
47
+ guide: 'design-hub guide',
48
+ check: 'design-hub check',
49
+ fix: 'design-hub check --fix',
50
+ guard: 'design-hub guard',
51
+ preflight: 'design-hub preflight',
52
+ signin: 'design-hub signin',
53
+ share: 'design-hub share',
54
+ comments: 'design-hub comments',
55
+ people: 'design-hub people',
56
+ calibrate: 'design-hub calibrate',
57
+ 'fixtures-pull': 'design-hub fixtures-pull',
58
+ 'visual-match': 'design-hub visual-match',
59
+ elyx: 'design-hub elyx',
60
+ skills: 'design-hub skills',
61
+ commands: 'design-hub commands',
62
+ };
63
+ /** Adds each missing script to the project's package.json; a script the project already has is never changed. */
64
+ export function addScripts(file = join(ROOT, 'package.json')) {
65
+ if (!existsSync(file))
66
+ return [];
67
+ const pkg = JSON.parse(readFileSync(file, 'utf8'));
68
+ const scripts = pkg.scripts ?? {};
69
+ const added = Object.keys(SCRIPTS).filter((name) => !(name in scripts));
70
+ if (!added.length)
71
+ return [];
72
+ for (const name of added)
73
+ scripts[name] = SCRIPTS[name];
74
+ pkg.scripts = scripts;
75
+ writeFileSync(file, `${JSON.stringify(pkg, null, 2)}\n`);
76
+ return added;
77
+ }
36
78
  export function main(_args) {
37
- return { installed: installSkills(), into: SKILLS };
79
+ return { installed: installSkills(), into: SKILLS, scripts: { added: addScripts() } };
38
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milesroxas/design-hub",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the password gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -56,7 +56,7 @@ Signed in, it prints `signedIn: true` and the account. Signed out, it starts the
56
56
 
57
57
  ## Comments
58
58
 
59
- Ask the user once whether reviewers should comment on the link; ask before the first deploy, so one `bootstrap` carries `--review`. If yes, `--review [--typesafe-key <key>]` adds Upstash Redis to the project through the Vercel Marketplace and copies the store's credentials into `.env`. The first time on a team it can stop on the Marketplace terms: send the user the link in its `fix` to accept, then rerun. With TypeSafe on, comments are sorted by kind and state as they arrive. `pnpm share` after it, so the env reaches the site, then invite the first editor:
59
+ Ask the user once whether reviewers should comment on the link; ask before the first deploy, so one `bootstrap` carries `--review`. If yes, `--review [--typesafe-key <key>]` adds Upstash Redis to the project through the Vercel Marketplace and copies the store's credentials into `.env`. The first time on a team it can stop on the Marketplace terms. Send the user the message in its `fix` as written: it links that team's terms page, names the one product to pick (**Upstash for Redis**, Redis Compatible Database) when Vercel lists several, and tells them not to create a database there, since the rerun creates the store and connects it. Rerun when they say it is done; if `stderr` shows another cause, show it to them instead. With TypeSafe on, comments are sorted by kind and state as they arrive. `pnpm share` after it, so the env reaches the site, then invite the first editor:
60
60
 
61
61
  ```bash
62
62
  pnpm people invite --name "<user>" --team "<studio>" --role editor --site <share.url>
@@ -88,7 +88,7 @@ The user does nothing in a terminal here; each step that needs them is one link
88
88
 
89
89
  1. `pnpm --dir <path> signin`. Signed out, it prints a `url`: send it to the user to approve, then `pnpm --dir <path> signin --wait 300`.
90
90
  2. `vercel teams ls`; with more than one team, ask which with the question tool (personal account first when it is listed).
91
- 3. `pnpm --dir <path> bootstrap --vercel <name> --team <team-slug>`, plus `--review` for comments. It links the project, connects the GitHub repo, sets the password and turns Vercel's own login off. A first `--review` on a team can stop on the Marketplace terms: send the user the link in `fix`, then rerun.
91
+ 3. `pnpm --dir <path> bootstrap --vercel <name> --team <team-slug>`, plus `--review` for comments. It links the project, connects the GitHub repo, sets the password and turns Vercel's own login off. A first `--review` on a team can stop on the Marketplace terms: send the user the message in `fix` as written (it names **Upstash for Redis** as the product to pick), then rerun.
92
92
  4. `pnpm --dir <path> share --cli`. `--cli` uploads the folder, since the setup may have left files uncommitted; later deploys push `main`. On `ok: false`, follow `stage` and `fix` (the pre-flight steps are in `miles-deploy`).
93
93
  5. With comments: `pnpm --dir <path> people invite --name "<user>" --role editor --site <share.url>`.
94
94