@webority/tokens 0.149.0 → 0.152.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.
Files changed (76) hide show
  1. package/dist/brand.d.ts +39 -25
  2. package/dist/brand.js +2 -2
  3. package/dist/build.d.ts +41 -0
  4. package/dist/build.js +5 -5
  5. package/dist/canvas/webority-phone.json +12 -12
  6. package/dist/canvas/webority-web-390.json +35 -3
  7. package/dist/canvas/webority-web.json +35 -3
  8. package/dist/check.d.ts +37 -0
  9. package/dist/check.js +3 -3
  10. package/dist/cli.d.ts +15 -96
  11. package/dist/cli.js +1 -1
  12. package/dist/emit/canvas.d.ts +8 -0
  13. package/dist/emit/canvas.js +1 -1
  14. package/dist/emit/email.d.ts +32 -0
  15. package/dist/emit/email.js +2 -2
  16. package/dist/emit/meanings.d.ts +3 -0
  17. package/dist/emit/phone.d.ts +26 -0
  18. package/dist/emit/phone.js +3 -3
  19. package/dist/emit/web.d.ts +18 -0
  20. package/dist/emit/web.js +14 -14
  21. package/dist/guards.d.ts +3 -0
  22. package/dist/guards.js +1 -0
  23. package/dist/index.d.ts +7 -7
  24. package/dist/meanings.json +97 -1
  25. package/dist/model/colour.d.ts +8 -0
  26. package/dist/model/colour.js +1 -1
  27. package/dist/model/contrast.d.ts +26 -0
  28. package/dist/model/contrast.js +1 -1
  29. package/dist/model/index.d.ts +52 -0
  30. package/dist/model/length.d.ts +21 -0
  31. package/dist/model/length.js +1 -1
  32. package/dist/model/load.d.ts +32 -0
  33. package/dist/model/load.js +1 -1
  34. package/dist/model/references.d.ts +3 -0
  35. package/dist/model/references.js +1 -1
  36. package/dist/model/resolve.d.ts +4 -0
  37. package/dist/model/resolve.js +2 -2
  38. package/dist/names.d.ts +1 -11
  39. package/dist/names.js +1 -1
  40. package/dist/outputs.d.ts +51 -102
  41. package/dist/present.d.ts +1 -0
  42. package/dist/present.js +1 -0
  43. package/dist/ramp.d.ts +8 -0
  44. package/dist/ramp.js +1 -1
  45. package/dist/source/meaning.tokens.json +144 -0
  46. package/dist/source/palette.tokens.json +9 -9
  47. package/dist/source/scale.tokens.json +39 -2
  48. package/dist/upgrade/classes.d.ts +13 -0
  49. package/dist/upgrade/classes.js +2 -2
  50. package/dist/upgrade/components.d.ts +19 -0
  51. package/dist/upgrade/components.js +3 -3
  52. package/dist/upgrade/css.d.ts +28 -0
  53. package/dist/upgrade/css.js +2 -2
  54. package/dist/upgrade/index.d.ts +64 -0
  55. package/dist/upgrade/index.js +2 -2
  56. package/dist/upgrade/razorAttributes.d.ts +19 -0
  57. package/dist/upgrade/razorAttributes.js +2 -2
  58. package/dist/upgrade/razorTags.d.ts +19 -0
  59. package/dist/upgrade/razorTags.js +2 -2
  60. package/dist/upgrade/razorValueSplits.d.ts +19 -0
  61. package/dist/upgrade/razorValueSplits.js +2 -2
  62. package/dist/upgrade/source.d.ts +19 -0
  63. package/dist/upgrade/source.js +3 -3
  64. package/dist/upgrade/tagScan.d.ts +7 -0
  65. package/dist/upgrade/tagScan.js +1 -1
  66. package/dist/upgrade/themeReads.d.ts +55 -0
  67. package/dist/upgrade/themeReads.js +2 -2
  68. package/dist/upgrade/valueSplits.d.ts +23 -0
  69. package/dist/upgrade/valueSplits.js +3 -3
  70. package/dist/upgrade/wrapperValues.d.ts +71 -0
  71. package/dist/upgrade/wrapperValues.js +1 -1
  72. package/dist/webority.d.ts +1 -0
  73. package/package.json +8 -3
  74. package/renames/0.130.0.json +15 -0
  75. package/renames/0.152.0.json +30 -0
  76. package/renames/renames.d.ts +1 -1
package/dist/brand.d.ts CHANGED
@@ -1,11 +1,23 @@
1
+ /**
2
+ * A product brand file may override palette steps, colour meanings, brand-only colours and effects
3
+ * (each with a $description), fonts and radius steps. A recorded deviation lifts the refusal of the
4
+ * groups it lists. Every override of a meaning that has a dark value carries it beside the light value,
5
+ * because the dark context is built from those values alone. The email group is checked against the
6
+ * email role tables and resolved by emitEmail, so its colour references never meet the base layer.
7
+ * A palette.primary written as #RRGGBB also supplies every primary step the file leaves out (ramp.ts); a step the file writes wins.
8
+ * 1a.L7a calls loadBrand once per brand, before loadModel.
9
+ */
10
+ export type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
11
+ export interface JsonObject {
12
+ [key: string]: JsonValue;
13
+ }
1
14
  /** The parsed library source trees the model already holds. */
2
15
  export interface LibrarySources {
3
16
  palette: object;
4
- scale: object;
17
+ scale: JsonObject;
5
18
  meaning: object;
6
19
  modeDark: object;
7
20
  }
8
-
9
21
  /** The brand file's email group as written (DTCG tokens). Each key is an email.json role key. */
10
22
  export interface BrandEmailGroup {
11
23
  /** <email colour role>: { $type: "color", $value: "#RRGGBB" | "{color.<meaning>}", $extensions.com.webority.dark?: "#RRGGBB" | "{color.<meaning>}" } */
@@ -17,38 +29,40 @@ export interface BrandEmailGroup {
17
29
  /** <email shape key>: { $type: "dimension", $value: { value, unit: "px" } } */
18
30
  shape?: Record<string, object>;
19
31
  /** radius: a dimension token; padding: { $value: "14px 28px" } */
20
- button?: { radius?: object; padding?: object };
32
+ button?: {
33
+ radius?: object;
34
+ padding?: object;
35
+ };
21
36
  }
22
-
23
37
  /** A validated brand: base overrides every mode, dark overrides the dark context only. */
24
38
  export interface BrandLayer {
25
39
  name: string;
26
- base: object;
27
- dark: object;
40
+ base: JsonObject;
41
+ dark: JsonObject;
28
42
  /** The email group, kept outside base because the web model never reads it; null when the file has none. */
29
43
  email: BrandEmailGroup | null;
30
44
  /** Phone-only overrides the brand tool derives for a readable primary pair (color.primary per mode); loadBrand never sets it. */
31
- phone?: { light: object; dark: object };
45
+ phone?: {
46
+ light: JsonObject;
47
+ dark: JsonObject;
48
+ };
32
49
  }
33
-
34
50
  /** A brand group a recorded deviation can allow beyond palette, color, effect, font and radius. */
35
51
  export type DeviationGroup = "space" | "text" | "shadow" | "section" | "component" | "email";
36
-
37
52
  /** The recorded deviations, keyed by slug (src/deviations.json); groups lists the brand groups each one allows. */
38
- export type Deviations = Readonly<Record<string, { reason: string; groups: readonly DeviationGroup[] }>>;
39
-
40
- /** Reads and validates a product brand file; throws one Error listing every problem. */
41
- export declare function loadBrand(path: string, library: LibrarySources, deviations: Deviations): BrandLayer;
42
-
43
- export declare const BRAND_OUTPUT_FILES: {
44
- readonly css: "brand.css";
45
- readonly bootstrap: "_brand-variables.scss";
46
- readonly web: "webority-web.json";
47
- readonly web390: "webority-web-390.json";
48
- readonly phoneTheme: "webority-phone.json";
49
- readonly phone: "brand.phone.js";
50
- readonly email: "email.json";
51
- };
52
-
53
+ export type Deviations = Readonly<Record<string, {
54
+ reason: string;
55
+ groups: readonly DeviationGroup[];
56
+ }>>;
57
+ export declare const BRAND_OUTPUT_FILES: Readonly<{
58
+ css: "brand.css";
59
+ bootstrap: "_brand-variables.scss";
60
+ web: "webority-web.json";
61
+ web390: "webority-web-390.json";
62
+ phoneTheme: "webority-phone.json";
63
+ phone: "brand.phone.js";
64
+ email: "email.json";
65
+ }>;
53
66
  /** The folder inside each head that receives the copies of the generated files. */
54
- export declare const HEAD_FOLDER: "generated";
67
+ export declare const HEAD_FOLDER = "generated";
68
+ export declare function loadBrand(path: string, library: LibrarySources, deviations: Deviations): BrandLayer;
package/dist/brand.js CHANGED
@@ -1,2 +1,2 @@
1
- import{EMAIL_COLOR_ROLES as e,EMAIL_PADDING_PATTERN as t,EMAIL_PADDING_ROLES as n,EMAIL_SHAPE as r,EMAIL_SPACE as i,EMAIL_TYPE_ROLES as a}from"./emit/email.js";import{RAMP_STEPS as o,deriveRamp as s}from"./ramp.js";import{readFileSync as c}from"node:fs";var l=Object.freeze({css:`brand.css`,bootstrap:`_brand-variables.scss`,web:`webority-web.json`,web390:`webority-web-390.json`,phoneTheme:`webority-phone.json`,phone:`brand.phone.js`,email:`email.json`}),u=`generated`,d=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,f=[`palette`,`color`,`effect`,`font`,`radius`],p=[`space`,`text`,`shadow`,`section`,`component`,`email`],m=[`radius`,`padding`],h=[`size`,`lineHeight`,`phoneSize`,`phoneLineHeight`],g=[`narrowSize`,`narrowLineHeight`],_=/^(#[0-9a-fA-F]{6}|\{color\.[a-z0-9-]+\})$/;function v(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function y(e){return v(e)&&Object.hasOwn(e,`$value`)}function b(e,t){let n=[],r=(e,t)=>{for(let i of Object.keys(e)){if(i.startsWith(`$`))continue;let a=e[i],o=`${t}.${i}`;y(a)?n.push({path:o,node:a}):v(a)&&r(a,o)}};return r(e,t),n}function x(e,t){let n=e;for(let e of t.split(`.`)){if(!v(n)||!Object.hasOwn(n,e))return!1;n=n[e]}return y(n)}function S(e){let t=e?.$extensions?.[`com.webority`];return v(t)?t:{}}function C(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)&&!/^[0-9]+$/.test(e)}function w(e){return typeof e==`string`&&_.test(e)}function T(e){return v(e)&&Number.isInteger(e.value)&&e.value>=0&&e.unit===`px`}function E(e,t){return e===`space`?n.has(t):e===`button`&&t===`padding`}function D(e,n,r,i,a){let o=S(r);for(let t of Object.keys(o))(e!==`color`||t!==`dark`)&&a(i,`$extensions.com.webority.${t} is not allowed on this token`,`Remove it`);if(e===`color`)w(r.$value)||a(i,`$value is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`),Object.hasOwn(o,`dark`)&&!w(o.dark)&&a(i,`$extensions.com.webority.dark is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`);else if(e===`type`){let e=r.$value,t=v(e)?Object.keys(e):[],n=t.includes(`narrowSize`)||t.includes(`narrowLineHeight`)?[...h,...g]:h;v(e)&&t.length===n.length&&n.every(t=>Number.isInteger(e[t])&&e[t]>0)||a(i,`$value is not { size, lineHeight, phoneSize, phoneLineHeight } (optionally narrowSize, narrowLineHeight) in whole px`,`Write it as { "size": 16, "lineHeight": 24, "phoneSize": 15, "phoneLineHeight": 22 }`)}else E(e,n)?typeof r.$value==`string`&&t.test(r.$value)||a(i,`$value is not CSS px padding`,`Write it as "22px 24px", one to four px values or 0`):T(r.$value)||a(i,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}function O(t,n){let o={color:Object.keys(e),type:Object.keys(a),space:Object.keys(i),shape:Object.keys(r),button:m};for(let e of Object.keys(t))if(!e.startsWith(`$`)){if(!Object.hasOwn(o,e))n(`email.${e}`,`is not an email group`,`Use one of ${Object.keys(o).join(`, `)}`);else if(!v(t[e]))n(`email.${e}`,`is not a group`,`Write it as an object of tokens`);else for(let r of Object.keys(t[e])){if(r.startsWith(`$`))continue;let i=`email.${e}.${r}`;if(!o[e].includes(r)){n(i,`is not an email role`,`Use one of ${o[e].join(`, `)}`);continue}let a=t[e][r];y(a)?D(e,r,a,i,n):n(i,`is not a token`,`Give it a $value`)}}}function k(e,t,n){let r;try{r=JSON.parse(c(e,`utf8`))}catch(t){throw Error(`${e}: (file): cannot be read as JSON (${t.message}). Restore the file or fix the JSON`)}if(!v(r))throw Error(`${e}: (file): is not a JSON object. Write the brand as one object with the groups palette, color, effect, font and radius`);let i=[],a=(t,n,r)=>{let a=`${e}: ${t}: ${n}. ${r}`;i.includes(a)||i.push(a)},l=S(r);for(let e of Object.keys(l))e!==`brand`&&e!==`deviation`&&a(`$extensions.com.webority.${e}`,`is not a brand file key`,`Remove it`);let u=Object.hasOwn(l,`deviation`),m=u&&typeof l.deviation==`string`&&Object.hasOwn(n,l.deviation);u&&!m&&a(`$extensions.com.webority.deviation`,`${l.deviation} is not in deviations.json`,`Use one of: ${Object.keys(n).join(`, `)}`),typeof l.brand==`string`&&/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(l.brand)||a(`$extensions.com.webority.brand`,`is missing or not kebab case`,`Name the product in kebab case, such as acme`);let h=m?n[l.deviation].groups:[],g={},_=null;for(let e of Object.keys(r))e.startsWith(`$`)||(!f.includes(e)&&!p.includes(e)?a(e,`is not a brand group`,`A brand file holds only palette, color, effect, font and radius, plus the groups a recorded deviation allows`):p.includes(e)&&!h.includes(e)?a(e,`this group needs a recorded deviation`,`Add $extensions.com.webority.deviation naming an entry of deviations.json, or remove the group`):v(r[e])?e===`email`?_=r[e]:g[e]=r[e]:a(e,`is not a group`,`Write it as an object of tokens`));for(let[e,t]of Object.entries(g))for(let{path:n,node:r}of b(t,e)){let t=S(r);for(let r of Object.keys(t))r!==`platforms`&&r!==`dark`&&(r!==`faces`||e!==`font`)&&a(n,`$extensions.com.webority.${r} is not allowed on a token`,`Remove it`);if(Object.hasOwn(t,`platforms`)){let e=t.platforms;Array.isArray(e)&&e.length>0&&e.every(e=>e===`web`||e===`phone`)||a(n,`$extensions.com.webority.platforms is not a list of web and phone`,`Write it as ["phone"], ["web"] or both`)}Object.hasOwn(t,`dark`)&&e!==`color`&&e!==`effect`&&a(n,`$extensions.com.webority.dark applies to colour and effect tokens only`,`Remove it`)}for(let{path:e,node:t}of b(g.palette??{},`palette`))e.split(`.`).slice(1).every(C)||a(e,`the step name is not kebab case`,`Name it such as primary-500`),typeof t.$value!=`string`&&a(e,`$value is not a string`,`Write the colour as text such as "#0F766E" or a reference such as "{palette.primary}"`);let w=(e,n,r)=>{let i=`${e}.${n}`,o=S(r),s=x(t.meaning,i);typeof r.$value!=`string`&&a(i,`$value is not a string`,e===`color`?`Write a colour or a reference such as "{palette.primary}"`:`Write the effect as text such as a filter, colour or gradient`),s?x(t.modeDark,i)&&typeof o.dark!=`string`&&a(i,`needs $extensions.com.webority.dark because the meaning has a dark value`,`Add the dark value beside the light one`):(C(n)||a(i,`the name is not kebab case`,`Name it in kebab case`),(typeof r.$description!=`string`||r.$description===``)&&a(i,`is not a fleet meaning and has no $description`,`Add a $description saying what the colour is for, or use a meaning the library defines`)),Object.hasOwn(o,`dark`)&&typeof o.dark!=`string`&&a(i,`$extensions.com.webority.dark is not a string`,`Write a colour or a reference`)};for(let e of[`color`,`effect`]){let t=g[e]??{};for(let n of Object.keys(t))n.startsWith(`$`)||(y(t[n])?w(e,n,t[n]):a(`${e}.${n}`,`is not a token`,`Give it a $value`))}let T=Object.keys(t.scale.font??{}).filter(e=>y(t.scale.font[e]));for(let{path:e,node:n}of b(g.font??{},`font`)){x(t.scale,e)||a(e,`is not a fleet font`,`Use one of ${T.join(`, `)}`);let r=n.$value;if(Array.isArray(r)&&r.length!==0&&r.every(e=>typeof e==`string`)||a(e,`$value is not a list of font family names`,`Write it as ["Webority Sans", "system-ui", "sans-serif"]`),Object.hasOwn(S(n),`faces`)){let t=S(n).faces,r=[`normal`,`medium`,`semibold`,`bold`];v(t)&&Object.keys(t).length>0&&Object.keys(t).every(e=>r.includes(e))&&Object.values(t).every(e=>typeof e==`string`&&e!==``)||a(e,`faces is not a map of weight to font file name`,`Write it as { "normal": "AcmeSans-Regular", "semibold": "AcmeSans-SemiBold" }`)}}let E=Object.keys(t.scale.radius??{}).filter(e=>y(t.scale.radius[e]));for(let{path:e,node:n}of b(g.radius??{},`radius`)){x(t.scale,e)||a(e,`is not on the radius scale`,`Use one of ${E.join(`, `)}`);let r=n.$value;v(r)&&typeof r.value==`number`&&Number.isFinite(r.value)&&r.value>=0&&r.unit===`px`||a(e,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}_!==null&&O(_,a);let D=structuredClone(r);delete D.$extensions,delete D.$description,delete D.email;for(let e of[`color`,`effect`])for(let{node:t}of b(D[e]??{},e))Object.hasOwn(S(t),`dark`)&&(delete t.$extensions[`com.webority`].dark,Object.keys(t.$extensions[`com.webority`]).length===0&&delete t.$extensions[`com.webority`],Object.keys(t.$extensions).length===0&&delete t.$extensions);let k=g.palette?.primary?.$value;if(typeof k==`string`&&/^#[0-9a-fA-F]{6}$/.test(k)){let e=s(k);for(let t of o)x(D,`palette.${t}`)||(D.palette[t]={$type:`color`,$value:e[t]})}let A=e=>x(D,e)||x(t.palette,e)||x(t.scale,e)||x(t.meaning,e);for(let e of Object.keys(g))for(let{path:t,node:n}of b(g[e],e)){let e=[n.$value,S(n).dark].filter(e=>typeof e==`string`);for(let n of e)for(let e of n.matchAll(d))A(e[1])||a(t,`references {${e[1]}}, which no palette step, meaning, scale step or brand token defines`,`Name an existing token or add it to the brand file`)}if(i.length>0)throw Error(i.join(`
2
- `));let j={};for(let e of[`color`,`effect`])for(let{path:t,node:n}of b(g[e]??{},e)){let r=S(n).dark;if(typeof r!=`string`)continue;let i=t.slice(e.length+1);j[e]??={},j[e][i]=n.$type===void 0?{$value:r}:{$value:r,$type:n.$type}}return{name:l.brand,base:D,dark:j,email:_}}export{l as BRAND_OUTPUT_FILES,u as HEAD_FOLDER,k as loadBrand};
1
+ import{EMAIL_COLOR_ROLES as e,EMAIL_PADDING_PATTERN as t,EMAIL_PADDING_ROLES as n,EMAIL_SHAPE as r,EMAIL_SPACE as i,EMAIL_TYPE_ROLES as a}from"./emit/email.js";import{messageOf as o}from"./guards.js";import{RAMP_STEPS as s,deriveRamp as c}from"./ramp.js";import{readFileSync as l}from"node:fs";var u=Object.freeze({css:`brand.css`,bootstrap:`_brand-variables.scss`,web:`webority-web.json`,web390:`webority-web-390.json`,phoneTheme:`webority-phone.json`,phone:`brand.phone.js`,email:`email.json`}),d=`generated`,f=/\{([a-z0-9-]+(?:\.[a-z0-9-]+)+)\}/g,p=[`palette`,`color`,`effect`,`font`,`radius`],m=[`space`,`text`,`shadow`,`section`,`component`,`email`],h=[`radius`,`padding`],g=[`size`,`lineHeight`,`phoneSize`,`phoneLineHeight`],_=[`narrowSize`,`narrowLineHeight`],v=/^(#[0-9a-fA-F]{6}|\{color\.[a-z0-9-]+\})$/;function y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function b(e){return y(e)?e:{}}function x(e){return y(e)&&Object.hasOwn(e,`$value`)}function S(e,t){let n=[],r=(e,t)=>{for(let i of Object.keys(e)){if(i.startsWith(`$`))continue;let a=e[i],o=`${t}.${i}`;x(a)?n.push({path:o,node:a}):y(a)&&r(a,o)}};return r(e,t),n}function C(e,t){let n=e;for(let e of t.split(`.`)){if(!y(n)||!Object.hasOwn(n,e))return!1;n=n[e]}return x(n)}function w(e){let t=y(e)?e.$extensions:void 0,n=y(t)?t[`com.webority`]:void 0;return y(n)?n:{}}function T(e){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e)&&!/^[0-9]+$/.test(e)}function E(e){return typeof e==`string`&&v.test(e)}function D(e){return y(e)&&typeof e.value==`number`&&Number.isInteger(e.value)&&e.value>=0&&e.unit===`px`}function O(e){return typeof e==`number`&&Number.isInteger(e)&&e>0}function k(e,t){return e===`space`?n.has(t):e===`button`&&t===`padding`}function A(e,n,r,i,a){let o=w(r);for(let t of Object.keys(o))(e!==`color`||t!==`dark`)&&a(i,`$extensions.com.webority.${t} is not allowed on this token`,`Remove it`);if(e===`color`)E(r.$value)||a(i,`$value is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`),Object.hasOwn(o,`dark`)&&!E(o.dark)&&a(i,`$extensions.com.webority.dark is not a colour`,`Write "#RRGGBB" or a reference such as "{color.primary}"`);else if(e===`type`){let e=r.$value,t=y(e)?Object.keys(e):[],n=t.includes(`narrowSize`)||t.includes(`narrowLineHeight`)?[...g,..._]:g;y(e)&&t.length===n.length&&n.every(t=>O(e[t]))||a(i,`$value is not { size, lineHeight, phoneSize, phoneLineHeight } (optionally narrowSize, narrowLineHeight) in whole px`,`Write it as { "size": 16, "lineHeight": 24, "phoneSize": 15, "phoneLineHeight": 22 }`)}else k(e,n)?typeof r.$value==`string`&&t.test(r.$value)||a(i,`$value is not CSS px padding`,`Write it as "22px 24px", one to four px values or 0`):D(r.$value)||a(i,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}function j(e){return y(e)&&[`color`,`type`,`space`,`shape`,`button`].every(t=>e[t]===void 0||y(e[t]))}function M(t,n){let o=new Map([[`color`,Object.keys(e)],[`type`,Object.keys(a)],[`space`,Object.keys(i)],[`shape`,Object.keys(r)],[`button`,h]]);for(let e of Object.keys(t)){if(e.startsWith(`$`))continue;let r=o.get(e);if(r===void 0){n(`email.${e}`,`is not an email group`,`Use one of ${[...o.keys()].join(`, `)}`);continue}let i=t[e];if(!y(i))n(`email.${e}`,`is not a group`,`Write it as an object of tokens`);else for(let t of Object.keys(i)){if(t.startsWith(`$`))continue;let a=`email.${e}.${t}`;if(!r.includes(t)){n(a,`is not an email role`,`Use one of ${r.join(`, `)}`);continue}let o=i[t];x(o)?A(e,t,o,a,n):n(a,`is not a token`,`Give it a $value`)}}}function N(e,t,n){let r;try{r=JSON.parse(l(e,`utf8`))}catch(t){throw Error(`${e}: (file): cannot be read as JSON (${o(t)}). Restore the file or fix the JSON`)}if(!y(r))throw Error(`${e}: (file): is not a JSON object. Write the brand as one object with the groups palette, color, effect, font and radius`);let i=[],a=(t,n,r)=>{let a=`${e}: ${t}: ${n}. ${r}`;i.includes(a)||i.push(a)},u=w(r);for(let e of Object.keys(u))e!==`brand`&&e!==`deviation`&&a(`$extensions.com.webority.${e}`,`is not a brand file key`,`Remove it`);let d=Object.hasOwn(u,`deviation`),h=typeof u.deviation==`string`?u.deviation:void 0,g=d&&h!==void 0&&Object.hasOwn(n,h);d&&!g&&a(`$extensions.com.webority.deviation`,`${u.deviation} is not in deviations.json`,`Use one of: ${Object.keys(n).join(`, `)}`);let _=typeof u.brand==`string`?u.brand:``;/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(_)||a(`$extensions.com.webority.brand`,`is missing or not kebab case`,`Name the product in kebab case, such as acme`);let v=h===void 0?void 0:n[h],E=g&&v!==void 0?v.groups:[],D={},O=null;for(let e of Object.keys(r)){if(e.startsWith(`$`))continue;if(!p.includes(e)&&!m.includes(e)){a(e,`is not a brand group`,`A brand file holds only palette, color, effect, font and radius, plus the groups a recorded deviation allows`);continue}if(m.includes(e)&&!E.includes(e)){a(e,`this group needs a recorded deviation`,`Add $extensions.com.webority.deviation naming an entry of deviations.json, or remove the group`);continue}let t=r[e];y(t)?e===`email`?O=t:D[e]=t:a(e,`is not a group`,`Write it as an object of tokens`)}for(let[e,t]of Object.entries(D))for(let{path:n,node:r}of S(t,e)){let t=w(r);for(let r of Object.keys(t))r!==`platforms`&&r!==`dark`&&(r!==`faces`||e!==`font`)&&a(n,`$extensions.com.webority.${r} is not allowed on a token`,`Remove it`);if(Object.hasOwn(t,`platforms`)){let e=t.platforms;Array.isArray(e)&&e.length>0&&e.every(e=>e===`web`||e===`phone`)||a(n,`$extensions.com.webority.platforms is not a list of web and phone`,`Write it as ["phone"], ["web"] or both`)}Object.hasOwn(t,`dark`)&&e!==`color`&&e!==`effect`&&a(n,`$extensions.com.webority.dark applies to colour and effect tokens only`,`Remove it`)}for(let{path:e,node:t}of S(D.palette??{},`palette`))e.split(`.`).slice(1).every(T)||a(e,`the step name is not kebab case`,`Name it such as primary-500`),typeof t.$value!=`string`&&a(e,`$value is not a string`,`Write the colour as text such as "#0F766E" or a reference such as "{palette.primary}"`);let k=(e,n,r)=>{let i=`${e}.${n}`,o=w(r),s=C(t.meaning,i);typeof r.$value!=`string`&&a(i,`$value is not a string`,e===`color`?`Write a colour or a reference such as "{palette.primary}"`:`Write the effect as text such as a filter, colour or gradient`),s?C(t.modeDark,i)&&typeof o.dark!=`string`&&a(i,`needs $extensions.com.webority.dark because the meaning has a dark value`,`Add the dark value beside the light one`):(T(n)||a(i,`the name is not kebab case`,`Name it in kebab case`),(typeof r.$description!=`string`||r.$description===``)&&a(i,`is not a fleet meaning and has no $description`,`Add a $description saying what the colour is for, or use a meaning the library defines`)),Object.hasOwn(o,`dark`)&&typeof o.dark!=`string`&&a(i,`$extensions.com.webority.dark is not a string`,`Write a colour or a reference`)};for(let e of[`color`,`effect`]){let t=D[e]??{};for(let n of Object.keys(t)){if(n.startsWith(`$`))continue;let r=t[n];x(r)?k(e,n,r):a(`${e}.${n}`,`is not a token`,`Give it a $value`)}}let A=b(t.scale.font),N=Object.keys(A).filter(e=>x(A[e]));for(let{path:e,node:n}of S(D.font??{},`font`)){C(t.scale,e)||a(e,`is not a fleet font`,`Use one of ${N.join(`, `)}`);let r=n.$value;if(Array.isArray(r)&&r.length!==0&&r.every(e=>typeof e==`string`)||a(e,`$value is not a list of font family names`,`Write it as ["Webority Sans", "system-ui", "sans-serif"]`),Object.hasOwn(w(n),`faces`)){let t=w(n).faces,r=[`normal`,`medium`,`semibold`,`bold`];y(t)&&Object.keys(t).length>0&&Object.keys(t).every(e=>r.includes(e))&&Object.values(t).every(e=>typeof e==`string`&&e!==``)||a(e,`faces is not a map of weight to font file name`,`Write it as { "normal": "AcmeSans-Regular", "semibold": "AcmeSans-SemiBold" }`)}}let P=b(t.scale.radius),F=Object.keys(P).filter(e=>x(P[e]));for(let{path:e,node:n}of S(D.radius??{},`radius`)){C(t.scale,e)||a(e,`is not on the radius scale`,`Use one of ${F.join(`, `)}`);let r=n.$value,i=y(r)&&typeof r.value==`number`&&Number.isFinite(r.value)&&r.value>=0,o=y(r)?r.unit:void 0;i&&o===`px`||a(e,`$value is not { value, unit }`,`Write it as { "value": 12, "unit": "px" }`)}O!==null&&M(O,a);let I=structuredClone(r);delete I.$extensions,delete I.$description,delete I.email;for(let e of[`color`,`effect`])for(let{node:t}of S(b(I[e]),e))Object.hasOwn(w(t),`dark`)&&(delete w(t).dark,y(t.$extensions)&&(Object.keys(w(t)).length===0&&delete t.$extensions[`com.webority`],Object.keys(t.$extensions).length===0&&delete t.$extensions));let L=D.palette?.primary,R=x(L)?L.$value:void 0;if(typeof R==`string`&&/^#[0-9a-fA-F]{6}$/.test(R)){let e=c(R),t=I.palette;if(!y(t))throw Error(`webority-tokens: the palette group is missing.`);for(let n of s)C(I,`palette.${n}`)||(t[n]={$type:`color`,$value:e[n]})}let z=e=>C(I,e)||C(t.palette,e)||C(t.scale,e)||C(t.meaning,e);for(let e of Object.keys(D))for(let{path:t,node:n}of S(D[e]??{},e)){let e=[n.$value,w(n).dark].filter(e=>typeof e==`string`);for(let n of e)for(let e of n.matchAll(f)){let[,n=``]=e;z(n)||a(t,`references {${n}}, which no palette step, meaning, scale step or brand token defines`,`Name an existing token or add it to the brand file`)}}if(i.length>0)throw Error(i.join(`
2
+ `));let B={};for(let e of[`color`,`effect`])for(let{path:t,node:n}of S(D[e]??{},e)){let r=w(n).dark;if(typeof r!=`string`)continue;let i=t.slice(e.length+1),a=B[e];a===void 0&&(a={},B[e]=a),a[i]=n.$type===void 0?{$value:r}:{$value:r,$type:n.$type}}if(O!==null&&!j(O))throw Error(`${e}: email: is not an email group. Write it as an object of email role groups.`);return{name:_,base:I,dark:B,email:O}}export{u as BRAND_OUTPUT_FILES,d as HEAD_FOLDER,N as loadBrand};
@@ -0,0 +1,41 @@
1
+ export interface BrandOptions {
2
+ root?: string;
3
+ library?: boolean;
4
+ brand?: string;
5
+ out?: string;
6
+ web?: string;
7
+ phone?: string;
8
+ check?: boolean;
9
+ }
10
+ export interface BrandResult {
11
+ written: string[];
12
+ stale: string[];
13
+ }
14
+ export interface BrandEntry {
15
+ name: string;
16
+ source: string;
17
+ export: string;
18
+ }
19
+ export interface HeadEntry {
20
+ path: string;
21
+ brand: string;
22
+ kind: string;
23
+ }
24
+ export interface DesignTokens {
25
+ brands: BrandEntry[];
26
+ heads?: HeadEntry[];
27
+ }
28
+ export interface DesignMap {
29
+ tokens?: DesignTokens;
30
+ color?: {
31
+ roles?: Record<string, string>;
32
+ };
33
+ scale?: Record<string, {
34
+ roles?: Record<string, string>;
35
+ durations?: Record<string, string>;
36
+ }>;
37
+ iconography?: {
38
+ sizes?: Record<string, string>;
39
+ };
40
+ }
41
+ export declare function brand(options: BrandOptions): Promise<BrandResult>;
package/dist/build.js CHANGED
@@ -1,5 +1,5 @@
1
- import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{require__2020 as t}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{BRAND_OUTPUT_FILES as n,HEAD_FOLDER as r,loadBrand as i}from"./brand.js";import a from"./canvas-renames.js";import o from"./deviations.js";import{emitCanvas as s}from"./emit/canvas.js";import{emitEmail as c}from"./emit/email.js";import{emitMeanings as l}from"./emit/meanings.js";import{emitPhoneBrand as u,emitPhoneTheme as d,phoneSets as f}from"./emit/phone.js";import{emitWeb as p}from"./emit/web.js";import{phonePairLayer as m}from"./model/contrast.js";import{loadModel as h}from"./model/index.js";import{mkdir as g,readFile as _,writeFile as v}from"node:fs/promises";import y from"node:path";var b=e(t(),1),x=new URL(`../schema/design-map.schema.json`,import.meta.url),S=new URL(`../package.json`,import.meta.url),C={palette:`palette.tokens.json`,scale:`scale.tokens.json`,meaning:`meaning.tokens.json`,modeDark:`mode.dark.tokens.json`},w=/^.+: \S+: .+\. .+$/;async function T(e){let t=y.resolve(e.root??process.cwd()),r=e.check===!0,{version:C}=JSON.parse(await _(S,`utf8`)),T=[],k=[],A=async(e,t)=>{if(r){let n=null;try{n=await _(e,`utf8`)}catch(e){if(e.code!==`ENOENT`)throw e}n!==t&&k.push(e)}else await g(y.dirname(e),{recursive:!0}),await v(e,t,`utf8`),T.push(e)};if(e.library===!0){if(e.brand!==void 0)throw Error(`brand: --brand: not allowed with --library. Remove it.`);if(!e.out)throw Error(`brand: --out: required with --library. Pass --out <dir>.`);let r=y.resolve(t,e.out),i=await h(),o=s(i),c=[[y.join(r,`canvas`,n.web),E(o.web)],[y.join(r,`canvas`,n.web390),E(o.web390)],[y.join(r,`canvas`,n.phoneTheme),E(o.phone)],[y.join(r,`meanings.json`),E(l(i))],[y.join(r,`canvas`,`renames.json`),E(a)]];if(e.web){let n=p(i),r=y.resolve(t,e.web);c.push([r,n.tokens]),c.push([y.join(y.dirname(r),`_bootstrap.generated.scss`),n.bootstrap])}if(e.phone){let n={light:f(i,`light`),dark:f(i,`dark`)},r=d(n);c.push([y.resolve(t,e.phone),r.contents])}for(let[e,t]of c)await A(e,t);return{written:T,stale:k}}let j=y.join(t,`.webority`,`design.json`),M;try{M=await _(j,`utf8`)}catch(e){throw e.code===`ENOENT`?Error(`${j}: file missing. Run from the repo root or create the design map.`):e}let N;try{N=JSON.parse(M)}catch(e){throw Error(`${j}: /: ${e.message}. Fix the design map.`)}let P=JSON.parse(await _(x,`utf8`)),F=new b.Ajv2020({allErrors:!0,strict:!1}).compile(P);if(!F(N))throw Error(F.errors.map(e=>`${j}: ${e.instancePath||`/`}: ${e.message}. Fix the design map.`).join(`
2
- `));if(N.tokens===void 0)throw Error(`${j}: /tokens: missing. Add tokens.brands to .webority/design.json.`);let I=N.tokens.brands,L=N.tokens.heads??[];if((e.brand!==void 0||e.out!==void 0)&&I.length>1)throw Error(`brand: --brand/--out: the repo has ${I.length} brands. Remove the flag to build every brand.`);let R=[];if(I.forEach((e,t)=>{e.source===`library`&&R.push(`${j}: tokens.brands[${t}].source: "library" is built with --library. Run webority brand --library --out <dir>.`)}),L.forEach((e,t)=>{I.some(t=>t.name===e.brand)||R.push(`${j}: tokens.heads[${t}].brand: no brand named ${e.brand}. Add it to tokens.brands.`)}),R.length>0)throw Error(R.join(`
3
- `));let z=await O(),B=await h(),V={light:f(B,`light`),dark:f(B,`dark`)},H=[];for(let r of I){let a=I.length===1&&e.brand!==void 0?e.brand:r.source,l=I.length===1&&e.out!==void 0?e.out:r.export,d=y.resolve(t,a);try{let e=i(d,z,o),a=await h({brand:e}),g=m(a,B),_=Object.keys(g.light).length+Object.keys(g.dark).length>0?await h({brand:{...e,phone:g}}):a,v=s(_),b=p(_,{library:B}),x={light:f(_,`light`),dark:f(_,`dark`)},S=u(V,x,{package:`@webority/tokens`,version:C,brand:e.name}),w=E(c(v.web,v.web390,e.email)),T={css:b.css,phone:S.contents,email:w},O=y.resolve(t,l),k=[[y.join(O,n.css),b.css],[y.join(O,n.bootstrap),b.variables],[y.join(O,n.web),E(v.web)],[y.join(O,n.web390),E(v.web390)],[y.join(O,n.phoneTheme),E(v.phone)],[y.join(O,n.phone),S.contents],[y.join(O,n.email),w]];H.push(...k);for(let e of L)e.brand===r.name&&H.push(D(t,e,T))}catch(e){for(let t of String(e?.message??e).split(`
4
- `))t.length!==0&&R.push(w.test(t)?t:`${d}: -: ${t}. Fix the source.`)}}if(R.length>0)throw Error(R.join(`
5
- `));for(let[e,t]of H)await A(e,t);return{written:T,stale:k}}function E(e){return`${JSON.stringify(e,null,4)}\n`}function D(e,t,i){let a=y.resolve(e,t.path);return t.kind===`razor`?[y.join(a,`wwwroot`,r,n.css),i.css]:t.kind===`spa`?[y.join(a,`src`,r,n.css),i.css]:t.kind===`phone`?[y.join(a,r,n.phone),i.phone]:[y.join(a,r,n.email),i.email]}async function O(){let e={};for(let[t,n]of Object.entries(C))e[t]=JSON.parse(await _(new URL(`./source/${n}`,import.meta.url),`utf8`));return e}export{T as brand};
1
+ import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{require__2020 as t}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{BRAND_OUTPUT_FILES as n,HEAD_FOLDER as r,loadBrand as i}from"./brand.js";import a from"./canvas-renames.js";import o from"./deviations.js";import{emitCanvas as s}from"./emit/canvas.js";import{emitEmail as c}from"./emit/email.js";import{emitMeanings as l}from"./emit/meanings.js";import{emitPhoneBrand as u,emitPhoneTheme as d,phoneSets as f}from"./emit/phone.js";import{emitWeb as p}from"./emit/web.js";import{messageOf as m}from"./guards.js";import{phonePairLayer as h}from"./model/contrast.js";import{loadModel as g}from"./model/index.js";import{mkdir as _,readFile as v,writeFile as y}from"node:fs/promises";import b from"node:path";var x=e(t(),1),S=new URL(`../schema/design-map.schema.json`,import.meta.url),C=new URL(`../package.json`,import.meta.url),w={palette:`palette.tokens.json`,scale:`scale.tokens.json`,meaning:`meaning.tokens.json`,modeDark:`mode.dark.tokens.json`},T=/^.+: \S+: .+\. .+$/;async function E(e){let t=b.resolve(e.root??process.cwd()),r=e.check===!0,{version:w}=JSON.parse(await v(C,`utf8`)),E=[],j=[],M=async(e,t)=>{if(r){let n=null;try{n=await v(e,`utf8`)}catch(e){if(O(e)!==`ENOENT`)throw e}n!==t&&j.push(e)}else await _(b.dirname(e),{recursive:!0}),await y(e,t,`utf8`),E.push(e)};if(e.library===!0){if(e.brand!==void 0)throw Error(`brand: --brand: not allowed with --library. Remove it.`);if(!e.out)throw Error(`brand: --out: required with --library. Pass --out <dir>.`);let r=b.resolve(t,e.out),i=await g(),o=s(i),c=[[b.join(r,`canvas`,n.web),D(o.web)],[b.join(r,`canvas`,n.web390),D(o.web390)],[b.join(r,`canvas`,n.phoneTheme),D(o.phone)],[b.join(r,`meanings.json`),D(l(i))],[b.join(r,`canvas`,`renames.json`),D(a)]];if(e.web){let n=p(i),r=b.resolve(t,e.web);c.push([r,n.tokens]),c.push([b.join(b.dirname(r),`_bootstrap.generated.scss`),n.bootstrap])}if(e.phone){let n={light:f(i,`light`),dark:f(i,`dark`)},r=d(n);c.push([b.resolve(t,e.phone),r.contents])}for(let[e,t]of c)await M(e,t);return{written:E,stale:j}}let P=b.join(t,`.webority`,`design.json`),F;try{F=await v(P,`utf8`)}catch(e){throw O(e)===`ENOENT`?Error(`${P}: file missing. Run from the repo root or create the design map.`):e}let I;try{I=JSON.parse(F)}catch(e){throw Error(`${P}: /: ${m(e)}. Fix the design map.`)}let L=JSON.parse(await v(S,`utf8`)),R=new x.Ajv2020({allErrors:!0,strict:!1}).compile(L);if(!R(I))throw Error((R.errors??[]).map(e=>`${P}: ${e.instancePath||`/`}: ${e.message}. Fix the design map.`).join(`
2
+ `));if(I.tokens===void 0)throw Error(`${P}: /tokens: missing. Add tokens.brands to .webority/design.json.`);let z=I.tokens.brands,B=I.tokens.heads??[];if((e.brand!==void 0||e.out!==void 0)&&z.length>1)throw Error(`brand: --brand/--out: the repo has ${z.length} brands. Remove the flag to build every brand.`);let V=[];if(z.forEach((e,t)=>{e.source===`library`&&V.push(`${P}: tokens.brands[${t}].source: "library" is built with --library. Run webority brand --library --out <dir>.`)}),B.forEach((e,t)=>{z.some(t=>t.name===e.brand)||V.push(`${P}: tokens.heads[${t}].brand: no brand named ${e.brand}. Add it to tokens.brands.`)}),V.length>0)throw Error(V.join(`
3
+ `));let H=await A(),U=await g(),W={light:f(U,`light`),dark:f(U,`dark`)},G=N(o),K=[];for(let r of z){let a=z.length===1&&e.brand!==void 0?e.brand:r.source,o=z.length===1&&e.out!==void 0?e.out:r.export,l=b.resolve(t,a);try{let e=i(l,H,G),a=await g({brand:e}),d=h(a,U),m=Object.keys(d.light).length+Object.keys(d.dark).length>0?await g({brand:{...e,phone:d}}):a,_=s(m),v=p(m,{library:U}),y={light:f(m,`light`),dark:f(m,`dark`)},x=u(W,y,{package:`@webority/tokens`,version:w,brand:e.name}),S=D(c(_.web,_.web390,e.email)),C={css:v.css,phone:x.contents,email:S},T=b.resolve(t,o),E=[[b.join(T,n.css),v.css],[b.join(T,n.bootstrap),v.variables],[b.join(T,n.web),D(_.web)],[b.join(T,n.web390),D(_.web390)],[b.join(T,n.phoneTheme),D(_.phone)],[b.join(T,n.phone),x.contents],[b.join(T,n.email),S]];K.push(...E);for(let e of B)e.brand===r.name&&K.push(k(t,e,C))}catch(e){for(let t of m(e).split(`
4
+ `))t.length!==0&&V.push(T.test(t)?t:`${l}: -: ${t}. Fix the source.`)}}if(V.length>0)throw Error(V.join(`
5
+ `));for(let[e,t]of K)await M(e,t);return{written:E,stale:j}}function D(e){return`${JSON.stringify(e,null,4)}\n`}function O(e){return e instanceof Error&&`code`in e?e.code:void 0}function k(e,t,i){let a=b.resolve(e,t.path);return t.kind===`razor`?[b.join(a,`wwwroot`,r,n.css),i.css]:t.kind===`spa`?[b.join(a,`src`,r,n.css),i.css]:t.kind===`phone`?[b.join(a,r,n.phone),i.phone]:[b.join(a,r,n.email),i.email]}async function A(){return{palette:await P(w.palette),scale:await P(w.scale),meaning:await P(w.meaning),modeDark:await P(w.modeDark)}}var j=[`space`,`text`,`shadow`,`section`,`component`,`email`];function M(e){return j.some(t=>t===e)}function N(e){let t={};for(let[n,r]of Object.entries(e)){let e=[];for(let t of r.groups){if(!M(t))throw Error(`webority-tokens: deviations.json names an unknown group "${t}".`);e.push(t)}t[n]={reason:r.reason,groups:e}}return t}async function P(e){return JSON.parse(await v(new URL(`./source/${e}`,import.meta.url),`utf8`))}export{E as brand};
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.149.0",
5
+ "version": "0.152.0",
6
6
  "brand": null,
7
7
  "platform": "phone",
8
8
  "width": null
@@ -28,23 +28,23 @@
28
28
  "text-muted": "#52525b",
29
29
  "text-subtle": "#62626b",
30
30
  "text-inverse": "#ffffff",
31
- "link": "#5b5bd6",
31
+ "link": "#4f46e5",
32
32
  "border": "#e5e5ec",
33
33
  "border-subtle": "#efeff3",
34
34
  "field-bg": "#f9fbfc",
35
35
  "field-border": "#ebedf3",
36
36
  "field-border-focus": "#bed2f9",
37
- "focus-ring": "#5b5bd6",
37
+ "focus-ring": "#4f46e5",
38
38
  "scrim": "#0f0f1a80",
39
39
  "on-scrim": "#ffffff",
40
40
  "thumb": "#ffffff",
41
- "primary": "#5b5bd6",
42
- "primary-hover": "#4f4fbf",
43
- "primary-soft": "#eeeefc",
44
- "primary-text": "#4f4fd3",
41
+ "primary": "#4f46e5",
42
+ "primary-hover": "#4338ca",
43
+ "primary-soft": "#e0e7ff",
44
+ "primary-text": "#4f46e5",
45
45
  "on-primary": "#ffffff",
46
- "primary-wash": "#5b5bd614",
47
- "primary-wash-strong": "#5b5bd633",
46
+ "primary-wash": "#4f46e514",
47
+ "primary-wash-strong": "#4f46e533",
48
48
  "neutral": "#f4f4f8",
49
49
  "neutral-hover": "#e9e9f0",
50
50
  "neutral-text": "#52525b",
@@ -68,13 +68,13 @@
68
68
  "info-soft": "#e9f3ff",
69
69
  "info-text": "#0958d9",
70
70
  "on-info": "#ffffff",
71
- "primary-pressed": "#4040a8",
71
+ "primary-pressed": "#3730a3",
72
72
  "switch-thumb": "#ffffff",
73
73
  "on-neutral-strong": "#ffffff",
74
74
  "text-disabled": "#b4b4bb",
75
75
  "surface-pressed": "#0f0f1a0f",
76
76
  "surface-hover": "#0f0f1a0a",
77
- "surface-selected": "#5b5bd61a",
77
+ "surface-selected": "#4f46e51a",
78
78
  "surface-disabled": "#f1f1f5",
79
79
  "skeleton": "#ebedf3",
80
80
  "skeleton-highlight": "#f5f6fa",
@@ -95,7 +95,7 @@
95
95
  "field-icon-disabled": "#c4cada",
96
96
  "field-caret": "#5b8dee",
97
97
  "field-message": "#d81736",
98
- "avatar-1": "#5b5bd6",
98
+ "avatar-1": "#4f46e5",
99
99
  "avatar-2": "#0a7979",
100
100
  "avatar-3": "#a45a05",
101
101
  "avatar-4": "#cd226e",
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.149.0",
5
+ "version": "0.152.0",
6
6
  "brand": null,
7
7
  "platform": "web",
8
8
  "width": 390
@@ -127,7 +127,23 @@
127
127
  "chart-neutral": "#99a1b7",
128
128
  "chart-grid": "#ebedf3",
129
129
  "chart-axis": "#c4cada",
130
- "chart-label": "#626a82"
130
+ "chart-label": "#626a82",
131
+ "shell-bg": "#1f2d5c",
132
+ "shell-bg-deep": "#141e42",
133
+ "shell-bg-raised": "#2c3f7a",
134
+ "shell-text": "#c9d1e6",
135
+ "shell-text-strong": "#ffffff",
136
+ "shell-text-muted": "#8792b4",
137
+ "shell-accent": "#f4a261",
138
+ "shell-accent-ring": "#f4a26140",
139
+ "shell-hover": "#ffffff12",
140
+ "shell-active": "#ffffff1f",
141
+ "shell-rule": "#ffffff1a",
142
+ "shell-fill-subtle": "#ffffff14",
143
+ "shell-fill": "#ffffff1f",
144
+ "shell-fill-strong": "#ffffff2e",
145
+ "shell-border": "#ffffff38",
146
+ "shell-border-strong": "#ffffff66"
131
147
  },
132
148
  "dark": {
133
149
  "bg": "#0f1117",
@@ -244,7 +260,23 @@
244
260
  "chart-neutral": "#5d6475",
245
261
  "chart-grid": "#3d4554",
246
262
  "chart-axis": "#515b6e",
247
- "chart-label": "#8a90a0"
263
+ "chart-label": "#8a90a0",
264
+ "shell-bg": "#1f2d5c",
265
+ "shell-bg-deep": "#141e42",
266
+ "shell-bg-raised": "#2c3f7a",
267
+ "shell-text": "#c9d1e6",
268
+ "shell-text-strong": "#ffffff",
269
+ "shell-text-muted": "#8792b4",
270
+ "shell-accent": "#f4a261",
271
+ "shell-accent-ring": "#f4a26140",
272
+ "shell-hover": "#ffffff12",
273
+ "shell-active": "#ffffff1f",
274
+ "shell-rule": "#ffffff1a",
275
+ "shell-fill-subtle": "#ffffff14",
276
+ "shell-fill": "#ffffff1f",
277
+ "shell-fill-strong": "#ffffff2e",
278
+ "shell-border": "#ffffff38",
279
+ "shell-border-strong": "#ffffff66"
248
280
  }
249
281
  },
250
282
  "space": {
@@ -2,7 +2,7 @@
2
2
  "format": "webority-theme-tokens/2",
3
3
  "source": {
4
4
  "package": "@webority/tokens",
5
- "version": "0.149.0",
5
+ "version": "0.152.0",
6
6
  "brand": null,
7
7
  "platform": "web",
8
8
  "width": 1440
@@ -127,7 +127,23 @@
127
127
  "chart-neutral": "#99a1b7",
128
128
  "chart-grid": "#ebedf3",
129
129
  "chart-axis": "#c4cada",
130
- "chart-label": "#626a82"
130
+ "chart-label": "#626a82",
131
+ "shell-bg": "#1f2d5c",
132
+ "shell-bg-deep": "#141e42",
133
+ "shell-bg-raised": "#2c3f7a",
134
+ "shell-text": "#c9d1e6",
135
+ "shell-text-strong": "#ffffff",
136
+ "shell-text-muted": "#8792b4",
137
+ "shell-accent": "#f4a261",
138
+ "shell-accent-ring": "#f4a26140",
139
+ "shell-hover": "#ffffff12",
140
+ "shell-active": "#ffffff1f",
141
+ "shell-rule": "#ffffff1a",
142
+ "shell-fill-subtle": "#ffffff14",
143
+ "shell-fill": "#ffffff1f",
144
+ "shell-fill-strong": "#ffffff2e",
145
+ "shell-border": "#ffffff38",
146
+ "shell-border-strong": "#ffffff66"
131
147
  },
132
148
  "dark": {
133
149
  "bg": "#0f1117",
@@ -244,7 +260,23 @@
244
260
  "chart-neutral": "#5d6475",
245
261
  "chart-grid": "#3d4554",
246
262
  "chart-axis": "#515b6e",
247
- "chart-label": "#8a90a0"
263
+ "chart-label": "#8a90a0",
264
+ "shell-bg": "#1f2d5c",
265
+ "shell-bg-deep": "#141e42",
266
+ "shell-bg-raised": "#2c3f7a",
267
+ "shell-text": "#c9d1e6",
268
+ "shell-text-strong": "#ffffff",
269
+ "shell-text-muted": "#8792b4",
270
+ "shell-accent": "#f4a261",
271
+ "shell-accent-ring": "#f4a26140",
272
+ "shell-hover": "#ffffff12",
273
+ "shell-active": "#ffffff1f",
274
+ "shell-rule": "#ffffff1a",
275
+ "shell-fill-subtle": "#ffffff14",
276
+ "shell-fill": "#ffffff1f",
277
+ "shell-fill-strong": "#ffffff2e",
278
+ "shell-border": "#ffffff38",
279
+ "shell-border-strong": "#ffffff66"
248
280
  }
249
281
  },
250
282
  "space": {
@@ -0,0 +1,37 @@
1
+ import type { BrandOptions, BrandResult } from "./build.ts";
2
+ import { loadModel as realLoadModel } from "./model/index.ts";
3
+ export interface CheckFinding {
4
+ check: "generated" | "design-map" | "repo-checks";
5
+ file: string | null;
6
+ message: string;
7
+ }
8
+ export interface CheckResult {
9
+ findings: CheckFinding[];
10
+ }
11
+ export interface CheckOptions {
12
+ /** Defaults to process.cwd(). */
13
+ root?: string;
14
+ }
15
+ export interface RepoCheckEntry {
16
+ pkg: string;
17
+ id: string;
18
+ message: string;
19
+ }
20
+ export interface RepoChecksBody {
21
+ new: RepoCheckEntry[];
22
+ root?: string;
23
+ known?: unknown[];
24
+ stale?: unknown[];
25
+ warnings?: unknown[];
26
+ }
27
+ type Model = Awaited<ReturnType<typeof realLoadModel>>;
28
+ type BrandFn = (options: BrandOptions) => Promise<BrandResult>;
29
+ type RepoChecksFn = (root: string) => RepoChecksBody | Promise<RepoChecksBody>;
30
+ export interface CheckSeams {
31
+ brand?: BrandFn;
32
+ repoChecks?: RepoChecksFn;
33
+ loadModel?: () => Promise<Model>;
34
+ }
35
+ export declare function check(options?: CheckOptions, seams?: CheckSeams): Promise<CheckResult>;
36
+ export declare function parseRepoChecksOutput(stdout: string): RepoChecksBody;
37
+ export {};
package/dist/check.js CHANGED
@@ -1,4 +1,4 @@
1
- import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{require__2020 as t}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{BRAND_OUTPUT_FILES as n}from"./brand.js";import{brand as r}from"./build.js";import{loadModel as i}from"./model/index.js";import{readFileSync as a,readdirSync as o}from"node:fs";import{join as s,resolve as c}from"node:path";import{spawnSync as l}from"node:child_process";var u=e(t(),1),d=`.webority/design.json`,f=c(import.meta.dirname,`../schema/design-map.schema.json`),p=new Set([`vite.config.js`,`vite.config.mjs`,`vite.config.cjs`,`vite.config.ts`,`vite.config.mts`,`vite.config.cts`]);async function m(e={},t={}){let{brand:n=r,repoChecks:a=w,loadModel:o=i}=t,s=e.root??process.cwd(),c=[],l=h(s,c);return l!==null&&(g(l,c),c.length===0&&l.tokens!==void 0&&v(l,s,c)),c.length===0&&(await b(l,s,o,c),l.tokens!==void 0&&await S(l,s,n,c)),await C(s,a,c),{findings:c}}function h(e,t){let n;try{n=a(s(e,d),`utf8`)}catch{return t.push({check:`design-map`,file:d,message:`Cannot read the file. Run webority check from the repo root and create the file.`}),null}try{return JSON.parse(n)}catch(e){return t.push({check:`design-map`,file:d,message:`${e.message}. Fix the file.`}),null}}function g(e,t){let n=new u.Ajv2020({allErrors:!0}).compile(JSON.parse(a(f,`utf8`)));if(!n(e))for(let r of n.errors)t.push({check:`design-map`,file:d,message:_(r,e)})}function _(e,t){let n=e.instancePath.split(`/`).filter(Boolean),r=n.length>0?n.join(`.`):`design.json`;if(e.keyword===`additionalProperties`)return r+=`.${e.params.additionalProperty}`,`${r}: is not a design map key, retired or misspelled. Remove it.`;if(e.keyword===`required`)return r+=`.${e.params.missingProperty}`,`${r}: is required. Add it.`;let i=n.reduce((e,t)=>e?.[t],t);return typeof i==`string`&&(i.startsWith(`--`)||i.includes(`var(`))?`${r}: a CSS variable is not a role. Use the meaning name, or <group>.<name> for a scale role.`:`${r}: ${e.message}. Fix the file.`}function v(e,t,n){let r=e.tokens.brands,i=e.tokens.heads??[],a=e=>n.push({check:`design-map`,file:d,message:e}),o=new Map;for(let e of r)o.set(e.name,(o.get(e.name)??0)+1);for(let[e,t]of o)t>1&&a(`tokens.brands: ${e} is listed more than once. Give each brand its own name.`);let c=new Set(r.map(e=>e.name));i.forEach((e,t)=>{c.has(e.brand)||a(`tokens.heads[${t}]: brand ${e.brand} is not in tokens.brands. Use a listed brand name.`)});let l=new Set(i.map(e=>e.brand));for(let e of r)e.source!==`library`&&!l.has(e.name)&&a(`tokens.brands: ${e.name} has no head. List a head for it or remove the brand.`);if(r.length>1)for(let e of r)e.source===`library`&&a(`tokens.brands: a library source cannot be combined with other brands. Keep one brand.`);i.forEach((e,n)=>{let r=y(s(t,e.path));r!==null&&(e.kind===`spa`&&r.some(e=>e.endsWith(`.csproj`))&&a(`tokens.heads[${n}]: ${e.path} holds a .csproj, so its kind is razor. Set kind razor.`),e.kind===`razor`&&r.some(e=>p.has(e))&&a(`tokens.heads[${n}]: ${e.path} holds a Vite project, so its kind is spa. Set kind spa.`))})}function y(e){try{return o(e)}catch{return null}}async function b(e,t,r,i){let a=e=>i.push({check:`design-map`,file:d,message:e});if(e.tokens!==void 0)for(let r of e.tokens.brands){let i=r.source===`library`?`${r.export}/canvas`:r.export,o=x(s(t,i));if(o!==null)for(let[t,s]of Object.entries(e.color?.roles??{}))o.has(s)||a(`color.roles.${t}: ${s} is not a colour of brand ${r.name}. Use a name from ${i}/${n.web}.`)}let o=[];for(let[t,n]of Object.entries(e.scale??{})){for(let[e,r]of Object.entries(n.roles??{}))o.push([`scale.${t}.roles.${e}`,r]);for(let[e,r]of Object.entries(n.durations??{}))o.push([`scale.${t}.durations.${e}`,r])}for(let[t,n]of Object.entries(e.iconography?.sizes??{}))o.push([`iconography.sizes.${t}`,n]);if(o.length===0)return;let c;try{c=await r()}catch(e){i.push({check:`design-map`,file:null,message:`${e.message}. Fix the token source.`});return}let l=new Set;for(let e of c.tokens.values())l.add(`${e.group}.${e.name}`);for(let[e,t]of o)l.has(t)||a(`${e}: ${t} is not a token. Use a <group>.<name> the library defines.`)}function x(e){let t=new Set,r=!1;for(let i of[n.web,n.phoneTheme]){let n;try{n=JSON.parse(a(s(e,i),`utf8`))}catch{continue}r=!0;for(let e of Object.keys(n?.colors?.light??{}))t.add(e)}return r?t:null}async function S(e,t,n,r){let i=e.tokens.brands,a=i.length===1&&i[0].source===`library`,o;try{o=a?await n({root:t,library:!0,out:i[0].export,check:!0}):await n({root:t,check:!0})}catch(e){for(let t of String(e?.message??e).split(`
2
- `))t.trim()!==``&&r.push({check:`generated`,file:null,message:t});return}let s=a?`stale. Run webority brand --library --out ${i[0].export}`:`stale. Run webority brand`;for(let e of o.stale)r.push({check:`generated`,file:e,message:s})}async function C(e,t,n){let r;try{r=await t(e)}catch{n.push({check:`repo-checks`,file:null,message:`repo-checks did not run. Add @webority/repo-checks at the lockstep version.`});return}for(let e of r.new)n.push({check:`repo-checks`,file:e.pkg===`.`?null:e.pkg,message:`${e.id}: ${e.message}`})}function w(e){return T(l(`corepack pnpm exec webority-repo-checks --json`,{cwd:e,encoding:`utf8`,shell:!0,maxBuffer:67108864}).stdout??``)}function T(e){let t=e.split(`
1
+ import{__toESM as e}from"./_virtual/_rolldown/runtime.js";import{require__2020 as t}from"./node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js";import{BRAND_OUTPUT_FILES as n}from"./brand.js";import{brand as r}from"./build.js";import{messageOf as i}from"./guards.js";import{loadModel as a}from"./model/index.js";import{readFileSync as o,readdirSync as s}from"node:fs";import{join as c,resolve as l}from"node:path";import{spawnSync as u}from"node:child_process";var d=e(t(),1),f=`.webority/design.json`,p=l(import.meta.dirname,`../schema/design-map.schema.json`),m=new Set([`vite.config.js`,`vite.config.mjs`,`vite.config.cjs`,`vite.config.ts`,`vite.config.mts`,`vite.config.cts`]);async function h(e={},t={}){let{brand:n=r,repoChecks:i=E,loadModel:o=a}=t,s=e.root??process.cwd(),c=[],l=g(s,c);return l!==null&&(_(l,c),c.length===0&&l.tokens!==void 0&&b(l.tokens,s,c)),c.length===0&&l!==null&&(await S(l,s,o,c),l.tokens!==void 0&&await w(l.tokens,s,n,c)),await T(s,i,c),{findings:c}}function g(e,t){let n;try{n=o(c(e,f),`utf8`)}catch{return t.push({check:`design-map`,file:f,message:`Cannot read the file. Run webority check from the repo root and create the file.`}),null}try{return JSON.parse(n)}catch(e){return t.push({check:`design-map`,file:f,message:`${i(e)}. Fix the file.`}),null}}function _(e,t){let n=new d.Ajv2020({allErrors:!0}),r=JSON.parse(o(p,`utf8`)),i=n.compile(r);if(!i(e))for(let n of i.errors??[])t.push({check:`design-map`,file:f,message:v(n,e)})}function v(e,t){let n=e.instancePath.split(`/`).filter(Boolean),r=n.length>0?n.join(`.`):`design.json`;if(e.keyword===`additionalProperties`)return r+=`.${e.params.additionalProperty}`,`${r}: is not a design map key, retired or misspelled. Remove it.`;if(e.keyword===`required`)return r+=`.${e.params.missingProperty}`,`${r}: is required. Add it.`;let i=n.reduce((e,t)=>y(e,t),t);return typeof i==`string`&&(i.startsWith(`--`)||i.includes(`var(`))?`${r}: a CSS variable is not a role. Use the meaning name, or <group>.<name> for a scale role.`:`${r}: ${e.message}. Fix the file.`}function y(e,t){return typeof e==`object`&&e?Reflect.get(e,t):void 0}function b(e,t,n){let r=e.brands,i=e.heads??[],a=e=>{n.push({check:`design-map`,file:f,message:e})},o=new Map;for(let e of r)o.set(e.name,(o.get(e.name)??0)+1);for(let[e,t]of o)t>1&&a(`tokens.brands: ${e} is listed more than once. Give each brand its own name.`);let s=new Set(r.map(e=>e.name));i.forEach((e,t)=>{s.has(e.brand)||a(`tokens.heads[${t}]: brand ${e.brand} is not in tokens.brands. Use a listed brand name.`)});let l=new Set(i.map(e=>e.brand));for(let e of r)e.source!==`library`&&!l.has(e.name)&&a(`tokens.brands: ${e.name} has no head. List a head for it or remove the brand.`);if(r.length>1)for(let e of r)e.source===`library`&&a(`tokens.brands: a library source cannot be combined with other brands. Keep one brand.`);i.forEach((e,n)=>{let r=x(c(t,e.path));r!==null&&(e.kind===`spa`&&r.some(e=>e.endsWith(`.csproj`))&&a(`tokens.heads[${n}]: ${e.path} holds a .csproj, so its kind is razor. Set kind razor.`),e.kind===`razor`&&r.some(e=>m.has(e))&&a(`tokens.heads[${n}]: ${e.path} holds a Vite project, so its kind is spa. Set kind spa.`))})}function x(e){try{return s(e)}catch{return null}}async function S(e,t,r,a){let o=e=>{a.push({check:`design-map`,file:f,message:e})};if(e.tokens!==void 0)for(let r of e.tokens.brands){let i=r.source===`library`?`${r.export}/canvas`:r.export,a=C(c(t,i));if(a!==null)for(let[t,s]of Object.entries(e.color?.roles??{}))a.has(s)||o(`color.roles.${t}: ${s} is not a colour of brand ${r.name}. Use a name from ${i}/${n.web}.`)}let s=[];for(let[t,n]of Object.entries(e.scale??{})){for(let[e,r]of Object.entries(n.roles??{}))s.push([`scale.${t}.roles.${e}`,r]);for(let[e,r]of Object.entries(n.durations??{}))s.push([`scale.${t}.durations.${e}`,r])}for(let[t,n]of Object.entries(e.iconography?.sizes??{}))s.push([`iconography.sizes.${t}`,n]);if(s.length===0)return;let l;try{l=await r()}catch(e){a.push({check:`design-map`,file:null,message:`${i(e)}. Fix the token source.`});return}let u=new Set;for(let e of l.tokens.values())u.add(`${e.group}.${e.name}`);for(let[e,t]of s)u.has(t)||o(`${e}: ${t} is not a token. Use a <group>.<name> the library defines.`)}function C(e){let t=new Set,r=!1;for(let i of[n.web,n.phoneTheme]){let n;try{n=JSON.parse(o(c(e,i),`utf8`))}catch{continue}r=!0;for(let e of Object.keys(n?.colors?.light??{}))t.add(e)}return r?t:null}async function w(e,t,n,r){let a=e.brands,o=a.length===1?a[0]:void 0,s=o?.source===`library`,c;try{c=s?await n({root:t,library:!0,out:o?.export,check:!0}):await n({root:t,check:!0})}catch(e){for(let t of i(e).split(`
2
+ `))t.trim()!==``&&r.push({check:`generated`,file:null,message:t});return}let l=s?`stale. Run webority brand --library --out ${o?.export}`:`stale. Run webority brand`;for(let e of c.stale)r.push({check:`generated`,file:e,message:l})}async function T(e,t,n){let r;try{r=await t(e)}catch{n.push({check:`repo-checks`,file:null,message:`repo-checks did not run. Add @webority/repo-checks at the lockstep version.`});return}for(let e of r.new)n.push({check:`repo-checks`,file:e.pkg===`.`?null:e.pkg,message:`${e.id}: ${e.message}`})}function E(e){return D(u(`corepack pnpm exec webority-repo-checks --json`,{cwd:e,encoding:`utf8`,shell:!0,maxBuffer:67108864}).stdout??``)}function D(e){let t=e.split(`
3
3
  `),n=t.findIndex(e=>e.startsWith(`{`)),r;try{if(n===-1)throw Error(`no JSON line`);r=JSON.parse(t.slice(n).join(`
4
- `))}catch{throw Error(`repo-checks printed no JSON`)}if(!Array.isArray(r?.new))throw Error(`repo-checks printed no new array`);return r}export{m as check,T as parseRepoChecksOutput};
4
+ `))}catch{throw Error(`repo-checks printed no JSON`)}if(!Array.isArray(r?.new))throw Error(`repo-checks printed no new array`);return r}export{h as check,D as parseRepoChecksOutput};
package/dist/cli.d.ts CHANGED
@@ -1,100 +1,19 @@
1
+ import type { BrandOptions, BrandResult } from "./build.ts";
2
+ import { brand } from "./build.ts";
3
+ import type { CheckResult } from "./check.ts";
4
+ import { check } from "./check.ts";
5
+ import type { UpgradeOptions, UpgradeResult } from "./upgrade/index.ts";
6
+ import { upgrade } from "./upgrade/index.ts";
7
+ export type { BrandOptions, BrandResult } from "./build.ts";
8
+ export type { CheckFinding, CheckOptions, CheckResult } from "./check.ts";
9
+ export type { UpgradeChoice, UpgradeHit, UpgradeOptions, UpgradeResult } from "./upgrade/index.ts";
10
+ export { brand, check, upgrade };
1
11
  /** 0 ok, 1 refused or stale, 2 usage error. */
2
12
  export type ExitCode = 0 | 1 | 2;
3
-
4
13
  export type CliCommand = "brand" | "upgrade" | "check";
5
-
6
- /**
7
- * webority brand [--brand <file>] [--library] [--out <dir>] [--web <scss>] [--phone <ts>] [--check]
8
- *
9
- * Product mode (no --library) reads .webority/design.json and builds every entry of tokens.brands: it writes the
10
- * seven BRAND_OUTPUT_FILES into the brand's export folder, then copies brand.css into <head>/wwwroot/generated/,
11
- * brand.phone.js into <head>/generated/ and email.json into <head>/generated/ for each head of that brand, by its
12
- * kind. --brand and --out replace the source and export of the repo's one brand, and are refused when it has more.
13
- * Library mode (--library) writes canvas/*.json, meanings.json and canvas/renames.json into --out; --web and --phone
14
- * name the generated SCSS and TS files. --check compares instead of writing.
15
- */
16
- export interface BrandOptions {
17
- brand?: string;
18
- library?: boolean;
19
- out?: string;
20
- web?: string;
21
- phone?: string;
22
- check?: boolean;
23
- /** Defaults to process.cwd(). */
24
- root?: string;
14
+ export interface Commands {
15
+ brand(options: BrandOptions): Promise<BrandResult>;
16
+ upgrade(options: UpgradeOptions): Promise<UpgradeResult>;
17
+ check(): Promise<CheckResult>;
25
18
  }
26
-
27
- export interface BrandResult {
28
- written: string[];
29
- /** Files whose contents differ from what brand would write; only filled with check. */
30
- stale: string[];
31
- }
32
-
33
- /**
34
- * webority upgrade <version> [--dry-run] [--app <folder>] [--path <p>]...
35
- *
36
- * With no --path, moves every pin in the lockstep list to <version>, installs, applies every rename table from the
37
- * installed version up to <version> in order, then runs brand. With --app, the same run covers one app folder inside
38
- * the repo: the design map is read from the repo root, and the pins, install (pnpm or npm, by the folder's lockfile)
39
- * and tables are the app's. With --path (repeatable), applies the tables to those paths only, with no pin move,
40
- * install or brand run; webority-ui uses it on itself. --alias <pkg>=<library pkg> (repeatable) matches the wrapper
41
- * package as its library. --report <path> is written by the command line only: it stores the result as JSON.
42
- */
43
- export interface UpgradeOptions {
44
- version: string;
45
- dryRun?: boolean;
46
- /** An app folder inside the repo, relative to root. */
47
- app?: string;
48
- paths?: string[];
49
- /** Wrapper package name to the library package its rules name: `{ "@acme/ui": "@webority/ui-react" }`. */
50
- aliases?: Record<string, string>;
51
- /** Path of a JSON file for the command line to write the UpgradeResult to; upgrade() ignores it. */
52
- report?: string;
53
- /** Defaults to process.cwd(). */
54
- root?: string;
55
- }
56
-
57
- /** One rewrite upgrade made, or would make on a dry run. */
58
- export interface UpgradeHit {
59
- file: string;
60
- line: number;
61
- from: string;
62
- to: string;
63
- }
64
-
65
- /** A use upgrade cannot rewrite on its own; a person picks the new name. */
66
- export interface UpgradeChoice {
67
- file: string;
68
- line: number;
69
- name: string;
70
- hint: string;
71
- }
72
-
73
- export interface UpgradeResult {
74
- hits: UpgradeHit[];
75
- choose: UpgradeChoice[];
76
- changedFiles: string[];
77
- }
78
-
79
- /** webority check: fresh generated files, a valid design map, and repo-checks with no count above its record. */
80
- export interface CheckOptions {
81
- /** Defaults to process.cwd(). */
82
- root?: string;
83
- }
84
-
85
- export interface CheckFinding {
86
- check: "generated" | "design-map" | "repo-checks";
87
- file: string | null;
88
- message: string;
89
- }
90
-
91
- export interface CheckResult {
92
- findings: CheckFinding[];
93
- }
94
-
95
- export declare function brand(options: BrandOptions): Promise<BrandResult>;
96
- export declare function upgrade(options: UpgradeOptions): Promise<UpgradeResult>;
97
- export declare function check(options?: CheckOptions): Promise<CheckResult>;
98
-
99
- /** The command line: parses argv (without node and the script), runs one command and maps its result to an exit code. */
100
- export declare function run(argv: string[]): Promise<ExitCode>;
19
+ export declare function run(argv: string[], commands?: Commands): Promise<ExitCode>;
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import{brand as e}from"./build.js";import{check as t}from"./check.js";import{upgrade as n}from"./upgrade/index.js";import{writeFileSync as r}from"node:fs";var i=`Usage: webority <command>
2
2
  brand [--brand <file>] [--library] [--out <dir>] [--web <scss>] [--phone <ts>] [--check]
3
3
  upgrade <version> [--dry-run] [--app <folder>] [--path <p>]... [--alias <pkg>=<library pkg>]... [--report <path>]
4
- check`,a=[`brand`,`upgrade`,`check`],o=[`generated`,`design-map`,`repo-checks`],s={"--brand":`brand`,"--out":`out`,"--web":`web`,"--phone":`phone`},c=class extends Error{};function l(e){return console.error(e),console.error(i),2}function u(e){if(!(e instanceof Error))throw e;return console.error(e.message),1}function d(e,t,n){let r=[],i={},a=new Set;for(let o=0;o<e.length;o+=1){let s=e[o];if(t.includes(s)){let t=e[o+1];if(t===void 0||t.startsWith(`--`))throw new c(`${s} needs a value.`);i[s]=[...i[s]??[],t],o+=1}else if(n.includes(s))a.add(s);else if(s.startsWith(`--`))throw new c(`Unknown flag ${s}.`);else r.push(s)}return{positionals:r,values:i,flags:a}}function f(e,t){if(e===`brand`){let{positionals:e,values:n,flags:r}=d(t,Object.keys(s),[`--library`,`--check`]);if(e.length>0)throw new c(`brand takes no argument, got ${e[0]}.`);let i={};for(let[e,t]of Object.entries(s))n[e]!==void 0&&(i[t]=n[e].at(-1));return r.has(`--library`)&&(i.library=!0),r.has(`--check`)&&(i.check=!0),{kind:`brand`,options:i}}if(e===`upgrade`){let{positionals:e,values:n,flags:r}=d(t,[`--path`,`--app`,`--alias`,`--report`],[`--dry-run`]);if(e.length===0)throw new c(`upgrade needs a <version>.`);if(e.length>1)throw new c(`Unexpected argument ${e[1]}.`);let i={version:e[0]};if(r.has(`--dry-run`)&&(i.dryRun=!0),n[`--alias`]!==void 0){i.aliases={};for(let e of n[`--alias`]){let[t,n]=e.split(`=`);if(!t||!n||e.split(`=`).length!==2)throw new c(`--alias takes <pkg>=<library pkg>, got ${e}.`);i.aliases[t]=n}}if(n[`--report`]!==void 0){if(n[`--report`].length>1)throw new c(`--report takes one path.`);i.report=n[`--report`][0]}if(n[`--app`]!==void 0){if(n[`--app`].length>1)throw new c(`--app takes one folder.`);if(n[`--path`]!==void 0)throw new c(`--app and --path cannot be combined.`);i.app=n[`--app`][0]}return n[`--path`]!==void 0&&(i.paths=n[`--path`]),{kind:`upgrade`,options:i}}if(t.length>0)throw new c(`check takes no arguments, got ${t[0]}.`);return{kind:`check`}}async function p(s,d={brand:e,upgrade:n,check:t}){if(s.includes(`--help`)||s.includes(`-h`))return console.log(i),0;if(s.length===0)return console.error(i),2;let[p,...m]=s;if(!a.includes(p))return l(`Unknown command ${p}. Commands: brand, upgrade, check.`);let h;try{h=f(p,m)}catch(e){if(e instanceof c)return l(e.message);throw e}if(h.kind===`brand`){let e;try{e=await d.brand(h.options)}catch(e){return u(e)}for(let t of e.written)console.log(`wrote ${t}`);if(!h.options.check)return 0;for(let t of e.stale)console.log(`stale ${t}`);return+(e.stale.length>0)}if(h.kind===`upgrade`){let{report:e,...t}=h.options,n;try{n=await d.upgrade(t)}catch(e){return u(e)}for(let e of n.hits)console.log(`${e.file}:${e.line} ${e.from} -> ${e.to}`);for(let e of n.choose)console.log(`choose ${e.file}:${e.line} ${e.name}: ${e.hint}`);if(e!==void 0)try{r(e,`${JSON.stringify({hits:n.hits,choose:n.choose,changedFiles:n.changedFiles},null,4)}\n`,`utf8`)}catch(e){return u(e)}return+(n.choose.length>0)}let g;try{g=await d.check()}catch(e){return u(e)}for(let e of o)g.findings.some(t=>t.check===e)||console.log(`ok ${e}`);for(let e of g.findings){let t=e.file?`${e.file}: `:``;console.log(`FAIL ${e.check}: ${t}${e.message}`)}return+(g.findings.length>0)}export{e as brand,t as check,p as run,n as upgrade};
4
+ check`,a=[`brand`,`upgrade`,`check`],o=[`generated`,`design-map`,`repo-checks`],s={"--brand":`brand`,"--out":`out`,"--web":`web`,"--phone":`phone`},c=class extends Error{};function l(e){return console.error(e),console.error(i),2}function u(e){if(!(e instanceof Error))throw e;return console.error(e.message),1}function d(e,t,n){let r=[],i={},a=new Set;for(let o=0;o<e.length;o+=1){let s=e[o]??``;if(t.includes(s)){let t=e[o+1];if(t===void 0||t.startsWith(`--`))throw new c(`${s} needs a value.`);i[s]=[...i[s]??[],t],o+=1}else if(n.includes(s))a.add(s);else if(s.startsWith(`--`))throw new c(`Unknown flag ${s}.`);else r.push(s)}return{positionals:r,values:i,flags:a}}function f(e,t){if(e===`brand`){let{positionals:e,values:n,flags:r}=d(t,Object.keys(s),[`--library`,`--check`]);if(e.length>0)throw new c(`brand takes no argument, got ${e[0]}.`);let i={};for(let[e,t]of Object.entries(s)){let r=n[e]?.at(-1);r!==void 0&&(i[t]=r)}return r.has(`--library`)&&(i.library=!0),r.has(`--check`)&&(i.check=!0),{kind:`brand`,options:i}}if(e===`upgrade`){let{positionals:e,values:n,flags:r}=d(t,[`--path`,`--app`,`--alias`,`--report`],[`--dry-run`]),[i,...a]=e;if(i===void 0)throw new c(`upgrade needs a <version>.`);if(a.length>0)throw new c(`Unexpected argument ${a[0]}.`);let o={version:i};r.has(`--dry-run`)&&(o.dryRun=!0);let s=n[`--alias`];if(s!==void 0){o.aliases={};for(let e of s){let[t,n]=e.split(`=`);if(!t||!n||e.split(`=`).length!==2)throw new c(`--alias takes <pkg>=<library pkg>, got ${e}.`);o.aliases[t]=n}}let l=n[`--report`];if(l!==void 0){if(l.length>1)throw new c(`--report takes one path.`);let e=l[0];e!==void 0&&(o.report=e)}let u=n[`--app`];if(u!==void 0){if(u.length>1)throw new c(`--app takes one folder.`);if(n[`--path`]!==void 0)throw new c(`--app and --path cannot be combined.`);let e=u[0];e!==void 0&&(o.app=e)}let f=n[`--path`];return f!==void 0&&(o.paths=f),{kind:`upgrade`,options:o}}if(t.length>0)throw new c(`check takes no arguments, got ${t[0]}.`);return{kind:`check`}}async function p(s,d={brand:e,upgrade:n,check:t}){if(s.includes(`--help`)||s.includes(`-h`))return console.log(i),0;if(s.length===0)return console.error(i),2;let[p=``,...m]=s;if(!a.includes(p))return l(`Unknown command ${p}. Commands: brand, upgrade, check.`);let h;try{h=f(p,m)}catch(e){if(e instanceof c)return l(e.message);throw e}if(h.kind===`brand`){let e;try{e=await d.brand(h.options)}catch(e){return u(e)}for(let t of e.written)console.log(`wrote ${t}`);if(!h.options.check)return 0;for(let t of e.stale)console.log(`stale ${t}`);return+(e.stale.length>0)}if(h.kind===`upgrade`){let{report:e,...t}=h.options,n;try{n=await d.upgrade(t)}catch(e){return u(e)}for(let e of n.hits)console.log(`${e.file}:${e.line} ${e.from} -> ${e.to}`);for(let e of n.choose)console.log(`choose ${e.file}:${e.line} ${e.name}: ${e.hint}`);if(e!==void 0)try{r(e,`${JSON.stringify({hits:n.hits,choose:n.choose,changedFiles:n.changedFiles},null,4)}\n`,`utf8`)}catch(e){return u(e)}return+(n.choose.length>0)}let g;try{g=await d.check()}catch(e){return u(e)}for(let e of o)g.findings.some(t=>t.check===e)||console.log(`ok ${e}`);for(let e of g.findings){let t=e.file?`${e.file}: `:``;console.log(`FAIL ${e.check}: ${t}${e.message}`)}return+(g.findings.length>0)}export{e as brand,t as check,p as run,n as upgrade};