@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.
- package/README.md +13 -11
- package/core/controls.test.ts +176 -0
- package/core/controls.ts +195 -0
- 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 +144 -2
- package/core/review/policy.test.ts +79 -22
- package/core/review/policy.ts +36 -8
- package/core/review/service.test.ts +1525 -322
- package/core/review/service.ts +810 -183
- package/core/review/store.test.ts +91 -0
- package/core/review/store.ts +143 -26
- package/dist/core/controls.d.ts +55 -0
- package/dist/core/controls.js +174 -0
- 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 +87 -2
- package/dist/core/review/model.js +97 -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 +222 -43
- package/dist/core/review/service.js +727 -182
- package/dist/core/review/store.d.ts +84 -24
- package/dist/core/review/store.js +66 -26
- 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/guard.d.ts +11 -0
- package/dist/scripts/guard.js +44 -0
- 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/rules.d.ts +1 -0
- package/dist/scripts/lib/rules.js +1 -0
- 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 +125 -44
- 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/Artboard.tsx +21 -8
- package/kit/Space.tsx +4 -3
- package/kit/Variants.tsx +193 -65
- package/kit/ViewTools.tsx +77 -11
- package/kit/audience.ts +85 -0
- package/kit/dials.css +59 -0
- package/kit/dials.tsx +272 -35
- package/kit/harness.css +34 -0
- package/kit/prefs.ts +23 -1
- package/package.json +3 -2
- package/shell/ClientViewNote.tsx +31 -3
- package/shell/Guide.tsx +11 -5
- package/shell/Index.tsx +32 -10
- package/shell/Notice.tsx +1 -1
- package/shell/controls.ts +26 -0
- package/shell/hub.ts +5 -1
- package/shell/main.tsx +33 -6
- 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 +8 -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-brand/SKILL.md +11 -1
- package/skills/miles-deploy/SKILL.md +121 -64
- package/skills/miles-design-hub/SKILL.md +11 -9
- package/skills/miles-prototype/SKILL.md +34 -1
- 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,41 +1,101 @@
|
|
|
1
|
+
import { type Scope } from './model.ts';
|
|
1
2
|
export interface KV {
|
|
2
3
|
hget(key: string, field: string): Promise<string | null>;
|
|
3
4
|
hset(key: string, field: string, value: string): Promise<void>;
|
|
4
5
|
/** How many fields it removed: 1, or 0 when the field was not there. Atomic, so it can claim a record. */
|
|
5
6
|
hdel(key: string, field: string): Promise<number>;
|
|
7
|
+
/** Sets a field only when it is not there: true when this call set it. Atomic, so of two at once one claims it. */
|
|
8
|
+
hsetnx(key: string, field: string, value: string): Promise<boolean>;
|
|
6
9
|
hgetall(key: string): Promise<Record<string, string>>;
|
|
7
10
|
/** Adds `by` to a field's integer (absent is 0) and returns the result. Atomic: two calls always add both. */
|
|
8
11
|
hincrby(key: string, field: string, by: number): Promise<number>;
|
|
9
12
|
sadd(key: string, member: string): Promise<void>;
|
|
10
13
|
smembers(key: string): Promise<string[]>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/** A person's profile: everything but revocation and epoch, which nothing here can overwrite. */
|
|
14
|
-
readonly people: "hub3:people";
|
|
15
|
-
/** When a person was revoked. Written once by revoke, never cleared. */
|
|
16
|
-
readonly revoked: "hub3:revoked";
|
|
17
|
-
/** A person's session epoch, only ever raised, by HINCRBY. Absent is 0. */
|
|
18
|
-
readonly epochs: "hub3:epochs";
|
|
19
|
-
/** One-time sign-in links: hex(sha256(token)) to a Link. */
|
|
20
|
-
readonly links: "hub3:links";
|
|
21
|
-
/** Project settings, one field each: `access` is the default access length. */
|
|
22
|
-
readonly settings: "hub3:settings";
|
|
23
|
-
readonly prototypes: "hub3:prototypes";
|
|
24
|
-
/**
|
|
25
|
-
* Which prototypes are client-facing: field `<slug>`, value `client`. Only
|
|
26
|
-
* client-facing is stored; internal is the field's absence, and any other
|
|
27
|
-
* value reads as internal too.
|
|
28
|
-
*/
|
|
29
|
-
readonly audiences: "hub3:audiences";
|
|
14
|
+
/** Removes a whole key, a hash or a set; one that is not there is no error. */
|
|
15
|
+
del(key: string): Promise<void>;
|
|
30
16
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
17
|
+
* Removes every key, hash or set, whose name starts with `prefix`, taken as
|
|
18
|
+
* plain text (no character in it is a pattern); none is no error. Not one
|
|
19
|
+
* atomic step: a key written while it runs may stay. Redis: SCAN … MATCH,
|
|
20
|
+
* then DEL; Postgres: DELETE … WHERE key LIKE, the prefix escaped.
|
|
33
21
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
delPrefix(prefix: string): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The studio's own records: Studio people (profile, revocation, epoch and
|
|
26
|
+
* links, as a client's below) and `settings`, one field each: `access` is the
|
|
27
|
+
* default access length. `mark`, one field, `id`: the id of the one studio
|
|
28
|
+
* this database serves (its studio.json `id`), set once by `studio create`
|
|
29
|
+
* and checked by every command before it acts (server/mark.ts). No other
|
|
30
|
+
* key names a studio, so two studios on one database would be one studio.
|
|
31
|
+
*/
|
|
32
|
+
type StudioName = 'people' | 'revoked' | 'epochs' | 'links' | 'settings' | 'mark';
|
|
33
|
+
/**
|
|
34
|
+
* The studio's clients, outside every scope: `clients`, a client's slug to
|
|
35
|
+
* its Client; `hosts`, a host name to the slug of the client it serves;
|
|
36
|
+
* `claims`, one counter per slug (`client:<slug>`) and per host
|
|
37
|
+
* (`host:<host>`), raised by HINCRBY when a client is added: whoever raised
|
|
38
|
+
* it to 1 holds it, so two adds at once never both get one. Archiving a
|
|
39
|
+
* client deletes its fields, so the slug and the host can be claimed again.
|
|
40
|
+
* `held`, the same fields, each the time a client that had it was archived:
|
|
41
|
+
* neither is added again until every gate's cached answer for the host has
|
|
42
|
+
* surely run out (REUSE_SECONDS in service.ts).
|
|
43
|
+
*/
|
|
44
|
+
type DirectoryName = 'clients' | 'hosts' | 'claims' | 'held';
|
|
45
|
+
/**
|
|
46
|
+
* A client's people, in four records. `people`: a profile, everything but
|
|
47
|
+
* revocation and epoch, which nothing here can overwrite. `revoked`: when a
|
|
48
|
+
* person was revoked, written once by revoke, never cleared. `epochs`: a
|
|
49
|
+
* person's session epoch, only ever raised, by HINCRBY; absent is 0.
|
|
50
|
+
* `links`: one-time sign-in links, hex(sha256(token)) to a Link. And
|
|
51
|
+
* `projects`: the client's projects, a slug to its Project. `proof`: while
|
|
52
|
+
* `client add` waits for the client's host, one field, hex(sha256(ask)) to
|
|
53
|
+
* the answer the gate gives for that ask (PROOF_PATH in prototype.ts).
|
|
54
|
+
*/
|
|
55
|
+
type ClientName = 'people' | 'revoked' | 'epochs' | 'links';
|
|
56
|
+
type ClientOnlyName = 'projects' | 'proof';
|
|
57
|
+
/**
|
|
58
|
+
* A project's records. `audiences`: which prototypes are client-facing,
|
|
59
|
+
* field `<slug>`, value `client`; only client-facing is stored, internal is
|
|
60
|
+
* the field's absence, and any other value reads as internal too.
|
|
61
|
+
* `counters`: the last thread number given on each prototype, only ever
|
|
62
|
+
* raised by HINCRBY: field `<prototype>` counts client-facing threads,
|
|
63
|
+
* `<prototype>:internal` internal ones. `prototypes`: the set of prototypes
|
|
64
|
+
* with comments. `comments`, per prototype: one field per comment.
|
|
65
|
+
* `controls`, per prototype: what Studio marked on its controls
|
|
66
|
+
* (core/controls.ts): field `dial:<id>` is `client` or `internal`, overruling
|
|
67
|
+
* the code either way; field `variant:<name>` is `client`, and internal is
|
|
68
|
+
* its absence. One field per control, so two people marking at once never
|
|
69
|
+
* undo each other. `builds`: every build a share started for the project,
|
|
70
|
+
* field `<build>` to `{ n, live }`: `n` is the order it was started in, from
|
|
71
|
+
* field `next` (HINCRBY), and `live` whether the project ever pointed at it
|
|
72
|
+
* (startBuild and setBuild in service.ts).
|
|
73
|
+
*/
|
|
74
|
+
type ProjectName = 'audiences' | 'counters' | 'prototypes' | 'builds';
|
|
75
|
+
type PrototypeName = 'comments' | 'controls';
|
|
76
|
+
/**
|
|
77
|
+
* Every store key, and the only place one is built. `'studio'` names the
|
|
78
|
+
* studio's own records; a Scope names its client's, and its project's for a
|
|
79
|
+
* project name. Every part is checked (a client slug, a project slug, a
|
|
80
|
+
* kebab-case prototype), so no value can reach into another client's keys:
|
|
81
|
+
* no part can hold the `:` that joins them.
|
|
82
|
+
*/
|
|
83
|
+
export declare function keyOf(scope: 'studio', name: StudioName | DirectoryName): string;
|
|
84
|
+
export declare function keyOf(scope: 'studio' | Scope, name: ClientName): string;
|
|
85
|
+
export declare function keyOf(scope: Scope, name: ClientOnlyName | ProjectName): string;
|
|
86
|
+
export declare function keyOf(scope: Scope, name: PrototypeName, prototype: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* What every key of a client starts with, or of one of its projects when the
|
|
89
|
+
* scope names one: what `delPrefix` takes to sweep that scope clean, whatever
|
|
90
|
+
* index names its keys or not. Built by the parts keyOf builds keys from, and
|
|
91
|
+
* ending in the `:` no part can hold, so `acme` never reaches `acme-two` and
|
|
92
|
+
* no client reaches the studio's keys. Never the local store's client: its
|
|
93
|
+
* records are this machine's own, and nothing archives or reuses it.
|
|
94
|
+
*/
|
|
95
|
+
export declare function sweepPrefix(scope: Scope): string;
|
|
37
96
|
export type Snapshot = {
|
|
38
97
|
hashes: Record<string, Record<string, string>>;
|
|
39
98
|
sets: Record<string, string[]>;
|
|
40
99
|
};
|
|
41
100
|
export declare function memoryKV(initial?: Snapshot, onChange?: (s: Snapshot) => void): KV;
|
|
101
|
+
export {};
|
|
@@ -2,37 +2,56 @@
|
|
|
2
2
|
// and set operations. Production is Upstash Redis over REST
|
|
3
3
|
// (server/upstash.ts); dev and tests use the in-memory store below, which
|
|
4
4
|
// the dev server persists to a file (server/file-kv.ts).
|
|
5
|
+
import { SLUG } from '../feature.js';
|
|
6
|
+
import { isClientSlug, isProjectSlug } from '../prototype.js';
|
|
7
|
+
import { LOCAL_CLIENT } from './model.js';
|
|
8
|
+
/** A comment's or a control's prototype: any kebab-case name, so reading one that is reserved finds nothing, as before. */
|
|
9
|
+
const isKebab = (v) => typeof v === 'string' && SLUG.test(v);
|
|
5
10
|
/**
|
|
6
11
|
* Every key the hub writes starts here, so a shared Redis never mixes it with
|
|
7
12
|
* another app's data. Bumped when the stored shapes change without a
|
|
8
13
|
* migration: records under an older prefix are simply never read.
|
|
9
14
|
*/
|
|
10
|
-
const PREFIX = '
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
15
|
+
const PREFIX = 'hub4:';
|
|
16
|
+
const DIRECTORY = ['clients', 'hosts', 'claims', 'held'];
|
|
17
|
+
const PROJECT_NAMES = [
|
|
18
|
+
'audiences',
|
|
19
|
+
'counters',
|
|
20
|
+
'prototypes',
|
|
21
|
+
'builds',
|
|
22
|
+
'comments',
|
|
23
|
+
'controls',
|
|
24
|
+
];
|
|
25
|
+
const PER_PROTOTYPE = ['comments', 'controls'];
|
|
26
|
+
function part(ok, v, what) {
|
|
27
|
+
// A bad part is a bug in the caller, never input to answer: fail closed before any store call.
|
|
28
|
+
if (!ok(v))
|
|
29
|
+
throw new Error(`Not a store key: ${what} is ${JSON.stringify(v)}.`);
|
|
30
|
+
return v;
|
|
31
|
+
}
|
|
32
|
+
const clientPrefix = (client) => `${PREFIX}c:${part(isClientSlug, client, 'client')}:`;
|
|
33
|
+
const projectPrefix = (scope) => `${clientPrefix(scope.client)}p:${part(isProjectSlug, scope.project, 'project')}:`;
|
|
34
|
+
export function keyOf(scope, name, prototype) {
|
|
35
|
+
if (scope === 'studio')
|
|
36
|
+
return DIRECTORY.includes(name) ? `${PREFIX}${name}` : `${PREFIX}studio:${name}`;
|
|
37
|
+
if (!PROJECT_NAMES.includes(name))
|
|
38
|
+
return `${clientPrefix(scope.client)}${name}`;
|
|
39
|
+
const project = `${projectPrefix(scope)}${name}`;
|
|
40
|
+
return PER_PROTOTYPE.includes(name) ? `${project}:${part(isKebab, prototype, 'prototype')}` : project;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* What every key of a client starts with, or of one of its projects when the
|
|
44
|
+
* scope names one: what `delPrefix` takes to sweep that scope clean, whatever
|
|
45
|
+
* index names its keys or not. Built by the parts keyOf builds keys from, and
|
|
46
|
+
* ending in the `:` no part can hold, so `acme` never reaches `acme-two` and
|
|
47
|
+
* no client reaches the studio's keys. Never the local store's client: its
|
|
48
|
+
* records are this machine's own, and nothing archives or reuses it.
|
|
49
|
+
*/
|
|
50
|
+
export function sweepPrefix(scope) {
|
|
51
|
+
if (scope.client === LOCAL_CLIENT)
|
|
52
|
+
throw new Error('Not a scope to sweep: the local store’s records stay.');
|
|
53
|
+
return scope.project === undefined ? clientPrefix(scope.client) : projectPrefix(scope);
|
|
54
|
+
}
|
|
36
55
|
export function memoryKV(initial = { hashes: {}, sets: {} }, onChange) {
|
|
37
56
|
const hashes = new Map(Object.entries(initial.hashes).map(([k, v]) => [k, new Map(Object.entries(v))]));
|
|
38
57
|
const sets = new Map(Object.entries(initial.sets).map(([k, v]) => [k, new Set(v)]));
|
|
@@ -53,6 +72,13 @@ export function memoryKV(initial = { hashes: {}, sets: {} }, onChange) {
|
|
|
53
72
|
changed();
|
|
54
73
|
return 1;
|
|
55
74
|
},
|
|
75
|
+
hsetnx: async (key, field, value) => {
|
|
76
|
+
if (hashes.get(key)?.has(field))
|
|
77
|
+
return false;
|
|
78
|
+
hash(key).set(field, value);
|
|
79
|
+
changed();
|
|
80
|
+
return true;
|
|
81
|
+
},
|
|
56
82
|
hgetall: async (key) => Object.fromEntries(hashes.get(key) ?? []),
|
|
57
83
|
hincrby: async (key, field, by) => {
|
|
58
84
|
const n = Number(hash(key).get(field) ?? 0) + by;
|
|
@@ -65,5 +91,19 @@ export function memoryKV(initial = { hashes: {}, sets: {} }, onChange) {
|
|
|
65
91
|
changed();
|
|
66
92
|
},
|
|
67
93
|
smembers: async (key) => [...(sets.get(key) ?? [])],
|
|
94
|
+
del: async (key) => {
|
|
95
|
+
const had = hashes.delete(key);
|
|
96
|
+
if (sets.delete(key) || had)
|
|
97
|
+
changed();
|
|
98
|
+
},
|
|
99
|
+
delPrefix: async (prefix) => {
|
|
100
|
+
const gone = [...hashes.keys(), ...sets.keys()].filter((k) => k.startsWith(prefix));
|
|
101
|
+
for (const key of gone) {
|
|
102
|
+
hashes.delete(key);
|
|
103
|
+
sets.delete(key);
|
|
104
|
+
}
|
|
105
|
+
if (gone.length)
|
|
106
|
+
changed();
|
|
107
|
+
},
|
|
68
108
|
};
|
|
69
109
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { type Args } from './lib/cli.ts';
|
|
3
3
|
export declare const spec: {
|
|
4
4
|
readonly name: 'bootstrap';
|
|
5
|
-
readonly summary: 'Set the project up on this machine,
|
|
5
|
+
readonly summary: 'Set the project up on this machine: Node, its own port, the install, TypeSafe and Conductor. Safe to run again.';
|
|
6
6
|
readonly flags: {
|
|
7
7
|
readonly port: {
|
|
8
8
|
readonly type: 'number';
|
|
@@ -25,25 +25,8 @@ export declare const spec: {
|
|
|
25
25
|
readonly default: 'main';
|
|
26
26
|
readonly description: 'The branch Conductor workspaces land on.';
|
|
27
27
|
};
|
|
28
|
-
readonly vercel: {
|
|
29
|
-
readonly type: 'string';
|
|
30
|
-
readonly description: 'Link this Vercel project and set the gate’s signing secret on it.';
|
|
31
|
-
};
|
|
32
|
-
readonly team: {
|
|
33
|
-
readonly type: 'string';
|
|
34
|
-
readonly description: 'The Vercel team (its slug) the project lives in or is created in. Absent, the CLI’s current team.';
|
|
35
|
-
};
|
|
36
|
-
readonly review: {
|
|
37
|
-
readonly type: 'boolean';
|
|
38
|
-
readonly description: 'Provision the review store (Upstash Redis) on the Vercel project.';
|
|
39
|
-
};
|
|
40
|
-
readonly access: {
|
|
41
|
-
readonly type: 'string';
|
|
42
|
-
readonly choices: readonly ["3m", "6m", "open"];
|
|
43
|
-
readonly description: 'With --review: how long a new client keeps access by default, 3m, 6m or open. Absent, the store keeps what it has (3m when unset).';
|
|
44
|
-
};
|
|
45
28
|
};
|
|
46
|
-
readonly output: '{ ok, node, port, install, typesafe, conductor?,
|
|
29
|
+
readonly output: '{ ok, node, port, install, typesafe, conductor?, warnings }';
|
|
47
30
|
};
|
|
48
31
|
/**
|
|
49
32
|
* What `design-hub dev`, `open` and `preview` run first, so a fresh clone or
|
|
@@ -57,19 +40,6 @@ export declare function ensurePort(): {
|
|
|
57
40
|
claimed: boolean;
|
|
58
41
|
warnings: string[];
|
|
59
42
|
};
|
|
60
|
-
|
|
61
|
-
* Runs `steps` and then puts .gitignore back as `restoreGitignore` says, even
|
|
62
|
-
* when a step throws: `vercel link` appends to it, and a later failure (the
|
|
63
|
-
* Upstash terms, most often) would otherwise leave the tree dirty.
|
|
64
|
-
*/
|
|
65
|
-
export declare function keepingGitignore<T>(dir: string, steps: () => T | Promise<T>): Promise<T>;
|
|
66
|
-
/**
|
|
67
|
-
* The gate's env: the signing secret, kept when .env has one and made once
|
|
68
|
-
* otherwise. Nothing else: people sign in with their own one-time links.
|
|
69
|
-
*/
|
|
70
|
-
export declare function gateValues(env: Record<string, string>): {
|
|
71
|
-
GATE_SECRET: string;
|
|
72
|
-
};
|
|
73
|
-
export declare function main({ flags }: Args<typeof spec>): Promise<{
|
|
43
|
+
export declare function main({ flags }: Args<typeof spec>): {
|
|
74
44
|
warnings: string[];
|
|
75
|
-
}
|
|
45
|
+
};
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
// The mechanical setup of a project: what a prose step would
|
|
4
|
-
// improvise on some runs, where the failure is silent (a port another
|
|
5
|
-
// owns, a
|
|
3
|
+
// The mechanical setup of a project on this machine: what a prose step would
|
|
4
|
+
// skip or improvise on some runs, where the failure is silent (a port another
|
|
5
|
+
// project owns, a .env that is not ignored). Judgment stays in the skills. A
|
|
6
|
+
// project has no deployment of its own: it is shared into a studio
|
|
7
|
+
// (`design-hub project link`, `design-hub share`).
|
|
6
8
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
7
|
-
import {
|
|
8
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
9
|
-
import { tmpdir } from 'node:os';
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
|
-
import { ACCESS } from '../core/review/model.js';
|
|
12
11
|
import { harnessPort, readEnv, writeEnv } from '../server/env.js';
|
|
13
12
|
import { ROOT, TEMPLATES } from '../server/paths.js';
|
|
14
13
|
import { CliError } from './lib/cli.js';
|
|
15
|
-
import { gitConnected, restoreGitignore, upstashTerms } from './lib/deploy.js';
|
|
16
14
|
import { holderOf, pickPort, readClaims, writeClaim } from './lib/ports.js';
|
|
17
|
-
import { cliActor, cliReview } from './lib/review.js';
|
|
18
|
-
import { ENVIRONMENTS, envNames, linkedOrg, linkedProject, projectInfo, STORE_ENV, setEnv, vercel, whoami, } from './lib/vercel.js';
|
|
19
15
|
export const spec = {
|
|
20
16
|
name: 'bootstrap',
|
|
21
|
-
summary: 'Set the project up on this machine,
|
|
17
|
+
summary: 'Set the project up on this machine: Node, its own port, the install, TypeSafe and Conductor. Safe to run again.',
|
|
22
18
|
flags: {
|
|
23
19
|
port: {
|
|
24
20
|
type: 'number',
|
|
@@ -28,28 +24,10 @@ export const spec = {
|
|
|
28
24
|
'typesafe-key': { type: 'string', description: "Turn TypeSafe's Jev checks on with this API key." },
|
|
29
25
|
conductor: { type: 'boolean', description: 'Write .conductor/settings.toml for Conductor workspaces.' },
|
|
30
26
|
branch: { type: 'string', default: 'main', description: 'The branch Conductor workspaces land on.' },
|
|
31
|
-
vercel: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
description: 'Link this Vercel project and set the gate’s signing secret on it.',
|
|
34
|
-
},
|
|
35
|
-
team: {
|
|
36
|
-
type: 'string',
|
|
37
|
-
description: 'The Vercel team (its slug) the project lives in or is created in. Absent, the CLI’s current team.',
|
|
38
|
-
},
|
|
39
|
-
review: {
|
|
40
|
-
type: 'boolean',
|
|
41
|
-
description: 'Provision the review store (Upstash Redis) on the Vercel project.',
|
|
42
|
-
},
|
|
43
|
-
access: {
|
|
44
|
-
type: 'string',
|
|
45
|
-
choices: ACCESS,
|
|
46
|
-
description: 'With --review: how long a new client keeps access by default, 3m, 6m or open. Absent, the store keeps what it has (3m when unset).',
|
|
47
|
-
},
|
|
48
27
|
},
|
|
49
|
-
output: '{ ok, node, port, install, typesafe, conductor?,
|
|
28
|
+
output: '{ ok, node, port, install, typesafe, conductor?, warnings }',
|
|
50
29
|
};
|
|
51
30
|
const MIN_NODE = [22, 18];
|
|
52
|
-
const UPSTASH = 'upstash/upstash-kv';
|
|
53
31
|
function run(cmd, argv, cwd = ROOT) {
|
|
54
32
|
const out = spawnSync(cmd, argv, { cwd, encoding: 'utf8', env: process.env });
|
|
55
33
|
if (out.error)
|
|
@@ -163,160 +141,6 @@ function writeConductor(branch, warnings) {
|
|
|
163
141
|
writeFileSync(file, text);
|
|
164
142
|
return 'written';
|
|
165
143
|
}
|
|
166
|
-
function cli(args, input) {
|
|
167
|
-
const out = vercel(ROOT, args, input);
|
|
168
|
-
if (!out)
|
|
169
|
-
throw new CliError('The Vercel CLI is not installed.', { fix: 'npm i -g vercel, then vercel login.' });
|
|
170
|
-
if (out.status !== 0)
|
|
171
|
-
throw new CliError(`vercel ${args.slice(0, 2).join(' ')} failed.`, {
|
|
172
|
-
stderr: out.stderr.trim().slice(-600),
|
|
173
|
-
fix: /log ?in|credentials|token/i.test(out.stderr)
|
|
174
|
-
? 'design-hub signin, send the user its url, then run this again.'
|
|
175
|
-
: undefined,
|
|
176
|
-
});
|
|
177
|
-
return out.stdout;
|
|
178
|
-
}
|
|
179
|
-
function link(project, team, warnings) {
|
|
180
|
-
const current = linkedProject(ROOT);
|
|
181
|
-
if (current === project)
|
|
182
|
-
return 'kept';
|
|
183
|
-
if (current)
|
|
184
|
-
warnings.push(`.vercel/project.json pointed at ${current}; relinked to ${project}.`);
|
|
185
|
-
// A new project is created in the scope given; without one the CLI's current team wins, which
|
|
186
|
-
// is whichever team the user last switched to, not necessarily where this project belongs.
|
|
187
|
-
cli(['link', '--yes', '--project', project, ...(team ? ['--scope', team] : [])]);
|
|
188
|
-
return 'ran';
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Runs `steps` and then puts .gitignore back as `restoreGitignore` says, even
|
|
192
|
-
* when a step throws: `vercel link` appends to it, and a later failure (the
|
|
193
|
-
* Upstash terms, most often) would otherwise leave the tree dirty.
|
|
194
|
-
*/
|
|
195
|
-
export async function keepingGitignore(dir, steps) {
|
|
196
|
-
const file = join(dir, '.gitignore');
|
|
197
|
-
const read = () => (existsSync(file) ? readFileSync(file, 'utf8') : '');
|
|
198
|
-
const before = read();
|
|
199
|
-
try {
|
|
200
|
-
return await steps();
|
|
201
|
-
}
|
|
202
|
-
finally {
|
|
203
|
-
const kept = restoreGitignore(before, read());
|
|
204
|
-
if (kept !== null)
|
|
205
|
-
writeFileSync(file, kept);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
/** The `origin` remote, or null when the project has none. */
|
|
209
|
-
function origin() {
|
|
210
|
-
const out = spawnSync('git', ['-C', ROOT, 'remote', 'get-url', 'origin'], { encoding: 'utf8' });
|
|
211
|
-
return out.status === 0 ? out.stdout.trim() || null : null;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Connects the Vercel project to the repo, so pushing the production branch
|
|
215
|
-
* deploys it. Without a remote, or when Vercel cannot reach the repo, it stays
|
|
216
|
-
* unconnected and `design-hub share` uploads the folder instead.
|
|
217
|
-
*/
|
|
218
|
-
function connectGit(project, team, warnings) {
|
|
219
|
-
const remote = origin();
|
|
220
|
-
if (!remote)
|
|
221
|
-
return 'none';
|
|
222
|
-
if (gitConnected(projectInfo(ROOT, project, team ?? linkedOrg(ROOT))))
|
|
223
|
-
return 'kept';
|
|
224
|
-
const out = vercel(ROOT, ['git', 'connect', remote, '--yes']);
|
|
225
|
-
if (out?.status === 0)
|
|
226
|
-
return 'connected';
|
|
227
|
-
warnings.push(`Could not connect ${remote} to the Vercel project, so design-hub share will upload the folder instead of deploying on push. ` +
|
|
228
|
-
'To deploy on push, the user gives Vercel access to the repo at https://github.com/apps/vercel/installations/new, then run this again. ' +
|
|
229
|
-
(out?.stderr.trim().split('\n').pop() ?? ''));
|
|
230
|
-
return 'none';
|
|
231
|
-
}
|
|
232
|
-
/** Sets each value where it is missing, and keeps the ones already there. */
|
|
233
|
-
function ensureEnv(values) {
|
|
234
|
-
const state = {};
|
|
235
|
-
for (const target of ENVIRONMENTS) {
|
|
236
|
-
const names = envNames(ROOT, target);
|
|
237
|
-
if (!names)
|
|
238
|
-
throw new CliError(`vercel env ls ${target} failed.`, {
|
|
239
|
-
fix: 'design-hub signin, then run this again.',
|
|
240
|
-
});
|
|
241
|
-
for (const [name, value] of Object.entries(values)) {
|
|
242
|
-
const key = `${name}:${target}`;
|
|
243
|
-
if (names.has(name)) {
|
|
244
|
-
state[key] = 'kept';
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
const out = setEnv(ROOT, name, target, value);
|
|
248
|
-
if (out?.status !== 0)
|
|
249
|
-
throw new CliError(`vercel env add ${name} ${target} failed.`, { stderr: out?.stderr.trim() });
|
|
250
|
-
state[key] = 'set';
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return state;
|
|
254
|
-
}
|
|
255
|
-
/** Reads one environment's values into memory and deletes the file, keeping only `names`. */
|
|
256
|
-
function pullValues(target, names) {
|
|
257
|
-
const dir = mkdtempSync(join(tmpdir(), 'hub-env-'));
|
|
258
|
-
try {
|
|
259
|
-
const file = join(dir, '.env');
|
|
260
|
-
cli(['env', 'pull', file, `--environment=${target}`, '--yes']);
|
|
261
|
-
const pulled = readEnv(dir);
|
|
262
|
-
return Object.fromEntries(names.filter((n) => pulled[n]).map((n) => [n, pulled[n]]));
|
|
263
|
-
}
|
|
264
|
-
finally {
|
|
265
|
-
rmSync(dir, { recursive: true, force: true });
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/** `--scope` for the commands that name the project instead of reading the link. */
|
|
269
|
-
const scopeArgs = (team) => {
|
|
270
|
-
const scope = team ?? linkedOrg(ROOT);
|
|
271
|
-
return scope ? ['--scope', scope] : [];
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
274
|
-
* Vercel Authentication is on for every new project on a team, and it sends each
|
|
275
|
-
* visitor to a Vercel login before the gate. The gate is the protection, so it goes
|
|
276
|
-
* off. Idempotent: disabling twice is fine.
|
|
277
|
-
*/
|
|
278
|
-
function protection(project, team) {
|
|
279
|
-
cli(['project', 'protection', 'disable', project, '--sso', ...scopeArgs(team)]);
|
|
280
|
-
return 'off';
|
|
281
|
-
}
|
|
282
|
-
function provisionReview(project, team, warnings) {
|
|
283
|
-
const names = envNames(ROOT, 'production');
|
|
284
|
-
let store = 'kept';
|
|
285
|
-
if (!names || !STORE_ENV.every((n) => names.has(n))) {
|
|
286
|
-
const out = vercel(ROOT, [
|
|
287
|
-
'integration',
|
|
288
|
-
'add',
|
|
289
|
-
UPSTASH,
|
|
290
|
-
'--name',
|
|
291
|
-
`${project}-review`,
|
|
292
|
-
'-e',
|
|
293
|
-
'production',
|
|
294
|
-
'-e',
|
|
295
|
-
'preview',
|
|
296
|
-
'-e',
|
|
297
|
-
'development',
|
|
298
|
-
'--no-env-pull',
|
|
299
|
-
// Unlike env and deploy, this command ignores the project link and takes the CLI's current team.
|
|
300
|
-
...scopeArgs(team),
|
|
301
|
-
]);
|
|
302
|
-
if (out?.status !== 0) {
|
|
303
|
-
const terms = upstashTerms(out?.stderr ?? '', team);
|
|
304
|
-
throw new CliError('Could not add the Upstash for Redis store; most often the team has not accepted the Upstash terms yet.', {
|
|
305
|
-
stderr: out?.stderr.trim().slice(-600),
|
|
306
|
-
terms: terms.url,
|
|
307
|
-
fix: `Tell the user, word for word: "${terms.say}" Then run this again.`,
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
store = 'created';
|
|
311
|
-
}
|
|
312
|
-
// The local commands (design-hub people, design-hub comments) read the same store.
|
|
313
|
-
const values = pullValues('production', STORE_ENV);
|
|
314
|
-
const missing = STORE_ENV.filter((n) => !values[n]);
|
|
315
|
-
if (missing.length)
|
|
316
|
-
warnings.push(`Could not read ${missing.join(', ')} back; copy them from the store's page on Vercel into .env.`);
|
|
317
|
-
writeEnv(ROOT, values);
|
|
318
|
-
return { store, local: missing.length ? 'partial' : 'written' };
|
|
319
|
-
}
|
|
320
144
|
function install(skip) {
|
|
321
145
|
if (skip)
|
|
322
146
|
return 'skipped';
|
|
@@ -332,56 +156,6 @@ function typesafe(given, current) {
|
|
|
332
156
|
writeEnv(ROOT, { TYPESAFE_API_KEY: given });
|
|
333
157
|
return given;
|
|
334
158
|
}
|
|
335
|
-
/**
|
|
336
|
-
* The gate's env: the signing secret, kept when .env has one and made once
|
|
337
|
-
* otherwise. Nothing else: people sign in with their own one-time links.
|
|
338
|
-
*/
|
|
339
|
-
export function gateValues(env) {
|
|
340
|
-
return { GATE_SECRET: env.GATE_SECRET || randomBytes(32).toString('base64') };
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Sets the project default access length in the deployed store. When the
|
|
344
|
-
* store's credentials did not reach .env, the CLI would reach the local
|
|
345
|
-
* store instead, so it says how to set it later rather than set the wrong one.
|
|
346
|
-
*/
|
|
347
|
-
async function setDefaultAccess(access, warnings) {
|
|
348
|
-
const { review, store } = cliReview(false);
|
|
349
|
-
if (store !== 'deployed') {
|
|
350
|
-
warnings.push(`Could not set the default access length: the store's credentials are not in .env. Once they are, run design-hub people access --access ${access}.`);
|
|
351
|
-
return undefined;
|
|
352
|
-
}
|
|
353
|
-
return review.setDefaultAccess(cliActor(), access);
|
|
354
|
-
}
|
|
355
|
-
async function setUpVercel(project, flags, env, typesafeKey, warnings) {
|
|
356
|
-
if (!whoami(ROOT))
|
|
357
|
-
throw new CliError('The Vercel CLI is not installed or not signed in.', {
|
|
358
|
-
fix: 'design-hub signin, send the user its url, then run this again.',
|
|
359
|
-
});
|
|
360
|
-
const linked = link(project, flags.team, warnings);
|
|
361
|
-
const gate = gateValues(env);
|
|
362
|
-
writeEnv(ROOT, gate);
|
|
363
|
-
const values = { ...gate };
|
|
364
|
-
// Comment triage runs on the server, so with the review store on, the key goes to Vercel too.
|
|
365
|
-
if (flags.review && typesafeKey)
|
|
366
|
-
values.TYPESAFE_API_KEY = typesafeKey;
|
|
367
|
-
const result = {
|
|
368
|
-
vercel: {
|
|
369
|
-
project,
|
|
370
|
-
linked,
|
|
371
|
-
git: connectGit(project, flags.team, warnings),
|
|
372
|
-
protection: protection(project, flags.team),
|
|
373
|
-
env: ensureEnv(values),
|
|
374
|
-
},
|
|
375
|
-
};
|
|
376
|
-
if (!flags.review) {
|
|
377
|
-
warnings.push('Nobody can sign in yet: each person signs in with a one-time link the review store keeps. Run this again with --review.');
|
|
378
|
-
return result;
|
|
379
|
-
}
|
|
380
|
-
const review = provisionReview(project, flags.team, warnings);
|
|
381
|
-
const access = flags.access ? await setDefaultAccess(flags.access, warnings) : undefined;
|
|
382
|
-
warnings.push('Run design-hub share so the new env reaches the site; then design-hub people add --name "<you>" --team "<studio>" --kind studio --site <url>.');
|
|
383
|
-
return { ...result, review: access ? { ...review, access } : review };
|
|
384
|
-
}
|
|
385
159
|
function envIgnored(warnings) {
|
|
386
160
|
try {
|
|
387
161
|
execFileSync('git', ['-C', ROOT, 'check-ignore', '-q', '.env']);
|
|
@@ -396,13 +170,7 @@ function envIgnored(warnings) {
|
|
|
396
170
|
if (tracked.status === 0)
|
|
397
171
|
warnings.push('.claude/launch.json is committed but holds this folder’s port. Run `git rm --cached .claude/launch.json` and add it to .gitignore.');
|
|
398
172
|
}
|
|
399
|
-
export
|
|
400
|
-
if (flags.review && !flags.vercel)
|
|
401
|
-
throw new CliError('--review needs --vercel <project>.');
|
|
402
|
-
if (flags.access && !flags.review)
|
|
403
|
-
throw new CliError('--access needs --review.', {
|
|
404
|
-
fix: 'Or set it later: design-hub people access --access <3m|6m|open>.',
|
|
405
|
-
});
|
|
173
|
+
export function main({ flags }) {
|
|
406
174
|
const warnings = [];
|
|
407
175
|
const node = checkNode();
|
|
408
176
|
const env = readEnv(ROOT);
|
|
@@ -417,9 +185,6 @@ export async function main({ flags }) {
|
|
|
417
185
|
};
|
|
418
186
|
if (flags.conductor)
|
|
419
187
|
result.conductor = writeConductor(flags.branch, warnings);
|
|
420
|
-
const project = flags.vercel;
|
|
421
|
-
if (project)
|
|
422
|
-
Object.assign(result, await keepingGitignore(ROOT, () => setUpVercel(project, flags, env, typesafeKey, warnings)));
|
|
423
188
|
envIgnored(warnings);
|
|
424
189
|
return { ...result, warnings };
|
|
425
190
|
}
|
package/dist/scripts/cli.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import * as bootstrap from './bootstrap.js';
|
|
10
10
|
import * as calibrate from './calibrate.js';
|
|
11
11
|
import * as check from './check.js';
|
|
12
|
+
import * as client from './client.js';
|
|
12
13
|
import * as commands from './commands.js';
|
|
13
14
|
import * as comments from './comments.js';
|
|
14
15
|
import * as dev from './dev.js';
|
|
@@ -21,11 +22,13 @@ import { runCommand } from './lib/cli.js';
|
|
|
21
22
|
import * as create from './new.js';
|
|
22
23
|
import * as people from './people.js';
|
|
23
24
|
import * as preflight from './preflight.js';
|
|
25
|
+
import * as project from './project.js';
|
|
24
26
|
import * as releaseCheck from './release-check.js';
|
|
25
27
|
import * as share from './share.js';
|
|
26
28
|
import * as signin from './signin.js';
|
|
27
29
|
import * as skillHint from './skill-hint.js';
|
|
28
30
|
import * as skills from './skills.js';
|
|
31
|
+
import * as studio from './studio.js';
|
|
29
32
|
import * as tracks from './tracks.js';
|
|
30
33
|
import * as upgrade from './upgrade.js';
|
|
31
34
|
import * as visualMatch from './visual-match.js';
|
|
@@ -47,6 +50,9 @@ const COMMANDS = {
|
|
|
47
50
|
signin,
|
|
48
51
|
share,
|
|
49
52
|
people,
|
|
53
|
+
studio,
|
|
54
|
+
client,
|
|
55
|
+
project,
|
|
50
56
|
comments,
|
|
51
57
|
calibrate,
|
|
52
58
|
'fixtures-pull': fixturesPull,
|