Skip to content

Commit

Permalink
Feat(variables-scss): Sort barrel files by alphabet
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelklibani committed Oct 8, 2024
1 parent dbd2d5d commit e8b7bea
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion exporters/variables-scss/generated/exporter.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@forward 'borders';
@forward 'gradients';
@forward 'other';
@forward 'radii';
@forward 'spacing';
@forward 'shadows';
@forward 'gradients';
@forward 'spacing';
@forward 'typography';
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions exporters/variables-scss/src/generators/fileGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit e8b7bea

Please sign in to comment.