@milesroxas/design-hub 0.9.0 → 0.11.0

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 (150) hide show
  1. package/README.md +13 -11
  2. package/core/controls.test.ts +176 -0
  3. package/core/controls.ts +195 -0
  4. package/core/files.test.ts +76 -0
  5. package/core/files.ts +131 -0
  6. package/core/prototype.test.ts +124 -7
  7. package/core/prototype.ts +133 -24
  8. package/core/review/model.ts +144 -2
  9. package/core/review/policy.test.ts +79 -22
  10. package/core/review/policy.ts +36 -8
  11. package/core/review/service.test.ts +1525 -322
  12. package/core/review/service.ts +810 -183
  13. package/core/review/store.test.ts +91 -0
  14. package/core/review/store.ts +143 -26
  15. package/dist/core/controls.d.ts +55 -0
  16. package/dist/core/controls.js +174 -0
  17. package/dist/core/files.d.ts +39 -0
  18. package/dist/core/files.js +107 -0
  19. package/dist/core/prototype.d.ts +61 -12
  20. package/dist/core/prototype.js +105 -26
  21. package/dist/core/review/model.d.ts +87 -2
  22. package/dist/core/review/model.js +97 -1
  23. package/dist/core/review/policy.d.ts +11 -4
  24. package/dist/core/review/policy.js +14 -2
  25. package/dist/core/review/service.d.ts +222 -43
  26. package/dist/core/review/service.js +727 -182
  27. package/dist/core/review/store.d.ts +84 -24
  28. package/dist/core/review/store.js +66 -26
  29. package/dist/scripts/bootstrap.d.ts +4 -34
  30. package/dist/scripts/bootstrap.js +9 -244
  31. package/dist/scripts/cli.js +6 -0
  32. package/dist/scripts/client.d.ts +45 -0
  33. package/dist/scripts/client.js +320 -0
  34. package/dist/scripts/commands.js +6 -0
  35. package/dist/scripts/comments.d.ts +8 -26
  36. package/dist/scripts/comments.js +27 -14
  37. package/dist/scripts/guard.d.ts +11 -0
  38. package/dist/scripts/guard.js +44 -0
  39. package/dist/scripts/lib/builds.d.ts +40 -0
  40. package/dist/scripts/lib/builds.js +198 -0
  41. package/dist/scripts/lib/cli.js +3 -1
  42. package/dist/scripts/lib/deploy.d.ts +6 -90
  43. package/dist/scripts/lib/deploy.js +24 -137
  44. package/dist/scripts/lib/dns.d.ts +49 -0
  45. package/dist/scripts/lib/dns.js +141 -0
  46. package/dist/scripts/lib/fake-host.d.ts +168 -0
  47. package/dist/scripts/lib/fake-host.js +244 -0
  48. package/dist/scripts/lib/host.d.ts +87 -0
  49. package/dist/scripts/lib/host.js +362 -0
  50. package/dist/scripts/lib/linked.d.ts +51 -0
  51. package/dist/scripts/lib/linked.js +124 -0
  52. package/dist/scripts/lib/names.d.ts +35 -0
  53. package/dist/scripts/lib/names.js +77 -0
  54. package/dist/scripts/lib/review.d.ts +23 -2
  55. package/dist/scripts/lib/review.js +32 -15
  56. package/dist/scripts/lib/rules.d.ts +1 -0
  57. package/dist/scripts/lib/rules.js +1 -0
  58. package/dist/scripts/lib/studio-deps.d.ts +35 -0
  59. package/dist/scripts/lib/studio-deps.js +79 -0
  60. package/dist/scripts/lib/studios.d.ts +70 -0
  61. package/dist/scripts/lib/studios.js +187 -0
  62. package/dist/scripts/lib/update.d.ts +33 -0
  63. package/dist/scripts/lib/update.js +40 -0
  64. package/dist/scripts/lib/vercel.d.ts +1 -23
  65. package/dist/scripts/lib/vercel.js +6 -81
  66. package/dist/scripts/people.d.ts +7 -11
  67. package/dist/scripts/people.js +51 -46
  68. package/dist/scripts/preflight.d.ts +8 -1
  69. package/dist/scripts/preflight.js +36 -19
  70. package/dist/scripts/project.d.ts +86 -0
  71. package/dist/scripts/project.js +141 -0
  72. package/dist/scripts/share.d.ts +105 -30
  73. package/dist/scripts/share.js +82 -154
  74. package/dist/scripts/skills.d.ts +18 -2
  75. package/dist/scripts/skills.js +22 -3
  76. package/dist/scripts/studio.d.ts +75 -0
  77. package/dist/scripts/studio.js +401 -0
  78. package/dist/scripts/upgrade.d.ts +10 -2
  79. package/dist/scripts/upgrade.js +44 -14
  80. package/dist/server/api.d.ts +22 -11
  81. package/dist/server/api.js +125 -44
  82. package/dist/server/blob.d.ts +10 -0
  83. package/dist/server/blob.js +53 -0
  84. package/dist/server/checks.js +2 -2
  85. package/dist/server/dev.js +4 -4
  86. package/dist/server/env.d.ts +2 -0
  87. package/dist/server/env.js +9 -0
  88. package/dist/server/fake-upstash.js +52 -3
  89. package/dist/server/hosts.d.ts +11 -0
  90. package/dist/server/hosts.js +31 -0
  91. package/dist/server/local.d.ts +7 -1
  92. package/dist/server/local.js +10 -1
  93. package/dist/server/mark.d.ts +41 -0
  94. package/dist/server/mark.js +111 -0
  95. package/dist/server/session.d.ts +17 -9
  96. package/dist/server/session.js +22 -45
  97. package/dist/server/upstash.js +20 -0
  98. package/dist/vercel/files.d.ts +11 -0
  99. package/dist/vercel/files.js +68 -0
  100. package/dist/vercel/index.d.ts +4 -3
  101. package/dist/vercel/index.js +12 -8
  102. package/dist/vercel/proxy.d.ts +69 -4
  103. package/dist/vercel/proxy.js +171 -107
  104. package/dist/vite/plugin.d.ts +24 -1
  105. package/dist/vite/plugin.js +46 -2
  106. package/kit/Artboard.tsx +21 -8
  107. package/kit/Space.tsx +4 -3
  108. package/kit/Variants.tsx +193 -65
  109. package/kit/ViewTools.tsx +77 -11
  110. package/kit/audience.ts +85 -0
  111. package/kit/dials.css +59 -0
  112. package/kit/dials.tsx +272 -35
  113. package/kit/harness.css +34 -0
  114. package/kit/prefs.ts +23 -1
  115. package/package.json +3 -2
  116. package/shell/ClientViewNote.tsx +31 -3
  117. package/shell/Guide.tsx +11 -5
  118. package/shell/Index.tsx +32 -10
  119. package/shell/Notice.tsx +1 -1
  120. package/shell/controls.ts +26 -0
  121. package/shell/hub.ts +5 -1
  122. package/shell/main.tsx +33 -6
  123. package/shell/review/Review.tsx +2 -2
  124. package/shell/review/ThreadCard.tsx +5 -5
  125. package/shell/review/client.ts +28 -11
  126. package/shell/review/view.test.ts +19 -0
  127. package/shell/review/view.ts +25 -0
  128. package/shell/shell.css +8 -0
  129. package/shell/studio/ClientHub.tsx +98 -0
  130. package/shell/studio/hub.css +48 -0
  131. package/shell/studio/index.html +14 -0
  132. package/shell/studio/main.tsx +17 -0
  133. package/skills/miles-brand/SKILL.md +11 -1
  134. package/skills/miles-deploy/SKILL.md +121 -64
  135. package/skills/miles-design-hub/SKILL.md +11 -9
  136. package/skills/miles-prototype/SKILL.md +34 -1
  137. package/skills/miles-review/SKILL.md +5 -7
  138. package/skills/miles-worktrees/SKILL.md +3 -3
  139. package/templates/conductor/settings.toml +1 -1
  140. package/templates/studio/.env.example +9 -0
  141. package/templates/studio/.vercelignore +5 -0
  142. package/templates/studio/README.md +84 -0
  143. package/templates/studio/_gitignore +7 -0
  144. package/templates/studio/api/files.ts +4 -0
  145. package/templates/studio/api/review.ts +4 -0
  146. package/templates/studio/build.mjs +4 -0
  147. package/templates/studio/package.json +16 -0
  148. package/templates/studio/proxy.ts +4 -0
  149. package/templates/studio/studio.json +9 -0
  150. package/templates/studio/vercel.json +27 -0
@@ -1,73 +1,15 @@
1
1
  /// <reference types="node" />
2
- // The Vercel CLI calls the scripts make, in one place. Each returns null when
3
- // the CLI is missing or signed out, so a caller decides whether that is a
4
- // failure (bootstrap --vercel) or a skipped check (preflight).
2
+ // The Vercel CLI, called the one way the scripts call it: `vercel` returns
3
+ // null when the CLI is missing, so a caller decides whether that is a
4
+ // failure, and `whoami` names the signed-in account. The studio's host
5
+ // adapter (host.ts) and `design-hub signin` are its callers.
5
6
  import { spawnSync } from 'node:child_process';
6
- import { existsSync, readFileSync } from 'node:fs';
7
- import { join } from 'node:path';
8
- export const ENVIRONMENTS = ['production', 'preview'];
9
- /** What the gate needs: the secret that signs each person's session. */
10
- const GATE_ENV = ['GATE_SECRET'];
11
- /** What the Upstash for Redis integration injects (Vercel Marketplace). */
12
- export const STORE_ENV = ['KV_REST_API_URL', 'KV_REST_API_TOKEN'];
13
- export function vercel(cwd, args, input) {
14
- const out = spawnSync('vercel', args, { cwd, encoding: 'utf8', input, env: process.env });
7
+ export function vercel(cwd, args, input, env = process.env) {
8
+ const out = spawnSync('vercel', args, { cwd, encoding: 'utf8', input, env });
15
9
  if (out.error)
16
10
  return null;
17
11
  return { status: out.status ?? 1, stdout: out.stdout ?? '', stderr: out.stderr ?? '' };
18
12
  }
19
- function readLink(cwd) {
20
- const file = join(cwd, '.vercel', 'project.json');
21
- if (!existsSync(file))
22
- return null;
23
- try {
24
- return JSON.parse(readFileSync(file, 'utf8'));
25
- }
26
- catch {
27
- return null;
28
- }
29
- }
30
- export const linkedProject = (cwd) => readLink(cwd)?.projectName ?? null;
31
- /** The team the linked project belongs to. The commands that take a project name instead of the link need it as `--scope`. */
32
- export const linkedOrg = (cwd) => readLink(cwd)?.orgId ?? null;
33
- /** The variable names set for a target, read from `vercel env ls`'s table. */
34
- export function envNames(cwd, target) {
35
- const out = vercel(cwd, ['env', 'ls', target]);
36
- if (out?.status !== 0)
37
- return null;
38
- return new Set([...out.stdout.matchAll(/^\s*([A-Z][A-Z0-9_]*)\s/gm)].map((m) => m[1]));
39
- }
40
- /** Adds one variable for one target that does not have it yet. */
41
- export function setEnv(cwd, name, target, value) {
42
- // The value goes on stdin, never argv, so it stays out of the process list.
43
- return vercel(cwd, ['env', 'add', name, target, '--yes'], value);
44
- }
45
- /** The Upstash console's names for the same store; server/upstash.ts reads either pair. */
46
- const UPSTASH_ENV = ['UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN'];
47
- /**
48
- * What the gate needs that a target lacks, as `NAME:target`: the secret, and
49
- * the review store, without which nobody can sign in, since it keeps the
50
- * people and their links. Null when a target's names could not be read.
51
- */
52
- export function missingGateEnv(names) {
53
- const missing = [];
54
- for (const target of ENVIRONMENTS) {
55
- const have = names[target];
56
- if (!have)
57
- return null;
58
- for (const name of GATE_ENV)
59
- if (!have.has(name))
60
- missing.push(`${name}:${target}`);
61
- const store = [STORE_ENV, UPSTASH_ENV].some((pair) => pair.every((n) => have.has(n)));
62
- if (!store)
63
- missing.push(...STORE_ENV.filter((n) => !have.has(n)).map((n) => `${n}:${target}`));
64
- }
65
- return missing;
66
- }
67
- /** The gate variables missing from production or preview, or null when the CLI cannot say. */
68
- export function gateEnvMissing(cwd) {
69
- return missingGateEnv({ production: envNames(cwd, 'production'), preview: envNames(cwd, 'preview') });
70
- }
71
13
  /** The signed-in account, or null when the CLI is missing or signed out. */
72
14
  export function whoami(cwd) {
73
15
  const out = vercel(cwd, ['whoami']);
@@ -75,20 +17,3 @@ export function whoami(cwd) {
75
17
  return null;
76
18
  return out.stdout.trim().split('\n').pop()?.trim() || null;
77
19
  }
78
- /** `GET /v9/projects/<name>` through the CLI's own credentials, or null when it fails. */
79
- export function projectInfo(cwd, project, scope) {
80
- const out = vercel(cwd, [
81
- 'api',
82
- `/v9/projects/${encodeURIComponent(project)}`,
83
- '--raw',
84
- ...(scope ? ['--scope', scope] : []),
85
- ]);
86
- if (out?.status !== 0)
87
- return null;
88
- try {
89
- return JSON.parse(out.stdout);
90
- }
91
- catch {
92
- return null;
93
- }
94
- }
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { type Args } from './lib/cli.ts';
3
+ import { type ProjectDeps } from './lib/linked.ts';
3
4
  export declare const spec: {
4
5
  readonly name: 'people';
5
6
  readonly summary: 'List or add the people who comment on the deployed prototypes, give them sign-in links, sign them out, revoke them, and set how long they keep access.';
6
7
  readonly positionals: [{
7
8
  readonly name: 'action';
8
- readonly description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the project default, or sets it with --access.';
9
+ readonly description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the default a new Client gets (the client’s own, else the studio’s), or sets the client’s with --access.';
9
10
  }, {
10
11
  readonly name: 'id';
11
12
  readonly description: 'The person, for link, sign-out, revoke and access';
@@ -28,19 +29,14 @@ export declare const spec: {
28
29
  readonly access: {
29
30
  readonly type: 'string';
30
31
  readonly choices: readonly ["3m", "6m", "open"];
31
- readonly description: 'How long they keep access: 3m, 6m or open. For add, absent means the project default for a client and open for studio.';
32
- };
33
- readonly site: {
34
- readonly type: 'string';
35
- readonly description: 'The deployed URL, so the link prints whole.';
32
+ readonly description: 'How long they keep access: 3m, 6m or open. For add, absent means the client’s default for a client (people access reads it) and open for studio.';
36
33
  };
37
34
  readonly local: {
38
35
  readonly type: 'boolean';
39
- readonly description: 'Use the local dev store even when the deployed one is configured.';
36
+ readonly description: 'Use this machine’s dev store, even in a project linked to a studio.';
40
37
  };
41
38
  };
42
- readonly output: '{ ok, store, people } or { ok, store, person, link } or { ok, store, person } or { ok, store, access }';
39
+ readonly output: '{ ok, store, studio?, people } or { ok, store, studio?, person, link, next?, notice? } or { ok, store, studio?, person } or { ok, store, studio?, access }; store is studio in a linked project, with studio: { studio, client, host, project }, and notice when a Studio person is added there; local otherwise';
43
40
  };
44
- export declare function main({ positionals: [action, id], flags }: Args<typeof spec>): Promise<{
45
- store: "deployed" | "local";
46
- }>;
41
+ export declare function run({ positionals: [action, id], flags }: Args<typeof spec>, deps: ProjectDeps): Promise<Record<string, unknown>>;
42
+ export declare const main: (args: Args<typeof spec>) => Promise<Record<string, unknown>>;
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  /// <reference types="node" />
3
- // The people who comment on the deployed prototypes. The first Studio person
4
- // is added from here; after that, Studio adds people from the People tab.
5
- // Each person signs in with a one-time link: it signs in one device, then
6
- // stops working, so a second device needs a new link.
3
+ // The people who comment on a project's prototypes in its studio: its
4
+ // client's people, each signing in with a one-time link on the client's own
5
+ // host. A link signs in one device, then stops working, so a second device
6
+ // needs a new link. Studio also adds people from the People tab. Without a
7
+ // link to a studio, and with --local, they are this machine's dev store's,
8
+ // whose links open nothing anywhere.
7
9
  import { ACCESS, PERSON_KINDS } from '../core/review/model.js';
8
10
  import { CliError } from './lib/cli.js';
11
+ import { realProjectDeps } from './lib/linked.js';
9
12
  import { cliActor, cliReview } from './lib/review.js';
10
13
  export const spec = {
11
14
  name: 'people',
@@ -13,7 +16,7 @@ export const spec = {
13
16
  positionals: [
14
17
  {
15
18
  name: 'action',
16
- description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the project default, or sets it with --access.',
19
+ description: 'list (default): everyone. add: a new person and their link. link <id>: another one-time link, for another device. sign-out <id>: ends every session and unused link, and gives one new link. revoke <id>: ends their access everywhere. access [id]: with an id and --access, sets that person’s access from now; without an id, reads the default a new Client gets (the client’s own, else the studio’s), or sets the client’s with --access.',
17
20
  },
18
21
  { name: 'id', description: 'The person, for link, sign-out, revoke and access' },
19
22
  ],
@@ -29,26 +32,24 @@ export const spec = {
29
32
  access: {
30
33
  type: 'string',
31
34
  choices: ACCESS,
32
- description: 'How long they keep access: 3m, 6m or open. For add, absent means the project default for a client and open for studio.',
35
+ description: 'How long they keep access: 3m, 6m or open. For add, absent means the client’s default for a client (people access reads it) and open for studio.',
33
36
  },
34
- site: { type: 'string', description: 'The deployed URL, so the link prints whole.' },
35
37
  local: {
36
38
  type: 'boolean',
37
- description: 'Use the local dev store even when the deployed one is configured.',
39
+ description: 'Use this machine’s dev store, even in a project linked to a studio.',
38
40
  },
39
41
  },
40
- output: '{ ok, store, people } or { ok, store, person, link } or { ok, store, person } or { ok, store, access }',
42
+ output: '{ ok, store, studio?, people } or { ok, store, studio?, person, link, next?, notice? } or { ok, store, studio?, person } or { ok, store, studio?, access }; store is studio in a linked project, with studio: { studio, client, host, project }, and notice when a Studio person is added there; local otherwise',
41
43
  };
42
- const linkFor = (token, site) => {
44
+ /** A link on the client's own host; a local one is a path the dev server never asks for. */
45
+ const linkFor = (token, host) => {
43
46
  const path = `/invite/${token}`;
44
- if (!site)
45
- return { link: path, next: 'Prefix the link with the deployed URL, or pass --site <url>.' };
46
- try {
47
- return { link: new URL(path, site).href };
48
- }
49
- catch {
50
- throw new CliError('--site takes a URL.', { got: site });
51
- }
47
+ if (!host)
48
+ return {
49
+ link: path,
50
+ next: 'A local link signs in nowhere: the dev server has no sign-in. Link the project to a studio (design-hub project link) for links people can use.',
51
+ };
52
+ return { link: `https://${host}${path}` };
52
53
  };
53
54
  const strip = ({ epoch: _e, ...rest }) => rest;
54
55
  function needId(action, id) {
@@ -56,51 +57,55 @@ function needId(action, id) {
56
57
  throw new CliError(`Name the person: pnpm people ${action} <id>.`, { fix: 'pnpm people lists ids.' });
57
58
  return id;
58
59
  }
59
- const withLink = (r, site) => ({
60
+ const withLink = (r, host) => ({
60
61
  person: strip(r.person),
61
- ...linkFor(r.token, site),
62
+ ...linkFor(r.token, host),
62
63
  });
63
- /** One person's access with an id, else the project default: read it, or set it with --access. */
64
- async function access({ review, actor, flags, id }) {
64
+ /** One person's access with an id, else the default for a new Client: read it, or set it with --access. */
65
+ async function access({ review, scope, actor, flags, id }) {
65
66
  if (id) {
66
67
  if (!flags.access)
67
68
  throw new CliError('Say how long: pnpm people access <id> --access 3m|6m|open.');
68
- return { person: strip(await review.setAccess(actor, id, flags.access)) };
69
+ return { person: strip(await review.setAccess(scope, actor, id, flags.access)) };
69
70
  }
70
71
  return {
71
72
  access: flags.access
72
- ? await review.setDefaultAccess(actor, flags.access)
73
- : await review.defaultAccess(actor),
73
+ ? await review.setDefaultAccess(scope, actor, flags.access)
74
+ : await review.defaultAccess(scope, actor),
74
75
  };
75
76
  }
77
+ /** What adding a Studio person in a linked project means, in plain words. */
78
+ const studioWide = ({ studio, client, host }) => `A Studio person sees every client of studio ${studio}, not only ${client}: every project, comment and person. This link signs them in on ${host}. For someone who should see ${client} alone, add them with --kind client.`;
76
79
  const ACTIONS = {
77
- list: async ({ review, actor }) => ({ people: (await review.listPeople(actor)).map(strip) }),
78
- add: async ({ review, actor, flags }) => withLink(await review.addPerson(actor, {
80
+ list: async ({ review, scope, actor }) => ({ people: (await review.listPeople(scope, actor)).map(strip) }),
81
+ add: async ({ review, scope, actor, flags, host }) => withLink(await review.addPerson(scope, actor, {
79
82
  name: flags.name,
80
83
  team: flags.team,
81
84
  kind: flags.kind,
82
85
  access: flags.access,
83
- }), flags.site),
84
- link: async ({ review, actor, flags, id }) => withLink(await review.newLink(actor, needId('link', id)), flags.site),
85
- 'sign-out': async ({ review, actor, flags, id }) => withLink(await review.signOutEverywhere(actor, needId('sign-out', id)), flags.site),
86
- revoke: async ({ review, actor, id }) => ({
87
- person: strip(await review.revoke(actor, needId('revoke', id))),
86
+ }), host),
87
+ link: async ({ review, scope, actor, id, host }) => withLink(await review.newLink(scope, actor, needId('link', id)), host),
88
+ 'sign-out': async ({ review, scope, actor, id, host }) => withLink(await review.signOutEverywhere(scope, actor, needId('sign-out', id)), host),
89
+ revoke: async ({ review, scope, actor, id }) => ({
90
+ person: strip(await review.revoke(scope, actor, needId('revoke', id))),
88
91
  }),
89
92
  access,
90
93
  };
91
- export async function main({ positionals: [action = 'list', id], flags }) {
92
- const run = Object.hasOwn(ACTIONS, action) ? ACTIONS[action] : undefined;
93
- if (!run)
94
+ export async function run({ positionals: [action = 'list', id], flags }, deps) {
95
+ const act = Object.hasOwn(ACTIONS, action) ? ACTIONS[action] : undefined;
96
+ if (!act)
94
97
  throw new CliError(`Unknown action ${action}.`, { fix: 'list, add, link, sign-out, revoke or access' });
95
- if (flags.local && flags.site)
96
- throw new CliError('--local and --site do not go together: a local link opens nothing on the deployed site.', {
97
- fix: 'Drop --site for a local link, or drop --local to use the deployed store.',
98
- });
99
- const { review, store } = cliReview(flags.local);
100
- // A link made in the local store opens nothing on the deployed site, so never print one under its URL.
101
- if (flags.site && store === 'local')
102
- throw new CliError('--site names the deployed site, but its store is not configured here.', {
103
- fix: 'KV_REST_API_URL and KV_REST_API_TOKEN are missing from .env: pnpm bootstrap --vercel <project> --review puts them there. For a local link, pass --local without --site.',
104
- });
105
- return { store, ...(await run({ review, actor: cliActor(), flags, id })) };
98
+ const found = await cliReview(flags.local, deps);
99
+ const { review, store, scope } = found;
100
+ // A linked project's links sign in on its client's own host, and nowhere else.
101
+ const done = await act({ review, scope, actor: cliActor(), flags, id, host: found.studio?.host });
102
+ return {
103
+ store,
104
+ ...(found.studio ? { studio: found.studio } : {}),
105
+ ...done,
106
+ ...(found.studio && action === 'add' && flags.kind === 'studio'
107
+ ? { notice: studioWide(found.studio) }
108
+ : {}),
109
+ };
106
110
  }
111
+ export const main = (args) => run(args, realProjectDeps());
@@ -2,6 +2,7 @@
2
2
  import { type OnDisk } from './lib/catalog.ts';
3
3
  import type { Args } from './lib/cli.ts';
4
4
  import { judge } from './lib/judge.ts';
5
+ import { type ProjectDeps } from './lib/linked.ts';
5
6
  export declare const STEPS: readonly ['checks', 'types', 'lint', 'build', 'elyx', 'guides', 'states', 'contacts', 'gate', 'secrets'];
6
7
  type StepName = (typeof STEPS)[number];
7
8
  export declare const spec: {
@@ -28,7 +29,13 @@ type Step = {
28
29
  };
29
30
  export declare function states(all: OnDisk[], ask?: typeof judge): Promise<Step>;
30
31
  export declare function contacts(all: OnDisk[], allow: Set<string>, ask?: typeof judge): Promise<Step>;
31
- export declare function main({ flags }: Args<typeof spec>): Promise<{
32
+ /**
33
+ * In a project linked to a studio: the studio agrees with the link (its
34
+ * database, the client, the project) and its file store's token is in the
35
+ * studio folder, so a share can go up. Null in a project with no link.
36
+ */
37
+ export declare function studioGate(deps: ProjectDeps): Promise<Step | null>;
38
+ export declare function main({ flags }: Args<typeof spec>, deps?: ProjectDeps): Promise<{
32
39
  ok: boolean;
33
40
  steps: Step[];
34
41
  }>;
@@ -17,8 +17,8 @@ import { build } from './dev.js';
17
17
  import * as elyxCommand from './elyx.js';
18
18
  import { prototypes } from './lib/catalog.js';
19
19
  import { judge } from './lib/judge.js';
20
+ import { addressOf, openLinked, readLink, realProjectDeps } from './lib/linked.js';
20
21
  import { NOULS } from './lib/rules.js';
21
- import { gateEnvMissing } from './lib/vercel.js';
22
22
  export const STEPS = [
23
23
  'checks',
24
24
  'types',
@@ -177,25 +177,42 @@ function elyx() {
177
177
  };
178
178
  }
179
179
  }
180
- function gate() {
181
- if (!existsSync(join(ROOT, '.vercel', 'project.json')))
180
+ /**
181
+ * In a project linked to a studio: the studio agrees with the link (its
182
+ * database, the client, the project) and its file store's token is in the
183
+ * studio folder, so a share can go up. Null in a project with no link.
184
+ */
185
+ export async function studioGate(deps) {
186
+ try {
187
+ const link = readLink(deps.root);
188
+ if (!link)
189
+ return null;
190
+ const { studio, client } = await openLinked(deps, link);
191
+ deps.files(studio);
192
+ const { project } = link;
193
+ const address = addressOf(client, project);
194
+ return { step: 'gate', ok: true, detail: { studio: link.studio, client: client.slug, project, address } };
195
+ }
196
+ catch (error) {
197
+ const fix = error.detail?.fix;
182
198
  return {
183
- step: 'gate',
184
- ok: true,
185
- skipped: 'not linked to Vercel yet',
186
- fix: 'design-hub bootstrap --vercel <project> --review',
187
- };
188
- const missing = gateEnvMissing(ROOT);
189
- if (missing === null)
190
- return { step: 'gate', ok: true, skipped: 'vercel CLI unavailable or signed out' };
191
- return missing.length
192
- ? {
193
199
  step: 'gate',
194
200
  ok: false,
195
- detail: { missing },
196
- fix: 'pnpm bootstrap --vercel <project> --review sets GATE_SECRET and adds the review store, which keeps the people and their links: without it nobody can sign in.',
197
- }
198
- : { step: 'gate', ok: true };
201
+ detail: error instanceof Error ? error.message : String(error),
202
+ fix: typeof fix === 'string' ? fix : 'Check the studio this project is linked to, then run this again.',
203
+ };
204
+ }
205
+ }
206
+ async function gate(deps) {
207
+ const linked = await studioGate(deps);
208
+ if (linked)
209
+ return linked;
210
+ return {
211
+ step: 'gate',
212
+ ok: true,
213
+ skipped: 'not linked to a studio yet',
214
+ fix: 'design-hub project link --studio <slug> --client <slug> --project <slug>',
215
+ };
199
216
  }
200
217
  function secrets() {
201
218
  const ignored = spawnSync('git', ['-C', ROOT, 'check-ignore', '-q', '.env']).status === 0;
@@ -221,7 +238,7 @@ function allowContacts(values) {
221
238
  }
222
239
  return allow;
223
240
  }
224
- export async function main({ flags }) {
241
+ export async function main({ flags }, deps = realProjectDeps()) {
225
242
  const skip = new Set(flags.skip);
226
243
  const all = prototypes();
227
244
  const allow = allowContacts(flags['allow-contact']);
@@ -241,7 +258,7 @@ export async function main({ flags }) {
241
258
  guides: () => guides(all),
242
259
  states: () => states(all),
243
260
  contacts: () => contacts(all, allow),
244
- gate,
261
+ gate: () => gate(deps),
245
262
  secrets,
246
263
  };
247
264
  const steps = [];
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ import { type Args } from './lib/cli.ts';
3
+ import { type ProjectDeps } from './lib/linked.ts';
4
+ export declare const spec: {
5
+ readonly name: 'project';
6
+ readonly summary: 'Link this project to a client of a studio: makes the project in the studio and writes .design-hub/studio.json, which share, people and comments then act through.';
7
+ readonly positionals: [{
8
+ readonly name: 'action';
9
+ readonly required: true;
10
+ readonly description: 'link: the project in the studio under --client, and .design-hub/studio.json naming it. Run again with the same flags, on any machine that lists the studio, it keeps both.';
11
+ }];
12
+ readonly flags: {
13
+ readonly studio: {
14
+ readonly type: 'string';
15
+ readonly required: true;
16
+ readonly description: 'The studio’s slug, as this machine lists it (design-hub studio link lists a studio folder).';
17
+ };
18
+ readonly client: {
19
+ readonly type: 'string';
20
+ readonly required: true;
21
+ readonly description: 'The client the project is for, by slug.';
22
+ };
23
+ readonly project: {
24
+ readonly type: 'string';
25
+ readonly required: true;
26
+ readonly description: `The project’s slug, its path on the client’s host (/<project>/): kebab-case, never ${string}.`;
27
+ };
28
+ readonly name: {
29
+ readonly type: 'string';
30
+ readonly description: 'The project’s name in the client’s hub. Absent, the slug.';
31
+ };
32
+ };
33
+ readonly output: '{ ok, studio, client, project: { slug, name }, record: created | kept, file, gitignore: added | kept | unknown | ignored, fix? (with ignored: the .gitignore rule to change), address, next }';
34
+ };
35
+ export declare function run({ positionals: [action], flags }: Args<typeof spec>, deps: ProjectDeps): Promise<{
36
+ gitignore: 'added' | 'kept' | 'unknown';
37
+ studio: string;
38
+ client: string;
39
+ project: {
40
+ slug: string;
41
+ name: string;
42
+ };
43
+ record: string;
44
+ file: string;
45
+ address: string;
46
+ next: string;
47
+ } | {
48
+ gitignore: 'ignored';
49
+ fix: string;
50
+ studio: string;
51
+ client: string;
52
+ project: {
53
+ slug: string;
54
+ name: string;
55
+ };
56
+ record: string;
57
+ file: string;
58
+ address: string;
59
+ next: string;
60
+ }>;
61
+ export declare const main: (args: Args<typeof spec>) => Promise<{
62
+ gitignore: 'added' | 'kept' | 'unknown';
63
+ studio: string;
64
+ client: string;
65
+ project: {
66
+ slug: string;
67
+ name: string;
68
+ };
69
+ record: string;
70
+ file: string;
71
+ address: string;
72
+ next: string;
73
+ } | {
74
+ gitignore: 'ignored';
75
+ fix: string;
76
+ studio: string;
77
+ client: string;
78
+ project: {
79
+ slug: string;
80
+ name: string;
81
+ };
82
+ record: string;
83
+ file: string;
84
+ address: string;
85
+ next: string;
86
+ }>;
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ /// <reference types="node" />
3
+ // A project's place in a studio. `project link` names the studio, the client
4
+ // and the project's slug, makes the project's record in the studio's store
5
+ // under that client, and writes `.design-hub/studio.json` (no secrets) to be
6
+ // committed, so `share`, `people` and `comments` act there from any machine
7
+ // that lists the studio. A project is served at `/<project>/` on its client's
8
+ // own host; it has no deployment of its own.
9
+ import { spawnSync } from 'node:child_process';
10
+ import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
11
+ import { join } from 'node:path';
12
+ import { isProjectSlug, RESERVED } from '../core/prototype.js';
13
+ import { isStudioClient, STUDIO_CLIENT_SLUG } from '../core/review/model.js';
14
+ import { localStudio } from '../server/local.js';
15
+ import { CliError } from './lib/cli.js';
16
+ import { addressOf, inStudio, LINK_FILE, readLink, realProjectDeps, writeLink, } from './lib/linked.js';
17
+ export const spec = {
18
+ name: 'project',
19
+ summary: 'Link this project to a client of a studio: makes the project in the studio and writes .design-hub/studio.json, which share, people and comments then act through.',
20
+ positionals: [
21
+ {
22
+ name: 'action',
23
+ required: true,
24
+ description: 'link: the project in the studio under --client, and .design-hub/studio.json naming it. Run again with the same flags, on any machine that lists the studio, it keeps both.',
25
+ },
26
+ ],
27
+ flags: {
28
+ studio: {
29
+ type: 'string',
30
+ required: true,
31
+ description: 'The studio’s slug, as this machine lists it (design-hub studio link lists a studio folder).',
32
+ },
33
+ client: { type: 'string', required: true, description: 'The client the project is for, by slug.' },
34
+ project: {
35
+ type: 'string',
36
+ required: true,
37
+ description: `The project’s slug, its path on the client’s host (/<project>/): kebab-case, never ${RESERVED.filter((r) => !r.includes('.')).join(', ')}.`,
38
+ },
39
+ name: { type: 'string', description: 'The project’s name in the client’s hub. Absent, the slug.' },
40
+ },
41
+ output: '{ ok, studio, client, project: { slug, name }, record: created | kept, file, gitignore: added | kept | unknown | ignored, fix? (with ignored: the .gitignore rule to change), address, next }',
42
+ };
43
+ const PROJECT_SLUG = `project: kebab-case, and not ${RESERVED.join(', ')}`;
44
+ /** Whether git ignores the link: 'yes', 'no', or 'unknown' when git cannot say (no git, or not a repo). */
45
+ function gitIgnores(root) {
46
+ const { status } = spawnSync('git', ['-C', root, 'check-ignore', '-q', LINK_FILE]);
47
+ return status === 0 ? 'yes' : status === 1 ? 'no' : 'unknown';
48
+ }
49
+ /** What `git check-ignore -v` says ignores the link: its file, line and pattern, when git names one. */
50
+ function ruleOf(root) {
51
+ const out = spawnSync('git', ['-C', root, 'check-ignore', '-v', LINK_FILE], { encoding: 'utf8' }).stdout ?? '';
52
+ const [, source, line, pattern] = out.match(/^(.*):(\d+):(.*)\t/) ?? [];
53
+ return source ? { source, line, pattern } : null;
54
+ }
55
+ /** What to change so git includes the link, naming the rule git reports, whatever it is. */
56
+ function ruleFix(root) {
57
+ const rule = ruleOf(root);
58
+ const named = rule ? `${rule.source} line ${rule.line} (${rule.pattern})` : 'a rule git has';
59
+ // git never takes a file back from inside an ignored folder, so a folder rule needs its files instead.
60
+ const folder = rule && /^\/?\.design-hub\/?$/.test(rule.pattern)
61
+ ? ' (it ignores the whole folder: make it .design-hub/*, the folder’s files, not the folder)'
62
+ : '';
63
+ return `${named} ignores ${LINK_FILE}, and the project’s .gitignore cannot take it back. Change that rule so git includes ${LINK_FILE}${folder}, then run this again: it names the link in the project’s .gitignore.`;
64
+ }
65
+ /**
66
+ * Keeps the link committed: when git ignores it, the project's own
67
+ * .gitignore names it (`!.design-hub/studio.json`), which git honours over
68
+ * a parent folder's .gitignore and this clone's exclude files, but not over
69
+ * a rule that ignores the whole `.design-hub/` folder (git never takes a file
70
+ * back from inside an ignored folder), a later line of the same file, or a
71
+ * .gitignore nearer the link. The line goes in once, and stays only if git
72
+ * then includes the link; otherwise the .gitignore is put back as it was and
73
+ * the answer names the rule git reports, to change. No .gitignore is made
74
+ * unless git ignores the link.
75
+ */
76
+ function keepCommitted(root) {
77
+ const before = gitIgnores(root);
78
+ if (before !== 'yes')
79
+ return { gitignore: before === 'no' ? 'kept' : 'unknown' };
80
+ const file = join(root, '.gitignore');
81
+ const had = existsSync(file);
82
+ const text = had ? readFileSync(file, 'utf8') : '';
83
+ const line = `!${LINK_FILE}`;
84
+ if (!text.split(/\r?\n/).includes(line)) {
85
+ writeFileSync(file, `${text}${text && !text.endsWith('\n') ? '\n' : ''}${line}\n`);
86
+ if (gitIgnores(root) === 'no')
87
+ return { gitignore: 'added' };
88
+ if (had)
89
+ writeFileSync(file, text);
90
+ else
91
+ rmSync(file);
92
+ }
93
+ return { gitignore: 'ignored', fix: ruleFix(root) };
94
+ }
95
+ const sameSlugs = (l, flags) => l.studio === flags.studio && l.client === flags.client && l.project === flags.project;
96
+ async function link(flags, deps) {
97
+ if (!isStudioClient(flags.client))
98
+ throw new CliError(`${flags.client} cannot be a client.`, { problems: [STUDIO_CLIENT_SLUG] });
99
+ if (!isProjectSlug(flags.project))
100
+ throw new CliError(`${flags.project} cannot be a project.`, { problems: [PROJECT_SLUG] });
101
+ const before = readLink(deps.root);
102
+ if (before && !sameSlugs(before, flags))
103
+ throw new CliError(`This project is linked to studio ${before.studio}, client ${before.client}, project ${before.project}; nothing was changed.`, {
104
+ code: 'linked_elsewhere',
105
+ fix: `To move it, delete ${LINK_FILE} and run this again. What it shared there stays until that client is archived.`,
106
+ });
107
+ // Linked before, the studio listed under the slug must be the one of the link's id.
108
+ const { studio, review, client } = await inStudio(deps, flags.studio, before?.id ?? null, flags.client);
109
+ // Its database's mark was checked against the studio's id, so the id is there.
110
+ const linked = {
111
+ studio: studio.config.slug,
112
+ id: String(studio.config.id),
113
+ client: client.slug,
114
+ project: flags.project,
115
+ };
116
+ const scope = { client: client.slug, project: flags.project };
117
+ const kept = await review.projectOf(scope);
118
+ const made = kept ??
119
+ (await review.addProject({ client: client.slug }, localStudio('cli', 'CLI'), {
120
+ slug: flags.project,
121
+ name: flags.name ?? flags.project,
122
+ }));
123
+ writeLink(deps.root, linked);
124
+ const committed = keepCommitted(deps.root);
125
+ return {
126
+ studio: studio.config.slug,
127
+ client: client.slug,
128
+ project: { slug: made.slug, name: made.name },
129
+ record: kept ? 'kept' : 'created',
130
+ file: LINK_FILE,
131
+ ...committed,
132
+ address: addressOf(client, made.slug),
133
+ next: `${committed.gitignore === 'ignored' ? 'Change that .gitignore rule (fix), then commit' : 'Commit'} ${LINK_FILE}. Then design-hub share builds the project and uploads it to the address, which opens once it has.`,
134
+ };
135
+ }
136
+ export async function run({ positionals: [action], flags }, deps) {
137
+ if (action !== 'link')
138
+ throw new CliError(`Unknown action ${action}.`, { fix: 'link' });
139
+ return link(flags, deps);
140
+ }
141
+ export const main = (args) => run(args, realProjectDeps());