2017-12-14 15:08:08 -06:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
|
|
const ROOT_DIR = path.join(__dirname, '..');
|
|
|
|
|
const SRC_DIR = path.join(ROOT_DIR, 'src');
|
|
|
|
|
const SRC_SVG_DIR = path.join(SRC_DIR, 'svg');
|
2018-05-10 13:37:50 -05:00
|
|
|
const PKG_JSON = path.join(ROOT_DIR, 'package.json');
|
2017-12-14 15:08:08 -06:00
|
|
|
const SRC_JSON = path.join(SRC_DIR, 'data.json');
|
|
|
|
|
const DST_DIR = path.join(ROOT_DIR, 'dist');
|
|
|
|
|
const DST_JSON = path.join(DST_DIR, 'ionicons/data.json');
|
2018-08-22 22:03:19 +02:00
|
|
|
const DST_JS = path.join(DST_DIR, 'svg/index.js');
|
2017-12-14 15:08:08 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('checking icon data: ' + SRC_JSON);
|
|
|
|
|
|
|
|
|
|
let srcData = fs.readJsonSync(SRC_JSON);
|
|
|
|
|
let svgFiles = fs.readdirSync(SRC_SVG_DIR);
|
2018-05-10 13:37:50 -05:00
|
|
|
let pkgData = fs.readJsonSync(PKG_JSON);
|
|
|
|
|
srcData['version'] = pkgData.version;
|
2018-08-22 22:03:19 +02:00
|
|
|
let iconFilenames = [];
|
2017-12-14 15:08:08 -06:00
|
|
|
|
2018-08-22 22:03:19 +02:00
|
|
|
svgFiles = svgFiles.filter(f => f.indexOf('.svg') > -1);
|
|
|
|
|
svgFiles.forEach(svgFile => {
|
2017-12-14 15:08:08 -06:00
|
|
|
let iconName = svgFile.split('.')[0];
|
|
|
|
|
|
|
|
|
|
let icon = srcData.icons.find(i => i.icons.indexOf(iconName) > -1);
|
|
|
|
|
if (!icon) {
|
|
|
|
|
console.log('icon data missing for: ' + svgFile);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
srcData.icons.forEach(i => {
|
|
|
|
|
if (i.tags.length === 0) {
|
|
|
|
|
console.log('icon data missing search tags for: ' + i.icons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i.icons.forEach(iconName => {
|
|
|
|
|
let svgFile = iconName + '.svg';
|
|
|
|
|
|
|
|
|
|
let f = svgFiles.find(f => f === svgFile);
|
|
|
|
|
if (!f) {
|
|
|
|
|
console.log('icon data contains "' + iconName + '", but the file "' + path.join(SRC_SVG_DIR, svgFile) + '" doesn\'t exist');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-08-22 22:03:19 +02:00
|
|
|
const jsonContent = JSON.stringify(srcData);
|
|
|
|
|
fs.writeFileSync(DST_JSON, jsonContent);
|
2018-08-23 19:16:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const jsContent = `
|
|
|
|
|
if (require && require.context) {
|
|
|
|
|
require.context('!!file-loader?name=[name].[ext]&outputPath=svg!./', false, /\.svg$/);
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
fs.writeFileSync(DST_JS, jsContent)
|