@buffercreations/levelsui 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.
Files changed (116) hide show
  1. package/01. Elements/.gitkeep +0 -0
  2. package/01. Elements/actions/controls/button/api.json +106 -0
  3. package/01. Elements/actions/controls/button/button.definition.json +38 -0
  4. package/01. Elements/actions/controls/button/button.scss +80 -0
  5. package/01. Elements/actions/controls/button/docs.md +41 -0
  6. package/01. Elements/actions/controls/button/examples/contexts/code.html +3 -0
  7. package/01. Elements/actions/controls/button/examples/contexts/preview.html +3 -0
  8. package/01. Elements/actions/controls/button/examples/icons/code.html +6 -0
  9. package/01. Elements/actions/controls/button/examples/icons/preview.html +5 -0
  10. package/01. Elements/actions/controls/button/examples/index.json +51 -0
  11. package/01. Elements/actions/controls/button/examples/links/code.html +1 -0
  12. package/01. Elements/actions/controls/button/examples/links/preview.html +3 -0
  13. package/01. Elements/actions/controls/button/examples/native-default/code.html +9 -0
  14. package/01. Elements/actions/controls/button/examples/native-default/preview.html +9 -0
  15. package/01. Elements/actions/controls/button/examples/sizes/code.html +1 -0
  16. package/01. Elements/actions/controls/button/examples/sizes/preview.html +7 -0
  17. package/01. Elements/actions/controls/button/examples/states/code.html +1 -0
  18. package/01. Elements/actions/controls/button/examples/states/preview.html +5 -0
  19. package/01. Elements/actions/controls/button/examples/treatments/code.html +1 -0
  20. package/01. Elements/actions/controls/button/examples/treatments/preview.html +5 -0
  21. package/01. Elements/media/identity/avatar/api.json +126 -0
  22. package/01. Elements/media/identity/avatar/avatar.definition.json +38 -0
  23. package/01. Elements/media/identity/avatar/avatar.scss +80 -0
  24. package/01. Elements/media/identity/avatar/docs.md +64 -0
  25. package/01. Elements/media/identity/avatar/examples/badges/code.html +10 -0
  26. package/01. Elements/media/identity/avatar/examples/badges/preview.html +29 -0
  27. package/01. Elements/media/identity/avatar/examples/fallbacks/code.html +5 -0
  28. package/01. Elements/media/identity/avatar/examples/fallbacks/preview.html +23 -0
  29. package/01. Elements/media/identity/avatar/examples/index.json +37 -0
  30. package/01. Elements/media/identity/avatar/examples/presence/code.html +6 -0
  31. package/01. Elements/media/identity/avatar/examples/presence/preview.html +26 -0
  32. package/01. Elements/media/identity/avatar/examples/shapes/code.html +5 -0
  33. package/01. Elements/media/identity/avatar/examples/shapes/preview.html +17 -0
  34. package/01. Elements/media/identity/avatar/examples/sizes/code.html +5 -0
  35. package/01. Elements/media/identity/avatar/examples/sizes/preview.html +32 -0
  36. package/02. Layouts/.gitkeep +0 -0
  37. package/02. Layouts/UTILITY-RECIPES.md +55 -0
  38. package/02. Layouts/application/app-shell/api.json +46 -0
  39. package/02. Layouts/application/app-shell/app-shell.definition.json +25 -0
  40. package/02. Layouts/application/app-shell/app-shell.scss +68 -0
  41. package/02. Layouts/application/app-shell/docs.md +31 -0
  42. package/02. Layouts/application/app-shell/examples/basic/code.html +17 -0
  43. package/02. Layouts/application/app-shell/examples/basic/preview.html +17 -0
  44. package/02. Layouts/application/app-shell/examples/collapsed/code.html +17 -0
  45. package/02. Layouts/application/app-shell/examples/collapsed/preview.html +17 -0
  46. package/02. Layouts/application/app-shell/examples/hidden/code.html +17 -0
  47. package/02. Layouts/application/app-shell/examples/hidden/preview.html +17 -0
  48. package/02. Layouts/application/app-shell/examples/index.json +23 -0
  49. package/02. Layouts/composition/stack/api.json +1 -0
  50. package/02. Layouts/composition/stack/docs.md +5 -0
  51. package/02. Layouts/composition/stack/examples/basic/code.html +4 -0
  52. package/02. Layouts/composition/stack/examples/basic/preview.html +4 -0
  53. package/02. Layouts/composition/stack/examples/index.json +1 -0
  54. package/02. Layouts/composition/stack/stack.definition.json +7 -0
  55. package/02. Layouts/composition/stack/stack.html +4 -0
  56. package/02. Layouts/content/grid/api.json +23 -0
  57. package/02. Layouts/content/grid/docs.md +19 -0
  58. package/02. Layouts/content/grid/examples/basic/code.html +5 -0
  59. package/02. Layouts/content/grid/examples/basic/preview.html +5 -0
  60. package/02. Layouts/content/grid/examples/index.json +9 -0
  61. package/02. Layouts/content/grid/grid.definition.json +25 -0
  62. package/02. Layouts/content/grid/grid.scss +5 -0
  63. package/02. Layouts/content/split/api.json +23 -0
  64. package/02. Layouts/content/split/docs.md +18 -0
  65. package/02. Layouts/content/split/examples/basic/code.html +4 -0
  66. package/02. Layouts/content/split/examples/basic/preview.html +4 -0
  67. package/02. Layouts/content/split/examples/index.json +9 -0
  68. package/02. Layouts/content/split/split.definition.json +25 -0
  69. package/02. Layouts/content/split/split.scss +7 -0
  70. package/02. Layouts/primitives/overlay/api.json +23 -0
  71. package/02. Layouts/primitives/overlay/docs.md +19 -0
  72. package/02. Layouts/primitives/overlay/examples/basic/code.html +5 -0
  73. package/02. Layouts/primitives/overlay/examples/basic/preview.html +5 -0
  74. package/02. Layouts/primitives/overlay/examples/index.json +9 -0
  75. package/02. Layouts/primitives/overlay/overlay.definition.json +25 -0
  76. package/02. Layouts/primitives/overlay/overlay.scss +4 -0
  77. package/02. Layouts/sections/section/api.json +23 -0
  78. package/02. Layouts/sections/section/docs.md +19 -0
  79. package/02. Layouts/sections/section/examples/basic/code.html +5 -0
  80. package/02. Layouts/sections/section/examples/basic/preview.html +5 -0
  81. package/02. Layouts/sections/section/examples/index.json +9 -0
  82. package/02. Layouts/sections/section/section.definition.json +25 -0
  83. package/02. Layouts/sections/section/section.scss +4 -0
  84. package/02. Layouts/sections/sidebar/api.json +23 -0
  85. package/02. Layouts/sections/sidebar/docs.md +18 -0
  86. package/02. Layouts/sections/sidebar/examples/basic/code.html +4 -0
  87. package/02. Layouts/sections/sidebar/examples/basic/preview.html +4 -0
  88. package/02. Layouts/sections/sidebar/examples/index.json +9 -0
  89. package/02. Layouts/sections/sidebar/sidebar.definition.json +25 -0
  90. package/02. Layouts/sections/sidebar/sidebar.scss +7 -0
  91. package/03. Components/.gitkeep +0 -0
  92. package/04. Templates/.gitkeep +0 -0
  93. package/05. Pages/.gitkeep +0 -0
  94. package/LICENSE +17 -0
  95. package/README.md +95 -2
  96. package/dist/components/app-shell.css +95 -0
  97. package/dist/components/avatar.css +232 -0
  98. package/dist/components/button.css +150 -0
  99. package/dist/components/grid.css +22 -0
  100. package/dist/components/overlay.css +17 -0
  101. package/dist/components/section.css +14 -0
  102. package/dist/components/sidebar.css +22 -0
  103. package/dist/components/split.css +22 -0
  104. package/package.json +48 -4
  105. package/schemas/reusable-ui.schema.json +351 -0
  106. package/tooling/cli/build.mjs +82 -0
  107. package/tooling/cli/cli.mjs +56 -0
  108. package/tooling/cli/migrate.mjs +57 -0
  109. package/tooling/cli/project.mjs +261 -0
  110. package/tooling/cli/registry-location.mjs +32 -0
  111. package/tooling/cli/registry.mjs +3 -0
  112. package/tooling/registry/definitions.mjs +69 -0
  113. package/tooling/registry/index.mjs +3 -0
  114. package/tooling/registry/paths.mjs +15 -0
  115. package/tools/build-css.mjs +75 -0
  116. package/tools/validate.mjs +6 -0
@@ -0,0 +1,22 @@
1
+ @charset "UTF-8";
2
+ /* BufferCore Level 03 — split; custom layout rules only. */
3
+ .bcl-split {
4
+ display: grid;
5
+ grid-template-columns: minmax(0, 1fr);
6
+ gap: var(--bc-fluid-lg);
7
+ align-items: var(--bcl-split-align, center);
8
+ min-width: 0;
9
+ }
10
+
11
+ .bcl-split > * {
12
+ min-width: 0;
13
+ }
14
+
15
+ @media (min-width: 48rem) {
16
+ .bcl-split {
17
+ grid-template-columns: minmax(0, var(--bcl-split-first, 1fr)) minmax(0, var(--bcl-split-second, 1fr));
18
+ }
19
+ .bcl-split--reverse > :first-child {
20
+ order: 2;
21
+ }
22
+ }
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@buffercreations/levelsui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "private": false,
4
+ "version": "0.1.1",
5
+ "type": "module",
6
+ "description": "BufferCore LevelsUI: optional Assets and management tooling",
7
+ "scripts": {
8
+ "build": "node tools/build-css.mjs",
9
+ "validate": "node tools/validate.mjs",
10
+ "test": "node --test tests/*.test.mjs",
11
+ "test:avatar": "node tools/test-avatar.mjs",
12
+ "prepack": "npm run build && npm run validate"
13
+ },
14
+ "devDependencies": {
15
+ "sass": "1.93.3",
16
+ "@buffercreations/buffercore": "file:../01. BufferCore"
17
+ },
18
+ "files": [
19
+ "01. Elements/",
20
+ "02. Layouts/",
21
+ "03. Components/",
22
+ "04. Templates/",
23
+ "05. Pages/",
24
+ "dist/",
25
+ "tooling/",
26
+ "schemas/",
27
+ "README.md",
28
+ "LICENSE",
29
+ "tools/build-css.mjs",
30
+ "tools/validate.mjs"
31
+ ],
32
+ "exports": {
33
+ "./package.json": "./package.json",
34
+ "./registry": "./tooling/registry/index.mjs",
35
+ "./schema": "./schemas/reusable-ui.schema.json"
36
+ },
37
+ "bin": {
38
+ "levelsui": "./tooling/cli/cli.mjs",
39
+ "buffercore": "./tooling/cli/cli.mjs"
40
+ },
41
+ "dependencies": {
42
+ "ajv": "8.20.0"
43
+ },
44
+ "peerDependencies": {
45
+ "@buffercreations/buffercore": "^0.8.0"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ }
50
+ }
@@ -0,0 +1,351 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://buffercreations.co.uk/schemas/reusable-ui.schema.json",
4
+ "title": "BufferCore Reusable UI Definition",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "schemaVersion",
9
+ "id",
10
+ "displayName",
11
+ "description",
12
+ "level",
13
+ "category",
14
+ "source"
15
+ ],
16
+ "properties": {
17
+ "schemaVersion": {
18
+ "const": 1
19
+ },
20
+ "id": {
21
+ "type": "string",
22
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
23
+ },
24
+ "displayName": {
25
+ "type": "string",
26
+ "minLength": 1
27
+ },
28
+ "description": {
29
+ "type": "string",
30
+ "minLength": 1
31
+ },
32
+ "level": {
33
+ "enum": [
34
+ "elements",
35
+ "layout",
36
+ "components",
37
+ "templates",
38
+ "pages"
39
+ ]
40
+ },
41
+ "category": {
42
+ "type": "array",
43
+ "items": {
44
+ "type": "string",
45
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
46
+ },
47
+ "minItems": 1
48
+ },
49
+ "className": {
50
+ "type": "string",
51
+ "pattern": "^(?:bce|bcl|bcc|bct|bcp)-[a-z0-9-]+$"
52
+ },
53
+ "source": {
54
+ "type": "object",
55
+ "required": [],
56
+ "additionalProperties": false,
57
+ "properties": {
58
+ "scss": {
59
+ "type": "string",
60
+ "pattern": "^[a-zA-Z0-9_ ./-]+\\.scss$"
61
+ },
62
+ "css": {
63
+ "type": "string",
64
+ "pattern": "^[a-zA-Z0-9_ ./-]+\\.css$"
65
+ },
66
+ "js": {
67
+ "type": "string",
68
+ "pattern": "^[a-zA-Z0-9_ ./-]+\\.js$"
69
+ },
70
+ "html": {
71
+ "type": "string",
72
+ "pattern": "^[a-zA-Z0-9_ ./-]+\\.html$"
73
+ }
74
+ }
75
+ },
76
+ "dependencies": {
77
+ "type": "object",
78
+ "additionalProperties": false,
79
+ "properties": {
80
+ "css": {
81
+ "type": "array",
82
+ "items": {
83
+ "type": "string",
84
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
85
+ "enum": [
86
+ "foundations",
87
+ "tokens",
88
+ "utilities"
89
+ ]
90
+ },
91
+ "uniqueItems": true
92
+ },
93
+ "behaviours": {
94
+ "type": "array",
95
+ "items": {
96
+ "type": "string",
97
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
98
+ "enum": [
99
+ "disclosure"
100
+ ]
101
+ },
102
+ "uniqueItems": true
103
+ },
104
+ "elements": {
105
+ "type": "array",
106
+ "items": {
107
+ "type": "string",
108
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
109
+ },
110
+ "uniqueItems": true
111
+ },
112
+ "runtime": {
113
+ "type": "boolean"
114
+ },
115
+ "layout": {
116
+ "type": "array",
117
+ "items": {
118
+ "type": "string",
119
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
120
+ },
121
+ "uniqueItems": true
122
+ },
123
+ "components": {
124
+ "type": "array",
125
+ "items": {
126
+ "type": "string",
127
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
128
+ },
129
+ "uniqueItems": true
130
+ },
131
+ "templates": {
132
+ "type": "array",
133
+ "items": {
134
+ "type": "string",
135
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
136
+ },
137
+ "uniqueItems": true
138
+ },
139
+ "pages": {
140
+ "type": "array",
141
+ "items": {
142
+ "type": "string",
143
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
144
+ },
145
+ "uniqueItems": true
146
+ }
147
+ }
148
+ },
149
+ "variants": {
150
+ "type": "array",
151
+ "items": {
152
+ "$ref": "#/$defs/choice"
153
+ }
154
+ },
155
+ "sizes": {
156
+ "type": "array",
157
+ "items": {
158
+ "$ref": "#/$defs/choice"
159
+ }
160
+ },
161
+ "anatomy": {
162
+ "type": "array",
163
+ "items": {
164
+ "type": "string"
165
+ },
166
+ "uniqueItems": true
167
+ },
168
+ "notes": {
169
+ "type": "array",
170
+ "items": {
171
+ "type": "string"
172
+ }
173
+ },
174
+ "documentation": {
175
+ "type": "object",
176
+ "additionalProperties": false,
177
+ "required": [
178
+ "guide",
179
+ "api",
180
+ "examples"
181
+ ],
182
+ "properties": {
183
+ "guide": {
184
+ "type": "string",
185
+ "minLength": 1
186
+ },
187
+ "api": {
188
+ "type": "string",
189
+ "minLength": 1
190
+ },
191
+ "examples": {
192
+ "type": "string",
193
+ "minLength": 1
194
+ }
195
+ }
196
+ },
197
+ "previewControls": {
198
+ "type": "object",
199
+ "additionalProperties": false,
200
+ "required": [
201
+ "colourContexts"
202
+ ],
203
+ "properties": {
204
+ "colourContexts": {
205
+ "type": "array",
206
+ "minItems": 1,
207
+ "uniqueItems": true,
208
+ "items": {
209
+ "enum": [
210
+ "primary",
211
+ "secondary",
212
+ "accent",
213
+ "neutral",
214
+ "success",
215
+ "warning",
216
+ "error",
217
+ "info"
218
+ ]
219
+ }
220
+ }
221
+ }
222
+ },
223
+ "resolvedCss": {
224
+ "type": "array",
225
+ "items": {
226
+ "type": "string",
227
+ "minLength": 1
228
+ }
229
+ },
230
+ "mount": {
231
+ "type": "object",
232
+ "required": [
233
+ "export",
234
+ "selector"
235
+ ],
236
+ "properties": {
237
+ "export": {
238
+ "type": "string",
239
+ "minLength": 1,
240
+ "pattern": "^[A-Za-z_$][\\w$]*$"
241
+ },
242
+ "selector": {
243
+ "type": "string",
244
+ "minLength": 1
245
+ }
246
+ },
247
+ "additionalProperties": false
248
+ },
249
+ "examples": {
250
+ "type": "array"
251
+ },
252
+ "usage": {
253
+ "type": "string"
254
+ },
255
+ "properties": {
256
+ "type": "array"
257
+ },
258
+ "accessibility": {
259
+ "type": "array"
260
+ },
261
+ "tags": {
262
+ "type": "array"
263
+ },
264
+ "status": {
265
+ "type": "string"
266
+ },
267
+ "reference": {
268
+ "type": "object"
269
+ },
270
+ "kind": {
271
+ "enum": [
272
+ "authored",
273
+ "recipe"
274
+ ]
275
+ },
276
+ "version": {
277
+ "type": "string"
278
+ }
279
+ },
280
+ "$defs": {
281
+ "choice": {
282
+ "type": "object",
283
+ "required": [
284
+ "id",
285
+ "className"
286
+ ],
287
+ "additionalProperties": false,
288
+ "properties": {
289
+ "id": {
290
+ "type": "string"
291
+ },
292
+ "className": {
293
+ "type": "string"
294
+ },
295
+ "default": {
296
+ "type": "boolean"
297
+ }
298
+ }
299
+ }
300
+ },
301
+ "allOf": [
302
+ {
303
+ "if": {
304
+ "properties": {
305
+ "kind": {
306
+ "const": "recipe"
307
+ }
308
+ },
309
+ "required": [
310
+ "kind"
311
+ ]
312
+ },
313
+ "then": {
314
+ "properties": {
315
+ "source": {
316
+ "required": [
317
+ "html"
318
+ ],
319
+ "not": {
320
+ "anyOf": [
321
+ {
322
+ "required": [
323
+ "scss"
324
+ ]
325
+ },
326
+ {
327
+ "required": [
328
+ "css"
329
+ ]
330
+ }
331
+ ]
332
+ }
333
+ }
334
+ }
335
+ },
336
+ "else": {
337
+ "required": [
338
+ "className"
339
+ ],
340
+ "properties": {
341
+ "source": {
342
+ "required": [
343
+ "scss",
344
+ "css"
345
+ ]
346
+ }
347
+ }
348
+ }
349
+ }
350
+ ]
351
+ }
@@ -0,0 +1,82 @@
1
+ import fs from 'node:fs';
2
+ import {assertWithin} from '../registry/paths.mjs';
3
+ import path from 'node:path';
4
+ import {createRequire} from 'node:module';
5
+
6
+ function dependency(project, name) {
7
+ const require=createRequire(path.join(project,'package.json'));
8
+ try{return require(name);}catch(error){
9
+ if(error.code==='MODULE_NOT_FOUND')throw Error(`Missing project build dependency: ${name}. Install it as a dev dependency in ${project}`);
10
+ throw error;
11
+ }
12
+ }
13
+
14
+ /** Build only active assets. Requires Sass; esbuild is needed only for active JS mounts.
15
+ * Both tools resolve from the consumer's project, never from BufferCore runtime.
16
+ */
17
+ /** Build the active dependency closure without publishing partial output.
18
+ * CSS is compiled first, but no previous successful output is replaced until
19
+ * the optional JS bundle has completed. Temporary artefacts are always removed.
20
+ */
21
+ export async function buildProject(app,{minify=true}={}) {
22
+ const project=path.dirname(app.manifestFile);
23
+ const entries=app.generate();
24
+ const sass=dependency(project,'sass');
25
+ const scriptAssets=app.activeClosure().filter(asset=>asset.source?.js && asset.mount?.export && asset.mount?.selector);
26
+ const needsJs=scriptAssets.length>0 || app.activeClosure().some(asset=>asset.dependencies?.behaviours?.length>0);
27
+ const esbuild=needsJs?dependency(project,'esbuild'):null;
28
+ const input=path.join(project,'src/buffercore/_active.scss');
29
+ const output=path.join(project,'dist/buffercore-levels.css');
30
+ const jsOutput=path.join(project,'dist/buffercore-levels.js');
31
+ const css=sass.compile(input,{
32
+ style:minify?'compressed':'expanded',
33
+ loadPaths:[path.join(project,'node_modules'),path.join(project,'src')],
34
+ sourceMap:false,
35
+ silenceDeprecations:['legacy-js-api']
36
+ });
37
+ assertWithin(project,output);assertWithin(project,jsOutput);
38
+ const outputDir=path.dirname(output);
39
+ fs.mkdirSync(outputDir,{recursive:true});
40
+ const cssTemporary=path.join(outputDir,`.buffercore-levels-${process.pid}.css.tmp`);
41
+ const jsTemporary=path.join(outputDir,`.buffercore-levels-${process.pid}.js.tmp`);
42
+ let bundleReport = null;
43
+ try {
44
+ fs.writeFileSync(cssTemporary,css.css);
45
+ if(needsJs) {
46
+ const bundled = await esbuild.build({
47
+ entryPoints:[path.join(project,'src/buffercore/active.mjs')],
48
+ outfile:jsTemporary,bundle:true,format:'esm',platform:'browser',
49
+ target:'es2020',minify,logLevel:'silent',metafile:true,
50
+ });
51
+ // esbuild's metafile tracks source modules once per input, regardless of
52
+ // how many Assets requested the same Core Behaviour. This report is
53
+ // diagnostic only; no additional file is shipped to production.
54
+ const inputs = Object.keys(bundled.metafile?.inputs ?? {});
55
+ let coreRoot;try{coreRoot=fs.realpathSync(path.dirname(createRequire(path.join(project,'package.json')).resolve('@buffercreations/buffercore/package.json')));}catch{}
56
+ const coreInputs = inputs.filter(input => (coreRoot && path.resolve(input).startsWith(coreRoot+path.sep)) || /(?:^|[/\\])@buffercreations[/\\]buffercore[/\\]/.test(input));
57
+ bundleReport = {
58
+ bytes:fs.statSync(jsTemporary).size,
59
+ inputs:inputs.length,
60
+ coreModules:coreInputs.length,
61
+ coreModulePaths:coreInputs.sort(),
62
+ };
63
+ }
64
+ const previousCss=fs.existsSync(output)?fs.readFileSync(output):null;
65
+ const previousJs=fs.existsSync(jsOutput)?fs.readFileSync(jsOutput):null;
66
+ try {
67
+ // Update completed outputs only after *both* compilers succeeded.
68
+ // A CSS-only build removes JS from an earlier interactive build.
69
+ if(needsJs)fs.renameSync(jsTemporary,jsOutput);
70
+ else if(fs.existsSync(jsOutput))fs.unlinkSync(jsOutput);
71
+ fs.renameSync(cssTemporary,output);
72
+ } catch(error) {
73
+ const cleanup=[];
74
+ for(const [file,previous] of [[output,previousCss],[jsOutput,previousJs]])try{if(previous!==null)fs.writeFileSync(file,previous);else if(fs.existsSync(file))fs.unlinkSync(file);}catch(e){cleanup.push(e);}
75
+ if(cleanup.length)throw new AggregateError([error,...cleanup],"Bundle publication and rollback failed",{cause:error});
76
+ throw error;
77
+ }
78
+ } finally {
79
+ for(const temporary of [cssTemporary,jsTemporary])if(fs.existsSync(temporary))fs.unlinkSync(temporary);
80
+ }
81
+ return {css:output,js:needsJs?jsOutput:null,assets:entries.assets,bytes:Buffer.byteLength(css.css),bundleReport};
82
+ }
@@ -0,0 +1,56 @@
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 {parseArgs} from 'node:util';
6
+ import {openProject} from './project.mjs';
7
+ import {buildProject} from './build.mjs';
8
+ import {resolveRegistryLocation} from './registry-location.mjs';
9
+ import {migrateInstalled} from './migrate.mjs';
10
+ import {assertWithin} from '../registry/paths.mjs';
11
+ const packageRoot=fileURLToPath(new URL('../../',import.meta.url));
12
+ const pkg=JSON.parse(fs.readFileSync(path.join(packageRoot,'package.json')));
13
+ const help=`LevelsUI ${pkg.version}
14
+ Usage: levelsui <command> [asset] [options]
15
+ Commands: init, list [--installed], info <asset>, add <asset>, activate <asset>,
16
+ deactivate <asset>, update <asset>, remove <asset>, prune, entries, build,
17
+ validate, doctor, migrate [--rollback], help, --version
18
+ Options: --project <dir>, --registry <dir>, --dry-run, --apply,
19
+ --expanded, --report, --verbose. remove/prune/migrate preview until --apply.
20
+ Compatibility: buffercore executable and use/unuse verbs delegate to LevelsUI.
21
+ Installed source is not activated, bundled or mounted automatically.`;
22
+ try{
23
+ const {values:v,positionals:p}=parseArgs({allowPositionals:true,strict:true,options:{project:{type:'string'},registry:{type:'string'},'dry-run':{type:'boolean'},apply:{type:'boolean'},expanded:{type:'boolean'},report:{type:'boolean'},verbose:{type:'boolean'},installed:{type:'boolean'},rollback:{type:'boolean'},help:{type:'boolean'},version:{type:'boolean'}}});
24
+ if(v.help||(!p.length&&!v.version)||p[0]==='help'){console.log(help);}
25
+ else if(v.version){console.log(pkg.version);}
26
+ else {
27
+ const command=({use:'activate',unuse:'deactivate'})[p[0]]||p[0],id=p[1];
28
+ const opts={init:[],list:['installed'],info:[],add:['dry-run'],activate:[],deactivate:[],update:['dry-run'],remove:['apply','dry-run'],prune:['apply','dry-run'],entries:['dry-run'],build:['expanded','report','verbose'],validate:[],doctor:[],migrate:['apply','dry-run','rollback']};
29
+ if(!(command in opts))throw Error('Unknown command: '+command);
30
+ for(const key of Object.keys(v))if(!['project','registry'].includes(key)&&!opts[command].includes(key))throw Error(`--${key} is not supported by ${command}`);
31
+ if(v.apply&&v['dry-run'])throw Error('--apply and --dry-run are mutually exclusive');
32
+ const needsId=['info','add','activate','deactivate','update','remove'].includes(command);
33
+ if(needsId&&(!id||!/^[a-z][a-z0-9-]*$/.test(id)))throw Error('Specify a valid asset id');
34
+ if(p.length>(needsId?2:1))throw Error('Unexpected positional argument');
35
+ const project=path.resolve(v.project||process.cwd());
36
+ if(command==='init'){
37
+ const f=assertWithin(project,path.join(project,'buffercore.assets.json'));
38
+ if(fs.existsSync(f))openProject(project).doctor();else {fs.mkdirSync(project,{recursive:true});fs.writeFileSync(f,JSON.stringify({schemaVersion:3,installed:{},active:[]},null,2)+'\n',{flag:'wx'});}
39
+ console.log('Project ready. Install BufferCore and Sass; esbuild is needed for interactive builds.');
40
+ } else if(command==='migrate')console.log(JSON.stringify(migrateInstalled(project,{apply:!!v.apply,rollback:!!v.rollback}),null,2));
41
+ else {
42
+ const needsRegistry=['info','add','update','validate'].includes(command)||(command==='list'&&!v.installed);
43
+ const registry=needsRegistry?resolveRegistryLocation({project,explicit:v.registry,packageRoot}):undefined;
44
+ const app=openProject(project,registry);
45
+ if(command==='list')console.log(JSON.stringify(v.installed?Object.entries(app.state.installed).map(([id,e])=>({id,level:e.level,version:e.version,catalogue:e.catalogue,active:app.state.active.includes(id)})):[...app.registry.values()],null,2));
46
+ else if(command==='info'){if(!app.registry.has(id))throw Error('Unknown asset: '+id);console.log(JSON.stringify(app.registry.get(id),null,2));}
47
+ else if(command==='validate')console.log(`Valid LevelsUI catalogue: ${app.registry.size} Assets`);
48
+ else if(command==='add'||command==='update')console.log(JSON.stringify(app.add([id],{update:command==='update',dryRun:!!v['dry-run']}),null,2));
49
+ else if(command==='activate'||command==='deactivate'){app.activate(id,command==='activate');console.log(command+': '+id);}
50
+ else if(command==='remove'||command==='prune')console.log(JSON.stringify(command==='remove'?app.remove([id],{apply:!!v.apply}):app.prune({apply:!!v.apply}),null,2));
51
+ else if(command==='entries')console.log(JSON.stringify(app.generate({write:!v['dry-run']}),null,2));
52
+ else if(command==='doctor'){const r=app.doctor();console.log(JSON.stringify(r,null,2));if(r.warnings.length)process.exitCode=1;}
53
+ else if(command==='build'){const r=await buildProject(app,{minify:!v.expanded});console.log(`Built ${r.css} (${r.bytes} bytes)`);if(r.js)console.log('Built '+r.js);if(v.report)console.log(JSON.stringify(r.bundleReport||{bytes:0,inputs:0},null,2));if(v.verbose&&r.bundleReport)for(const p of r.bundleReport.coreModulePaths)console.log('Core: '+p);}
54
+ }
55
+ }
56
+ }catch(error){console.error('LevelsUI: '+error.message);process.exitCode=1;}
@@ -0,0 +1,57 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import crypto from 'node:crypto';
4
+ import {assertWithin,safeRelative} from '../registry/paths.mjs';
5
+ import {validateReusableUiDefinition,resolveAssets} from '../registry/definitions.mjs';
6
+ const folders={'02. Elements':'01. Elements','03. Layout':'02. Layouts','04. Components':'03. Components','05. Templates':'04. Templates','06. Pages':'05. Pages'};
7
+ const hash=p=>crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex');
8
+ export function migrateInstalled(project,{apply=false,rollback=false}={}){
9
+ const stateFile=assertWithin(project,path.join(project,'buffercore.assets.json'));
10
+ const journal=assertWithin(project,path.join(project,'.levelsui-migration.json'));
11
+ if(rollback){
12
+ if(!fs.existsSync(journal))throw Error('No migration journal');
13
+ const j=JSON.parse(fs.readFileSync(journal));
14
+ if(!safeRelative(j.backup))throw Error('Invalid migration backup');
15
+ const backup=assertWithin(project,path.join(project,j.backup));
16
+ if(hash(backup)!==j.sha256)throw Error('Migration backup changed');
17
+ if(apply){fs.copyFileSync(backup,stateFile);fs.unlinkSync(journal);}
18
+ return [{action:'restore-state',backup:j.backup,note:'New copies remain untouched; old source trees were retained.'}];
19
+ }
20
+ const state=JSON.parse(fs.readFileSync(stateFile));
21
+ if(![1,2,3].includes(state.schemaVersion)||!state.installed||!Array.isArray(state.active))throw Error('Invalid installed state');
22
+ if(state.schemaVersion===3&&Object.values(state.installed).every(e=>e.definition))return [];
23
+ if(fs.existsSync(journal))throw Error('Existing migration journal; review or rollback first');
24
+ const root=assertWithin(project,path.join(project,'src/buffercore')),plan=[];
25
+ const next=structuredClone(state);next.schemaVersion=3;
26
+ for(const [id,e] of Object.entries(next.installed)){
27
+ if(!/^[a-z][a-z0-9-]*$/.test(id)||!safeRelative(e.path))throw Error('Invalid installed identity/path');
28
+ const old=assertWithin(root,path.join(root,e.path));
29
+ const prefix=e.path.split('/')[0],newPath=folders[prefix]?folders[prefix]+e.path.slice(prefix.length):e.path;
30
+ const target=assertWithin(root,path.join(root,newPath));
31
+ if(old!==target&&fs.existsSync(target))throw Error('Destination collision: '+newPath);
32
+ const defFile=assertWithin(old,path.join(old,id+'.definition.json'));
33
+ if(!e.files||!e.files[id+'.definition.json']||hash(defFile)!==e.files[id+'.definition.json'])throw Error('Missing/untracked/modified installed definition: '+id+'; review manually');
34
+ const def=JSON.parse(fs.readFileSync(defFile)),errors=validateReusableUiDefinition(def);
35
+ if(errors.length||def.id!==id)throw Error('Invalid installed definition: '+id);
36
+ const modified=[];
37
+ for(const [name,digest] of Object.entries(e.files)){
38
+ if(!safeRelative(name))throw Error('Invalid tracked path');const f=assertWithin(old,path.join(old,name));
39
+ if(!fs.existsSync(f))throw Error('Missing tracked file: '+f);
40
+ if(hash(f)!==digest)modified.push(name);
41
+ }
42
+ // Recursively reject redirected untracked files as well before copying anything.
43
+ const scan=d=>{for(const x of fs.readdirSync(d,{withFileTypes:true})){const f=assertWithin(old,path.join(d,x.name));if(x.isDirectory())scan(f);}};scan(old);
44
+ e.path=newPath;e.definition=def;e.dependencies=def.dependencies||{};
45
+ plan.push({id,action:'migrate',from:state.installed[id].path,to:newPath,modified,old,target});
46
+ }
47
+ resolveAssets(new Map(Object.entries(next.installed).map(([id,e])=>[id,e.definition])),next.active);
48
+ if(apply){
49
+ const backup='buffercore.assets.pre-levelsui-'+Date.now()+'.json',backupFile=assertWithin(project,path.join(project,backup));
50
+ fs.copyFileSync(stateFile,backupFile,fs.constants.COPYFILE_EXCL);
51
+ fs.writeFileSync(journal,JSON.stringify({schemaVersion:1,backup,sha256:hash(backupFile),plan:plan.map(({old,target,...p})=>p)},null,2),{flag:'wx'});
52
+ // Originals remain intact for recovery. No stale hashes are refreshed.
53
+ for(const p of plan)if(p.old!==p.target){fs.mkdirSync(path.dirname(p.target),{recursive:true});fs.cpSync(p.old,p.target,{recursive:true,errorOnExist:true,force:false});}
54
+ const temp=assertWithin(project,stateFile+'.tmp');fs.writeFileSync(temp,JSON.stringify(next,null,2)+'\n');fs.renameSync(temp,stateFile);
55
+ }
56
+ return plan.map(({old,target,...p})=>p);
57
+ }