cache-busting-assets
Advanced tools
Comparing version 0.0.1 to 0.0.2
15
index.js
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const process = require('process'); | ||
const generateHash = (sourceFile) => { | ||
const file = fs.readFileSync((`.${sourceFile}`), 'utf8'); | ||
const generateHash = (dir, sourceFile) => { | ||
const file = fs.readFileSync((`${dir}${sourceFile}`), 'utf8'); | ||
const hash = crypto | ||
@@ -15,2 +16,8 @@ .createHash('sha1') | ||
const destination = sourceFile.replace(fileName, `${fileName}-${hash}`); | ||
console.log(`${dir}${sourceFile}`, `${dir}${destination}`); | ||
fs.copyFile(`${dir}${sourceFile}`, `${dir}${destination}`, (copyErr) => { | ||
if (copyErr) { | ||
throw copyErr; | ||
} | ||
}); | ||
@@ -20,6 +27,6 @@ return destination; | ||
const createHashFile = (sources) => { | ||
const createHashFile = (dir, sources) => { | ||
const hashes = sources.map(file => ( | ||
{ | ||
[file]: generateHash(file), | ||
[file]: generateHash(dir, file), | ||
} | ||
@@ -26,0 +33,0 @@ )); |
{ | ||
"name": "cache-busting-assets", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
2653
32