Skip to content

Commit

Permalink
Fix(exporter-tokens): Pass all tokens to the `computeTokensByApplying…
Browse files Browse the repository at this point in the history
…Themes` so references work
  • Loading branch information
crishpeen committed Oct 31, 2024
1 parent efe71c9 commit 54800f5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion exporters/tokens/generated/exporter.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ ${a?`};
`}`;return ue(f,a)},ko=async(n,a,u,i,m)=>{const y=[],f=L(n,a,u,J),r=L(n,a,u,J,!0),t=w(f),o=w(r,!0);y.push(...f.map(c=>({path:`./${R}/${N}`,fileName:`_${c.fileName}.scss`,content:c.content})),...r.map(c=>({path:`./${x}/${N}/`,fileName:`${c.fileName}.ts`,content:c.content}))),y.push({path:`./${R}/${N}/`,fileName:"index.scss",content:t}),y.push({path:`./${x}/${N}/`,fileName:"index.ts",content:o}),y.push({path:`./${R}/`,fileName:"@global.scss",content:`@forward '${N}';
`}),y.push({path:`./${x}/`,fileName:"index.ts",content:`export * from './${N}';
export * from './${D}';
`});const e=await Promise.all(i.map(async c=>({themedTokens:m.tokens.computeTokensByApplyingThemes([],n,[c]),theme:c})));for(const{themedTokens:c,theme:p}of e){const l=L(c,a,u,ee),d=L(c,a,u,ee,!0),g=w(l),S=w(d,!0);y.push(...l.map(b=>({path:`./${R}/${D}/${p.name}/`,fileName:`_${b.fileName}.scss`,content:b.content})),...d.map(b=>({path:`./${x}/${D}/${p.name}/`,fileName:`${b.fileName}.ts`,content:b.content}))),y.push({path:`./${R}/${D}/${p.name}/`,fileName:"index.scss",content:g}),y.push({path:`./${x}/${D}/${p.name}/`,fileName:"index.ts",content:S})}const s=te(i),T=te(i,!0);return y.push({path:`./${R}/`,fileName:"@themes.scss",content:s}),y.push({path:`./${x}/${D}`,fileName:"index.ts",content:T}),y},Co=n=>{let a=[];const u=JSON.stringify(n,(i,m)=>{if(typeof m=="object"&&m!==null){if(a!=null&&a.includes(m))return"CIRCULAR_REFERENCE";a==null||a.push(m)}return m},2);return a=null,u},ve=Pulsar.exportConfig();Pulsar.export(async(n,a)=>{const u={designSystemId:a.dsId,versionId:a.versionId};let i=await n.tokens.getTokens(u),m=await n.tokens.getTokenGroups(u);a.brandId&&(i=i.filter(e=>e.brandId===a.brandId),m=m.filter(e=>e.brandId===a.brandId));const y=new Map(i.map(e=>[e.id,e])),f=await n.tokens.getTokenThemes(u),r=(e,s,T)=>P.FileHelper.createTextFile({relativePath:e,fileName:s,content:T});let t=[];return t=(await ko(i,y,m,f,n)).map(e=>r(e.path,e.fileName,e.content)),ve.generateOriginalDataFiles&&t.push(r("./original-data/","_original-tokens.json",Co(i)),r("./original-data/","_original-groups.json",JSON.stringify(m,null,2))),t});exports.exportConfiguration=ve;
`});const e=await Promise.all(i.map(async c=>({themedTokens:m.tokens.computeTokensByApplyingThemes(n,n,[c]),theme:c})));for(const{themedTokens:c,theme:p}of e){const l=L(c,a,u,ee),d=L(c,a,u,ee,!0),g=w(l),S=w(d,!0);y.push(...l.map(b=>({path:`./${R}/${D}/${p.name}/`,fileName:`_${b.fileName}.scss`,content:b.content})),...d.map(b=>({path:`./${x}/${D}/${p.name}/`,fileName:`${b.fileName}.ts`,content:b.content}))),y.push({path:`./${R}/${D}/${p.name}/`,fileName:"index.scss",content:g}),y.push({path:`./${x}/${D}/${p.name}/`,fileName:"index.ts",content:S})}const s=te(i),T=te(i,!0);return y.push({path:`./${R}/`,fileName:"@themes.scss",content:s}),y.push({path:`./${x}/${D}`,fileName:"index.ts",content:T}),y},Co=n=>{let a=[];const u=JSON.stringify(n,(i,m)=>{if(typeof m=="object"&&m!==null){if(a!=null&&a.includes(m))return"CIRCULAR_REFERENCE";a==null||a.push(m)}return m},2);return a=null,u},ve=Pulsar.exportConfig();Pulsar.export(async(n,a)=>{const u={designSystemId:a.dsId,versionId:a.versionId};let i=await n.tokens.getTokens(u),m=await n.tokens.getTokenGroups(u);a.brandId&&(i=i.filter(e=>e.brandId===a.brandId),m=m.filter(e=>e.brandId===a.brandId));const y=new Map(i.map(e=>[e.id,e])),f=await n.tokens.getTokenThemes(u),r=(e,s,T)=>P.FileHelper.createTextFile({relativePath:e,fileName:s,content:T});let t=[];return t=(await ko(i,y,m,f,n)).map(e=>r(e.path,e.fileName,e.content)),ve.generateOriginalDataFiles&&t.push(r("./original-data/","_original-tokens.json",Co(i)),r("./original-data/","_original-groups.json",JSON.stringify(m,null,2))),t});exports.exportConfiguration=ve;
2 changes: 1 addition & 1 deletion exporters/tokens/src/generators/fileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const generateOutputFilesByThemes = async (
// Compute themed tokens for all themes in parallel
const allThemes = await Promise.all(
themes.map(async (theme) => {
const themedTokens = sdk.tokens.computeTokensByApplyingThemes([], tokens, [theme]);
const themedTokens = sdk.tokens.computeTokensByApplyingThemes(tokens, tokens, [theme]);

return { themedTokens, theme };
}),
Expand Down

0 comments on commit 54800f5

Please sign in to comment.