icon-maker-loader
Advanced tools
Comparing version 0.1.8 to 0.1.9
76
index.js
@@ -5,2 +5,3 @@ const loaderUtils = require('loader-utils'); | ||
const fs = require('fs'); | ||
const crypto = require('crypto'); | ||
const createTmpDir = require('./create-tmp-dir.js'); | ||
@@ -12,3 +13,6 @@ | ||
const fonts = {}; | ||
const filesForFont = {}; | ||
const getSha1ForContent = content => crypto.createHash('sha1').update(content).digest('hex'); | ||
const writeFontFiles = (fontFamily, iconMaker, cb) => { | ||
@@ -77,3 +81,2 @@ const pathToFontJs = path.join(tmpFolder, `${fontFamily}.js`); | ||
const pathToSvg = this.resourcePath; | ||
console.log('load', pathToSvg); | ||
const params = loaderUtils.parseQuery(this.query); | ||
@@ -87,2 +90,3 @@ const fileName = path.basename(pathToSvg, '.svg'); | ||
doOnFinish: [], | ||
paths: [], | ||
iconMaker: new IconMaker({ fontFamily, files, isLocalCss }) | ||
@@ -95,22 +99,68 @@ }; | ||
const cb = this.async(); | ||
const moduleContent = ` | ||
var style = require(${JSON.stringify(`${tmpFolderForNode}/${fontFamily}.js`)}); | ||
if (style) { | ||
module.exports = style[${JSON.stringify(fontFamily)}] + " " + style[${JSON.stringify(`${fontFamily}-${fileName}`)}]; | ||
} else { | ||
module.exports = ${JSON.stringify(`${fontFamily} ${fontFamily}-${fileName}`)}; | ||
} | ||
`; | ||
font.paths.push(pathToSvg); | ||
font.doOnFinish.push(err => { | ||
const moduleContent = ` | ||
var style = require(${JSON.stringify(`${tmpFolderForNode}/${fontFamily}.js`)}); | ||
if (style) { | ||
module.exports = style[${JSON.stringify(fontFamily)}] + " " + style[${JSON.stringify(`${fontFamily}-${fileName}`)}]; | ||
} else { | ||
module.exports = ${JSON.stringify(`${fontFamily} ${fontFamily}-${fileName}`)}; | ||
} | ||
`; | ||
cb(err, moduleContent); | ||
}); | ||
font.timeoutIdentifier = setTimeout(() => { | ||
writeFontFiles(fontFamily, font.iconMaker, err => { | ||
console.log(err); | ||
setTimeout(() => { | ||
const isFirstTime = filesForFont[fontFamily] === undefined; | ||
Promise.all( | ||
[ | ||
isFirstTime ? Promise.resolve : new Promise((res, rej) => { | ||
const isThereAChangeInLength = Object.keys(filesForFont[fontFamily]).length !== font.paths.length; | ||
if (isThereAChangeInLength) { | ||
res(); | ||
} else { | ||
rej(); | ||
} | ||
}) | ||
].concat(isFirstTime ? [] : font.paths.map(currPathToSvg => new Promise((res, rej) => { | ||
fs.readFile(currPathToSvg, (err, data) => { | ||
const isThereAChangeInHashForSvg = filesForFont[fontFamily][currPathToSvg] === getSha1ForContent(data); | ||
if (isThereAChangeInHashForSvg) { | ||
res(); | ||
} else { | ||
rej(); | ||
} | ||
}); | ||
}))) | ||
).then(() => { | ||
filesForFont[fontFamily] = {}; | ||
Promise.all( | ||
[ | ||
new Promise((res, rej) => { | ||
writeFontFiles(fontFamily, font.iconMaker, err => { | ||
if (err) { | ||
rej(err); | ||
} else { | ||
res(); | ||
} | ||
}); | ||
}) | ||
].concat(font.paths.map(currPathToSvg => new Promise((res, rej) => { | ||
fs.readFile(currPathToSvg, (err, data) => { | ||
if (err) { | ||
rej(err); | ||
} else { | ||
filesForFont[fontFamily][currPathToSvg] = getSha1ForContent(data); | ||
res(); | ||
} | ||
}); | ||
}))) | ||
).then(() => { | ||
font.doOnFinish.forEach(fn => fn()); | ||
delete fonts[fontFamily]; | ||
}, err => { | ||
font.doOnFinish.forEach(fn => fn(err)); | ||
delete fonts[fontFamily]; | ||
}, 1000); | ||
}); | ||
}); | ||
}, 1000); | ||
}; |
{ | ||
"name": "icon-maker-loader", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "", | ||
@@ -32,2 +32,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"crypto": "0.0.3", | ||
"icon-maker": "^0.2.4", | ||
@@ -34,0 +35,0 @@ "loader-utils": "^0.2.16", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
52845
262
0
4
+ Addedcrypto@0.0.3
+ Addedcrypto@0.0.3(transitive)