2019-10-28 16:07:49 +00:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as path from 'path';
|
|
|
|
import * as prettier from 'prettier';
|
|
|
|
|
2021-02-25 12:07:07 +00:00
|
|
|
import * as iconsConfig from '../icons-config.json';
|
|
|
|
|
2019-10-28 16:07:49 +00:00
|
|
|
const ROOT_DIR = path.join(__dirname, '..');
|
|
|
|
|
2021-02-25 12:07:07 +00:00
|
|
|
async function genIconsList(iconsDirPath: string) {
|
|
|
|
const iconsDirName = path.basename(iconsDirPath);
|
|
|
|
const resultPath = path.join(ROOT_DIR, iconsConfig.resultIconsDirPath, `${iconsDirName}.json`);
|
|
|
|
|
|
|
|
const icons = fs.readdirSync(iconsDirPath).map((file) => file.slice(0, -4));
|
2019-10-28 16:07:49 +00:00
|
|
|
const filePath = await prettier.resolveConfigFile();
|
|
|
|
const options = await prettier.resolveConfig(filePath);
|
|
|
|
const formatted = prettier.format(JSON.stringify(icons), { ...options, parser: 'json' });
|
2021-02-25 12:07:07 +00:00
|
|
|
fs.writeFileSync(resultPath, formatted);
|
|
|
|
|
2020-11-26 11:45:20 +00:00
|
|
|
// tslint:disable-next-line:no-console
|
2021-02-25 12:07:07 +00:00
|
|
|
console.log(`Icons list generated: ${resultPath}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
return await Promise.all(iconsConfig.sourceIconsDirPaths.map((sourcePath) => genIconsList(sourcePath)));
|
2019-10-28 16:07:49 +00:00
|
|
|
})();
|