Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icons test #1466

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const svgoConfig = require('./svgo-config');
const svgoConfig = require('./svgo.config');

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

Expand Down
1 change: 1 addition & 0 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
appPackageJson: resolveApp('package.json'),
appDemo: resolveApp('www'),
appSrc: resolveApp('src'),
iconsSrc: resolveApp('icons/src'),
appDir: resolveApp(''),
appNodeModules: resolveApp('node_modules'),
assetsPath: resolveApp('www/assets'),
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = webpackMerge(commonConfig, {
},
{
test: /\.(js|jsx)$/,
include: [paths.appSrc, paths.appDemo],
include: [paths.appSrc, paths.iconsSrc, paths.appDemo],
loader: 'babel-loader',
options: {
cacheDirectory: true,
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.config.dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = webpackMerge(commonConfig, {
},
{
test: /\.(js|jsx)$/,
include: [paths.appSrc, paths.appDemo],
include: [paths.appSrc, paths.iconsSrc, paths.appDemo],
loader: 'babel-loader',
options: {
cacheDirectory: true,
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = webpackMerge(commonConfig, {
},
{
test: /\.(js|jsx)$/,
include: [paths.appSrc, paths.appDemo],
include: [paths.appSrc, paths.iconsSrc, paths.appDemo],
loader: 'babel-loader',
},
{
Expand Down
53 changes: 53 additions & 0 deletions icons/src/generateIconNames.js
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();
Loading