From e8b7bea68eedc4c98bbfaa5bb1dad1444585df7d Mon Sep 17 00:00:00 2001 From: Pavel Klibani Date: Fri, 4 Oct 2024 12:14:23 +0200 Subject: [PATCH] Feat(variables-scss): Sort barrel files by alphabet --- exporters/variables-scss/generated/exporter.cjs | 2 +- .../src/generators/__fixtures__/barrelFileMock.scss | 4 ++-- .../src/generators/__tests__/fileGenerator.test.ts | 4 ++-- exporters/variables-scss/src/generators/fileGenerator.ts | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/exporters/variables-scss/generated/exporter.cjs b/exporters/variables-scss/generated/exporter.cjs index d5f8758b82..f286340259 100644 --- a/exporters/variables-scss/generated/exporter.cjs +++ b/exporters/variables-scss/generated/exporter.cjs @@ -32,7 +32,7 @@ ${tt(p)} ${et(p)} ) !default;${at(n,a)}`,it=(a,i)=>{const p=Object.entries(a);return p.map(i(p.length)).join("")},so=a=>it(a,co),uo=a=>it(a,lo),po=(a,i,p)=>{let n;if(i&&i.length>0){const m=a.filter(f=>!i.some(r=>{var t,o;return(o=(t=f.origin)==null?void 0:t.name)==null?void 0:o.includes(r)})).reduce((f,r)=>{var o,e;const t=(e=(o=r.origin)==null?void 0:o.name)==null?void 0:e.split("/")[0];return t&&!f.includes(t)&&f.push(t),f},[]);n=[...new Set(m)]}else n=p;return n},yo=(a,i,p,n,T)=>{let m="",f={};const{groupNames:r=[""],hasParentPrefix:t=!0,sortByNumValue:o=!1,hasStylesObject:e=!0,tokenTypes:c,excludeGroupNames:d=null}=n;c.forEach(s=>{po(a,d,r).forEach(y=>{const g=io(a,s,y);s!==v.TokenType.typography&&(m+=no(g,i,p,y,t,o,T),m+=` -`);const b=Yt(g,i,p,t,T);f=Je(f,b)})});let l=m;return e&&(l+=T?so(f):uo(f)),{content:ao(Ze(l,T))}},we=[{fileName:"borders",tokenTypes:[v.TokenType.dimension],groupNames:["Border"],hasStylesObject:!1,sortByNumValue:!0},{fileName:"other",tokenTypes:[v.TokenType.dimension,v.TokenType.string],excludeGroupNames:["Border","Radius","Spacing"],sortByNumValue:!0},{fileName:"radii",tokenTypes:[v.TokenType.dimension],groupNames:["Radius"],hasParentPrefix:!1,sortByNumValue:!0},{fileName:"spacing",tokenTypes:[v.TokenType.dimension],groupNames:["Spacing"],hasParentPrefix:!1,sortByNumValue:!0},{fileName:"shadows",tokenTypes:[v.TokenType.shadow],hasParentPrefix:!1},{fileName:"gradients",tokenTypes:[v.TokenType.gradient],hasParentPrefix:!0},{fileName:"typography",tokenTypes:[v.TokenType.typography],hasParentPrefix:!1}],He=[{fileName:"colors",tokenTypes:[v.TokenType.color]}],L="themes",N="global",R="scss",B="js",M=(a,i,p,n,T=!1)=>n.map(m=>{const f=yo(a,i,p,m,T);return{fileName:m.fileName,...f}}),$=(a,i=!1)=>`${a.map(p=>{const n=i?"ts":"scss",T=p.fileName.replace(/^_/,"").replace(new RegExp(`\\.${n}$`),"");return i?`export * from './${T}';`:`@forward '${T}';`}).join(` +`);const b=Yt(g,i,p,t,T);f=Je(f,b)})});let l=m;return e&&(l+=T?so(f):uo(f)),{content:ao(Ze(l,T))}},we=[{fileName:"borders",tokenTypes:[v.TokenType.dimension],groupNames:["Border"],hasStylesObject:!1,sortByNumValue:!0},{fileName:"other",tokenTypes:[v.TokenType.dimension,v.TokenType.string],excludeGroupNames:["Border","Radius","Spacing"],sortByNumValue:!0},{fileName:"radii",tokenTypes:[v.TokenType.dimension],groupNames:["Radius"],hasParentPrefix:!1,sortByNumValue:!0},{fileName:"spacing",tokenTypes:[v.TokenType.dimension],groupNames:["Spacing"],hasParentPrefix:!1,sortByNumValue:!0},{fileName:"shadows",tokenTypes:[v.TokenType.shadow],hasParentPrefix:!1},{fileName:"gradients",tokenTypes:[v.TokenType.gradient],hasParentPrefix:!0},{fileName:"typography",tokenTypes:[v.TokenType.typography],hasParentPrefix:!1}],He=[{fileName:"colors",tokenTypes:[v.TokenType.color]}],L="themes",N="global",R="scss",B="js",M=(a,i,p,n,T=!1)=>n.map(m=>{const f=yo(a,i,p,m,T);return{fileName:m.fileName,...f}}),$=(a,i=!1)=>`${a.map(p=>{const n=i?"ts":"scss",T=p.fileName.replace(/^_/,"").replace(new RegExp(`\\.${n}$`),"");return i?`export * from './${T}';`:`@forward '${T}';`}).sort().join(` `)} `,To=a=>`import * as ${C(a)} from './${L}/${a}';`,mo=a=>`@use '${L}/${a}';`,fo=a=>i=>a?To(i.name):mo(i.name),go=(a,i)=>a.map(fo(i)).join(` `),bo=(a,i)=>a.map(p=>i?`${C(p.name)}: { diff --git a/exporters/variables-scss/src/generators/__fixtures__/barrelFileMock.scss b/exporters/variables-scss/src/generators/__fixtures__/barrelFileMock.scss index bcece1ac50..2b65192ccc 100644 --- a/exporters/variables-scss/src/generators/__fixtures__/barrelFileMock.scss +++ b/exporters/variables-scss/src/generators/__fixtures__/barrelFileMock.scss @@ -1,7 +1,7 @@ @forward 'borders'; +@forward 'gradients'; @forward 'other'; @forward 'radii'; -@forward 'spacing'; @forward 'shadows'; -@forward 'gradients'; +@forward 'spacing'; @forward 'typography'; diff --git a/exporters/variables-scss/src/generators/__tests__/fileGenerator.test.ts b/exporters/variables-scss/src/generators/__tests__/fileGenerator.test.ts index 5b3e2e9a3d..fc4baff153 100644 --- a/exporters/variables-scss/src/generators/__tests__/fileGenerator.test.ts +++ b/exporters/variables-scss/src/generators/__tests__/fileGenerator.test.ts @@ -25,11 +25,11 @@ const emptyFile = "/* This file was generated by Supernova, don't change manuall const barrelFile = fs.readFileSync(path.join(__dirname, '../__fixtures__/barrelFileMock.scss'), 'utf-8'); const barrelColorFile = "@forward 'colors';\n"; const barrelJsFile = `export * from './borders'; +export * from './gradients'; export * from './other'; export * from './radii'; -export * from './spacing'; export * from './shadows'; -export * from './gradients'; +export * from './spacing'; export * from './typography'; `; const barrelJsColorFile = "export * from './colors';\n"; diff --git a/exporters/variables-scss/src/generators/fileGenerator.ts b/exporters/variables-scss/src/generators/fileGenerator.ts index a36ab892bc..7db13ee0bd 100644 --- a/exporters/variables-scss/src/generators/fileGenerator.ts +++ b/exporters/variables-scss/src/generators/fileGenerator.ts @@ -35,6 +35,7 @@ export const generateBarrelFile = (files: { fileName: string; content: string }[ return hasJsOutput ? `export * from './${baseName}';` : `@forward '${baseName}';`; }) + .sort() .join('\n')}\n`; }; export const jsImportStatement = (name: string) => {