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

Update Material Design Icons to 4.0.0 #60

Merged
merged 2 commits into from
Dec 18, 2020
Merged
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
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
51 changes: 38 additions & 13 deletions scripts/extract-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,61 @@
const fs = require('fs');
const path = require('path');
const { writeIconModule, createExportLine,
readFromSvgContent, findAllSvgFiles : baseFindAllSvgFiles } = require('./utils');
const baseFolder = 'material-design-icons-3.0.1';
readFromSvgContent, findAllSvgFiles } = require('./utils');
const baseFolder = __dirname + 'material-design-icons-4.0.0';

const outFolder = path.join('..', 'src', 'md');
const outFolder = __dirname + '/' + path.join('..', 'src', 'md');
/**
* Download latest from:
* https://github.com/google/material-design-icons/releases
*
*
*
*/
const filterName = f => f.indexOf('svg/production') >= 0;
const filterSize = f => f.indexOf('_24px') >= 0;
const findAllSvgFiles = baseFindAllSvgFiles(filterName);
const filterName = f => (
(f.indexOf('24px.svg') >= 0) && (
(f.indexOf('materialicons/') >= 0) ||
(f.indexOf('materialiconsoutlined/') >= 0) ||
(f.indexOf('materialiconstwotone/') >= 0)
)
);

const filterSize = f => f.indexOf('24px') >= 0;

const extractName = fname => {
const index = fname.indexOf('_24px.svg');
return fname.substring(0, index);
const modifierMap = {
outline: /materialiconsoutlined/,
twotone: /materialiconstwotone/,
};

const nameRegex = /^.*\/(\w+)\/materialicons.*\/24px.svg$/;

const extractName = (fname, path) => {
const modifier = (
Object.entries(modifierMap)
.find(([, regex]) => regex.test(path)) || []
)[0];

const name = path.match(nameRegex)[1];

if (!name) {
throw new Error(`Did not find a valid name for ${path}`);
}

return [
'ic',
name,
modifier,
].filter(Boolean).join('_');
};

const generateFiles = () => {
const svgs = findAllSvgFiles(baseFolder).filter(filterSize);
const svgs = findAllSvgFiles(filterName, undefined, baseFolder).filter(filterSize);

const processed = {};

const exportLines = svgs.map( svgFile => {
const filename = path.basename(svgFile);
const name = extractName(filename);

const name = extractName(filename, svgFile);
if ( !processed[name] ) { //there seems to be some duplicate names
const content = fs.readFileSync(svgFile, { encoding: 'UTF-8' });
const { viewBox, children } = readFromSvgContent(content);
Expand All @@ -46,4 +71,4 @@ const generateFiles = () => {

};

generateFiles();
generateFiles();
24 changes: 16 additions & 8 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const readFromSvgContent = (content) => {
const attribs = filteredAttribs.reduce( (partial, key) => {
if ( $svg[0].attribs && $svg[0].attribs[key] ) {
return Object.assign({}, partial, { [key]: $svg[0].attribs[key] })
}
}
return partial
}, {})
return { children, viewBox: $svg[0].attribs['viewBox'], attribs };
Expand All @@ -149,7 +149,7 @@ const generateFromSvgFiles = (svgFolder, outFolder, options = {} ) => {
const content = fs.readFileSync(path.join(svgFolder,f), { encoding: 'UTF-8' });

const { viewBox, children, attribs } = readFromSvgContent(content, f);

return { name: exportableName(extractName(f)), children, viewBox, f, attribs };
});
//write it
Expand All @@ -159,8 +159,8 @@ const generateFromSvgFiles = (svgFolder, outFolder, options = {} ) => {
if ( !exportedNames[name] ) {
const safeExportName = TRANSLATE_MAP[name] ? TRANSLATE_MAP[name] : name;
const { viewBox, children, attribs } = parsed;
const exportLine = createExportLine(safeExportName, viewBox, children, attribs); //`export const ${safeExportName} = ${exportedObject};`;

const exportLine = createExportLine(safeExportName, viewBox, children, attribs); //`export const ${safeExportName} = ${exportedObject};`;
fs.writeFileSync(path.join(outFolder, `${safeExportName}.js`), exportLine);

exportedNames[name] = name;
Expand All @@ -177,10 +177,18 @@ const generateFromSvgFiles = (svgFolder, outFolder, options = {} ) => {

const findAllSvgFiles = (filterName, filterDir, dir, filelist = []) => {
fs.readdirSync(dir).forEach(file => {
filelist = fs.statSync(path.join(dir, file)).isDirectory()
? findAllSvgFiles(filterName, filterDir, path.join(dir, file), filelist)
: filelist.filter(filterName).concat(path.join(dir, file));
const isDir = fs.statSync(path.join(dir, file)).isDirectory();

if (isDir) {
filelist = findAllSvgFiles(filterName, filterDir, path.join(dir, file), filelist);
return;
}

const pathToAdd = path.join(dir, file);

if (!filterName(pathToAdd)) return;

filelist = filelist.concat(pathToAdd);
});
return filelist;

Expand All @@ -196,4 +204,4 @@ module.exports = {
generateExportCode,
writeIconModule,
generateFromSvgFiles
};
};
1 change: 1 addition & 0 deletions src/md/ic_10k.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_10mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_11mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_12mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_13mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_14mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_15mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_16mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_17mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_18mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_19mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_1k.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_1k_plus.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_20mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_21mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_22mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_23mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_24mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_2k.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_2k_plus.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_2mp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_360.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_360_outline.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/md/ic_360_twotone.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading