Skip to content

Commit

Permalink
feat(tokens): add componentIndex (#4572)
Browse files Browse the repository at this point in the history
  • Loading branch information
redallen committed Jul 20, 2020
1 parent 2fe41f9 commit 3c7e7f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 270 deletions.
43 changes: 25 additions & 18 deletions packages/react-tokens/scripts/writeTokens.js
Expand Up @@ -33,7 +33,25 @@ export default ${tokenName};
`.trim()
);

const index = [];
const allIndex = [];
const componentIndex = [];

const outputIndex = (index, indexFile) => {
const esmIndexString = index.map(file => `export * from './${file}';`).join('\n');
outputFileSync(join(outDir, 'esm', indexFile), esmIndexString);
outputFileSync(join(outDir, 'js', indexFile.replace('.js', 'd.ts')), esmIndexString);
outputFileSync(
join(outDir, 'js', 'index.js'),
`
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.__esModule = true;
${index.map(file => `__export(require('./${file}'));`).join('\n')}
`.trim()
);
};

/**
* Writes CJS and ESM tokens to `dist` directory
Expand All @@ -47,7 +65,8 @@ function writeTokens(tokens) {
writeESMExport(tokenName, tokenString);
writeCJSExport(tokenName, tokenString);
writeDTSExport(tokenName, tokenString);
index.push(tokenName);
allIndex.push(tokenName);
componentIndex.push(tokenName);

// Legacy token support -- values may be incorrect.
Object.values(tokenValue)
Expand All @@ -63,28 +82,16 @@ function writeTokens(tokens) {
writeESMExport(oldTokenName, oldTokenString);
writeCJSExport(oldTokenName, oldTokenString);
writeDTSExport(oldTokenName, oldTokenString);
index.push(oldTokenName);
allIndex.push(oldTokenName);
});
});

// Index files including legacy tokens
const esmIndexString = index.map(file => `export * from './${file}';`).join('\n');
outputFileSync(join(outDir, 'esm', 'index.js'), esmIndexString);
outputFileSync(join(outDir, 'js', 'index.d.ts'), esmIndexString);
outputFileSync(
join(outDir, 'js', 'index.js'),
`
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.__esModule = true;
${index.map(file => `__export(require('./${file}'));`).join('\n')}
`.trim()
);
outputIndex(allIndex, 'index.js');
outputIndex(componentIndex, 'componentIndex.js');

// eslint-disable-next-line no-console
console.log('Wrote', index.length * 3 + 3, 'token files');
console.log('Wrote', allIndex.length * 3 + 3, 'token files');
}

writeTokens(generateTokens());
252 changes: 0 additions & 252 deletions packages/react-tokens/src/variablesByFile.js

This file was deleted.

0 comments on commit 3c7e7f8

Please sign in to comment.