Skip to content

Commit

Permalink
Add support for separating glyph map from icon component oblador#256
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed Oct 26, 2016
1 parent f92e7a2 commit f7d47fb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
13 changes: 11 additions & 2 deletions generate-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ var argv = require('yargs')
.default('p', '.icon-')
.describe('p', 'CSS selector prefix')
.alias('p', 'prefix')
.default('t', __dirname + '/template/iconSet.tpl')
.default('t', __dirname + '/templates/bundled-icon-set.tpl')
.describe('t', 'Template in lodash format')
.alias('t', 'template')
.describe('o', 'Save output to file, defaults to STDOUT')
.alias('o', 'output')
.describe('g', 'Save glyphmap JSON to file')
.alias('g', 'glyphmap')
.argv;

var _ = require('lodash');
Expand All @@ -23,7 +25,7 @@ if(argv.template) {
template = fs.readFileSync(argv.template, { encoding: 'utf8' });
}

var data = _.omit(argv, '_ $0 o output p prefix t template'.split(' '));
var data = _.omit(argv, '_ $0 o output p prefix t template g glyphmap'.split(' '));


var content = generateIconSetFromCss(argv._, argv.prefix, template, data);
Expand All @@ -35,3 +37,10 @@ if(argv.output) {
} else {
console.log(content);
}

if (argv.glyphmap) {
fs.writeFileSync(
argv.glyphmap,
generateIconSetFromCss(argv._, argv.prefix)
);
}
13 changes: 11 additions & 2 deletions generate-material-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
var argv = require('yargs')
.usage('Usage: $0 [options] path/to/codepoints \nFor default template please provide --componentName and --fontFamily')
.demand(1)
.default('t', __dirname + '/template/iconSet.tpl')
.default('t', __dirname + '/templates/bundled-icon-set.tpl')
.describe('t', 'Template in lodash format')
.alias('t', 'template')
.describe('o', 'Save output to file, defaults to STDOUT')
.alias('o', 'output')
.describe('g', 'Save glyphmap JSON to file')
.alias('g', 'glyphmap')
.argv;

var _ = require('lodash');
Expand All @@ -32,7 +34,7 @@ if(argv.template) {
template = fs.readFileSync(argv.template, { encoding: 'utf8' });
}

var data = _.omit(argv, '_ $0 o output t template'.split(' '));
var data = _.omit(argv, '_ $0 o output t template g glyphmap'.split(' '));
var glyphMap = extractGlyphMapFromCodepoints(argv._[0]);

var content = JSON.stringify(glyphMap, null, ' ');
Expand All @@ -51,3 +53,10 @@ if(argv.output) {
} else {
console.log(content);
}

if (argv.glyphmap) {
fs.writeFileSync(
argv.glyphmap,
JSON.stringify(glyphMap, null, ' ')
);
}
5 changes: 1 addition & 4 deletions template/iconSet.tpl → templates/bundled-icon-set.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@
import createIconSet from 'react-native-vector-icons/lib/create-icon-set';
const glyphMap = ${glyphMap};

let ${componentName} = createIconSet(glyphMap, '${fontFamily}', '${componentName}.ttf');

module.exports = ${componentName};
module.exports.glyphMap = glyphMap;
export default createIconSet(glyphMap, '${fontFamily}', '${componentName}.ttf');
9 changes: 9 additions & 0 deletions templates/separated-icon-set.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* ${componentName} icon set component.
* Usage: <${componentName} name="icon-name" size={20} color="#4F8EF7" />
*/

import createIconSet from './lib/create-icon-set';
import glyphMap from './glyphmaps/${componentName}.json';

export default createIconSet(glyphMap, '${fontFamily}', '${componentName}.ttf');

0 comments on commit f7d47fb

Please sign in to comment.