@milesroxas/design-hub 0.2.0 → 0.4.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 (71) hide show
  1. package/README.md +1 -1
  2. package/core/catalog.test.ts +10 -1
  3. package/core/catalog.ts +11 -0
  4. package/core/cms.test.ts +103 -0
  5. package/core/cms.ts +178 -0
  6. package/core/export.test.ts +127 -0
  7. package/core/export.ts +120 -0
  8. package/core/formats.ts +60 -0
  9. package/core/project.test.ts +71 -0
  10. package/core/project.ts +147 -0
  11. package/dist/core/catalog.d.ts +5 -0
  12. package/dist/core/catalog.js +10 -0
  13. package/dist/core/cms.d.ts +40 -0
  14. package/dist/core/cms.js +141 -0
  15. package/dist/core/export.d.ts +52 -0
  16. package/dist/core/export.js +84 -0
  17. package/dist/core/formats.d.ts +90 -0
  18. package/dist/core/formats.js +39 -0
  19. package/dist/core/project.d.ts +56 -0
  20. package/dist/core/project.js +121 -0
  21. package/dist/scripts/bootstrap.d.ts +1 -1
  22. package/dist/scripts/bootstrap.js +38 -6
  23. package/dist/scripts/cli.js +8 -0
  24. package/dist/scripts/commands.js +8 -0
  25. package/dist/scripts/export.d.ts +42 -0
  26. package/dist/scripts/export.js +192 -0
  27. package/dist/scripts/fixtures-pull.d.ts +31 -19
  28. package/dist/scripts/fixtures-pull.js +102 -62
  29. package/dist/scripts/lib/cdp.d.ts +11 -0
  30. package/dist/scripts/lib/cdp.js +110 -0
  31. package/dist/scripts/lib/deploy.d.ts +76 -0
  32. package/dist/scripts/lib/deploy.js +94 -0
  33. package/dist/scripts/lib/vercel.d.ts +5 -0
  34. package/dist/scripts/lib/vercel.js +24 -0
  35. package/dist/scripts/new.d.ts +13 -1
  36. package/dist/scripts/new.js +43 -4
  37. package/dist/scripts/share.d.ts +63 -0
  38. package/dist/scripts/share.js +181 -0
  39. package/dist/scripts/signin.d.ts +31 -0
  40. package/dist/scripts/signin.js +119 -0
  41. package/dist/scripts/tracks.d.ts +40 -0
  42. package/dist/scripts/tracks.js +93 -0
  43. package/dist/server/paths.d.ts +2 -0
  44. package/dist/server/paths.js +2 -0
  45. package/dist/server/project.d.ts +7 -0
  46. package/dist/server/project.js +29 -0
  47. package/kit/Artboard.tsx +160 -0
  48. package/kit/artboard.css +47 -0
  49. package/kit/dials.tsx +2 -1
  50. package/package.json +1 -1
  51. package/shell/Index.tsx +49 -4
  52. package/shell/main.tsx +6 -2
  53. package/shell/shell.css +7 -3
  54. package/skills/miles-brand/SKILL.md +52 -0
  55. package/skills/miles-deploy/SKILL.md +26 -19
  56. package/skills/miles-design-hub/SKILL.md +77 -25
  57. package/skills/miles-get-hostile/SKILL.md +7 -5
  58. package/skills/miles-new-feature/SKILL.md +8 -7
  59. package/skills/miles-port/SKILL.md +14 -2
  60. package/skills/miles-port/references/emdash.md +43 -0
  61. package/skills/miles-port/references/payload.md +31 -0
  62. package/skills/miles-port/references/wordpress.md +31 -0
  63. package/skills/miles-prototype/SKILL.md +2 -2
  64. package/templates/app/README.md +1 -0
  65. package/templates/brand/README.md +48 -0
  66. package/templates/brand/index.tsx +16 -0
  67. package/templates/brand/styles.css +5 -0
  68. package/templates/site/README.md +42 -0
  69. package/templates/site/index.tsx +22 -0
  70. package/templates/site/styles.css +6 -0
  71. package/templates/space/README.md +1 -0
@@ -0,0 +1,76 @@
1
+ /** The device sign-in `vercel login` prints and then waits on. */
2
+ export declare function deviceLink(log: string): {
3
+ url: string;
4
+ code: string;
5
+ } | null;
6
+ /** The parts of `GET /v9/projects/<name>` a deploy reads. */
7
+ export type ProjectInfo = {
8
+ link?: {
9
+ type?: string;
10
+ repo?: string;
11
+ org?: string;
12
+ productionBranch?: string;
13
+ } | null;
14
+ targets?: {
15
+ production?: {
16
+ alias?: string[];
17
+ } | null;
18
+ } | null;
19
+ };
20
+ export declare const gitConnected: (info: ProjectInfo | null) => boolean;
21
+ /** The address a reviewer is sent: the first production alias (a custom domain when there is one). */
22
+ export declare function productionUrl(info: ProjectInfo | null, project: string): string;
23
+ export type Repo = {
24
+ connected: boolean;
25
+ branch: string | null;
26
+ productionBranch: string;
27
+ dirty: string[];
28
+ };
29
+ export type Plan = {
30
+ via: 'git';
31
+ branch: string;
32
+ } | {
33
+ via: 'cli';
34
+ reason: string;
35
+ } | {
36
+ error: string;
37
+ fix: string;
38
+ detail?: unknown;
39
+ };
40
+ /**
41
+ * A project connected to its repo deploys by pushing the production branch, so
42
+ * the deployment matches a commit; otherwise the CLI uploads the folder.
43
+ * Pushing is refused from another branch or with uncommitted changes, since
44
+ * neither would deploy what is on disk.
45
+ */
46
+ export declare function plan(repo: Repo, forceCli: boolean): Plan;
47
+ export type Answer = {
48
+ status: number;
49
+ location: string | null;
50
+ robots: string | null;
51
+ body: string;
52
+ };
53
+ export type Verdict = {
54
+ ok: true;
55
+ } | {
56
+ ok: false;
57
+ problem: string;
58
+ fix: string;
59
+ };
60
+ /** Whether the production URL answers a signed-out visitor with the hub's password page. */
61
+ export declare function gateVerdict(answer: Answer): Verdict;
62
+ export type Seen = {
63
+ url: string;
64
+ state: string;
65
+ } | null;
66
+ export type Next = {
67
+ done: string;
68
+ } | {
69
+ wait: true;
70
+ } | {
71
+ error: string;
72
+ fix: string;
73
+ deployment?: string;
74
+ };
75
+ /** One look at the deployment Vercel started for a pushed commit: done, keep waiting, or stop. */
76
+ export declare function nextStep(seen: Seen, sha: string, waitedMs: number): Next;
@@ -0,0 +1,94 @@
1
+ /// <reference types="node" />
2
+ // What `design-hub signin` and `design-hub share` decide, kept apart from the
3
+ // vercel and git calls that feed them so every branch is tested: the sign-in
4
+ // link in the CLI's log, which way a deploy goes, the production URL, and
5
+ // whether the deployed site answers with the gate.
6
+ /** The device sign-in `vercel login` prints and then waits on. */
7
+ export function deviceLink(log) {
8
+ const m = log.match(/https:\/\/vercel\.com\/oauth\/device\?user_code=([A-Z0-9-]+)/);
9
+ return m ? { url: m[0], code: m[1] } : null;
10
+ }
11
+ export const gitConnected = (info) => Boolean(info?.link?.repo);
12
+ /** The address a reviewer is sent: the first production alias (a custom domain when there is one). */
13
+ export function productionUrl(info, project) {
14
+ const alias = info?.targets?.production?.alias?.find((a) => !a.includes('-git-')) ?? `${project}.vercel.app`;
15
+ return `https://${alias}`;
16
+ }
17
+ /**
18
+ * A project connected to its repo deploys by pushing the production branch, so
19
+ * the deployment matches a commit; otherwise the CLI uploads the folder.
20
+ * Pushing is refused from another branch or with uncommitted changes, since
21
+ * neither would deploy what is on disk.
22
+ */
23
+ export function plan(repo, forceCli) {
24
+ if (forceCli)
25
+ return { via: 'cli', reason: '--cli' };
26
+ if (!repo.connected)
27
+ return { via: 'cli', reason: 'the Vercel project is not connected to a Git repo' };
28
+ if (repo.branch !== repo.productionBranch)
29
+ return {
30
+ error: `On ${repo.branch ?? 'a detached HEAD'}; production deploys from ${repo.productionBranch}.`,
31
+ fix: `Merge into ${repo.productionBranch} and run this from there, or pass --cli to upload this folder as production.`,
32
+ };
33
+ if (repo.dirty.length)
34
+ return {
35
+ error: 'Uncommitted changes would not deploy.',
36
+ fix: 'Commit them (ask the user first), then run this again.',
37
+ detail: { dirty: repo.dirty.slice(0, 20) },
38
+ };
39
+ return { via: 'git', branch: repo.productionBranch };
40
+ }
41
+ /** Whether the production URL answers a signed-out visitor with the hub's password page. */
42
+ export function gateVerdict(answer) {
43
+ if (answer.status >= 300 && answer.status < 400 && /vercel\.com/.test(answer.location ?? ''))
44
+ return {
45
+ ok: false,
46
+ problem: 'Visitors are sent to a Vercel login before the password page.',
47
+ fix: 'design-hub bootstrap --vercel <project> turns Vercel Authentication off; run it, then deploy again.',
48
+ };
49
+ if (answer.status === 503)
50
+ return {
51
+ ok: false,
52
+ problem: 'The gate answers 503: GATE_PASSWORD or GATE_SECRET is missing on the deployment.',
53
+ fix: 'design-hub bootstrap --vercel <project>, then deploy again so the env reaches the site.',
54
+ };
55
+ if (answer.status !== 401 || !/name="password"/.test(answer.body))
56
+ return {
57
+ ok: false,
58
+ problem: `Expected the password page (401), got ${answer.status}.`,
59
+ fix: 'Check that proxy.ts and vercel.json are the template’s, then deploy again.',
60
+ };
61
+ if (!/noindex/.test(answer.robots ?? ''))
62
+ return {
63
+ ok: false,
64
+ problem: 'X-Robots-Tag: noindex is missing.',
65
+ fix: 'Restore vercel.json from the template.',
66
+ };
67
+ return { ok: true };
68
+ }
69
+ const APPEAR_MS = 2 * 60_000;
70
+ const BUILD_MS = 10 * 60_000;
71
+ /** One look at the deployment Vercel started for a pushed commit: done, keep waiting, or stop. */
72
+ export function nextStep(seen, sha, waitedMs) {
73
+ const deployment = seen ? `https://${seen.url}` : undefined;
74
+ if (seen?.state === 'READY')
75
+ return { done: `https://${seen.url}` };
76
+ if (seen && ['ERROR', 'CANCELED'].includes(seen.state))
77
+ return {
78
+ error: `The deployment of ${sha.slice(0, 7)} ended ${seen.state}.`,
79
+ fix: `vercel inspect ${deployment} --logs shows the build log.`,
80
+ deployment,
81
+ };
82
+ if (!seen && waitedMs > APPEAR_MS)
83
+ return {
84
+ error: `Vercel started no deployment for ${sha.slice(0, 7)}.`,
85
+ fix: 'Check the Git connection under Project Settings, Git, or run design-hub share --cli.',
86
+ };
87
+ if (waitedMs > BUILD_MS)
88
+ return {
89
+ error: 'The build is still running after 10 minutes.',
90
+ fix: 'Run design-hub share again once it finishes; nothing is pushed twice.',
91
+ deployment,
92
+ };
93
+ return { wait: true };
94
+ }
@@ -1,3 +1,4 @@
1
+ import type { ProjectInfo } from './deploy.ts';
1
2
  export declare const ENVIRONMENTS: readonly ['production', 'preview'];
2
3
  export type Target = (typeof ENVIRONMENTS)[number] | 'development';
3
4
  /** What the Upstash for Redis integration injects (Vercel Marketplace). */
@@ -17,3 +18,7 @@ export declare function envNames(cwd: string, target: Target): Set<string> | nul
17
18
  export declare function setEnv(cwd: string, name: string, target: Target, value: string, force: boolean): Run | null;
18
19
  /** The gate variables missing from production or preview, or null when the CLI cannot say. */
19
20
  export declare function gateEnvMissing(cwd: string): string[] | null;
21
+ /** The signed-in account, or null when the CLI is missing or signed out. */
22
+ export declare function whoami(cwd: string): string | null;
23
+ /** `GET /v9/projects/<name>` through the CLI's own credentials, or null when it fails. */
24
+ export declare function projectInfo(cwd: string, project: string, scope: string | null): ProjectInfo | null;
@@ -54,3 +54,27 @@ export function gateEnvMissing(cwd) {
54
54
  }
55
55
  return missing;
56
56
  }
57
+ /** The signed-in account, or null when the CLI is missing or signed out. */
58
+ export function whoami(cwd) {
59
+ const out = vercel(cwd, ['whoami']);
60
+ if (out?.status !== 0)
61
+ return null;
62
+ return out.stdout.trim().split('\n').pop()?.trim() || null;
63
+ }
64
+ /** `GET /v9/projects/<name>` through the CLI's own credentials, or null when it fails. */
65
+ export function projectInfo(cwd, project, scope) {
66
+ const out = vercel(cwd, [
67
+ 'api',
68
+ `/v9/projects/${encodeURIComponent(project)}`,
69
+ '--raw',
70
+ ...(scope ? ['--scope', scope] : []),
71
+ ]);
72
+ if (out?.status !== 0)
73
+ return null;
74
+ try {
75
+ return JSON.parse(out.stdout);
76
+ }
77
+ catch {
78
+ return null;
79
+ }
80
+ }
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { type Track } from '../core/project.ts';
2
3
  import { type Args } from './lib/cli.ts';
3
4
  export declare const spec: {
4
5
  readonly name: 'new';
@@ -11,7 +12,12 @@ export declare const spec: {
11
12
  readonly flags: {
12
13
  readonly app: {
13
14
  readonly type: 'boolean';
14
- readonly description: 'Inside the product or site shell instead of the Space.';
15
+ readonly description: "Inside the track's shell (AppShell for product, SiteShell for website) instead of the Space.";
16
+ };
17
+ readonly track: {
18
+ readonly type: 'string';
19
+ readonly choices: readonly ["product", "website", "brand"];
20
+ readonly description: "The track it belongs to. Default: the project's only track; required when it has several.";
15
21
  };
16
22
  readonly sprint: {
17
23
  readonly type: 'boolean';
@@ -37,6 +43,12 @@ export declare const spec: {
37
43
  readonly output: '{ ok, created, url, next }';
38
44
  };
39
45
  type Kind = 'sprint' | 'alternate' | 'exploration';
46
+ /**
47
+ * The template folder: brand collateral is always a board of artboards;
48
+ * otherwise the Space, or the shell of the prototype's track. A project
49
+ * without tracks gets the product shell, as before.
50
+ */
51
+ export declare function templateFor(track: Track | '', app: boolean): string;
40
52
  /** The kind the flags ask for, refused when the feature's state does not allow it. */
41
53
  export declare function kindFor(flags: Pick<Args<typeof spec>['flags'], 'sprint' | 'alternate'>, feature: string, primary?: (f: string) => string | undefined): Kind;
42
54
  export declare function main(args: Args<typeof spec>): {
@@ -1,14 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  /// <reference types="node" />
3
3
  // Scaffolds a prototype from the package's templates/ (a Space, or --app inside the
4
- // shell), or a feature's walkthrough at docs/sprints/<feature>/guide.md.
4
+ // track's shell: AppShell for a product, SiteShell for a website), or a
5
+ // feature's walkthrough at docs/sprints/<feature>/guide.md.
5
6
  // A feature has one primary prototype (--sprint); --alternate is refused
6
7
  // until it exists, so the index always has a primary to show first.
7
8
  import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
8
9
  import { dirname, join, relative } from 'node:path';
9
10
  import { featureTitle, guideHref, SLUG } from '../core/feature.js';
11
+ import { TRACKS, trackFor } from '../core/project.js';
10
12
  import { devPort, readEnv } from '../server/env.js';
11
13
  import { DOCS, PROTOTYPES, ROOT, TEMPLATES } from '../server/paths.js';
14
+ import { readProject } from '../server/project.js';
12
15
  import { primaryOf } from './lib/catalog.js';
13
16
  import { CliError } from './lib/cli.js';
14
17
  export const spec = {
@@ -18,7 +21,15 @@ export const spec = {
18
21
  { name: 'slug', description: 'kebab-case folder name (with --guide: the feature)', required: true },
19
22
  ],
20
23
  flags: {
21
- app: { type: 'boolean', description: 'Inside the product or site shell instead of the Space.' },
24
+ app: {
25
+ type: 'boolean',
26
+ description: "Inside the track's shell (AppShell for product, SiteShell for website) instead of the Space.",
27
+ },
28
+ track: {
29
+ type: 'string',
30
+ choices: TRACKS,
31
+ description: "The track it belongs to. Default: the project's only track; required when it has several.",
32
+ },
22
33
  sprint: { type: 'boolean', description: "The feature's one primary prototype. Needs --feature." },
23
34
  alternate: {
24
35
  type: 'boolean',
@@ -61,6 +72,31 @@ function guide(feature) {
61
72
  next: `Write it from the States table. Screenshots go in docs/sprints/${feature}/assets/guide/.`,
62
73
  };
63
74
  }
75
+ /**
76
+ * The template folder: brand collateral is always a board of artboards;
77
+ * otherwise the Space, or the shell of the prototype's track. A project
78
+ * without tracks gets the product shell, as before.
79
+ */
80
+ export function templateFor(track, app) {
81
+ if (track === 'brand')
82
+ return 'brand';
83
+ if (!app)
84
+ return 'space';
85
+ return track === 'website' ? 'site' : 'app';
86
+ }
87
+ /** The prototype's track from --track and project.json, refused when the project cannot take it. */
88
+ function resolveTrack(asked) {
89
+ const { project, problems } = readProject();
90
+ if (problems.length)
91
+ throw new CliError('.design-hub/project.json is invalid.', {
92
+ problems,
93
+ fix: 'Rewrite it with design-hub tracks set --track <track>.',
94
+ });
95
+ const resolved = trackFor(project, asked);
96
+ if ('problem' in resolved)
97
+ throw new CliError(resolved.problem);
98
+ return resolved.track;
99
+ }
64
100
  /** The kind the flags ask for, refused when the feature's state does not allow it. */
65
101
  export function kindFor(flags, feature, primary = (f) => primaryOf(f)?.slug) {
66
102
  if (flags.sprint && flags.alternate)
@@ -90,17 +126,20 @@ function prototype(slug, { flags }) {
90
126
  if (feature && !SLUG.test(feature))
91
127
  throw new CliError('--feature takes a kebab-case slug.', { got: feature });
92
128
  const kind = kindFor(flags, feature);
93
- const context = flags.app ? 'app' : 'space';
94
- scaffold(join(TEMPLATES, context), join(PROTOTYPES, slug), {
129
+ const track = resolveTrack(flags.track);
130
+ const context = track === 'brand' ? 'board' : flags.app ? 'app' : 'space';
131
+ scaffold(join(TEMPLATES, templateFor(track, flags.app)), join(PROTOTYPES, slug), {
95
132
  title: flags.title ?? featureTitle(slug),
96
133
  slug,
97
134
  created: created(),
98
135
  kind,
99
136
  feature,
137
+ track,
100
138
  });
101
139
  return {
102
140
  created: `prototypes/${slug}/`,
103
141
  context,
142
+ track,
104
143
  kind,
105
144
  feature,
106
145
  url: localUrl(`/${slug}/`),
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ import { type Args } from './lib/cli.ts';
3
+ export declare const spec: {
4
+ readonly name: 'share';
5
+ readonly summary: 'Pre-flight, deploy to production, wait for the build, and check the live URL shows the password page. Returns the share details.';
6
+ readonly flags: {
7
+ readonly skip: {
8
+ readonly type: 'list';
9
+ readonly description: 'A pre-flight step to skip, only with the user’s word (design-hub preflight --help lists them).';
10
+ };
11
+ readonly cli: {
12
+ readonly type: 'boolean';
13
+ readonly description: 'Upload this folder with the Vercel CLI even when the project deploys on push.';
14
+ };
15
+ };
16
+ readonly output: '{ ok, via, deployment, url, gate, share: { url, password, open: [{ title, path, guide? }] }, review, next } or { ok: false, stage, ... }';
17
+ };
18
+ export declare function main({ flags }: Args<typeof spec>): Promise<{
19
+ ok: boolean;
20
+ stage: string;
21
+ error: string;
22
+ steps: {
23
+ step: "build" | "checks" | "contacts" | "elyx" | "gate" | "guides" | "lint" | "secrets" | "states" | "types";
24
+ ok: boolean;
25
+ skipped?: string;
26
+ detail?: unknown;
27
+ fix?: string;
28
+ }[];
29
+ fix: string;
30
+ via?: undefined;
31
+ deployment?: undefined;
32
+ url?: undefined;
33
+ } | {
34
+ steps?: undefined;
35
+ ok: boolean;
36
+ stage: string;
37
+ via: "cli" | "git";
38
+ deployment: string;
39
+ url: string;
40
+ error: string;
41
+ fix: string;
42
+ } | {
43
+ share: {
44
+ url: string;
45
+ password: string;
46
+ open: {
47
+ title: string;
48
+ path: string;
49
+ guide?: string | undefined;
50
+ }[];
51
+ };
52
+ review: string;
53
+ next: string;
54
+ steps?: undefined;
55
+ ok?: undefined;
56
+ stage?: undefined;
57
+ error?: undefined;
58
+ fix?: undefined;
59
+ via: "cli" | "git";
60
+ deployment: string;
61
+ url: string;
62
+ gate: string;
63
+ }>;
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env node
2
+ /// <reference types="node" />
3
+ // One command from a passing project to a link that works: the pre-flight,
4
+ // the deploy (a push when the Vercel project is connected to the repo, an
5
+ // upload otherwise), the wait for the build, and a signed-out request that
6
+ // must come back as the password page. It ends with what the handover needs.
7
+ import { spawnSync } from 'node:child_process';
8
+ import { existsSync } from 'node:fs';
9
+ import { join } from 'node:path';
10
+ import { isLive } from '../core/catalog.js';
11
+ import { readEnv } from '../server/env.js';
12
+ import { DOCS, ROOT } from '../server/paths.js';
13
+ import { prototypes } from './lib/catalog.js';
14
+ import { CliError } from './lib/cli.js';
15
+ import { gateVerdict, gitConnected, nextStep, plan, productionUrl, } from './lib/deploy.js';
16
+ import { linkedOrg, linkedProject, projectInfo, STORE_ENV, vercel, whoami } from './lib/vercel.js';
17
+ import * as preflight from './preflight.js';
18
+ export const spec = {
19
+ name: 'share',
20
+ summary: 'Pre-flight, deploy to production, wait for the build, and check the live URL shows the password page. Returns the share details.',
21
+ flags: {
22
+ skip: {
23
+ type: 'list',
24
+ description: 'A pre-flight step to skip, only with the user’s word (design-hub preflight --help lists them).',
25
+ },
26
+ cli: {
27
+ type: 'boolean',
28
+ description: 'Upload this folder with the Vercel CLI even when the project deploys on push.',
29
+ },
30
+ },
31
+ output: '{ ok, via, deployment, url, gate, share: { url, password, open: [{ title, path, guide? }] }, review, next } or { ok: false, stage, ... }',
32
+ };
33
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
34
+ function git(args) {
35
+ const r = spawnSync('git', ['-C', ROOT, ...args], { encoding: 'utf8' });
36
+ return { ok: r.status === 0, out: (r.stdout ?? '').trim(), err: (r.stderr ?? '').trim() };
37
+ }
38
+ function deploymentFor(project, scope, sha) {
39
+ const out = vercel(ROOT, [
40
+ 'list',
41
+ project,
42
+ '--json',
43
+ '--limit',
44
+ '1',
45
+ '--environment',
46
+ 'production',
47
+ '-m',
48
+ `githubCommitSha=${sha}`,
49
+ ...(scope ? ['--scope', scope] : []),
50
+ ]);
51
+ if (out?.status !== 0)
52
+ return null;
53
+ try {
54
+ return JSON.parse(out.stdout).deployments[0] ?? null;
55
+ }
56
+ catch {
57
+ return null;
58
+ }
59
+ }
60
+ /** Pushes the branch and follows the deployment Vercel starts for that commit. */
61
+ async function viaGit(project, scope, branch) {
62
+ const sha = git(['rev-parse', 'HEAD']).out;
63
+ const push = git(['push', 'origin', branch]);
64
+ if (!push.ok)
65
+ throw new CliError(`git push origin ${branch} failed.`, { stderr: push.err.slice(-600) });
66
+ const start = Date.now();
67
+ for (;;) {
68
+ const step = nextStep(deploymentFor(project, scope, sha), sha, Date.now() - start);
69
+ if ('done' in step)
70
+ return step.done;
71
+ if ('error' in step)
72
+ throw new CliError(step.error, { fix: step.fix, deployment: step.deployment });
73
+ await sleep(5000);
74
+ }
75
+ }
76
+ function viaCli() {
77
+ const out = vercel(ROOT, ['deploy', '--prod', '--yes']);
78
+ if (!out)
79
+ throw new CliError('The Vercel CLI is not installed.', { fix: 'npm i -g vercel' });
80
+ const url = `${out.stdout}\n${out.stderr}`.match(/https:\/\/[\w.-]+\.vercel\.app/)?.[0];
81
+ if (out.status !== 0 || !url)
82
+ throw new CliError('vercel deploy --prod failed.', { stderr: out.stderr.trim().slice(-600) });
83
+ return url;
84
+ }
85
+ /** A signed-out request for the home page, the way a reviewer first meets the link. */
86
+ async function smoke(url) {
87
+ try {
88
+ const res = await fetch(`${url}/`, { redirect: 'manual' });
89
+ return gateVerdict({
90
+ status: res.status,
91
+ location: res.headers.get('location'),
92
+ robots: res.headers.get('x-robots-tag'),
93
+ body: await res.text(),
94
+ });
95
+ }
96
+ catch (error) {
97
+ return {
98
+ ok: false,
99
+ problem: `Could not reach ${url}: ${error instanceof Error ? error.message : error}`,
100
+ fix: 'Open the URL in a private window; a new domain can take a minute to resolve.',
101
+ };
102
+ }
103
+ }
104
+ /** What a reviewer is sent to open: each live sprint and its walkthrough. */
105
+ function opens() {
106
+ return prototypes()
107
+ .filter((p) => isLive(p) && p.kind === 'sprint')
108
+ .map((p) => ({
109
+ title: p.title,
110
+ path: `/${p.slug}/`,
111
+ ...(p.feature && existsSync(join(DOCS, 'sprints', p.feature, 'guide.md'))
112
+ ? { guide: `/guide/${p.feature}/` }
113
+ : {}),
114
+ }));
115
+ }
116
+ /** The signed-in CLI and the linked project, or the fix for whichever is missing. */
117
+ function target() {
118
+ if (!whoami(ROOT))
119
+ throw new CliError('The Vercel CLI is not installed or not signed in.', {
120
+ fix: 'design-hub signin, send the user its url, then run this again.',
121
+ });
122
+ const project = linkedProject(ROOT);
123
+ if (!project)
124
+ throw new CliError('This folder is not linked to a Vercel project.', {
125
+ fix: 'design-hub bootstrap --vercel <project> --team <team>',
126
+ });
127
+ return { project, scope: linkedOrg(ROOT) };
128
+ }
129
+ function repo(info) {
130
+ const branch = git(['rev-parse', '--abbrev-ref', 'HEAD']).out;
131
+ const status = git(['status', '--porcelain']).out;
132
+ return {
133
+ connected: gitConnected(info) && git(['remote', 'get-url', 'origin']).ok,
134
+ branch: branch && branch !== 'HEAD' ? branch : null,
135
+ productionBranch: info?.link?.productionBranch ?? 'main',
136
+ dirty: status ? status.split('\n') : [],
137
+ };
138
+ }
139
+ /**
140
+ * Deploys by the route the plan chose. A push the remote already has starts no
141
+ * build, but a deploy after an env change still needs one, so that uploads.
142
+ */
143
+ async function deploy(route, project, scope) {
144
+ if ('error' in route)
145
+ throw new CliError(route.error, { stage: 'deploy', fix: route.fix, ...(route.detail ?? {}) });
146
+ const head = git(['rev-parse', 'HEAD']).out;
147
+ const remote = route.via === 'git' ? git(['ls-remote', 'origin', `refs/heads/${route.branch}`]).out.split(/\s/)[0] : '';
148
+ if (route.via === 'git' && remote !== head)
149
+ return { via: 'git', deployment: await viaGit(project, scope, route.branch) };
150
+ return { via: 'cli', deployment: viaCli() };
151
+ }
152
+ function handover(url) {
153
+ const env = readEnv(ROOT);
154
+ const review = STORE_ENV.every((n) => env[n]) ? 'on' : 'off';
155
+ return {
156
+ share: { url, password: env.GATE_PASSWORD ?? null, open: opens() },
157
+ review,
158
+ next: review === 'on'
159
+ ? `Send the handover (miles-deploy). First share with comments: design-hub people invite --name "<user>" --role editor --site ${url}.`
160
+ : 'Send the handover (miles-deploy). Never send GATE_SECRET.',
161
+ };
162
+ }
163
+ export async function main({ flags }) {
164
+ const { project, scope } = target();
165
+ const checked = await preflight.main({ flags: { skip: flags.skip, 'allow-contact': [] }, positionals: [] });
166
+ if (!checked.ok)
167
+ return {
168
+ ok: false,
169
+ stage: 'preflight',
170
+ error: 'The pre-flight failed; nothing was deployed.',
171
+ steps: checked.steps.filter((s) => !s.ok),
172
+ fix: 'Fix each step (miles-deploy says how), then run this again.',
173
+ };
174
+ const info = projectInfo(ROOT, project, scope);
175
+ const { via, deployment } = await deploy(plan(repo(info), flags.cli), project, scope);
176
+ const url = productionUrl(projectInfo(ROOT, project, scope) ?? info, project);
177
+ const gate = await smoke(url);
178
+ if (!gate.ok)
179
+ return { ok: false, stage: 'gate', via, deployment, url, error: gate.problem, fix: gate.fix };
180
+ return { via, deployment, url, gate: 'ok', ...handover(url) };
181
+ }
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ import { type Args } from './lib/cli.ts';
3
+ export declare const spec: {
4
+ readonly name: 'signin';
5
+ readonly summary: 'Sign the Vercel CLI in from a link the user clicks. Returns the link at once; --wait blocks until signed in.';
6
+ readonly flags: {
7
+ readonly wait: {
8
+ readonly type: 'number';
9
+ readonly description: 'Seconds to wait for the user to approve the link. Absent, return the link without waiting.';
10
+ };
11
+ };
12
+ readonly output: '{ ok, signedIn, user? } or { ok, signedIn: false, url, code, next }';
13
+ };
14
+ export declare function main({ flags }: Args<typeof spec>): Promise<{
15
+ signedIn: boolean;
16
+ user: string;
17
+ } | {
18
+ user?: undefined;
19
+ url: string;
20
+ code: string;
21
+ signedIn: boolean;
22
+ next: string;
23
+ } | {
24
+ user?: undefined;
25
+ url: string;
26
+ code: string;
27
+ ok: boolean;
28
+ signedIn: boolean;
29
+ error: string;
30
+ fix: string;
31
+ }>;