@webority/tokens 0.147.0 → 0.149.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/brand.js +1 -1
- package/dist/canvas/webority-phone.json +1 -1
- package/dist/canvas/webority-web-390.json +1 -1
- package/dist/canvas/webority-web.json +1 -1
- package/dist/meanings.json +1 -1
- package/dist/upgrade/index.js +2 -2
- package/dist/upgrade/razorValueSplits.js +1 -1
- package/package.json +2 -2
- package/renames/0.139.0.json +8 -0
- package/renames/renames.d.ts +2 -0
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
|
|
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
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};
|
package/dist/meanings.json
CHANGED
package/dist/upgrade/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{brand as e}from"../build.js";import{applyClasses as t}from"./classes.js";import{applyComponents as n}from"./components.js";import{applyCssTable as r,isCssTarget as i,ownDeclarations as a}from"./css.js";import{applyRazorAttributes as o}from"./razorAttributes.js";import{applyRazorTags as s}from"./razorTags.js";import{applyRazorValueSplits as c}from"./razorValueSplits.js";import{applyMarkup as l,applySource as u}from"./source.js";import{applyComponentProps as d,applyPropSplits as f,applyPropValues as p,applyProps as m,applyThemeReads as h}from"./themeReads.js";import{applyValueSplits as g}from"./valueSplits.js";import{applyWrapperValues as _,findWrappers as v}from"./wrapperValues.js";import{createRequire as y}from"node:module";import{existsSync as b,readFileSync as x,readdirSync as S,realpathSync as C,writeFileSync as w}from"node:fs";import{dirname as T,isAbsolute as E,join as D,relative as O,resolve as k,sep as A}from"node:path";import{fileURLToPath as j,pathToFileURL as M}from"node:url";import{spawnSync as N}from"node:child_process";var P=/^\d+\.\d+\.\d+$/,F=/^(?:workspace:|file:|link:)/,I=`WEBORITY_UPGRADE_FROM`;function L(e){if(typeof e!=`string`||!P.test(e))throw Error(`invalid version "${e}"`)}function R(e,t){L(e),L(t);let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++)if(n[e]!==r[e])return n[e]-r[e];return 0}function z(){let e=T(j(import.meta.url));for(;;){let t=D(e,`package.json`);if(b(t)&&JSON.parse(x(t,`utf8`)).name===`@webority/tokens`)return e;let n=T(e);if(n===e)throw Error(`cannot find the @webority/tokens package folder`);e=n}}function B(){return JSON.parse(x(D(z(),`package.json`),`utf8`)).version}function V(e){let t=[];for(let n of S(e)){if(!n.endsWith(`.json`))continue;let r=n.slice(0,-5);P.test(r)&&t.push({version:r,table:JSON.parse(x(D(e,n),`utf8`))})}return t.sort((e,t)=>R(e.version,t.version))}function H(e,t){let n=N(`git`,[`ls-files`,`-z`,`--`,...t],{cwd:e,encoding:`utf8`,windowsHide:!0,maxBuffer:67108864});if(n.status!==0)throw Error(`not a git repository: ${e}`);let r=n.stdout.split(`\0`).filter(Boolean).map(e=>e.split(`\\`).join(`/`)).filter(t=>b(D(e,t)));return[...new Set(r)]}function U(e,t){let n=H(e,t??[`.`]);if(t!==void 0&&n.length===0)throw Error(`no tracked files under ${t.join(`, `)}`);return n}function W(e){return e.split(`/`).includes(`node_modules`)}var G=new Set([`node_modules`,`vendor`,`vendors`,`external`]),K=/\.(?:min|bundle)\.(?:js|css)
|
|
1
|
+
import{brand as e}from"../build.js";import{applyClasses as t}from"./classes.js";import{applyComponents as n}from"./components.js";import{applyCssTable as r,isCssTarget as i,ownDeclarations as a}from"./css.js";import{applyRazorAttributes as o}from"./razorAttributes.js";import{applyRazorTags as s}from"./razorTags.js";import{applyRazorValueSplits as c}from"./razorValueSplits.js";import{applyMarkup as l,applySource as u}from"./source.js";import{applyComponentProps as d,applyPropSplits as f,applyPropValues as p,applyProps as m,applyThemeReads as h}from"./themeReads.js";import{applyValueSplits as g}from"./valueSplits.js";import{applyWrapperValues as _,findWrappers as v}from"./wrapperValues.js";import{createRequire as y}from"node:module";import{existsSync as b,readFileSync as x,readdirSync as S,realpathSync as C,writeFileSync as w}from"node:fs";import{dirname as T,isAbsolute as E,join as D,relative as O,resolve as k,sep as A}from"node:path";import{fileURLToPath as j,pathToFileURL as M}from"node:url";import{spawnSync as N}from"node:child_process";var P=/^\d+\.\d+\.\d+$/,F=/^(?:workspace:|file:|link:)/,I=`WEBORITY_UPGRADE_FROM`;function L(e){if(typeof e!=`string`||!P.test(e))throw Error(`invalid version "${e}"`)}function R(e,t){L(e),L(t);let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++)if(n[e]!==r[e])return n[e]-r[e];return 0}function z(){let e=T(j(import.meta.url));for(;;){let t=D(e,`package.json`);if(b(t)&&JSON.parse(x(t,`utf8`)).name===`@webority/tokens`)return e;let n=T(e);if(n===e)throw Error(`cannot find the @webority/tokens package folder`);e=n}}function B(){return JSON.parse(x(D(z(),`package.json`),`utf8`)).version}function V(e){let t=[];for(let n of S(e)){if(!n.endsWith(`.json`))continue;let r=n.slice(0,-5);P.test(r)&&t.push({version:r,table:JSON.parse(x(D(e,n),`utf8`))})}return t.sort((e,t)=>R(e.version,t.version))}function H(e,t){let n=N(`git`,[`ls-files`,`-z`,`--`,...t],{cwd:e,encoding:`utf8`,windowsHide:!0,maxBuffer:67108864});if(n.status!==0)throw Error(`not a git repository: ${e}`);let r=n.stdout.split(`\0`).filter(Boolean).map(e=>e.split(`\\`).join(`/`)).filter(t=>b(D(e,t)));return[...new Set(r)]}function U(e,t){let n=H(e,t??[`.`]);if(t!==void 0&&n.length===0)throw Error(`no tracked files under ${t.join(`, `)}`);return n}function W(e){return e.split(`/`).includes(`node_modules`)}var G=new Set([`node_modules`,`vendor`,`vendors`,`external`]),K=/\.(?:min|bundle)\.(?:js|css)$/,q=new Set([`lib`,`theme`]);function J(e){let t=e.split(`/`);return t.some(e=>G.has(e))||t.some((e,n)=>e===`wwwroot`&&q.has(t[n+1]))?!0:K.test(e)}function Y(e,t){return[...new Set([...e,...t])]}function X(e,t,n){return V(e).filter(e=>R(e.version,t)>0&&R(e.version,n)<=0).map(e=>e.table)}function Z(e,t){let n=Object.entries(t);if(n.length===0)return e;let r=(e,t)=>e.flatMap(e=>[e,...n.filter(([,n])=>e[t]===n).map(([n])=>({...e,[t]:n}))]),i={...e};for(let t of[`props`,`componentProps`,`propValues`,`propSplits`,`valueSplits`,`components`])e[t]!==void 0&&(i[t]=r(e[t],`package`));return e.source!==void 0&&(i.source={...e.source,flags:r(e.source.flags,`importedFrom`)}),i}function Q(e,y,b,S,C,T={}){S&&C(`dry run: nothing written`);let E=b.map(e=>Z(e,T)),O=[],k=[],A=[],j=y.filter(e=>i(e)&&!J(e)),M=E.map(()=>new Set);if(E.some(e=>(e.css.ownable??[]).length>0))for(let t of j){let n=x(D(e,t),`utf8`);E.forEach((e,r)=>{for(let i of a(n,t,e))M[r].add(i)})}let N=H(e,[`package.json`,`:(glob)**/package.json`]).filter(e=>!W(e)),P=new Map,F=E.map(t=>v(e,[...j,...N],t,P));for(let i of j){let a=x(D(e,i),`utf8`),v=a,y=e=>{for(let t of e)t.from!==t.to&&(O.push({file:i,line:t.line,from:t.from,to:t.to}),C(`${i}:${t.line} ${t.from} -> ${t.to}`))},b=e=>{k.push({file:i,line:e.line,name:e.name,hint:e.hint}),C(`choose ${i}:${e.line} ${e.name}: ${e.hint}`)},T=e=>{for(let t of e)t.message.startsWith(`skipped, it does not parse`)?C(`skipped ${i}: ${t.message}`):b({line:t.line,name:t.path,hint:t.message})};for(let[e,a]of E.entries()){let x=r(v,i,a,M[e]);v=x.text,y(x.hits);for(let e of x.choose)b(e);for(let e of x.checkRole)C(`verify ${i}:${e.line} ${e.from} -> ${e.to}`);let S=h(v,i,a.themeReads);v=S.text,y(S.hits),T(S.findings);let w=[t=>_(t,i,F[e]),e=>m(e,i,a.props),e=>d(e,i,a.componentProps),e=>p(e,i,a.propValues),e=>g(e,i,a.valueSplits??[]),e=>f(e,i,a.propSplits),e=>o(e,i,a.razorAttributes),e=>n(e,i,a.components??[]),e=>s(e,i,a.razorTags??[]),e=>c(e,i,a.razorValueSplits??[]),e=>t(e,i,a.classes??[]),e=>l(e,i,a.markup),e=>u(e,i,a.source)];for(let e of w){let t=e(v);v=t.text,y(t.hits),T(t.findings)}}v!==a&&(A.push(i),S||w(D(e,i),v,`utf8`))}return{hits:O,choose:k,changedFiles:A}}function $(e){let t=/^([ \t]+)\S/m.exec(e);return t?t[1]:4}function ee(e,t,n,r,i){let a=[];for(let o of H(e,[`package.json`,`:(glob)**/package.json`])){if(W(o))continue;let s=x(D(e,o),`utf8`),c=JSON.parse(s),l=!1;for(let e of[`dependencies`,`devDependencies`]){let r=c[e];if(r)for(let e of n.npm){if(!Object.hasOwn(r,e))continue;let n=r[e];F.test(n)||n===t||(r[e]=t,l=!0,i(`pin ${o}: ${e} ${n} -> ${t}`))}}if(l&&(a.push(o),r)){let t=JSON.stringify(c,null,$(s));s.endsWith(`
|
|
2
2
|
`)&&(t+=`
|
|
3
3
|
`),s.includes(`\r
|
|
4
4
|
`)&&(t=t.replace(/\n/g,`\r
|
|
5
|
-
`)),w(D(e,o),t,`utf8`)}}return a}function
|
|
5
|
+
`)),w(D(e,o),t,`utf8`)}}return a}function te(e,t,n,r,i){let a=[];for(let o of H(e,[`Directory.Packages.props`,`:(glob)**/Directory.Packages.props`])){if(W(o))continue;let s=x(D(e,o),`utf8`),c=!1,l=s.replace(/<PackageVersion\b[^>]*>/g,e=>{let r=/\sInclude="([^"]*)"/.exec(e)?.[1],a=/\sVersion="([^"]*)"/.exec(e)?.[1];if(r===void 0||a===void 0)return e;let s=/^\[([^\]]*)\]$/.exec(a),l=s?s[1]:a,u=s?`[${t}]`:t;return!n.nuget.includes(r)||l===t?e:(i(`pin ${o}: ${r} ${a} -> ${u}`),c=!0,e.replace(/(\sVersion=")[^"]*(")/,`$1${u}$2`))});c&&(a.push(o),r&&w(D(e,o),l,`utf8`))}return a}function ne(e){let t;try{t=y(D(e,`package.json`)).resolve(`@webority/repo-checks/lockstep.json`)}catch{throw Error(`add @webority/repo-checks at the lockstep version and run again`)}return JSON.parse(x(t,`utf8`))}var re=[{file:`pnpm-lock.yaml`,manager:`pnpm`,command:[`corepack`,`pnpm`,`install`]},{file:`package-lock.json`,manager:`npm`,command:[`npm`,`install`]}];function ie(e){let t=re.filter(t=>b(D(e,t.file)));if(t.length===0)throw Error(`no pnpm-lock.yaml or package-lock.json in ${e}`);if(t.length>1)throw Error(`${e} has both ${t[0].file} and ${t[1].file}; keep one lockfile`);return t[0]}function ae(e,t){let n=k(e,t),r=O(e,n);if(r===``||E(r)||r.split(A)[0]===`..`)throw Error(`--app ${t}: give a folder inside the repo root`);if(!b(D(n,`package.json`)))throw Error(`--app ${t}: no package.json in that folder`);return n}function oe(e,t,n){return N(e,t,{cwd:n.cwd,env:process.env,stdio:`inherit`,windowsHide:!0,shell:process.platform===`win32`})}async function se({appRoot:e,designRoot:t,app:n,version:r,from:i,aliases:a}){let o=C.native(D(e,`node_modules`,`@webority`,`tokens`)),s=JSON.parse(x(D(o,`package.json`),`utf8`))?.exports?.[`.`],c=typeof s==`string`?s:s?.default;if(typeof c!=`string`)throw Error(`cannot find the installed @webority/tokens entry`);process.env[I]=i;try{return await(await import(M(D(o,c)).href)).upgrade({root:t,app:n,version:r,dryRun:!1,aliases:a})}finally{delete process.env[I]}}async function ce({root:e,designRoot:t,version:n,dryRun:r,from:i,dir:a,log:o,brandFn:s,aliases:c}){let l=X(a,i,n),u=Q(e,U(e),l,r,o,c);return r||await s({root:t}),u}async function le({root:e,designRoot:t,app:n,version:r,dryRun:i,deps:a,log:o,aliases:s}){let c=D(e,`node_modules`,`@webority`,`tokens`,`package.json`);if(!b(c))throw Error(`@webority/tokens is not installed; add it at the lockstep version and run again`);let l=JSON.parse(x(c,`utf8`)).version,u=ne(e),d=i?null:ie(e),f=[...ee(e,r,u,!i,o),...te(e,r,u,!i,o)];if(i){o(`dry run: install skipped; tables are those of the installed ${l}`);let t=X(a.renamesDir??D(e,`node_modules`,`@webority`,`tokens`,`renames`),l,r),n=Q(e,U(e),t,!0,o,s);return{...n,changedFiles:Y(f,n.changedFiles)}}let p=a.run??oe,[m,...h]=d.command,{status:g}=await p(m,h,{cwd:e});if(g!==0)throw Error(`${d.manager} install failed with exit code ${g}`);let _=await(a.reenter??se)({appRoot:e,designRoot:t,app:n,version:r,dryRun:!1,from:l,aliases:s});return{..._,changedFiles:Y(f,_.changedFiles)}}async function ue(t,n={}){let r=t.version;L(r);let i=t.root??process.cwd(),a=t.app===void 0?i:ae(i,t.app),o=t.dryRun??!1,s=t.aliases??{},c=n.log??console.log,l=()=>n.renamesDir??D(z(),`renames`);if(Array.isArray(t.paths)&&t.paths.length>0){let e=V(l()).filter(e=>e.version===r).map(e=>e.table);if(e.length===0&&r!==(n.ownVersion??B)())throw Error(`no rename table for ${r}`);return Q(a,U(a,t.paths),e,o,c,s)}if(!b(D(i,`.webority`,`design.json`)))throw Error(`write .webority/design.json (design-map.md) and run again`);let u=process.env[I];return u?ce({root:a,designRoot:i,version:r,dryRun:o,from:u,dir:l(),log:c,brandFn:n.brand??e,aliases:s}):le({root:a,designRoot:i,app:t.app,version:r,dryRun:o,deps:n,log:c,aliases:s})}export{ue as upgrade};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{findQuoteEnd as e,tagOccurrences as t}from"./tagScan.js";import{applyEdits as n}from"./themeReads.js";import{separatorAt as r}from"./valueSplits.js";var i=new Set([`.cshtml`,`.razor`]),a=/(\s*)([^\s=/>"']+)(\s*=\s*)?/y,o=e=>{let t=/\.[^./]*$/.exec(e);return t?t[0].toLowerCase():``},s=(e,t)=>e.slice(0,t).split(`
|
|
2
|
-
`).length;function c(t,n,r){let i=[],o=n;for(;;){a.lastIndex=o;let n=a.exec(t);if(n===null)break;let s=n.index+n[1].length,c={name:n[2],nameStart:s,nameEnd:s+n[2].length,wsStart:n.index,kind:`none`,attrEnd:s+n[2].length},l=n.index+n[0].length;if(n[3]!==void 0&&(t[l]===`"`||t[l]===`'`)){let n=e(t,l);if(n===-1)break;c.kind=`quoted`,c.value=t.slice(l+1,n),c.attrEnd=n+1}else n[3]!==void 0&&(c.kind=`bare`,c.attrEnd=l+/[^\s"'>]*/y.exec(t.slice(l))[0].length);if(c.attrEnd>r)break;i.push(c),o=c.attrEnd}return i}function l(e,a,l){if(l.length===0||!i.has(o(a)))return{text:e,hits:[],findings:[]};let u=[],d=[],f=[];for(let n of l)for(let i of n.tags)for(let{nameEnd:o,end:l}of t(e,i)){if(l===-1){f.push({file:a,line:s(e,o),path:`<${i}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let t=c(e,o,l),p=new Set(t.map(e=>e.name));for(let o of t){if(o.name!==n.attribute)continue;let t=s(e,o.nameStart),c=`<${i}> ${n.attribute}`,l=o.kind===`none`?`true`:o.kind===`quoted`?o.value.toLowerCase():void 0;if(l!==void 0&&!Object.hasOwn(n.values,l)&&n.keep?.includes(l))continue;if(l===void 0||!Object.hasOwn(n.values,l)){f.push({file:a,line:t,path:c,message:n.flag});continue}let m=Object.entries(n.values[l]).filter(([,e])=>e!==null),h=m.map(([e])=>e).filter(e=>e!==n.attribute&&p.has(e));if(h.length>0){f.push({file:a,line:t,path:c,message:`<${i}> already sets ${h.join(` and `)}; merge ${n.attribute} into it by hand`});continue}let g=m.map(([e,t])=>`${e}="${t}"`).join(r(e,o.nameStart)),_=m.length===0?o.wsStart:o.nameStart;u.push({start:_,end:o.attrEnd,text:g}),d.push({line:t,from:e.slice(o.nameStart,o.attrEnd),to:g.replace(/\n\s*/g,` `)})}}return d.sort((e,t)=>e.line-t.line||(e.from<t.from?-1:+(e.from>t.from))),f.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:n(e,u,a),hits:d,findings:f}}export{l as applyRazorValueSplits};
|
|
2
|
+
`).length;function c(t,n,r){let i=[],o=n;for(;;){a.lastIndex=o;let n=a.exec(t);if(n===null)break;let s=n.index+n[1].length,c={name:n[2],nameStart:s,nameEnd:s+n[2].length,wsStart:n.index,kind:`none`,attrEnd:s+n[2].length},l=n.index+n[0].length;if(n[3]!==void 0&&(t[l]===`"`||t[l]===`'`)){let n=e(t,l);if(n===-1)break;c.kind=`quoted`,c.value=t.slice(l+1,n),c.attrEnd=n+1}else n[3]!==void 0&&(c.kind=`bare`,c.attrEnd=l+/[^\s"'>]*/y.exec(t.slice(l))[0].length);if(c.attrEnd>r)break;i.push(c),o=c.attrEnd}return i}function l(e,a,l){if(l.length===0||!i.has(o(a)))return{text:e,hits:[],findings:[]};let u=[],d=[],f=[];for(let n of l)for(let i of n.tags)for(let{nameEnd:o,end:l}of t(e,i)){if(l===-1){f.push({file:a,line:s(e,o),path:`<${i}>`,message:`the tag could not be read (a quote in an attribute value does not pair up); set it by hand`});continue}let t=c(e,o,l),p=new Set(t.map(e=>e.name));for(let o of t){if(o.name!==n.attribute)continue;let t=s(e,o.nameStart),c=`<${i}> ${n.attribute}`,l=o.kind===`none`?`true`:o.kind===`quoted`?o.value.toLowerCase():void 0;if(l!==void 0&&!Object.hasOwn(n.values,l)&&n.keep?.includes(l))continue;if(l===void 0||!Object.hasOwn(n.values,l)){f.push({file:a,line:t,path:c,message:n.flag});continue}let m=Object.entries(n.values[l]).filter(([,e])=>e!==null),h=m.map(([e])=>e).filter(e=>e!==n.attribute&&p.has(e));if(h.length>0){f.push({file:a,line:t,path:c,message:`<${i}> already sets ${h.join(` and `)}; merge ${n.attribute} into it by hand`});continue}let g=m.map(([e,t])=>`${e}="${t}"`).join(r(e,o.nameStart));if(n.skipWritten&&g===e.slice(o.nameStart,o.attrEnd))continue;let _=m.length===0?o.wsStart:o.nameStart;u.push({start:_,end:o.attrEnd,text:g}),d.push({line:t,from:e.slice(o.nameStart,o.attrEnd),to:g.replace(/\n\s*/g,` `)})}}return d.sort((e,t)=>e.line-t.line||(e.from<t.from?-1:+(e.from>t.from))),f.sort((e,t)=>e.line-t.line||(e.path<t.path?-1:+(e.path>t.path))),{text:n(e,u,a),hits:d,findings:f}}export{l as applyRazorValueSplits};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/tokens",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.149.0",
|
|
4
4
|
"description": "The Webority design tokens in one W3C Design Tokens source (palette, scale, meaning and component tiers, with light and dark, web and phone, and 390 and 1440 widths), and the webority command that brands a product, upgrades it between releases and checks it against the token source.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"ajv": "8.20.0",
|
|
43
|
-
"vite": "^8.
|
|
43
|
+
"vite": "^8.3.6"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "vite build && node dist/webority.js brand --library --out dist",
|
package/renames/0.139.0.json
CHANGED
|
@@ -114,6 +114,14 @@
|
|
|
114
114
|
"false": {}
|
|
115
115
|
},
|
|
116
116
|
"flag": "compact is no longer a value: density=\"compact\" with size=\"sm\" replaces it; set the new attributes by hand"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"tags": ["app-select"],
|
|
120
|
+
"attribute": "searchable",
|
|
121
|
+
"values": { "true": { "searchable": "true" } },
|
|
122
|
+
"keep": ["false"],
|
|
123
|
+
"skipWritten": true,
|
|
124
|
+
"flag": "searchable is a true-or-false value now, so a bare searchable is written searchable=\"true\"; this value is left as written, check it by hand"
|
|
117
125
|
}
|
|
118
126
|
],
|
|
119
127
|
"razorTags": [
|
package/renames/renames.d.ts
CHANGED
|
@@ -137,4 +137,6 @@ export interface RazorValueSplitRule {
|
|
|
137
137
|
values: Readonly<Record<string, Readonly<Record<string, string | null>>>>;
|
|
138
138
|
flag: string;
|
|
139
139
|
keep?: readonly string[];
|
|
140
|
+
/** An attribute already written exactly as its value maps (a quoted searchable="true") gets no edit and no hit. */
|
|
141
|
+
skipWritten?: boolean;
|
|
140
142
|
}
|