-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add icon creation scripts & components
- Loading branch information
1 parent
8078b67
commit 789aad4
Showing
674 changed files
with
13,483 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fs = require('fs/promises'); | ||
const prettier = require('prettier'); | ||
const chalk = require('chalk'); | ||
const { join } = require('path'); | ||
const paths = require('../../config/paths'); | ||
const pkg = require('../../package.json'); | ||
|
||
const ignoreFiles = ['index.jsx', '.DS_Store']; | ||
const filesMap = async (p) => { | ||
const dir = await fs.readdir(p); | ||
const res = await Promise.all( | ||
dir.map(async (f) => { | ||
const stat = await fs.stat(join(p, f)); | ||
if (stat.isDirectory()) | ||
console.warn(chalk.red(`All icons should be in the top-level directory. Found sub-folder: ${chalk.yellow(f)}`)); | ||
if (stat.isFile() && !ignoreFiles.includes(f)) { | ||
return f.replace('.jsx', ''); | ||
} | ||
return null; | ||
}) | ||
); | ||
return res.filter(Boolean); | ||
}; | ||
|
||
const generateIconNamesArray = async () => { | ||
const data = await filesMap(`${paths.iconsSrc}/react`); | ||
const code = `export const iconNames = [${data.map((v) => `'${v}'`)}];`; | ||
return prettier.format(code, { parser: 'babel', ...pkg.prettier }); | ||
}; | ||
|
||
const writeToFile = async (code) => { | ||
const file = `${paths.iconsSrc}/iconNames.js`; | ||
await fs.writeFile(file, code); | ||
// eslint-disable-next-line no-console | ||
console.log(chalk.green(`Icon names successfully written to ${file}`)); | ||
}; | ||
|
||
/** | ||
* - Generate an array of all icon names for Icon's propTypes | ||
* - export the array from `iconNames.js` | ||
*/ | ||
const generateIconNames = async () => { | ||
const iconNamesArray = await generateIconNamesArray(); | ||
const comment = `/** | ||
* Generated automatically - see icons/src/generateIconNames.js | ||
*/ | ||
`; | ||
|
||
await writeToFile(comment + iconNamesArray); | ||
}; | ||
|
||
generateIconNames(); |
Oops, something went wrong.