zazz-ui 0.0.0 → 0.3.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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +37 -2
- package/dist/add-Bm5kc6TG.js +129 -0
- package/dist/cli.js +44 -0
- package/dist/diff-B38wvndQ.js +197 -0
- package/dist/errors-DC2U2USS.js +33 -0
- package/dist/init-CXljM6FO.js +193 -0
- package/dist/init-OVodXfKt.js +3 -0
- package/dist/update-BAfhUb3N.js +670 -0
- package/dist/update-CTuqOys3.js +3 -0
- package/dist/wiring-C77bl5LR.js +723 -0
- package/package.json +49 -11
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { t as ZazzError } from "./errors-DC2U2USS.js";
|
|
2
|
+
import { _ as resolveKit, a as renderIndexJs, c as createUi, f as baseFiles, g as kitSpec, h as loadFetchOptions, i as renderIndexCss, l as apply, o as sha256, r as renderHead, s as vendorFiles, t as appendJsImports, u as describe, v as loadConfig, y as filterCollisions } from "./wiring-C77bl5LR.js";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
//#region src/commands/init.ts
|
|
8
|
+
/**
|
|
9
|
+
* @fileoverview `zazz-ui init` — vendor the Zazz base platform.
|
|
10
|
+
* @description Fresh projects get the base css layers, the core runtime,
|
|
11
|
+
* CLI-composed entry files, `head.html`, and a `zazz.json` provenance record.
|
|
12
|
+
* Re-running in an initialized project is repair mode: restore what's
|
|
13
|
+
* missing, report what's edited, touch nothing edited without `--force`,
|
|
14
|
+
* and never re-ask identity decisions. No happy-path prompts.
|
|
15
|
+
*/
|
|
16
|
+
/** Strips the @-prefix off a version positional (`@0.1.0` → `0.1.0`). */
|
|
17
|
+
function parseVersionArg(arg) {
|
|
18
|
+
if (arg === void 0) return "latest";
|
|
19
|
+
const version = arg.startsWith("@") ? arg.slice(1) : arg;
|
|
20
|
+
if (version.length === 0) throw new ZazzError(`invalid version argument: ${arg}`);
|
|
21
|
+
return version;
|
|
22
|
+
}
|
|
23
|
+
async function runInit(versionArg, flags, global) {
|
|
24
|
+
const cwd = path.resolve(global.cwd);
|
|
25
|
+
const ui = createUi({
|
|
26
|
+
silent: global.silent === true,
|
|
27
|
+
yes: global.yes === true
|
|
28
|
+
});
|
|
29
|
+
const fetch = await loadFetchOptions({
|
|
30
|
+
cwd,
|
|
31
|
+
registry: global.registry,
|
|
32
|
+
offline: global.offline,
|
|
33
|
+
preferOffline: global.preferOffline
|
|
34
|
+
});
|
|
35
|
+
const existing = await loadConfig(cwd);
|
|
36
|
+
if (existing) {
|
|
37
|
+
await repair(existing.config, existing.root, {
|
|
38
|
+
fetch,
|
|
39
|
+
ui,
|
|
40
|
+
force: flags.force === true
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
ui.intro("zazz-ui init");
|
|
45
|
+
const version = parseVersionArg(versionArg);
|
|
46
|
+
const kit = await ui.spinner(`Resolving @zazz-ui/core@${version}…`, () => resolveKit(kitSpec(version), fetch), (resolved) => `Resolved @zazz-ui/core@${resolved.version}`);
|
|
47
|
+
const config = {
|
|
48
|
+
kit: {
|
|
49
|
+
version: kit.version,
|
|
50
|
+
integrity: kit.integrity
|
|
51
|
+
},
|
|
52
|
+
dir: flags.dir,
|
|
53
|
+
language: flags.ts === true ? "ts" : "js",
|
|
54
|
+
legacy: flags.legacy ?? null,
|
|
55
|
+
head: {
|
|
56
|
+
fonts: flags.fonts,
|
|
57
|
+
themeScript: flags.themeScript
|
|
58
|
+
},
|
|
59
|
+
base: { files: {} },
|
|
60
|
+
primitives: {}
|
|
61
|
+
};
|
|
62
|
+
const destRoot = path.join(cwd, config.dir);
|
|
63
|
+
const { writes, hashes } = await vendorFiles(kit, baseFiles(kit.manifest, config.language), destRoot);
|
|
64
|
+
for (const write of generatedWrites(kit, config, destRoot, hashes)) writes.push(write);
|
|
65
|
+
config.base.files = hashes;
|
|
66
|
+
const { kept, skipped } = await filterCollisions(writes, {
|
|
67
|
+
ui,
|
|
68
|
+
force: flags.force === true
|
|
69
|
+
});
|
|
70
|
+
const tx = {
|
|
71
|
+
root: cwd,
|
|
72
|
+
writes: kept,
|
|
73
|
+
config
|
|
74
|
+
};
|
|
75
|
+
if (flags.dryRun === true) {
|
|
76
|
+
ui.step(`plan:\n${describe(tx)}`);
|
|
77
|
+
ui.outro("Dry run — nothing written.");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
await apply(tx);
|
|
81
|
+
if (skipped.length > 0) {
|
|
82
|
+
ui.warn(`Skipped ${skipped.length} existing file(s) (kept yours; --force overwrites):\n ${skipped.map((dest) => path.relative(cwd, dest)).join("\n ")}`);
|
|
83
|
+
process.exitCode = 2;
|
|
84
|
+
}
|
|
85
|
+
ui.outro(`Vendored ${kept.length} files into ${config.dir}/. Paste the contents of ${config.dir}/head.html into your <head>, then: zazz-ui add button`);
|
|
86
|
+
}
|
|
87
|
+
/** The CLI-composed artifacts: entry css/js and head.html, hashed as generated. */
|
|
88
|
+
function generatedWrites(kit, config, destRoot, hashes) {
|
|
89
|
+
const entryScript = config.language === "ts" ? "index.ts" : "index.js";
|
|
90
|
+
return [
|
|
91
|
+
[
|
|
92
|
+
"index.css",
|
|
93
|
+
renderIndexCss({
|
|
94
|
+
kit,
|
|
95
|
+
legacy: config.legacy,
|
|
96
|
+
primitives: []
|
|
97
|
+
}),
|
|
98
|
+
"entry"
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
entryScript,
|
|
102
|
+
renderIndexJs({
|
|
103
|
+
kit,
|
|
104
|
+
language: config.language
|
|
105
|
+
}),
|
|
106
|
+
"entry"
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
"head.html",
|
|
110
|
+
renderHead(kit, config),
|
|
111
|
+
"head"
|
|
112
|
+
]
|
|
113
|
+
].map(([file, content, note]) => {
|
|
114
|
+
hashes[file] = sha256(content);
|
|
115
|
+
return {
|
|
116
|
+
dest: path.join(destRoot, file),
|
|
117
|
+
content,
|
|
118
|
+
note
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** Repair mode: restore missing files, report edits, keep identity decisions. */
|
|
123
|
+
async function repair(config, root, context) {
|
|
124
|
+
const { ui } = context;
|
|
125
|
+
ui.intro("zazz-ui init — already initialized, checking the vendored tree");
|
|
126
|
+
const kit = await ui.spinner(`Resolving @zazz-ui/core@${config.kit.version}…`, () => resolveKit(kitSpec(config.kit.version), context.fetch), (resolved) => `Using @zazz-ui/core@${resolved.version}`);
|
|
127
|
+
const destRoot = path.join(root, config.dir);
|
|
128
|
+
const inventory = { ...config.base.files };
|
|
129
|
+
for (const entry of Object.values(config.primitives)) Object.assign(inventory, entry.files);
|
|
130
|
+
const writes = [];
|
|
131
|
+
const modified = [];
|
|
132
|
+
let intact = 0;
|
|
133
|
+
for (const [file, recordedHash] of Object.entries(inventory)) {
|
|
134
|
+
const dest = path.join(destRoot, ...file.split("/"));
|
|
135
|
+
const content = await pristineContent(kit, config, file);
|
|
136
|
+
if (content === null) continue;
|
|
137
|
+
if (!existsSync(dest)) {
|
|
138
|
+
writes.push({
|
|
139
|
+
dest,
|
|
140
|
+
content,
|
|
141
|
+
note: "restore"
|
|
142
|
+
});
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (sha256(await readFile(dest)) === recordedHash) intact += 1;
|
|
146
|
+
else if (context.force) writes.push({
|
|
147
|
+
dest,
|
|
148
|
+
content,
|
|
149
|
+
note: "reset"
|
|
150
|
+
});
|
|
151
|
+
else modified.push(file);
|
|
152
|
+
}
|
|
153
|
+
if (writes.length > 0) await apply({
|
|
154
|
+
root,
|
|
155
|
+
writes,
|
|
156
|
+
config
|
|
157
|
+
});
|
|
158
|
+
const restored = writes.length;
|
|
159
|
+
const kept = modified.length;
|
|
160
|
+
ui.outro(`${intact} intact · ${restored} restored · ${kept} edited${kept > 0 ? " (left alone; --force resets them to pristine)" : ""}`);
|
|
161
|
+
}
|
|
162
|
+
/** Pristine bytes for a recorded file: tarball bytes, or regenerated artifact. */
|
|
163
|
+
async function pristineContent(kit, config, file) {
|
|
164
|
+
if (kit.has(file)) return kit.readFile(file);
|
|
165
|
+
const cascade = new Map(kit.manifest.cssCascadeOrder.map((name, index) => [name, index]));
|
|
166
|
+
const vendored = Object.keys(config.primitives).filter((name) => kit.manifest.primitives[name]).sort((a, b) => (cascade.get(a) ?? Infinity) - (cascade.get(b) ?? Infinity));
|
|
167
|
+
switch (file) {
|
|
168
|
+
case "index.css": return renderIndexCss({
|
|
169
|
+
kit,
|
|
170
|
+
legacy: config.legacy,
|
|
171
|
+
primitives: vendored.map((name) => ({
|
|
172
|
+
name,
|
|
173
|
+
css: kit.manifest.primitives[name]?.css ?? []
|
|
174
|
+
}))
|
|
175
|
+
});
|
|
176
|
+
case "index.js":
|
|
177
|
+
case "index.ts": {
|
|
178
|
+
const scripts = vendored.flatMap((name) => {
|
|
179
|
+
const entry = kit.manifest.primitives[name];
|
|
180
|
+
return entry ? [...entry.base, ...entry.js] : [];
|
|
181
|
+
});
|
|
182
|
+
return appendJsImports(renderIndexJs({
|
|
183
|
+
kit,
|
|
184
|
+
language: config.language
|
|
185
|
+
}), [...new Set(scripts)], config.language);
|
|
186
|
+
}
|
|
187
|
+
case "head.html": return renderHead(kit, config);
|
|
188
|
+
default: return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
export { runInit as n, parseVersionArg as t };
|