Skip to content

Commit 789aad4

Browse files
committed
fix: add icon creation scripts & components
1 parent 8078b67 commit 789aad4

674 files changed

Lines changed: 13483 additions & 8 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const svgoConfig = require('./svgo-config');
1+
const svgoConfig = require('./svgo.config');
22

33
const isDevelopment = process.env.TYPE === 'development';
44

config/paths.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
appPackageJson: resolveApp('package.json'),
1919
appDemo: resolveApp('www'),
2020
appSrc: resolveApp('src'),
21+
iconsSrc: resolveApp('icons/src'),
2122
appDir: resolveApp(''),
2223
appNodeModules: resolveApp('node_modules'),
2324
assetsPath: resolveApp('www/assets'),

config/webpack.config.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = webpackMerge(commonConfig, {
6060
},
6161
{
6262
test: /\.(js|jsx)$/,
63-
include: [paths.appSrc, paths.appDemo],
63+
include: [paths.appSrc, paths.iconsSrc, paths.appDemo],
6464
loader: 'babel-loader',
6565
options: {
6666
cacheDirectory: true,

config/webpack.config.dist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = webpackMerge(commonConfig, {
7676
},
7777
{
7878
test: /\.(js|jsx)$/,
79-
include: [paths.appSrc, paths.appDemo],
79+
include: [paths.appSrc, paths.iconsSrc, paths.appDemo],
8080
loader: 'babel-loader',
8181
options: {
8282
cacheDirectory: true,

config/webpack.config.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.exports = webpackMerge(commonConfig, {
8282
},
8383
{
8484
test: /\.(js|jsx)$/,
85-
include: [paths.appSrc, paths.appDemo],
85+
include: [paths.appSrc, paths.iconsSrc, paths.appDemo],
8686
loader: 'babel-loader',
8787
},
8888
{

icons/src/generateIconNames.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const fs = require('fs/promises');
2+
const prettier = require('prettier');
3+
const chalk = require('chalk');
4+
const { join } = require('path');
5+
const paths = require('../../config/paths');
6+
const pkg = require('../../package.json');
7+
8+
const ignoreFiles = ['index.jsx', '.DS_Store'];
9+
const filesMap = async (p) => {
10+
const dir = await fs.readdir(p);
11+
const res = await Promise.all(
12+
dir.map(async (f) => {
13+
const stat = await fs.stat(join(p, f));
14+
if (stat.isDirectory())
15+
console.warn(chalk.red(`All icons should be in the top-level directory. Found sub-folder: ${chalk.yellow(f)}`));
16+
if (stat.isFile() && !ignoreFiles.includes(f)) {
17+
return f.replace('.jsx', '');
18+
}
19+
return null;
20+
})
21+
);
22+
return res.filter(Boolean);
23+
};
24+
25+
const generateIconNamesArray = async () => {
26+
const data = await filesMap(`${paths.iconsSrc}/react`);
27+
const code = `export const iconNames = [${data.map((v) => `'${v}'`)}];`;
28+
return prettier.format(code, { parser: 'babel', ...pkg.prettier });
29+
};
30+
31+
const writeToFile = async (code) => {
32+
const file = `${paths.iconsSrc}/iconNames.js`;
33+
await fs.writeFile(file, code);
34+
// eslint-disable-next-line no-console
35+
console.log(chalk.green(`Icon names successfully written to ${file}`));
36+
};
37+
38+
/**
39+
* - Generate an array of all icon names for Icon's propTypes
40+
* - export the array from `iconNames.js`
41+
*/
42+
const generateIconNames = async () => {
43+
const iconNamesArray = await generateIconNamesArray();
44+
const comment = `/**
45+
* Generated automatically - see icons/src/generateIconNames.js
46+
*/
47+
48+
`;
49+
50+
await writeToFile(comment + iconNamesArray);
51+
};
52+
53+
generateIconNames();

0 commit comments

Comments
 (0)