Skip to content

Commit

Permalink
upgrade to webpack2
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavsinai committed Dec 12, 2016
1 parent b85185b commit 6b62135
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 129 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules/
atlassian-ide-plugin.xml
.idea
tets_folder/
coverage/
platform/dist/
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "src/svgstore.js",
"scripts": {
"test": "NODE_ENV=platform ./node_modules/.bin/_mocha ./src/__tests__/index.js",
"run": "webpack",
"code:coverage": "NODE_ENV=platform ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha ./src/__tests__/index.js && npm run code:report",
"code:report": "CODECLIMATE_REPO_TOKEN=29b2c943849c33562af12b70563d86e95c073e04c7510e9da5d9711cf3233b17 ./node_modules/.bin/codeclimate-test-reporter < coverage/lcov.info",
"build": "rm -rf platform/dist/* && NODE_ENV=platform webpack --progress --colors --bail"
Expand Down Expand Up @@ -36,7 +37,7 @@
"istanbul": "0.4.5",
"mocha": "3.2.0",
"path": "0.12.7",
"webpack": "1.13.3"
"webpack": "2.1.0-beta.27"
},
"repository": {
"type": "git",
Expand Down
3 changes: 0 additions & 3 deletions platform/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ module.exports = function(_path) {
chunkFilename: '[chunkhash].[id].js',
publicPath: '/platform/'
},
resolve: {
extensions: ['', '.js'],
},
plugins: [
// create svgStore instance object
new SvgStore.Options({
Expand Down
77 changes: 39 additions & 38 deletions src/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
'use strict';

// Depends
var _ = require('lodash');
var fs = require('fs');
var path = require('path');
var util = require('util');
var pug = require('pug');
var Svgo = require('svgo');
var globby = require('globby');
var parse = require('htmlparser2');
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
const util = require('util');
const crypto = require('crypto');
const pug = require('pug');
const Svgo = require('svgo');
const globby = require('globby');
const parse = require('htmlparser2');

/**
* Create sprite
* @param {object} data
* @param {string} template
* @return {string}
*/
var _createSprite = function(data, template) {
const _createSprite = function(data, template) {
return pug.renderFile(template, data);
};

Expand All @@ -26,7 +27,7 @@ var _createSprite = function(data, template) {
* @param {integer} depth Depth level
* @return {void}
*/
var _log = function(subject, depth) {
const _log = function(subject, depth) {
console.log(util.inspect(subject, {
showHidden: true, depth: depth || 2
}));
Expand All @@ -38,7 +39,7 @@ var _log = function(subject, depth) {
* @param {string} id
* @return {void}
*/
var _fixIds = function(obj, id) {
const _fixIds = function(obj, id) {
// add id
if (obj.attribs && obj.attribs.id) {
obj.attribs.id = [id, obj.attribs.id].join('-');
Expand All @@ -55,10 +56,10 @@ var _fixIds = function(obj, id) {
* @param {string} id
* @return {void}
*/
var _fixUrls = function(obj, id) {
var key;
var match;
var json = obj.attribs;
const _fixUrls = function(obj, id) {
let key;
let match;
const json = obj.attribs;
if (json) {
for (key in json) {
if (json.hasOwnProperty(key)) {
Expand All @@ -77,8 +78,8 @@ var _fixUrls = function(obj, id) {
* @param {[type]} id [description]
* @return {[type]} [description]
*/
var _parseSVG = function(arr, id) {
var data = [];
const _parseSVG = function(arr, id) {
const data = [];
arr.forEach(function(obj) {
if (obj) {
// add unic ids to urls
Expand All @@ -102,10 +103,10 @@ var _parseSVG = function(arr, id) {
* @param {[type]} data [description]
* @return {[type]} [description]
*/
var _defs = function(id, dom, data) {
const _defs = function(id, dom, data) {
// lets find defs into dom
var defs = _.filter(dom.children, { name: 'defs' });
var parseChilds = function(item, data) {
const defs = _.filter(dom.children, { name: 'defs' });
const parseChilds = function(item, data) {
item.forEach(function(child) {
switch (child.name) {
case 'use': {
Expand Down Expand Up @@ -143,9 +144,9 @@ var _defs = function(id, dom, data) {
* @param {[type]} data [description]
* @return {[type]} [description]
*/
var _symbols = function(id, dom, data, prefix) {
const _symbols = function(id, dom, data, prefix) {
// create symbol object
var symbol = {
const symbol = {
type: 'tag',
name: 'symbol',
attribs: {
Expand Down Expand Up @@ -176,7 +177,7 @@ var _symbols = function(id, dom, data, prefix) {
* @param {string} filename [description]
* @return {string} [description]
*/
var _convertFilenameToId = function(filename) {
const _convertFilenameToId = function(filename) {
return filename.split('.').join('-').toLowerCase();
};

Expand All @@ -185,8 +186,8 @@ var _convertFilenameToId = function(filename) {
* @param {string} input Destination path
* @return {array} Array of paths
*/
var _filesMap = function(input, cb) {
var data = input;
const _filesMap = function(input, cb) {
const data = input;

globby(data).then(function(fileList) {
cb(fileList);
Expand All @@ -198,8 +199,8 @@ var _filesMap = function(input, cb) {
* @param {[type]} dom [description]
* @return {[type]} [description]
*/
var _parseDomObject = function(data, filename, dom, prefix) {
var id = _convertFilenameToId(filename);
const _parseDomObject = function(data, filename, dom, prefix) {
const id = _convertFilenameToId(filename);
if (dom && dom[0]) {
_defs(id, dom[0], data.defs);
_symbols(id, dom[0], data.symbols, prefix);
Expand All @@ -214,9 +215,9 @@ var _parseDomObject = function(data, filename, dom, prefix) {
* @param {integer} loop loop count
* @return {[type]} minified source
*/
var _minify = function(file, svgoOptions) {
var min = new Svgo(svgoOptions);
var source = file;
const _minify = function(file, svgoOptions) {
const min = new Svgo(svgoOptions);
let source = file;

function svgoCallback(result) {
source = result.data;
Expand All @@ -231,9 +232,9 @@ var _minify = function(file, svgoOptions) {
* [parseFiles description]
* @return {[type]} [description]
*/
var _parseFiles = function(files, options) {
var self = this;
var data = {
const _parseFiles = function(files, options) {
const self = this;
let data = {
svg: options.svg,
defs: [],
symbols: []
Expand All @@ -242,17 +243,17 @@ var _parseFiles = function(files, options) {
// each over files
files.forEach(function(file) {
// load and minify
var buffer = _minify(fs.readFileSync(file, 'utf8'), options.svgoOptions);
const buffer = _minify(fs.readFileSync(file, 'utf8'), options.svgoOptions);
// get filename for id generation
var filename = path.basename(file, '.svg');
const filename = path.basename(file, '.svg');

var handler = new parse.DomHandler(function(error, dom) {
const handler = new parse.DomHandler(function(error, dom) {
if (error) self.log(error);
else data = _parseDomObject(data, filename, dom, options.prefix);
});

// lets create parser instance
var Parser = new parse.Parser(handler, {
const Parser = new parse.Parser(handler, {
xmlMode: true
});
Parser.write(buffer);
Expand All @@ -268,7 +269,7 @@ var _parseFiles = function(files, options) {
* @param {[type]} name [description]
* @return {[type]} [description]
*/
var _hash = function(str, hash) {
const _hash = function(str, hash) {
return str.indexOf('[hash]') >= 0
? str.replace('[hash]', hash)
: str;
Expand Down
Loading

0 comments on commit 6b62135

Please sign in to comment.