@milesroxas/design-hub 0.10.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.
- package/README.md +13 -11
- package/core/files.test.ts +76 -0
- package/core/files.ts +131 -0
- package/core/prototype.test.ts +124 -7
- package/core/prototype.ts +133 -24
- package/core/review/model.ts +119 -2
- package/core/review/policy.test.ts +79 -22
- package/core/review/policy.ts +36 -8
- package/core/review/service.test.ts +1464 -340
- package/core/review/service.ts +777 -191
- package/core/review/store.test.ts +91 -0
- package/core/review/store.ts +143 -33
- package/dist/core/files.d.ts +39 -0
- package/dist/core/files.js +107 -0
- package/dist/core/prototype.d.ts +61 -12
- package/dist/core/prototype.js +105 -26
- package/dist/core/review/model.d.ts +76 -2
- package/dist/core/review/model.js +76 -1
- package/dist/core/review/policy.d.ts +11 -4
- package/dist/core/review/policy.js +14 -2
- package/dist/core/review/service.d.ts +197 -45
- package/dist/core/review/service.js +702 -192
- package/dist/core/review/store.d.ts +84 -31
- package/dist/core/review/store.js +66 -33
- package/dist/scripts/bootstrap.d.ts +4 -34
- package/dist/scripts/bootstrap.js +9 -244
- package/dist/scripts/cli.js +6 -0
- package/dist/scripts/client.d.ts +45 -0
- package/dist/scripts/client.js +320 -0
- package/dist/scripts/commands.js +6 -0
- package/dist/scripts/comments.d.ts +8 -26
- package/dist/scripts/comments.js +27 -14
- package/dist/scripts/lib/builds.d.ts +40 -0
- package/dist/scripts/lib/builds.js +198 -0
- package/dist/scripts/lib/cli.js +3 -1
- package/dist/scripts/lib/deploy.d.ts +6 -90
- package/dist/scripts/lib/deploy.js +24 -137
- package/dist/scripts/lib/dns.d.ts +49 -0
- package/dist/scripts/lib/dns.js +141 -0
- package/dist/scripts/lib/fake-host.d.ts +168 -0
- package/dist/scripts/lib/fake-host.js +244 -0
- package/dist/scripts/lib/host.d.ts +87 -0
- package/dist/scripts/lib/host.js +362 -0
- package/dist/scripts/lib/linked.d.ts +51 -0
- package/dist/scripts/lib/linked.js +124 -0
- package/dist/scripts/lib/names.d.ts +35 -0
- package/dist/scripts/lib/names.js +77 -0
- package/dist/scripts/lib/review.d.ts +23 -2
- package/dist/scripts/lib/review.js +32 -15
- package/dist/scripts/lib/studio-deps.d.ts +35 -0
- package/dist/scripts/lib/studio-deps.js +79 -0
- package/dist/scripts/lib/studios.d.ts +70 -0
- package/dist/scripts/lib/studios.js +187 -0
- package/dist/scripts/lib/update.d.ts +33 -0
- package/dist/scripts/lib/update.js +40 -0
- package/dist/scripts/lib/vercel.d.ts +1 -23
- package/dist/scripts/lib/vercel.js +6 -81
- package/dist/scripts/people.d.ts +7 -11
- package/dist/scripts/people.js +51 -46
- package/dist/scripts/preflight.d.ts +8 -1
- package/dist/scripts/preflight.js +36 -19
- package/dist/scripts/project.d.ts +86 -0
- package/dist/scripts/project.js +141 -0
- package/dist/scripts/share.d.ts +105 -30
- package/dist/scripts/share.js +82 -154
- package/dist/scripts/skills.d.ts +18 -2
- package/dist/scripts/skills.js +22 -3
- package/dist/scripts/studio.d.ts +75 -0
- package/dist/scripts/studio.js +401 -0
- package/dist/scripts/upgrade.d.ts +10 -2
- package/dist/scripts/upgrade.js +44 -14
- package/dist/server/api.d.ts +22 -11
- package/dist/server/api.js +114 -46
- package/dist/server/blob.d.ts +10 -0
- package/dist/server/blob.js +53 -0
- package/dist/server/checks.js +2 -2
- package/dist/server/dev.js +4 -4
- package/dist/server/env.d.ts +2 -0
- package/dist/server/env.js +9 -0
- package/dist/server/fake-upstash.js +52 -3
- package/dist/server/hosts.d.ts +11 -0
- package/dist/server/hosts.js +31 -0
- package/dist/server/local.d.ts +7 -1
- package/dist/server/local.js +10 -1
- package/dist/server/mark.d.ts +41 -0
- package/dist/server/mark.js +111 -0
- package/dist/server/session.d.ts +17 -9
- package/dist/server/session.js +22 -45
- package/dist/server/upstash.js +20 -0
- package/dist/vercel/files.d.ts +11 -0
- package/dist/vercel/files.js +68 -0
- package/dist/vercel/index.d.ts +4 -3
- package/dist/vercel/index.js +12 -8
- package/dist/vercel/proxy.d.ts +69 -4
- package/dist/vercel/proxy.js +171 -107
- package/dist/vite/plugin.d.ts +24 -1
- package/dist/vite/plugin.js +46 -2
- package/kit/dials.tsx +2 -2
- package/package.json +2 -1
- package/shell/Guide.tsx +11 -5
- package/shell/Index.tsx +32 -10
- package/shell/Notice.tsx +1 -1
- package/shell/controls.ts +1 -1
- package/shell/hub.ts +5 -1
- package/shell/main.tsx +18 -3
- package/shell/review/Review.tsx +2 -2
- package/shell/review/ThreadCard.tsx +5 -5
- package/shell/review/client.ts +28 -11
- package/shell/review/view.test.ts +19 -0
- package/shell/review/view.ts +25 -0
- package/shell/shell.css +4 -0
- package/shell/studio/ClientHub.tsx +98 -0
- package/shell/studio/hub.css +48 -0
- package/shell/studio/index.html +14 -0
- package/shell/studio/main.tsx +17 -0
- package/skills/miles-deploy/SKILL.md +120 -65
- package/skills/miles-design-hub/SKILL.md +11 -9
- package/skills/miles-review/SKILL.md +5 -7
- package/skills/miles-worktrees/SKILL.md +3 -3
- package/templates/conductor/settings.toml +1 -1
- package/templates/studio/.env.example +9 -0
- package/templates/studio/.vercelignore +5 -0
- package/templates/studio/README.md +84 -0
- package/templates/studio/_gitignore +7 -0
- package/templates/studio/api/files.ts +4 -0
- package/templates/studio/api/review.ts +4 -0
- package/templates/studio/build.mjs +4 -0
- package/templates/studio/package.json +16 -0
- package/templates/studio/proxy.ts +4 -0
- package/templates/studio/studio.json +9 -0
- package/templates/studio/vercel.json +27 -0
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
import type { Scope } from '../../core/review/model.ts';
|
|
1
2
|
import { type Review } from '../../core/review/service.ts';
|
|
3
|
+
import { type ProjectDeps } from './linked.ts';
|
|
4
|
+
/** Where a linked project's command acts: the studio, the client and its host, and the project. */
|
|
5
|
+
type Where = {
|
|
6
|
+
studio: string;
|
|
7
|
+
client: string;
|
|
8
|
+
host: string;
|
|
9
|
+
project: string;
|
|
10
|
+
};
|
|
2
11
|
export type CliReview = {
|
|
3
12
|
review: Review;
|
|
4
|
-
store: '
|
|
13
|
+
store: 'local';
|
|
14
|
+
scope: Scope;
|
|
15
|
+
studio?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
review: Review;
|
|
18
|
+
store: 'studio';
|
|
19
|
+
scope: Scope;
|
|
20
|
+
studio: Where;
|
|
5
21
|
};
|
|
6
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The store a review command acts on, and the scope it acts in: a linked
|
|
24
|
+
* project's studio, else this machine's. --local is always this machine's.
|
|
25
|
+
*/
|
|
26
|
+
export declare function cliReview(local: boolean, deps?: ProjectDeps): Promise<CliReview>;
|
|
7
27
|
export declare const cliActor: () => import("../../core/review/model.ts").Person;
|
|
28
|
+
export {};
|
|
@@ -1,22 +1,39 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
// The review service from the command line: the deployed store when its
|
|
3
|
-
// credentials are in .env (`design-hub bootstrap --review` puts them there), else
|
|
4
|
-
// the local one the dev server uses. The CLI acts as Studio, because
|
|
5
|
-
// whoever holds the store's credentials can already do anything to it.
|
|
6
1
|
import { createReview } from '../../core/review/service.js';
|
|
7
2
|
import { jevTriager } from '../../core/review/triage.js';
|
|
8
3
|
import { checks } from '../../server/checks.js';
|
|
9
4
|
import { readEnv } from '../../server/env.js';
|
|
10
5
|
import { fileKV } from '../../server/file-kv.js';
|
|
11
|
-
import { LOCAL_STORE, localStudio } from '../../server/local.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const triage = jevTriager(
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
import { LOCAL_SCOPE, LOCAL_STORE, localStudio } from '../../server/local.js';
|
|
7
|
+
import { CliError } from './cli.js';
|
|
8
|
+
import { openLinked, readLink, realProjectDeps } from './linked.js';
|
|
9
|
+
import { isStudioFolder } from './studios.js';
|
|
10
|
+
/** This machine's store, the dev server's, in its one scope. */
|
|
11
|
+
function localReview(root) {
|
|
12
|
+
const triage = jevTriager(readEnv(root).TYPESAFE_API_KEY ?? '', checks);
|
|
13
|
+
return { review: createReview(fileKV(LOCAL_STORE), { triage }), store: 'local', scope: LOCAL_SCOPE };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The store a review command acts on, and the scope it acts in: a linked
|
|
17
|
+
* project's studio, else this machine's. --local is always this machine's.
|
|
18
|
+
*/
|
|
19
|
+
export async function cliReview(local, deps = realProjectDeps()) {
|
|
20
|
+
if (local)
|
|
21
|
+
return localReview(deps.root);
|
|
22
|
+
const link = readLink(deps.root);
|
|
23
|
+
if (!link) {
|
|
24
|
+
if (isStudioFolder(deps.root))
|
|
25
|
+
throw new CliError('This is a studio folder: people and comments belong to a project linked to it.', {
|
|
26
|
+
code: 'studio_folder',
|
|
27
|
+
fix: 'Run this in the project, once it is linked: design-hub project link --studio <slug> --client <slug> --project <slug>. A client’s first person comes from design-hub client add.',
|
|
28
|
+
});
|
|
29
|
+
return localReview(deps.root);
|
|
30
|
+
}
|
|
31
|
+
const { review, scope, client } = await openLinked(deps, link);
|
|
32
|
+
return {
|
|
33
|
+
review,
|
|
34
|
+
store: 'studio',
|
|
35
|
+
scope,
|
|
36
|
+
studio: { studio: link.studio, client: client.slug, host: client.host, project: link.project },
|
|
37
|
+
};
|
|
21
38
|
}
|
|
22
39
|
export const cliActor = () => localStudio('cli', 'CLI');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Files } from '../../core/files.ts';
|
|
2
|
+
import type { Client } from '../../core/review/model.ts';
|
|
3
|
+
import { type Review } from '../../core/review/service.ts';
|
|
4
|
+
import type { KV } from '../../core/review/store.ts';
|
|
5
|
+
import { type Dns } from './dns.ts';
|
|
6
|
+
import { type Host } from './host.ts';
|
|
7
|
+
import { type Names } from './names.ts';
|
|
8
|
+
import { type Studio, type StudioConfig } from './studios.ts';
|
|
9
|
+
import type { Run } from './vercel.ts';
|
|
10
|
+
export type StudioDeps = {
|
|
11
|
+
/** This machine's design-hub folder, which holds the studio list. */
|
|
12
|
+
home: string;
|
|
13
|
+
/** Where the command runs, so a studio folder names its own studio. */
|
|
14
|
+
cwd: string;
|
|
15
|
+
host(dir: string, config: StudioConfig): Host;
|
|
16
|
+
dns(studio: Studio, host: Host): Dns;
|
|
17
|
+
/** Whether a host is served by its DNS yet, asked of its zone's own nameservers before any system lookup of it. */
|
|
18
|
+
names: Names;
|
|
19
|
+
/** The studio's review store, as its `.env` names it, unchecked: a command opens it with openReview. */
|
|
20
|
+
store(studio: Studio): KV;
|
|
21
|
+
/** The review service's clock; tests move it. */
|
|
22
|
+
now?: () => Date;
|
|
23
|
+
files(studio: Studio): Files;
|
|
24
|
+
/** pnpm with these arguments in the studio folder, its output captured; null when pnpm is missing. */
|
|
25
|
+
pnpm(dir: string, args: string[]): Run | null;
|
|
26
|
+
};
|
|
27
|
+
export declare function realDeps(): StudioDeps;
|
|
28
|
+
/**
|
|
29
|
+
* The studio's review service, once its database is shown to be this
|
|
30
|
+
* studio's: the one way a command reads or changes a studio's clients,
|
|
31
|
+
* people and links, so none can act on another studio's.
|
|
32
|
+
*/
|
|
33
|
+
export declare function openReview(deps: StudioDeps, studio: Studio): Promise<Review>;
|
|
34
|
+
/** The client's record, or null when the studio has none; a store that does not answer is an error, never "none". */
|
|
35
|
+
export declare const recordOf: (review: Review, slug: string) => Promise<Client | null>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
// What the studio and client commands run against, built from a studio's
|
|
3
|
+
// folder: its host (Vercel, in its own team), its DNS adapter, its review
|
|
4
|
+
// store and its file store, each from the folder's own `.env`, how a host is
|
|
5
|
+
// seen to be served by its DNS, and pnpm in the folder. Tests hand the
|
|
6
|
+
// commands fakes of the same shape instead. A command reaches the review
|
|
7
|
+
// store only through openReview, which first checks that the database is
|
|
8
|
+
// this studio's (server/mark.ts).
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
import { createReview, ReviewError } from '../../core/review/service.js';
|
|
11
|
+
import { blobFiles } from '../../server/blob.js';
|
|
12
|
+
import { readEnv } from '../../server/env.js';
|
|
13
|
+
import { localStudio } from '../../server/local.js';
|
|
14
|
+
import { mustBeOwnDatabase } from '../../server/mark.js';
|
|
15
|
+
import { storeConfig, upstashKV } from '../../server/upstash.js';
|
|
16
|
+
import { CliError } from './cli.js';
|
|
17
|
+
import { cloudflareDns, manualDns, wildcardDns } from './dns.js';
|
|
18
|
+
import { vercelHost } from './host.js';
|
|
19
|
+
import { authoritativeNames } from './names.js';
|
|
20
|
+
import { BLOB_NAME, CLOUDFLARE_NAME, homeDir } from './studios.js';
|
|
21
|
+
const pull = (dir) => ({
|
|
22
|
+
fix: `design-hub studio link --dir ${dir} reads it back from the studio's Production env.`,
|
|
23
|
+
});
|
|
24
|
+
export function realDeps() {
|
|
25
|
+
return {
|
|
26
|
+
home: homeDir(),
|
|
27
|
+
cwd: process.cwd(),
|
|
28
|
+
host: (dir, { vercel }) => vercelHost({ dir, team: vercel.team, project: vercel.project }),
|
|
29
|
+
dns({ dir, config }, host) {
|
|
30
|
+
const target = (h) => host.recordFor(h);
|
|
31
|
+
if (config.dns.provider === 'vercel')
|
|
32
|
+
return wildcardDns();
|
|
33
|
+
if (config.dns.provider === 'manual')
|
|
34
|
+
return manualDns(target);
|
|
35
|
+
const token = readEnv(dir)[CLOUDFLARE_NAME];
|
|
36
|
+
if (!token)
|
|
37
|
+
throw new CliError(`No ${CLOUDFLARE_NAME} in the studio's .env.`, {
|
|
38
|
+
fix: `design-hub studio link --dir ${dir} --cloudflare-token-file <file> puts it there.`,
|
|
39
|
+
});
|
|
40
|
+
return cloudflareDns({ token, apex: config.apex, zone: config.dns.zone, studio: config.slug, target });
|
|
41
|
+
},
|
|
42
|
+
names: authoritativeNames(),
|
|
43
|
+
store({ dir }) {
|
|
44
|
+
const store = storeConfig(readEnv(dir));
|
|
45
|
+
if (!store)
|
|
46
|
+
throw new CliError("No review store in the studio's .env.", pull(dir));
|
|
47
|
+
return upstashKV(store);
|
|
48
|
+
},
|
|
49
|
+
files({ dir }) {
|
|
50
|
+
const token = readEnv(dir)[BLOB_NAME];
|
|
51
|
+
if (!token)
|
|
52
|
+
throw new CliError(`No ${BLOB_NAME} in the studio's .env.`, pull(dir));
|
|
53
|
+
return blobFiles(token);
|
|
54
|
+
},
|
|
55
|
+
pnpm(dir, args) {
|
|
56
|
+
// Captured, never passed through: the command's stdout is its one JSON object.
|
|
57
|
+
const out = spawnSync('pnpm', args, { cwd: dir, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
|
58
|
+
if (out.error)
|
|
59
|
+
return null;
|
|
60
|
+
return { status: out.status ?? 1, stdout: out.stdout ?? '', stderr: out.stderr ?? '' };
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The studio's review service, once its database is shown to be this
|
|
66
|
+
* studio's: the one way a command reads or changes a studio's clients,
|
|
67
|
+
* people and links, so none can act on another studio's.
|
|
68
|
+
*/
|
|
69
|
+
export async function openReview(deps, studio) {
|
|
70
|
+
const kv = deps.store(studio);
|
|
71
|
+
await mustBeOwnDatabase(kv, studio);
|
|
72
|
+
return createReview(kv, deps.now ? { now: deps.now } : {});
|
|
73
|
+
}
|
|
74
|
+
/** The client's record, or null when the studio has none; a store that does not answer is an error, never "none". */
|
|
75
|
+
export const recordOf = (review, slug) => review.clientRecord({ client: slug }, localStudio('cli', 'CLI')).catch((error) => {
|
|
76
|
+
if (error instanceof ReviewError && error.code === 'not_found')
|
|
77
|
+
return null;
|
|
78
|
+
throw error;
|
|
79
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Who serves DNS for the apex, and so how a client's host gets its record. */
|
|
2
|
+
export declare const DNS_PROVIDERS: readonly ['vercel', 'cloudflare', 'manual'];
|
|
3
|
+
export type DnsProvider = (typeof DNS_PROVIDERS)[number];
|
|
4
|
+
export type DnsMode = 'wildcard' | 'per-host' | 'manual';
|
|
5
|
+
/** Vercel DNS takes one wildcard for every client; Cloudflare gets a record per host by its API; anything else, a record a person adds. */
|
|
6
|
+
export declare const MODE_OF: Record<DnsProvider, DnsMode>;
|
|
7
|
+
export type StudioConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* A random id `studio create` makes once and never changes: the review
|
|
10
|
+
* store is marked with it (server/mark.ts), so no command acts on a
|
|
11
|
+
* database that is another studio's. A slug can repeat across teams and
|
|
12
|
+
* machines; this cannot. Absent only in a folder made before it existed,
|
|
13
|
+
* which `studio create` run again gives one.
|
|
14
|
+
*/
|
|
15
|
+
id?: string;
|
|
16
|
+
slug: string;
|
|
17
|
+
apex: string;
|
|
18
|
+
/** The studio's name, shown beside its people's names. */
|
|
19
|
+
name: string;
|
|
20
|
+
vercel: {
|
|
21
|
+
team: string;
|
|
22
|
+
project: string;
|
|
23
|
+
};
|
|
24
|
+
dns: {
|
|
25
|
+
provider: DnsProvider;
|
|
26
|
+
mode: DnsMode;
|
|
27
|
+
zone: string | null;
|
|
28
|
+
};
|
|
29
|
+
/** The first Studio person, who gets a link on each new client's host. */
|
|
30
|
+
owner: string | null;
|
|
31
|
+
providers: {
|
|
32
|
+
kv: 'upstash';
|
|
33
|
+
files: 'vercel-blob';
|
|
34
|
+
host: 'vercel';
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare const STUDIO_FILE = "studio.json";
|
|
38
|
+
/** The secrets a studio folder's `.env` holds. Studios share none of them. */
|
|
39
|
+
export declare const STORE_NAMES: readonly ['KV_REST_API_URL', 'KV_REST_API_TOKEN'];
|
|
40
|
+
export declare const BLOB_NAME = "BLOB_READ_WRITE_TOKEN";
|
|
41
|
+
export declare const CLOUDFLARE_NAME = "CLOUDFLARE_API_TOKEN";
|
|
42
|
+
/** The problems with a studio.json, by path; none for a well-formed one. */
|
|
43
|
+
export declare function studioProblems(c: Partial<StudioConfig> | null): string[];
|
|
44
|
+
/** The folder is a studio's: it holds a studio.json. A studio folder is never a project. */
|
|
45
|
+
export declare const isStudioFolder: (dir: string) => boolean;
|
|
46
|
+
export declare function readStudio(dir: string): StudioConfig;
|
|
47
|
+
export declare const writeStudio: (dir: string, config: StudioConfig) => void;
|
|
48
|
+
/** This machine's design-hub folder: `$DESIGN_HUB_HOME`, else `~/.design-hub`. */
|
|
49
|
+
export declare const homeDir: (env?: Record<string, string | undefined>) => string;
|
|
50
|
+
/** Lists a studio's folder under its slug. A slug already listed at another folder is refused. */
|
|
51
|
+
export declare function addToList(home: string, slug: string, dir: string): 'added' | 'kept';
|
|
52
|
+
export type Studio = {
|
|
53
|
+
dir: string;
|
|
54
|
+
config: StudioConfig;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The studio a command acts on: the one `--studio` names, else the studio
|
|
58
|
+
* folder the command runs in, which must be listed under its own slug. Its
|
|
59
|
+
* folder's studio.json must name the same slug, so a moved or copied folder
|
|
60
|
+
* never stands in for another studio.
|
|
61
|
+
*/
|
|
62
|
+
export declare function findStudio(home: string, named: string | undefined, cwd: string): Studio;
|
|
63
|
+
/**
|
|
64
|
+
* The host a client is served on: `<slug>.<apex>`, or a codename
|
|
65
|
+
* (`--host atlas` is `atlas.<apex>`). A client's host is exactly one label
|
|
66
|
+
* under the apex, and that label is never studio, www or api, which the
|
|
67
|
+
* studio keeps. So the apex itself, a host not under it, and one two labels
|
|
68
|
+
* down (`a.studio.<apex>`) are refused.
|
|
69
|
+
*/
|
|
70
|
+
export declare function clientHost(slug: string, apex: string, given: string | undefined): string;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
// Where a studio is, on this machine and on its accounts. A studio folder
|
|
3
|
+
// holds `studio.json` (its slug, apex, hosting team and project, DNS mode;
|
|
4
|
+
// no secrets) and a gitignored `.env` with its secrets. This machine keeps a
|
|
5
|
+
// list of its studios in `~/.design-hub/studios.json`, slug to folder, so a
|
|
6
|
+
// command finds a studio's credentials by its slug. A command acts on the
|
|
7
|
+
// studio its `--studio` names, or the studio folder it runs in; never on the
|
|
8
|
+
// only one listed, and never on one whose folder names another slug.
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { homedir } from 'node:os';
|
|
11
|
+
import { join, resolve } from 'node:path';
|
|
12
|
+
import { SLUG } from '../../core/feature.js';
|
|
13
|
+
import { hostName } from '../../core/prototype.js';
|
|
14
|
+
import { CliError } from './cli.js';
|
|
15
|
+
/** Who serves DNS for the apex, and so how a client's host gets its record. */
|
|
16
|
+
export const DNS_PROVIDERS = ['vercel', 'cloudflare', 'manual'];
|
|
17
|
+
/** Vercel DNS takes one wildcard for every client; Cloudflare gets a record per host by its API; anything else, a record a person adds. */
|
|
18
|
+
export const MODE_OF = {
|
|
19
|
+
vercel: 'wildcard',
|
|
20
|
+
cloudflare: 'per-host',
|
|
21
|
+
manual: 'manual',
|
|
22
|
+
};
|
|
23
|
+
export const STUDIO_FILE = 'studio.json';
|
|
24
|
+
/** The secrets a studio folder's `.env` holds. Studios share none of them. */
|
|
25
|
+
export const STORE_NAMES = ['KV_REST_API_URL', 'KV_REST_API_TOKEN'];
|
|
26
|
+
export const BLOB_NAME = 'BLOB_READ_WRITE_TOKEN';
|
|
27
|
+
export const CLOUDFLARE_NAME = 'CLOUDFLARE_API_TOKEN';
|
|
28
|
+
/** A Vercel team or project name as the CLI takes it: lower-case letters, digits, `-`, `_` and `.`. */
|
|
29
|
+
const isVercelName = (v) => typeof v === 'string' && /^[a-z0-9][a-z0-9._-]{0,99}$/.test(v);
|
|
30
|
+
/** An apex domain: a host name with at least one dot, as given. */
|
|
31
|
+
const isApex = (v) => typeof v === 'string' && hostName(v) === v;
|
|
32
|
+
const isText = (v) => typeof v === 'string' && v.trim().length > 0;
|
|
33
|
+
/** A studio's id: 16 random bytes, hex. */
|
|
34
|
+
const STUDIO_ID = /^[a-f0-9]{32}$/;
|
|
35
|
+
/** The problems with a studio.json, by path; none for a well-formed one. */
|
|
36
|
+
export function studioProblems(c) {
|
|
37
|
+
if (!c || typeof c !== 'object')
|
|
38
|
+
return ['studio.json: an object'];
|
|
39
|
+
const problems = [];
|
|
40
|
+
if (c.id !== undefined && !STUDIO_ID.test(String(c.id)))
|
|
41
|
+
problems.push('id: 32 hex characters');
|
|
42
|
+
if (!SLUG.test(String(c.slug)))
|
|
43
|
+
problems.push('slug: kebab-case');
|
|
44
|
+
if (!isApex(c.apex))
|
|
45
|
+
problems.push('apex: a domain such as example.com, lower case');
|
|
46
|
+
if (!isText(c.name))
|
|
47
|
+
problems.push('name: the studio’s name');
|
|
48
|
+
if (!isVercelName(c.vercel?.team))
|
|
49
|
+
problems.push('vercel.team: the Vercel team slug');
|
|
50
|
+
if (!isVercelName(c.vercel?.project))
|
|
51
|
+
problems.push('vercel.project: the Vercel project name');
|
|
52
|
+
const provider = c.dns?.provider;
|
|
53
|
+
if (!DNS_PROVIDERS.includes(provider))
|
|
54
|
+
problems.push(`dns.provider: one of ${DNS_PROVIDERS.join(', ')}`);
|
|
55
|
+
else if (c.dns?.mode !== MODE_OF[provider])
|
|
56
|
+
problems.push(`dns.mode: ${MODE_OF[provider]} for ${provider}`);
|
|
57
|
+
if (c.dns?.zone != null && !/^[a-f0-9]{32}$/.test(c.dns.zone))
|
|
58
|
+
problems.push('dns.zone: a Cloudflare zone id');
|
|
59
|
+
return problems;
|
|
60
|
+
}
|
|
61
|
+
/** The folder is a studio's: it holds a studio.json. A studio folder is never a project. */
|
|
62
|
+
export const isStudioFolder = (dir) => existsSync(join(dir, STUDIO_FILE));
|
|
63
|
+
export function readStudio(dir) {
|
|
64
|
+
const file = join(dir, STUDIO_FILE);
|
|
65
|
+
if (!existsSync(file))
|
|
66
|
+
throw new CliError(`${dir} is not a studio folder: it has no ${STUDIO_FILE}.`, {
|
|
67
|
+
fix: 'design-hub studio create --dir <path> makes one.',
|
|
68
|
+
});
|
|
69
|
+
let parsed;
|
|
70
|
+
try {
|
|
71
|
+
parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
parsed = null;
|
|
75
|
+
}
|
|
76
|
+
const problems = studioProblems(parsed);
|
|
77
|
+
if (problems.length)
|
|
78
|
+
throw new CliError(`${file} is not a studio's settings.`, { problems });
|
|
79
|
+
return parsed;
|
|
80
|
+
}
|
|
81
|
+
export const writeStudio = (dir, config) => writeFileSync(join(dir, STUDIO_FILE), `${JSON.stringify(config, null, 2)}\n`);
|
|
82
|
+
/** This machine's design-hub folder: `$DESIGN_HUB_HOME`, else `~/.design-hub`. */
|
|
83
|
+
export const homeDir = (env = process.env) => env.DESIGN_HUB_HOME ? resolve(env.DESIGN_HUB_HOME) : join(homedir(), '.design-hub');
|
|
84
|
+
const listFile = (home) => join(home, 'studios.json');
|
|
85
|
+
function readList(home) {
|
|
86
|
+
const file = listFile(home);
|
|
87
|
+
if (!existsSync(file))
|
|
88
|
+
return { studios: {} };
|
|
89
|
+
try {
|
|
90
|
+
const list = JSON.parse(readFileSync(file, 'utf8'));
|
|
91
|
+
return list && typeof list.studios === 'object' && list.studios ? list : { studios: {} };
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
throw new CliError(`${file} is not valid JSON.`, {
|
|
95
|
+
fix: 'Fix it, or delete it and run design-hub studio link.',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const real = (dir) => {
|
|
100
|
+
try {
|
|
101
|
+
return realpathSync(dir);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return resolve(dir);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/** Lists a studio's folder under its slug. A slug already listed at another folder is refused. */
|
|
108
|
+
export function addToList(home, slug, dir) {
|
|
109
|
+
const list = readList(home);
|
|
110
|
+
const at = real(dir);
|
|
111
|
+
// Own entries only: a slug such as `constructor` must not read Object.prototype's.
|
|
112
|
+
const listed = Object.hasOwn(list.studios, slug) ? list.studios[slug] : undefined;
|
|
113
|
+
if (listed && real(listed.dir) === at)
|
|
114
|
+
return 'kept';
|
|
115
|
+
if (listed && existsSync(join(listed.dir, STUDIO_FILE)))
|
|
116
|
+
throw new CliError(`Studio ${slug} is already listed on this machine at ${listed.dir}.`, {
|
|
117
|
+
fix: 'Use that folder, or give this studio another slug.',
|
|
118
|
+
});
|
|
119
|
+
list.studios[slug] = { dir: at };
|
|
120
|
+
mkdirSync(home, { recursive: true });
|
|
121
|
+
writeFileSync(listFile(home), `${JSON.stringify(list, null, 2)}\n`);
|
|
122
|
+
return 'added';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The studio a command acts on: the one `--studio` names, else the studio
|
|
126
|
+
* folder the command runs in, which must be listed under its own slug. Its
|
|
127
|
+
* folder's studio.json must name the same slug, so a moved or copied folder
|
|
128
|
+
* never stands in for another studio.
|
|
129
|
+
*/
|
|
130
|
+
export function findStudio(home, named, cwd) {
|
|
131
|
+
const list = readList(home);
|
|
132
|
+
const known = Object.keys(list.studios).sort();
|
|
133
|
+
let slug = named;
|
|
134
|
+
if (!slug) {
|
|
135
|
+
if (!existsSync(join(cwd, STUDIO_FILE)))
|
|
136
|
+
throw new CliError('Name the studio: --studio <slug>, or run this in its folder.', { studios: known });
|
|
137
|
+
slug = readStudio(cwd).slug;
|
|
138
|
+
const here = Object.hasOwn(list.studios, slug) ? list.studios[slug].dir : null;
|
|
139
|
+
if (here === null || real(here) !== real(cwd))
|
|
140
|
+
throw new CliError(`This folder's studio, ${slug}, is not listed on this machine.`, {
|
|
141
|
+
fix: 'design-hub studio link --dir . lists it.',
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const listed = Object.hasOwn(list.studios, slug) ? list.studios[slug] : undefined;
|
|
145
|
+
if (!listed)
|
|
146
|
+
throw new CliError(`No studio ${slug} on this machine.`, {
|
|
147
|
+
studios: known,
|
|
148
|
+
fix: 'design-hub studio link --dir <its folder> lists one.',
|
|
149
|
+
});
|
|
150
|
+
const config = readStudio(listed.dir);
|
|
151
|
+
if (config.slug !== slug)
|
|
152
|
+
throw new CliError(`The folder listed for ${slug} holds studio ${config.slug}.`, {
|
|
153
|
+
dir: listed.dir,
|
|
154
|
+
fix: 'design-hub studio link --dir <the right folder>.',
|
|
155
|
+
});
|
|
156
|
+
return { dir: listed.dir, config };
|
|
157
|
+
}
|
|
158
|
+
/** The first labels the studio keeps for itself, never a client's host. */
|
|
159
|
+
const KEPT_LABELS = ['studio', 'www', 'api'];
|
|
160
|
+
/** One DNS label: lower-case letters, digits and inner hyphens. */
|
|
161
|
+
const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
162
|
+
/**
|
|
163
|
+
* The host a client is served on: `<slug>.<apex>`, or a codename
|
|
164
|
+
* (`--host atlas` is `atlas.<apex>`). A client's host is exactly one label
|
|
165
|
+
* under the apex, and that label is never studio, www or api, which the
|
|
166
|
+
* studio keeps. So the apex itself, a host not under it, and one two labels
|
|
167
|
+
* down (`a.studio.<apex>`) are refused.
|
|
168
|
+
*/
|
|
169
|
+
export function clientHost(slug, apex, given) {
|
|
170
|
+
const raw = (given ?? slug).trim().toLowerCase();
|
|
171
|
+
const host = raw.includes('.') ? raw : `${raw}.${apex}`;
|
|
172
|
+
const label = host.endsWith(`.${apex}`) ? host.slice(0, -apex.length - 1) : null;
|
|
173
|
+
const problems = [];
|
|
174
|
+
if (hostName(host) !== host)
|
|
175
|
+
problems.push('host: a host name, such as atlas.example.com');
|
|
176
|
+
else if (host === apex)
|
|
177
|
+
problems.push('host: not the apex itself');
|
|
178
|
+
else if (label === null)
|
|
179
|
+
problems.push(`host: under ${apex}`);
|
|
180
|
+
else if (!LABEL.test(label))
|
|
181
|
+
problems.push(`host: one label under ${apex}, such as atlas.${apex}`);
|
|
182
|
+
else if (KEPT_LABELS.includes(label))
|
|
183
|
+
problems.push(`host: not ${KEPT_LABELS.join(', ')}.${apex}, which the studio keeps`);
|
|
184
|
+
if (problems.length)
|
|
185
|
+
throw new CliError(`${host} cannot be a client's host.`, { problems });
|
|
186
|
+
return host;
|
|
187
|
+
}
|
|
@@ -68,4 +68,37 @@ export declare function report(o: Outcome): {
|
|
|
68
68
|
systemMessage: string;
|
|
69
69
|
additionalContext: string;
|
|
70
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* What `skills` and `upgrade` say in a studio folder, and why they stop
|
|
73
|
+
* there: its proxy.ts, api/ and vercel.json are the studio's site, not a
|
|
74
|
+
* project's leftover deployment, and a studio takes a new version by its
|
|
75
|
+
* own deploy (templates/studio/README.md, Upgrade).
|
|
76
|
+
*/
|
|
77
|
+
export declare const STUDIO_FOLDER: {
|
|
78
|
+
readonly code: 'studio_folder';
|
|
79
|
+
readonly error: 'This is a studio folder, not a project: skills, upgrade and the session hook leave it as it is.';
|
|
80
|
+
readonly fix: "Upgrade a studio in its folder: pnpm add @milesroxas/design-hub@<version>, then design-hub studio deploy, which installs, builds and deploys it. Run skills and upgrade in a project.";
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* A project's own deployment, from before every project was shared into a
|
|
84
|
+
* studio: entry files that import what the package no longer exports, and
|
|
85
|
+
* the config that deployed them. A project keeps none of them.
|
|
86
|
+
*/
|
|
87
|
+
export declare const OWN_DEPLOYMENT: readonly ['proxy.ts', 'api/review.ts', 'vercel.json'];
|
|
88
|
+
/** The heading of the miles-deploy section that walks a project off its own deployment, in order. */
|
|
89
|
+
export declare const OWN_DEPLOYMENT_SECTION = "A project that still has its own site";
|
|
90
|
+
/**
|
|
91
|
+
* What the agent is told while a project still has them, by `design-hub
|
|
92
|
+
* skills` (which then fails, so the session it upgrades in hears it), by
|
|
93
|
+
* `design-hub upgrade`, and by the session hook after. An older hook calls
|
|
94
|
+
* that first session's upgrade failed and passes on only the last 400
|
|
95
|
+
* characters of what `skills` printed, so `fix` is short and starts by
|
|
96
|
+
* saying the upgrade is installed. `version`, when known, names the commit.
|
|
97
|
+
*/
|
|
98
|
+
export declare function ownDeployment(files: readonly string[], version?: string): {
|
|
99
|
+
error: string;
|
|
100
|
+
fix: string;
|
|
101
|
+
systemMessage: string;
|
|
102
|
+
additionalContext: string;
|
|
103
|
+
};
|
|
71
104
|
export {};
|
|
@@ -81,3 +81,43 @@ export function report(o) {
|
|
|
81
81
|
additionalContext: `Design Hub ${o.to} is available; this project has ${o.from} and DESIGN_HUB_AUTO_UPDATE=0. Mention it once; upgrade with \`${MANUAL}\` only if the user asks.`,
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* What `skills` and `upgrade` say in a studio folder, and why they stop
|
|
86
|
+
* there: its proxy.ts, api/ and vercel.json are the studio's site, not a
|
|
87
|
+
* project's leftover deployment, and a studio takes a new version by its
|
|
88
|
+
* own deploy (templates/studio/README.md, Upgrade).
|
|
89
|
+
*/
|
|
90
|
+
export const STUDIO_FOLDER = {
|
|
91
|
+
code: 'studio_folder',
|
|
92
|
+
error: 'This is a studio folder, not a project: skills, upgrade and the session hook leave it as it is.',
|
|
93
|
+
fix: `Upgrade a studio in its folder: pnpm add ${PACKAGE_NAME}@<version>, then design-hub studio deploy, which installs, builds and deploys it. Run skills and upgrade in a project.`,
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* A project's own deployment, from before every project was shared into a
|
|
97
|
+
* studio: entry files that import what the package no longer exports, and
|
|
98
|
+
* the config that deployed them. A project keeps none of them.
|
|
99
|
+
*/
|
|
100
|
+
export const OWN_DEPLOYMENT = ['proxy.ts', 'api/review.ts', 'vercel.json'];
|
|
101
|
+
/** The heading of the miles-deploy section that walks a project off its own deployment, in order. */
|
|
102
|
+
export const OWN_DEPLOYMENT_SECTION = 'A project that still has its own site';
|
|
103
|
+
/**
|
|
104
|
+
* What the agent is told while a project still has them, by `design-hub
|
|
105
|
+
* skills` (which then fails, so the session it upgrades in hears it), by
|
|
106
|
+
* `design-hub upgrade`, and by the session hook after. An older hook calls
|
|
107
|
+
* that first session's upgrade failed and passes on only the last 400
|
|
108
|
+
* characters of what `skills` printed, so `fix` is short and starts by
|
|
109
|
+
* saying the upgrade is installed. `version`, when known, names the commit.
|
|
110
|
+
*/
|
|
111
|
+
export function ownDeployment(files, version) {
|
|
112
|
+
const list = files.join(', ');
|
|
113
|
+
const error = `This project still has its own deployment (${list}), which imports what Design Hub no longer has: a project is shared into a studio.`;
|
|
114
|
+
const fix = `The upgrade is installed; one thing is left. Tell the user, then follow miles-deploy, ${OWN_DEPLOYMENT_SECTION}, in order. With their word, disconnect or delete the project's own Vercel project before deleting ${list} or pushing: a push without them publishes the prototypes with no sign-in.`;
|
|
115
|
+
const commit = version ? `"Upgrade Design Hub to ${version}"` : '"Upgrade Design Hub"';
|
|
116
|
+
return {
|
|
117
|
+
error,
|
|
118
|
+
fix,
|
|
119
|
+
systemMessage: `This project still has its own deployment files (${list}); Design Hub shares through a studio.`,
|
|
120
|
+
additionalContext: `${error} ${fix} Until they are gone, pnpm check fails on them and pnpm skills stops with this message. ` +
|
|
121
|
+
`Once they are gone, the upgrade's changes and the removal are not committed: git status lists them (package.json, pnpm-lock.yaml, .claude/, AGENTS.md, the removed files). Include them in the next commit the user asks for, as their own commit ${commit}.`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -1,30 +1,8 @@
|
|
|
1
|
-
import type { ProjectInfo } from './deploy.ts';
|
|
2
|
-
export declare const ENVIRONMENTS: readonly ['production', 'preview'];
|
|
3
|
-
export type Target = (typeof ENVIRONMENTS)[number] | 'development';
|
|
4
|
-
/** What the Upstash for Redis integration injects (Vercel Marketplace). */
|
|
5
|
-
export declare const STORE_ENV: readonly ['KV_REST_API_URL', 'KV_REST_API_TOKEN'];
|
|
6
1
|
export type Run = {
|
|
7
2
|
status: number;
|
|
8
3
|
stdout: string;
|
|
9
4
|
stderr: string;
|
|
10
5
|
};
|
|
11
|
-
export declare function vercel(cwd: string, args: string[], input?: string): Run | null;
|
|
12
|
-
export declare const linkedProject: (cwd: string) => string | null;
|
|
13
|
-
/** The team the linked project belongs to. The commands that take a project name instead of the link need it as `--scope`. */
|
|
14
|
-
export declare const linkedOrg: (cwd: string) => string | null;
|
|
15
|
-
/** The variable names set for a target, read from `vercel env ls`'s table. */
|
|
16
|
-
export declare function envNames(cwd: string, target: Target): Set<string> | null;
|
|
17
|
-
/** Adds one variable for one target that does not have it yet. */
|
|
18
|
-
export declare function setEnv(cwd: string, name: string, target: Target, value: string): Run | null;
|
|
19
|
-
/**
|
|
20
|
-
* What the gate needs that a target lacks, as `NAME:target`: the secret, and
|
|
21
|
-
* the review store, without which nobody can sign in, since it keeps the
|
|
22
|
-
* people and their links. Null when a target's names could not be read.
|
|
23
|
-
*/
|
|
24
|
-
export declare function missingGateEnv(names: Record<(typeof ENVIRONMENTS)[number], Set<string> | null>): string[] | null;
|
|
25
|
-
/** The gate variables missing from production or preview, or null when the CLI cannot say. */
|
|
26
|
-
export declare function gateEnvMissing(cwd: string): string[] | null;
|
|
6
|
+
export declare function vercel(cwd: string, args: string[], input?: string, env?: NodeJS.ProcessEnv): Run | null;
|
|
27
7
|
/** The signed-in account, or null when the CLI is missing or signed out. */
|
|
28
8
|
export declare function whoami(cwd: string): string | null;
|
|
29
|
-
/** `GET /v9/projects/<name>` through the CLI's own credentials, or null when it fails. */
|
|
30
|
-
export declare function projectInfo(cwd: string, project: string, scope: string | null): ProjectInfo | null;
|