@milesroxas/design-hub 0.1.3 → 0.3.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/core/catalog.test.ts +10 -1
- package/core/catalog.ts +11 -0
- package/core/cms.test.ts +103 -0
- package/core/cms.ts +178 -0
- package/core/export.test.ts +127 -0
- package/core/export.ts +120 -0
- package/core/formats.ts +60 -0
- package/core/project.test.ts +71 -0
- package/core/project.ts +147 -0
- package/dist/core/catalog.d.ts +5 -0
- package/dist/core/catalog.js +10 -0
- package/dist/core/cms.d.ts +40 -0
- package/dist/core/cms.js +141 -0
- package/dist/core/export.d.ts +52 -0
- package/dist/core/export.js +84 -0
- package/dist/core/formats.d.ts +90 -0
- package/dist/core/formats.js +39 -0
- package/dist/core/project.d.ts +56 -0
- package/dist/core/project.js +121 -0
- package/dist/scripts/bootstrap.d.ts +12 -0
- package/dist/scripts/bootstrap.js +62 -13
- package/dist/scripts/cli.js +4 -0
- package/dist/scripts/commands.js +4 -0
- package/dist/scripts/dev.d.ts +2 -2
- package/dist/scripts/dev.js +13 -2
- package/dist/scripts/export.d.ts +42 -0
- package/dist/scripts/export.js +192 -0
- package/dist/scripts/fixtures-pull.d.ts +31 -19
- package/dist/scripts/fixtures-pull.js +102 -62
- package/dist/scripts/lib/cdp.d.ts +11 -0
- package/dist/scripts/lib/cdp.js +110 -0
- package/dist/scripts/new.d.ts +13 -1
- package/dist/scripts/new.js +43 -4
- package/dist/scripts/skills.js +4 -0
- package/dist/scripts/tracks.d.ts +40 -0
- package/dist/scripts/tracks.js +93 -0
- package/dist/server/env.d.ts +15 -3
- package/dist/server/env.js +23 -5
- package/dist/server/paths.d.ts +2 -0
- package/dist/server/paths.js +2 -0
- package/dist/server/project.d.ts +7 -0
- package/dist/server/project.js +29 -0
- package/dist/vite/plugin.d.ts +3 -3
- package/dist/vite/plugin.js +7 -4
- package/kit/Artboard.tsx +160 -0
- package/kit/artboard.css +47 -0
- package/kit/dials.tsx +2 -1
- package/package.json +1 -1
- package/shell/Index.tsx +49 -4
- package/shell/main.tsx +6 -2
- package/shell/shell.css +7 -3
- package/skills/miles-brand/SKILL.md +52 -0
- package/skills/miles-design-hub/SKILL.md +60 -25
- package/skills/miles-get-hostile/SKILL.md +7 -5
- package/skills/miles-new-feature/SKILL.md +8 -7
- package/skills/miles-port/SKILL.md +14 -2
- package/skills/miles-port/references/emdash.md +43 -0
- package/skills/miles-port/references/payload.md +31 -0
- package/skills/miles-port/references/wordpress.md +31 -0
- package/skills/miles-prototype/SKILL.md +2 -2
- package/skills/miles-worktrees/SKILL.md +56 -0
- package/templates/app/README.md +1 -0
- package/templates/brand/README.md +48 -0
- package/templates/brand/index.tsx +16 -0
- package/templates/brand/styles.css +5 -0
- package/templates/site/README.md +42 -0
- package/templates/site/index.tsx +22 -0
- package/templates/site/styles.css +6 -0
- package/templates/space/README.md +1 -0
- package/skills/miles-conductor/SKILL.md +0 -37
package/dist/scripts/new.js
CHANGED
|
@@ -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
|
|
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: {
|
|
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
|
|
94
|
-
|
|
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}/`),
|
package/dist/scripts/skills.js
CHANGED
|
@@ -15,12 +15,16 @@ export const spec = {
|
|
|
15
15
|
output: '{ ok, installed: [name], into }',
|
|
16
16
|
};
|
|
17
17
|
const GLOBAL_ONLY = new Set(['miles-design-hub']);
|
|
18
|
+
/** Skills the package no longer ships, removed from a project on update. miles-conductor became miles-worktrees in 0.2.0. */
|
|
19
|
+
const RETIRED = ['miles-conductor'];
|
|
18
20
|
export function installSkills(from = PACKAGE_SKILLS, into = SKILLS) {
|
|
19
21
|
const names = readdirSync(from, { withFileTypes: true })
|
|
20
22
|
.filter((d) => d.isDirectory() && d.name.startsWith('miles-') && !GLOBAL_ONLY.has(d.name))
|
|
21
23
|
.map((d) => d.name)
|
|
22
24
|
.sort();
|
|
23
25
|
mkdirSync(into, { recursive: true });
|
|
26
|
+
for (const name of RETIRED)
|
|
27
|
+
rmSync(join(into, name), { recursive: true, force: true });
|
|
24
28
|
for (const name of names) {
|
|
25
29
|
const dest = join(into, name);
|
|
26
30
|
if (existsSync(dest))
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { type Track } from '../core/project.ts';
|
|
3
|
+
import { type Args } from './lib/cli.ts';
|
|
4
|
+
export declare const spec: {
|
|
5
|
+
readonly name: 'tracks';
|
|
6
|
+
readonly summary: "Show or set the project's tracks (product, website, brand) and its website platform.";
|
|
7
|
+
readonly positionals: [{
|
|
8
|
+
readonly name: 'action';
|
|
9
|
+
readonly description: 'show (default): what project.json says. set: write it.';
|
|
10
|
+
}];
|
|
11
|
+
readonly flags: {
|
|
12
|
+
readonly track: {
|
|
13
|
+
readonly type: 'list';
|
|
14
|
+
readonly description: `For set: a track, repeated for several. One of: ${string}.`;
|
|
15
|
+
};
|
|
16
|
+
readonly platform: {
|
|
17
|
+
readonly type: 'string';
|
|
18
|
+
readonly choices: readonly ["webflow", "payload", "wordpress", "emdash"];
|
|
19
|
+
readonly description: 'For set, with the website track: where the site is built.';
|
|
20
|
+
};
|
|
21
|
+
readonly frontend: {
|
|
22
|
+
readonly type: 'string';
|
|
23
|
+
readonly choices: readonly ["astro", "next"];
|
|
24
|
+
readonly description: 'For set: the front end, for Payload or WordPress. Webflow takes none; EmDash is always Astro.';
|
|
25
|
+
};
|
|
26
|
+
readonly 'remove-samples': {
|
|
27
|
+
readonly type: 'boolean';
|
|
28
|
+
readonly description: 'For set: delete the sample prototype and walkthrough of every track not set. Setup only.';
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
readonly output: '{ ok, tracks, website?, file, removed?, warnings }';
|
|
32
|
+
};
|
|
33
|
+
/** Deletes the samples of the tracks a project does not keep; returns what went, relative to the project. */
|
|
34
|
+
export declare function removeSamples(keep: readonly Track[], prototypes?: string, docs?: string, root?: string): string[];
|
|
35
|
+
export declare function main(args: Args<typeof spec>): {
|
|
36
|
+
tracks: Track[];
|
|
37
|
+
website?: import("../core/project.ts").Website;
|
|
38
|
+
file: string;
|
|
39
|
+
warnings: string[];
|
|
40
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
// `design-hub tracks`: what kind of engagement the project is. `set` writes
|
|
4
|
+
// .design-hub/project.json (the tracks, and for a website its platform and
|
|
5
|
+
// front end); with --remove-samples it also drops the sample prototype and
|
|
6
|
+
// walkthrough of every track the project does not have, which is what setup
|
|
7
|
+
// wants and nothing later should do unasked.
|
|
8
|
+
import { existsSync, rmSync } from 'node:fs';
|
|
9
|
+
import { join, relative } from 'node:path';
|
|
10
|
+
import { FRONTENDS, makeProject, needsPlatform, PLATFORMS, samplesOutside, TRACKS, } from '../core/project.js';
|
|
11
|
+
import { DOCS, PROJECT_JSON, PROTOTYPES, ROOT } from '../server/paths.js';
|
|
12
|
+
import { readProject, writeProject } from '../server/project.js';
|
|
13
|
+
import { CliError } from './lib/cli.js';
|
|
14
|
+
export const spec = {
|
|
15
|
+
name: 'tracks',
|
|
16
|
+
summary: "Show or set the project's tracks (product, website, brand) and its website platform.",
|
|
17
|
+
positionals: [{ name: 'action', description: 'show (default): what project.json says. set: write it.' }],
|
|
18
|
+
flags: {
|
|
19
|
+
track: {
|
|
20
|
+
type: 'list',
|
|
21
|
+
description: `For set: a track, repeated for several. One of: ${TRACKS.join(', ')}.`,
|
|
22
|
+
},
|
|
23
|
+
platform: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
choices: PLATFORMS,
|
|
26
|
+
description: 'For set, with the website track: where the site is built.',
|
|
27
|
+
},
|
|
28
|
+
frontend: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
choices: FRONTENDS,
|
|
31
|
+
description: 'For set: the front end, for Payload or WordPress. Webflow takes none; EmDash is always Astro.',
|
|
32
|
+
},
|
|
33
|
+
'remove-samples': {
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
description: 'For set: delete the sample prototype and walkthrough of every track not set. Setup only.',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
output: '{ ok, tracks, website?, file, removed?, warnings }',
|
|
39
|
+
};
|
|
40
|
+
/** Deletes the samples of the tracks a project does not keep; returns what went, relative to the project. */
|
|
41
|
+
export function removeSamples(keep, prototypes = PROTOTYPES, docs = DOCS, root = ROOT) {
|
|
42
|
+
const removed = [];
|
|
43
|
+
for (const { slug, feature } of samplesOutside(keep)) {
|
|
44
|
+
for (const dir of [join(prototypes, slug), join(docs, 'sprints', feature)]) {
|
|
45
|
+
if (!existsSync(dir))
|
|
46
|
+
continue;
|
|
47
|
+
rmSync(dir, { recursive: true, force: true });
|
|
48
|
+
removed.push(`${relative(root, dir)}/`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return removed;
|
|
52
|
+
}
|
|
53
|
+
const warningsFor = (project) => needsPlatform(project)
|
|
54
|
+
? ['The website track has no platform yet. Set it with --platform before porting: miles-port needs it.']
|
|
55
|
+
: [];
|
|
56
|
+
function show() {
|
|
57
|
+
const { project, problems } = readProject();
|
|
58
|
+
if (problems.length)
|
|
59
|
+
throw new CliError('project.json is invalid.', {
|
|
60
|
+
problems,
|
|
61
|
+
fix: 'Rewrite it with design-hub tracks set.',
|
|
62
|
+
});
|
|
63
|
+
if (!project)
|
|
64
|
+
return {
|
|
65
|
+
tracks: [],
|
|
66
|
+
file: relative(ROOT, PROJECT_JSON),
|
|
67
|
+
warnings: [
|
|
68
|
+
'No tracks recorded: every track is allowed. Record them with design-hub tracks set --track <track>.',
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
return { ...project, file: relative(ROOT, PROJECT_JSON), warnings: warningsFor(project) };
|
|
72
|
+
}
|
|
73
|
+
function set({ flags }) {
|
|
74
|
+
const made = makeProject(flags.track, { platform: flags.platform, frontend: flags.frontend });
|
|
75
|
+
if ('problems' in made)
|
|
76
|
+
throw new CliError(made.problems.join(' '), { fix: 'design-hub tracks --help lists the choices.' });
|
|
77
|
+
writeProject(made.project);
|
|
78
|
+
const removed = flags['remove-samples'] ? removeSamples(made.project.tracks) : undefined;
|
|
79
|
+
return {
|
|
80
|
+
...made.project,
|
|
81
|
+
file: relative(ROOT, PROJECT_JSON),
|
|
82
|
+
...(removed ? { removed } : {}),
|
|
83
|
+
warnings: warningsFor(made.project),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function main(args) {
|
|
87
|
+
const [action = 'show'] = args.positionals;
|
|
88
|
+
if (action === 'show')
|
|
89
|
+
return show();
|
|
90
|
+
if (action === 'set')
|
|
91
|
+
return set(args);
|
|
92
|
+
throw new CliError(`Unknown action ${action}.`, { fix: 'Use show or set.' });
|
|
93
|
+
}
|
package/dist/server/env.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
export declare function readEnv(dir: string): Record<string, string>;
|
|
2
2
|
export declare function writeEnv(dir: string, updates: Record<string, string>): void;
|
|
3
|
+
/** The variables a harness (Conductor, T3 Code, a script) may hand a worktree its port in, first wins. */
|
|
4
|
+
declare const HARNESS_PORT_VARS: readonly ['DESIGN_HUB_PORT', 'CONDUCTOR_PORT'];
|
|
3
5
|
/**
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* The port a harness gave this process, and the variable it came in. A
|
|
7
|
+
* harness owns these ports: they never enter the machine registry. A bare
|
|
8
|
+
* `PORT` is not one: shells and other tools export it for their own servers.
|
|
9
|
+
*/
|
|
10
|
+
export declare function harnessPort(processEnv?: Record<string, string | undefined>): {
|
|
11
|
+
port: number;
|
|
12
|
+
from: (typeof HARNESS_PORT_VARS)[number];
|
|
13
|
+
} | null;
|
|
14
|
+
/**
|
|
15
|
+
* The dev server's port: the harness's when one gave it, because its Open
|
|
16
|
+
* button points there; else the PORT in .env, which `design-hub dev` and
|
|
17
|
+
* `design-hub bootstrap` claim for this folder.
|
|
7
18
|
*/
|
|
8
19
|
export declare function devPort(fileEnv: Record<string, string>, processEnv?: Record<string, string | undefined>): number | undefined;
|
|
20
|
+
export {};
|
package/dist/server/env.js
CHANGED
|
@@ -46,12 +46,30 @@ export function writeEnv(dir, updates) {
|
|
|
46
46
|
const text = next.join('\n').replace(/\n*$/, '\n');
|
|
47
47
|
writeFileSync(file, text, { mode: 0o600 });
|
|
48
48
|
}
|
|
49
|
+
/** The variables a harness (Conductor, T3 Code, a script) may hand a worktree its port in, first wins. */
|
|
50
|
+
const HARNESS_PORT_VARS = ['DESIGN_HUB_PORT', 'CONDUCTOR_PORT'];
|
|
51
|
+
function asPort(value) {
|
|
52
|
+
const port = Number(value);
|
|
53
|
+
return Number.isInteger(port) && port > 0 ? port : undefined;
|
|
54
|
+
}
|
|
49
55
|
/**
|
|
50
|
-
* The
|
|
51
|
-
*
|
|
52
|
-
*
|
|
56
|
+
* The port a harness gave this process, and the variable it came in. A
|
|
57
|
+
* harness owns these ports: they never enter the machine registry. A bare
|
|
58
|
+
* `PORT` is not one: shells and other tools export it for their own servers.
|
|
59
|
+
*/
|
|
60
|
+
export function harnessPort(processEnv = process.env) {
|
|
61
|
+
for (const from of HARNESS_PORT_VARS) {
|
|
62
|
+
const port = asPort(processEnv[from]);
|
|
63
|
+
if (port !== undefined)
|
|
64
|
+
return { port, from };
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The dev server's port: the harness's when one gave it, because its Open
|
|
70
|
+
* button points there; else the PORT in .env, which `design-hub dev` and
|
|
71
|
+
* `design-hub bootstrap` claim for this folder.
|
|
53
72
|
*/
|
|
54
73
|
export function devPort(fileEnv, processEnv = process.env) {
|
|
55
|
-
|
|
56
|
-
return Number.isInteger(port) && port > 0 ? port : undefined;
|
|
74
|
+
return harnessPort(processEnv)?.port ?? asPort(fileEnv.PORT);
|
|
57
75
|
}
|
package/dist/server/paths.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare const SKILLS: string;
|
|
|
12
12
|
/** Local state, gitignored but for checks.json: the Jev log and its labels, the dev review store. */
|
|
13
13
|
export declare const STATE_DIR: string;
|
|
14
14
|
export declare const CHECKS_FILE: string;
|
|
15
|
+
/** The project's tracks and website platform (core/project.ts); committed, like checks.json. */
|
|
16
|
+
export declare const PROJECT_JSON: string;
|
|
15
17
|
/** The nearest ancestor of `from` whose package.json names this package, so source and dist agree. */
|
|
16
18
|
export declare function packageRoot(from: string): string;
|
|
17
19
|
/** This package on disk, wherever it is installed: the shell, the kit, the templates, the skills. */
|
package/dist/server/paths.js
CHANGED
|
@@ -53,6 +53,8 @@ export const SKILLS = join(ROOT, '.claude', 'skills');
|
|
|
53
53
|
/** Local state, gitignored but for checks.json: the Jev log and its labels, the dev review store. */
|
|
54
54
|
export const STATE_DIR = join(ROOT, '.design-hub');
|
|
55
55
|
export const CHECKS_FILE = join(STATE_DIR, 'checks.json');
|
|
56
|
+
/** The project's tracks and website platform (core/project.ts); committed, like checks.json. */
|
|
57
|
+
export const PROJECT_JSON = join(STATE_DIR, 'project.json');
|
|
56
58
|
/** The nearest ancestor of `from` whose package.json names this package, so source and dist agree. */
|
|
57
59
|
export function packageRoot(from) {
|
|
58
60
|
let dir = dirname(from);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Project } from '../core/project.ts';
|
|
2
|
+
export type LoadedProject = {
|
|
3
|
+
project: Project | null;
|
|
4
|
+
problems: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function readProject(file?: string): LoadedProject;
|
|
7
|
+
export declare function writeProject(project: Project, file?: string): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
// .design-hub/project.json on disk: the project's tracks and website
|
|
3
|
+
// platform (core/project.ts has the rules). A project made before tracks
|
|
4
|
+
// existed has no file; every reader treats that as "any track", so nothing
|
|
5
|
+
// an older project does stops working.
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
7
|
+
import { dirname } from 'node:path';
|
|
8
|
+
import { parseProject } from '../core/project.js';
|
|
9
|
+
import { PROJECT_JSON } from './paths.js';
|
|
10
|
+
export function readProject(file = PROJECT_JSON) {
|
|
11
|
+
if (!existsSync(file))
|
|
12
|
+
return { project: null, problems: [] };
|
|
13
|
+
try {
|
|
14
|
+
const parsed = parseProject(JSON.parse(readFileSync(file, 'utf8')));
|
|
15
|
+
return 'project' in parsed
|
|
16
|
+
? { project: parsed.project, problems: [] }
|
|
17
|
+
: { project: null, problems: parsed.problems };
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return {
|
|
21
|
+
project: null,
|
|
22
|
+
problems: [`${file}: ${error instanceof Error ? error.message : String(error)}`],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function writeProject(project, file = PROJECT_JSON) {
|
|
27
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
28
|
+
writeFileSync(file, `${JSON.stringify(project, null, 2)}\n`);
|
|
29
|
+
}
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type InlineConfig, type PluginOption } from 'vite';
|
|
2
2
|
export type HubOptions = {
|
|
3
3
|
/** The project: the folder with prototypes/, kit/ and docs/. */
|
|
4
4
|
root: string;
|
|
@@ -7,8 +7,8 @@ export type HubOptions = {
|
|
|
7
7
|
export declare function designHub({ root }: HubOptions): PluginOption[];
|
|
8
8
|
/**
|
|
9
9
|
* The whole config `design-hub dev` and `design-hub build` run on. One port per
|
|
10
|
-
*
|
|
11
|
-
* `design-hub bootstrap`
|
|
10
|
+
* folder: the harness's ($DESIGN_HUB_PORT, $CONDUCTOR_PORT) when one runs us,
|
|
11
|
+
* else the PORT `design-hub dev` or `bootstrap` claimed in .env. strictPort refuses a taken port rather
|
|
12
12
|
* than drifting to the next one, because a fallback silently serves the wrong
|
|
13
13
|
* project. A build needs no port, so Vercel builds without a .env.
|
|
14
14
|
*/
|
package/dist/vite/plugin.js
CHANGED
|
@@ -9,6 +9,7 @@ import { readFileSync } from 'node:fs';
|
|
|
9
9
|
import { createRequire } from 'node:module';
|
|
10
10
|
import { dirname, join } from 'node:path';
|
|
11
11
|
import react from '@vitejs/plugin-react';
|
|
12
|
+
import { searchForWorkspaceRoot } from 'vite';
|
|
12
13
|
import { devReview } from '../server/dev.js';
|
|
13
14
|
import { devPort, readEnv } from '../server/env.js';
|
|
14
15
|
import { PACKAGE, PACKAGE_KIT, SHELL } from '../server/paths.js';
|
|
@@ -61,15 +62,15 @@ export function designHub({ root }) {
|
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
63
64
|
* The whole config `design-hub dev` and `design-hub build` run on. One port per
|
|
64
|
-
*
|
|
65
|
-
* `design-hub bootstrap`
|
|
65
|
+
* folder: the harness's ($DESIGN_HUB_PORT, $CONDUCTOR_PORT) when one runs us,
|
|
66
|
+
* else the PORT `design-hub dev` or `bootstrap` claimed in .env. strictPort refuses a taken port rather
|
|
66
67
|
* than drifting to the next one, because a fallback silently serves the wrong
|
|
67
68
|
* project. A build needs no port, so Vercel builds without a .env.
|
|
68
69
|
*/
|
|
69
70
|
export function hubConfig({ root }, command) {
|
|
70
71
|
const port = devPort(readEnv(root));
|
|
71
72
|
if (command === 'serve' && port === undefined)
|
|
72
|
-
throw new Error('PORT is not set.
|
|
73
|
+
throw new Error('PORT is not set. `design-hub dev` claims one; a config of your own runs `design-hub bootstrap` first.');
|
|
73
74
|
return {
|
|
74
75
|
configFile: false,
|
|
75
76
|
root: SHELL,
|
|
@@ -79,7 +80,9 @@ export function hubConfig({ root }, command) {
|
|
|
79
80
|
plugins: designHub({ root }),
|
|
80
81
|
resolve: { dedupe: ['react', 'react-dom'] },
|
|
81
82
|
optimizeDeps: { entries: [join(SHELL, 'index.html'), join(root, 'prototypes', '*', 'index.tsx')] },
|
|
82
|
-
|
|
83
|
+
// A linked package (a checkout of this repo) keeps its dependencies in
|
|
84
|
+
// the checkout's node_modules, outside both; its workspace root covers them.
|
|
85
|
+
server: { port, strictPort: true, fs: { allow: [root, PACKAGE, searchForWorkspaceRoot(PACKAGE)] } },
|
|
83
86
|
preview: port === undefined ? undefined : { port, strictPort: true },
|
|
84
87
|
build: { outDir: join(root, 'dist'), emptyOutDir: true },
|
|
85
88
|
};
|
package/kit/Artboard.tsx
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
type ReactNode,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { FORMATS, type Format, type FormatName, sizeLabel, zoomFor } from '../core/formats.ts';
|
|
11
|
+
import { restoreDials, useDials } from './dials';
|
|
12
|
+
import { ViewTools } from './ViewTools';
|
|
13
|
+
import './artboard.css';
|
|
14
|
+
|
|
15
|
+
export { FORMAT_NAMES, FORMATS, type FormatName } from '../core/formats.ts';
|
|
16
|
+
|
|
17
|
+
const params = new URLSearchParams(location.search);
|
|
18
|
+
/** True when `design-hub export` opened the page: artboards only, at their real size, no tools. */
|
|
19
|
+
export const exporting = params.has('export');
|
|
20
|
+
|
|
21
|
+
type View = { zoom: string; guides: boolean; room: { width: number; height: number } };
|
|
22
|
+
const BoardView = createContext<View>({ zoom: '100%', guides: false, room: { width: 1e5, height: 1e5 } });
|
|
23
|
+
|
|
24
|
+
const ZOOMS = ['fit', '25%', '50%', '100%'];
|
|
25
|
+
const frames = (n: number) =>
|
|
26
|
+
new Promise<void>((resolve) => {
|
|
27
|
+
const step = (left: number) => (left ? requestAnimationFrame(() => step(left - 1)) : resolve());
|
|
28
|
+
step(n);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/** Applies the export's dial state, waits for fonts and images, then tells the exporter the page is ready. */
|
|
32
|
+
async function settleForExport() {
|
|
33
|
+
const dials = params.get('dials');
|
|
34
|
+
if (dials) restoreDials(JSON.parse(dials));
|
|
35
|
+
await document.fonts.ready;
|
|
36
|
+
await Promise.all([...document.images].map((img) => img.decode().catch(() => undefined)));
|
|
37
|
+
await frames(2);
|
|
38
|
+
document.documentElement.dataset.exportReady = '1';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The width the board has to draw in, and a height that keeps one artboard on screen. */
|
|
42
|
+
function useRoom() {
|
|
43
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
44
|
+
const [room, setRoom] = useState({ width: 1e5, height: 1e5 });
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
const el = ref.current;
|
|
47
|
+
if (!el || exporting) return;
|
|
48
|
+
const measure = () => setRoom({ width: el.clientWidth, height: Math.min(innerHeight * 0.6, 640) });
|
|
49
|
+
measure();
|
|
50
|
+
const observer = new ResizeObserver(measure);
|
|
51
|
+
observer.observe(el);
|
|
52
|
+
return () => observer.disconnect();
|
|
53
|
+
}, []);
|
|
54
|
+
return { ref, room };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type BoardProps = { title: string; lede?: ReactNode; children: ReactNode };
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The canvas brand collateral sits on: every artboard side by side, scaled to
|
|
61
|
+
* fit, with its format and size under it. Under `design-hub export` it is
|
|
62
|
+
* the artboards alone, at their real size.
|
|
63
|
+
*/
|
|
64
|
+
export function Board({ title, lede, children }: BoardProps) {
|
|
65
|
+
const view = useDials(
|
|
66
|
+
'Board',
|
|
67
|
+
{
|
|
68
|
+
zoom: { type: 'select', options: ZOOMS, default: 'fit' },
|
|
69
|
+
guides: true,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
hints: {
|
|
73
|
+
zoom: 'How large the artboards draw on screen. Export always writes them at their real size.',
|
|
74
|
+
guides: "Shade the bands a platform's own interface covers, where type and logos never go.",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
const { ref, room } = useRoom();
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (exporting) void settleForExport();
|
|
82
|
+
}, []);
|
|
83
|
+
|
|
84
|
+
if (exporting)
|
|
85
|
+
return (
|
|
86
|
+
<BoardView.Provider value={{ zoom: '100%', guides: false, room }}>
|
|
87
|
+
<div className="board-export">{children}</div>
|
|
88
|
+
</BoardView.Provider>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<BoardView.Provider value={{ zoom: view.zoom as string, guides: view.guides as boolean, room }}>
|
|
93
|
+
<main className="board">
|
|
94
|
+
<header className="board-head">
|
|
95
|
+
<h1 className="board-title">{title}</h1>
|
|
96
|
+
{lede ? <p className="board-lede">{lede}</p> : null}
|
|
97
|
+
</header>
|
|
98
|
+
<div className="board-grid" ref={ref}>
|
|
99
|
+
{children}
|
|
100
|
+
</div>
|
|
101
|
+
<ViewTools />
|
|
102
|
+
</main>
|
|
103
|
+
</BoardView.Provider>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type ArtboardProps = {
|
|
108
|
+
format: FormatName;
|
|
109
|
+
/** Names the file on export (`<slug>-<name>.png`) and labels it on screen. */
|
|
110
|
+
name?: string;
|
|
111
|
+
children: ReactNode;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* One piece of collateral at its real pixel size: type, spacing and images
|
|
116
|
+
* are drawn at the values that ship. On screen it scales with the Board's
|
|
117
|
+
* zoom; the content never knows.
|
|
118
|
+
*/
|
|
119
|
+
/** The bands a platform's own interface covers, shaded on screen, never exported. */
|
|
120
|
+
function SafeBands({ format }: { format: FormatName }) {
|
|
121
|
+
const f: Format = FORMATS[format];
|
|
122
|
+
if (!f.safe) return null;
|
|
123
|
+
return (
|
|
124
|
+
<>
|
|
125
|
+
<div className="artboard-safe" style={{ top: 0, height: f.safe.top }} aria-hidden="true" />
|
|
126
|
+
<div className="artboard-safe" style={{ bottom: 0, height: f.safe.bottom }} aria-hidden="true" />
|
|
127
|
+
</>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function Artboard({ format, name, children }: ArtboardProps) {
|
|
132
|
+
const { zoom, guides, room } = useContext(BoardView);
|
|
133
|
+
const f = FORMATS[format];
|
|
134
|
+
const scale = exporting ? 1 : zoomFor(zoom, format, room);
|
|
135
|
+
const frame = (
|
|
136
|
+
<div
|
|
137
|
+
className="artboard"
|
|
138
|
+
data-artboard=""
|
|
139
|
+
data-format={format}
|
|
140
|
+
data-name={name ?? ''}
|
|
141
|
+
data-output={f.output}
|
|
142
|
+
style={{ width: f.width, height: f.height, zoom: scale }}
|
|
143
|
+
>
|
|
144
|
+
{children}
|
|
145
|
+
{guides ? <SafeBands format={format} /> : null}
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
if (exporting) return frame;
|
|
149
|
+
return (
|
|
150
|
+
<figure className="artboard-slot">
|
|
151
|
+
{frame}
|
|
152
|
+
<figcaption className="artboard-label">
|
|
153
|
+
<span>{name ?? f.label}</span>
|
|
154
|
+
<span className="tabular">
|
|
155
|
+
{f.label} · {sizeLabel(format)}
|
|
156
|
+
</span>
|
|
157
|
+
</figcaption>
|
|
158
|
+
</figure>
|
|
159
|
+
);
|
|
160
|
+
}
|
package/kit/artboard.css
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* The board: artboards side by side on a quiet canvas, each scaled with CSS
|
|
2
|
+
zoom so its content keeps its real pixel values. Under export, only the
|
|
3
|
+
artboards, stacked at 1:1, with motion off and one page per artboard. */
|
|
4
|
+
.board { min-height: 100vh; display: flex; flex-direction: column; gap: 32px; padding: 64px 32px 128px; background: var(--bg-secondary); }
|
|
5
|
+
.board-head { display: flex; flex-direction: column; gap: 4px; max-width: 65ch; }
|
|
6
|
+
.board-title { font-size: 18px; line-height: 28px; font-weight: 600; color: var(--text-primary); text-wrap: balance; }
|
|
7
|
+
.board-lede { color: var(--text-tertiary); text-wrap: pretty; }
|
|
8
|
+
.board-grid { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 40px; min-width: 0; }
|
|
9
|
+
.artboard-slot { display: flex; flex-direction: column; gap: 10px; margin: 0; min-width: 0; }
|
|
10
|
+
.artboard { position: relative; flex: none; overflow: hidden; background: var(--bg-primary); box-shadow: 0 0 0 1px rgb(16 24 40 / 0.08), 0 12px 32px -12px rgb(16 24 40 / 0.18); }
|
|
11
|
+
.artboard-label { display: flex; justify-content: space-between; gap: 16px; font-size: 12px; line-height: 18px; color: var(--text-tertiary); }
|
|
12
|
+
.artboard-label > span:first-child { color: var(--text-secondary); font-weight: 500; }
|
|
13
|
+
.artboard-safe { position: absolute; inset-inline: 0; pointer-events: none; background: repeating-linear-gradient(-45deg, rgb(240 68 56 / 0.14) 0 12px, rgb(240 68 56 / 0.06) 12px 24px); outline: 1px dashed rgb(240 68 56 / 0.5); outline-offset: -1px; }
|
|
14
|
+
|
|
15
|
+
@media (max-width: 720px) {
|
|
16
|
+
.board { padding: 32px 16px 128px; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/* Export: the page is the artboards and nothing else. */
|
|
20
|
+
html[data-export] body { margin: 0; background: transparent; }
|
|
21
|
+
.board-export { display: flex; flex-direction: column; align-items: flex-start; width: max-content; }
|
|
22
|
+
.board-export .artboard { box-shadow: none; }
|
|
23
|
+
html[data-export] *, html[data-export] *::before, html[data-export] *::after { animation: none !important; transition: none !important; }
|
|
24
|
+
|
|
25
|
+
/* PDF: one page per artboard at the format's own size. The exporter prints
|
|
26
|
+
one format at a time, hiding the rest, because Chrome lays out one PDF at
|
|
27
|
+
a single width. */
|
|
28
|
+
@media print {
|
|
29
|
+
.board-export .artboard { break-after: page; }
|
|
30
|
+
.artboard[data-format="post-square"] { page: post-square; }
|
|
31
|
+
.artboard[data-format="post-portrait"] { page: post-portrait; }
|
|
32
|
+
.artboard[data-format="story"] { page: story; }
|
|
33
|
+
.artboard[data-format="link-preview"] { page: link-preview; }
|
|
34
|
+
.artboard[data-format="banner"] { page: banner; }
|
|
35
|
+
.artboard[data-format="slide"] { page: slide; }
|
|
36
|
+
.artboard[data-format="a4"] { page: a4; }
|
|
37
|
+
.artboard[data-format="letter"] { page: letter; }
|
|
38
|
+
}
|
|
39
|
+
@page { margin: 0; }
|
|
40
|
+
@page post-square { size: 1080px 1080px; margin: 0; }
|
|
41
|
+
@page post-portrait { size: 1080px 1350px; margin: 0; }
|
|
42
|
+
@page story { size: 1080px 1920px; margin: 0; }
|
|
43
|
+
@page link-preview { size: 1200px 630px; margin: 0; }
|
|
44
|
+
@page banner { size: 1584px 396px; margin: 0; }
|
|
45
|
+
@page slide { size: 1920px 1080px; margin: 0; }
|
|
46
|
+
@page a4 { size: 210mm 297mm; margin: 0; }
|
|
47
|
+
@page letter { size: 8.5in 11in; margin: 0; }
|
package/kit/dials.tsx
CHANGED
|
@@ -35,7 +35,8 @@ export const setGuide = (href: string) => {
|
|
|
35
35
|
|
|
36
36
|
// One DialRoot per page, in its own React root, however many panels register.
|
|
37
37
|
export function ensureDialRoot() {
|
|
38
|
-
|
|
38
|
+
// `design-hub export` captures the prototype alone; the panel never mounts.
|
|
39
|
+
if (mounted || document.documentElement.dataset.export !== undefined) return;
|
|
39
40
|
mounted = true;
|
|
40
41
|
const host = document.createElement('div');
|
|
41
42
|
host.dataset.harness = 'dials';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milesroxas/design-hub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The Design Hub product: the hub that lists and serves prototypes, the review panel and its API, the password gate, the kit, and the design-hub CLI. A project installs it and keeps only its prototypes, kit materials and docs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|