@auscera/design-labs 0.0.0-stage → 0.1.1
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/apps/workspace/.skills/design-labs/SKILL.md +63 -0
- package/apps/workspace/.skills/design-labs/references/commands.md +38 -0
- package/apps/workspace/AGENTS.md +9 -0
- package/apps/workspace/app/(lab)/compare/page.tsx +2 -0
- package/apps/workspace/app/(lab)/lab.css +412 -0
- package/apps/workspace/app/(lab)/layout.tsx +21 -0
- package/apps/workspace/app/(lab)/page.tsx +2 -0
- package/apps/workspace/app/api/annotations/route.ts +94 -0
- package/apps/workspace/app/api/versions/events/route.ts +63 -0
- package/apps/workspace/app/api/versions/route.ts +7 -0
- package/apps/workspace/components/animated-icons.tsx +72 -0
- package/apps/workspace/components/dotmatrix-loader.css +1228 -0
- package/apps/workspace/components/glass-controls.tsx +47 -0
- package/apps/workspace/components/lab-providers.tsx +17 -0
- package/apps/workspace/components/molecules/brand-lockup.tsx +13 -0
- package/apps/workspace/components/molecules/pane-url-popover.css +92 -0
- package/apps/workspace/components/molecules/pane-url-popover.tsx +191 -0
- package/apps/workspace/components/pane-preferences.tsx +75 -0
- package/apps/workspace/components/pane-viewport.css +34 -0
- package/apps/workspace/components/pane-viewport.tsx +199 -0
- package/apps/workspace/components/preview-pane.css +293 -0
- package/apps/workspace/components/preview-pane.tsx +662 -0
- package/apps/workspace/components/ui/dotm-triangle-11.tsx +170 -0
- package/apps/workspace/components/ui/dotmatrix-core.tsx +1649 -0
- package/apps/workspace/components/ui/dotmatrix-hooks.ts +224 -0
- package/apps/workspace/components/version-select.tsx +220 -0
- package/apps/workspace/components/workspace.tsx +313 -0
- package/apps/workspace/eslint.config.mjs +3 -0
- package/apps/workspace/lab.config.json +1 -0
- package/apps/workspace/lib/annotation-export.ts +28 -0
- package/apps/workspace/lib/annotation-types.ts +38 -0
- package/apps/workspace/lib/device-presets.ts +103 -0
- package/apps/workspace/lib/use-annotation-bridge.ts +130 -0
- package/apps/workspace/lib/version-types.ts +12 -0
- package/apps/workspace/lib/website-url.ts +78 -0
- package/apps/workspace/next-env.d.ts +6 -0
- package/apps/workspace/next.config.mjs +1 -0
- package/apps/workspace/package.json +35 -0
- package/apps/workspace/public/apple-touch-icon.png +0 -0
- package/apps/workspace/public/brand/design-labs-script.LICENSE.txt +93 -0
- package/apps/workspace/public/brand/design-labs-script.woff2 +0 -0
- package/apps/workspace/public/brand/logo.webp +0 -0
- package/apps/workspace/public/brand/wordmark.css +42 -0
- package/apps/workspace/public/favicon.ico +0 -0
- package/apps/workspace/public/icon-192.png +0 -0
- package/apps/workspace/public/icon-512.png +0 -0
- package/apps/workspace/public/preview-bridge.js +411 -0
- package/apps/workspace/public/site.webmanifest +1 -0
- package/apps/workspace/scripts/annotation-store.mjs +308 -0
- package/apps/workspace/scripts/lab.mjs +414 -0
- package/apps/workspace/scripts/migrate.mjs +2 -0
- package/apps/workspace/scripts/prepare-preview.mjs +203 -0
- package/apps/workspace/tsconfig.json +24 -0
- package/package.json +13 -3
- package/scripts/install.mjs +71 -0
- package/scripts/update.mjs +155 -0
- package/README.md +0 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { plan, runUpdate } from "./update.mjs";
|
|
6
|
+
const product = path.resolve(
|
|
7
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
8
|
+
"..",
|
|
9
|
+
);
|
|
10
|
+
export function install(workspace) {
|
|
11
|
+
workspace = fs.realpathSync(workspace);
|
|
12
|
+
const pkg = JSON.parse(
|
|
13
|
+
fs.existsSync(path.join(workspace, "package.json"))
|
|
14
|
+
? fs.readFileSync(path.join(workspace, "package.json"))
|
|
15
|
+
: "{}",
|
|
16
|
+
);
|
|
17
|
+
const mono =
|
|
18
|
+
fs.existsSync(path.join(workspace, "pnpm-workspace.yaml")) ||
|
|
19
|
+
!!pkg.workspaces ||
|
|
20
|
+
fs.existsSync(path.join(workspace, "turbo.json"));
|
|
21
|
+
const dest = path.join(workspace, mono ? "apps/design-lab" : "design-lab");
|
|
22
|
+
if (fs.existsSync(dest))
|
|
23
|
+
throw Error(
|
|
24
|
+
"Design Lab exists; refusing to overwrite. Use the reviewed platform migration workflow.",
|
|
25
|
+
);
|
|
26
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
27
|
+
for (const f of [
|
|
28
|
+
"app",
|
|
29
|
+
"components",
|
|
30
|
+
"lib",
|
|
31
|
+
"scripts",
|
|
32
|
+
"public",
|
|
33
|
+
"package.json",
|
|
34
|
+
"next.config.mjs",
|
|
35
|
+
"tsconfig.json",
|
|
36
|
+
"next-env.d.ts",
|
|
37
|
+
"eslint.config.mjs",
|
|
38
|
+
"lab.config.json",
|
|
39
|
+
"AGENTS.md",
|
|
40
|
+
".skills",
|
|
41
|
+
]) {
|
|
42
|
+
const src = path.join(product, "apps/workspace", f);
|
|
43
|
+
if (!fs.existsSync(src)) throw Error(`Distribution file missing: ${f}`);
|
|
44
|
+
fs.cpSync(src, path.join(dest, f), { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
for (const category of ["landing", "dashboard"])
|
|
47
|
+
fs.mkdirSync(path.join(dest, "versions", category), { recursive: true });
|
|
48
|
+
fs.writeFileSync(
|
|
49
|
+
path.join(dest, ".design-labs-install.json"),
|
|
50
|
+
JSON.stringify({ version: 2, files: plan(dest).files }, null, 2),
|
|
51
|
+
);
|
|
52
|
+
return dest;
|
|
53
|
+
}
|
|
54
|
+
if (
|
|
55
|
+
process.argv[1] &&
|
|
56
|
+
path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
|
57
|
+
) {
|
|
58
|
+
try {
|
|
59
|
+
if (process.argv[2] === "update") {
|
|
60
|
+
console.log(JSON.stringify(runUpdate(process.argv.slice(3)), null, 2));
|
|
61
|
+
} else {
|
|
62
|
+
console.log(install(process.argv[2] || process.cwd()));
|
|
63
|
+
console.log(
|
|
64
|
+
"Read the installed AGENTS.md and skill, install dependencies using the target project's package manager, then run pnpm dev from the installed Lab. Prepare snapshots and previews as described in the skill.",
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error(e.message);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { hashes, fingerprint } from '../apps/workspace/scripts/lab.mjs';
|
|
7
|
+
|
|
8
|
+
const product = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
|
+
const managed = ['app/(lab)', 'app/api/versions', 'app/api/annotations', 'lib', 'public/preview-bridge.js', 'components', 'scripts', 'public/brand', 'public/favicon.ico', 'public/apple-touch-icon.png', 'public/site.webmanifest', 'public/icon-192.png', 'public/icon-512.png', 'AGENTS.md', '.skills'];
|
|
10
|
+
const hash = p => fs.existsSync(p) ? crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex') : null;
|
|
11
|
+
const backupDir = target => path.join(path.dirname(target), '.design-labs-backups');
|
|
12
|
+
const pendingFile = target => path.join(backupDir(target), path.basename(target) + '.pending.json');
|
|
13
|
+
|
|
14
|
+
// Refuse symlinks in each managed path, including its parent directories.
|
|
15
|
+
function safePath(root, relative) {
|
|
16
|
+
let current = root;
|
|
17
|
+
for (const part of relative.split('/')) {
|
|
18
|
+
current = path.join(current, part);
|
|
19
|
+
try { if (fs.lstatSync(current).isSymbolicLink()) throw Error(`Symlink in update path: ${current}`); }
|
|
20
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
21
|
+
}
|
|
22
|
+
return current;
|
|
23
|
+
}
|
|
24
|
+
function list(dir, rel = '') {
|
|
25
|
+
return fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name)).flatMap(e => {
|
|
26
|
+
const name = rel + e.name;
|
|
27
|
+
if (['node_modules', '.next', '.git'].includes(e.name) || e.name.startsWith('.env')) return [];
|
|
28
|
+
if (e.isSymbolicLink()) throw Error(`Symlink in release: ${path.join(dir, e.name)}`);
|
|
29
|
+
return e.isDirectory() ? list(path.join(dir, e.name), name + '/') : [name];
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function plan(target, { allowPending = false } = {}) {
|
|
33
|
+
target = fs.realpathSync(target);
|
|
34
|
+
if (!allowPending && fs.existsSync(pendingFile(target))) throw Error(`Interrupted update: inspect ${pendingFile(target)} and roll back before continuing`);
|
|
35
|
+
const manifest = safePath(target, '.design-labs-install.json');
|
|
36
|
+
const previous = fs.existsSync(manifest) ? JSON.parse(fs.readFileSync(manifest)) : { files: {} };
|
|
37
|
+
if (!previous.files || typeof previous.files !== 'object') throw Error('Invalid install manifest');
|
|
38
|
+
const changes = [], files = {};
|
|
39
|
+
for (const entry of managed) {
|
|
40
|
+
const source = safePath(path.join(product, 'apps/workspace'), entry);
|
|
41
|
+
if (!fs.existsSync(source)) continue;
|
|
42
|
+
for (const f of fs.statSync(source).isDirectory() ? list(source).map(f => entry + '/' + f) : [entry]) {
|
|
43
|
+
const next = hash(safePath(path.join(product, 'apps/workspace'), f));
|
|
44
|
+
const current = hash(safePath(target, f));
|
|
45
|
+
files[f] = next;
|
|
46
|
+
if (next !== current) changes.push({ file: f, current, next, conflict: previous.files[f] !== undefined ? previous.files[f] !== current : current !== null });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const configFile = safePath(target, 'lab.config.json');
|
|
50
|
+
const packageFile = safePath(target, 'package.json');
|
|
51
|
+
const config = JSON.parse(fs.readFileSync(configFile));
|
|
52
|
+
const originDrift = (config.versions || []).filter(v => v.origin).map(v => {
|
|
53
|
+
try {
|
|
54
|
+
const origin = fs.realpathSync(v.origin);
|
|
55
|
+
const exclude = target.startsWith(origin + path.sep) ? target : null;
|
|
56
|
+
const currentHash = fingerprint(hashes(origin, exclude));
|
|
57
|
+
return { key: v.key, currentHash, drift: v.originHashes ? currentHash !== fingerprint(v.originHashes) : null };
|
|
58
|
+
} catch (error) { return { key: v.key, drift: null, error: error.message }; }
|
|
59
|
+
});
|
|
60
|
+
const report = {
|
|
61
|
+
target,
|
|
62
|
+
releaseVersion: JSON.parse(fs.readFileSync(path.join(product, 'package.json'))).version,
|
|
63
|
+
changes, files,
|
|
64
|
+
retainedObsoleteFiles: Object.keys(previous.files).filter(f => !Object.hasOwn(files, f)).sort(),
|
|
65
|
+
manifestHash: hash(manifest), configHash: hash(configFile), packageHash: hash(packageFile), originDrift,
|
|
66
|
+
requiredDependencies: JSON.parse(fs.readFileSync(path.join(product, 'apps/workspace/package.json'))),
|
|
67
|
+
};
|
|
68
|
+
return { ...report, token: crypto.createHash('sha256').update(JSON.stringify(report)).digest('hex') };
|
|
69
|
+
}
|
|
70
|
+
export function update(target, token, acceptLocal = false) {
|
|
71
|
+
const p = plan(target);
|
|
72
|
+
target = p.target;
|
|
73
|
+
if (token !== p.token) throw Error('Review the update plan and use its current token');
|
|
74
|
+
if (p.changes.some(c => c.conflict) && !acceptLocal) throw Error('Locally modified or untracked platform files; review before --accept-local');
|
|
75
|
+
if (!p.changes.length) return { changed: false, next: 'No platform changes; dependency settings were not changed.' };
|
|
76
|
+
const directory = backupDir(target);
|
|
77
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
78
|
+
const backup = path.join(directory, path.basename(target) + '-' + crypto.randomUUID());
|
|
79
|
+
const pending = pendingFile(target);
|
|
80
|
+
const fd = fs.openSync(pending, 'wx');
|
|
81
|
+
try { fs.writeFileSync(fd, JSON.stringify({ target, backup, stage: 'backup' }, null, 2)); }
|
|
82
|
+
finally { fs.closeSync(fd); }
|
|
83
|
+
try {
|
|
84
|
+
fs.cpSync(target, backup, { recursive: true, filter: src => {
|
|
85
|
+
const name = path.basename(src);
|
|
86
|
+
if (['node_modules', '.next', '.git'].includes(name) || name.startsWith('.env')) return false;
|
|
87
|
+
if (fs.lstatSync(src).isSymbolicLink()) throw Error(`Symlink in backup: ${src}`);
|
|
88
|
+
return true;
|
|
89
|
+
} });
|
|
90
|
+
// A review is only valid for the state that was backed up. Recheck all
|
|
91
|
+
// review-bound inputs before the first platform write.
|
|
92
|
+
if (plan(target, { allowPending: true }).token !== p.token) throw Error('Update inputs changed during backup; inspect the marker and review again');
|
|
93
|
+
for (const c of p.changes) {
|
|
94
|
+
if (c.current !== null && hash(safePath(backup, c.file)) !== c.current) throw Error(`Backup changed during copying: ${c.file}`);
|
|
95
|
+
}
|
|
96
|
+
if (hash(safePath(backup, '.design-labs-install.json')) !== p.manifestHash || hash(safePath(backup, 'package.json')) !== p.packageHash || hash(safePath(backup, 'lab.config.json')) !== p.configHash) throw Error('Backup settings changed during copying');
|
|
97
|
+
const nextManifest = JSON.stringify({ version: 2, files: p.files }, null, 2);
|
|
98
|
+
const nextManifestHash = crypto.createHash('sha256').update(nextManifest).digest('hex');
|
|
99
|
+
fs.writeFileSync(backup + '.json', JSON.stringify({ target, changes: p.changes, manifestHash: p.manifestHash, nextManifestHash }, null, 2));
|
|
100
|
+
fs.writeFileSync(pending, JSON.stringify({ target, backup, stage: 'apply' }, null, 2));
|
|
101
|
+
for (const c of p.changes) {
|
|
102
|
+
const dst = safePath(target, c.file);
|
|
103
|
+
if (hash(dst) !== c.current || hash(safePath(path.join(product, 'apps/workspace'), c.file)) !== c.next) throw Error(`Update file changed after review: ${c.file}`);
|
|
104
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
105
|
+
fs.copyFileSync(safePath(path.join(product, 'apps/workspace'), c.file), dst);
|
|
106
|
+
}
|
|
107
|
+
fs.writeFileSync(path.join(target, '.design-labs-install.json'), nextManifest);
|
|
108
|
+
fs.unlinkSync(pending);
|
|
109
|
+
return { changed: true, backup, retainedObsoleteFiles: p.retainedObsoleteFiles, next: 'Review dependency requirements, run checks and browser tests; use rollback if needed.' };
|
|
110
|
+
} catch (e) {
|
|
111
|
+
throw Error(`${e.message}; update marker: ${pending}; inspect backup before recovery: ${backup}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function rollback(target, backup) {
|
|
115
|
+
target = fs.realpathSync(target); backup = path.resolve(backup);
|
|
116
|
+
if (path.dirname(backup) !== backupDir(target) || !path.basename(backup).startsWith(path.basename(target) + '-') || !fs.existsSync(backup) || !fs.existsSync(backup + '.json')) throw Error('Invalid or incomplete backup');
|
|
117
|
+
const pending = pendingFile(target);
|
|
118
|
+
if (fs.existsSync(pending)) {
|
|
119
|
+
const record = JSON.parse(fs.readFileSync(pending));
|
|
120
|
+
if (record.backup !== backup || record.stage !== 'apply') throw Error('Backup is incomplete or does not match interrupted update; inspect manually');
|
|
121
|
+
}
|
|
122
|
+
const journal = JSON.parse(fs.readFileSync(backup + '.json'));
|
|
123
|
+
if (journal.target !== target || !Array.isArray(journal.changes)) throw Error('Invalid backup journal');
|
|
124
|
+
// Do not overwrite work done since the update; an interrupted apply may have
|
|
125
|
+
// left each file at either its reviewed old or new hash.
|
|
126
|
+
for (const change of journal.changes) {
|
|
127
|
+
if (typeof change.file !== 'string' || !managed.some(e => change.file === e || change.file.startsWith(e + '/')) || change.file.split('/').some(p => p === '..' || p === '.')) throw Error('Invalid backup journal path');
|
|
128
|
+
const current = hash(safePath(target, change.file));
|
|
129
|
+
if (current !== change.current && current !== change.next) throw Error(`Rollback conflict: ${change.file} changed since the update`);
|
|
130
|
+
if (change.current !== null && hash(safePath(backup, change.file)) !== change.current) throw Error(`Backup hash mismatch: ${change.file}`);
|
|
131
|
+
}
|
|
132
|
+
const manifest = safePath(target, '.design-labs-install.json');
|
|
133
|
+
const backedManifest = safePath(backup, '.design-labs-install.json');
|
|
134
|
+
if (hash(backedManifest) !== journal.manifestHash) throw Error('Backup manifest hash mismatch');
|
|
135
|
+
if (![journal.manifestHash, journal.nextManifestHash].includes(hash(manifest))) throw Error('Rollback conflict: install manifest changed since the update');
|
|
136
|
+
for (const change of journal.changes) {
|
|
137
|
+
const dest = safePath(target, change.file);
|
|
138
|
+
if (change.current === null) { if (fs.existsSync(dest)) fs.unlinkSync(dest); }
|
|
139
|
+
else { fs.mkdirSync(path.dirname(dest), { recursive: true }); fs.copyFileSync(safePath(backup, change.file), dest); }
|
|
140
|
+
}
|
|
141
|
+
if (journal.manifestHash === null) { if (fs.existsSync(manifest)) fs.unlinkSync(manifest); }
|
|
142
|
+
else fs.copyFileSync(backedManifest, manifest);
|
|
143
|
+
if (fs.existsSync(pending)) fs.unlinkSync(pending);
|
|
144
|
+
return { restored: target, backup, next: 'Run checks before launch. Local source, settings and environments were retained.' };
|
|
145
|
+
}
|
|
146
|
+
export function runUpdate(args) {
|
|
147
|
+
const [cmd, target, token, ...flags] = args;
|
|
148
|
+
if (!target || !['plan', 'fix', 'apply', 'rollback'].includes(cmd)) throw Error('Use update plan|fix <installed-lab>, update apply <lab> <token> [--accept-local], or update rollback <lab> <backup>');
|
|
149
|
+
if ((cmd === 'apply' || cmd === 'rollback') && !token) throw Error('Missing review token or backup path');
|
|
150
|
+
return cmd === 'plan' || cmd === 'fix' ? plan(path.resolve(target)) : cmd === 'apply' ? update(path.resolve(target), token, flags.includes('--accept-local')) : rollback(path.resolve(target), path.resolve(token));
|
|
151
|
+
}
|
|
152
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
153
|
+
try { console.log(JSON.stringify(runUpdate(process.argv.slice(2)), null, 2)); }
|
|
154
|
+
catch (e) { console.error(e.message); process.exitCode = 1; }
|
|
155
|
+
}
|
package/README.md
DELETED