Comparing version 2.3.0 to 2.3.1
@@ -17,3 +17,3 @@ 'use strict'; | ||
var mkdirp = nodefn.lift(require('mkdirp')); | ||
var fsp = nodefn.liftAll(require('fs')); | ||
var fsp = nodefn.liftAll(fs); | ||
@@ -67,3 +67,3 @@ // TODO: Consider using node-glob module instead of readdirp + through2 | ||
var noop = () => null | ||
var noop = () => null; | ||
@@ -114,28 +114,27 @@ module.exports = function(inputDir, outputDir, options) { | ||
var inFiles = existingShas.map(sha => | ||
sha && fsp.readFile(getInputFile(sha), 'utf8').then(contents => contents, noop) | ||
); | ||
return when.all([when.all(inFiles), when.all(outFiles)]) | ||
.then(fileContents => | ||
matchingCompilerShas.filter( | ||
(sha, i) => | ||
(fileContents[0][i] && (sha.inputSha === createHash(fileContents[0][i]))) && | ||
(fileContents[1][i] && (sha.outputSha === createHash(fileContents[1][i]))) | ||
) | ||
); | ||
// Verify that the output file hasn't changed | ||
return when.all(outFiles) | ||
.then(fileContents => | ||
matchingCompilerShas.filter((sha, i) => | ||
(fileContents[i] && (sha.outputSha === createHash(fileContents[i]))) | ||
) | ||
); | ||
}) | ||
.then(filtered => | ||
// Verify that the input files haven't changed | ||
when.all(filtered.map(sha => | ||
when.all(sha.inputSha.map(input => | ||
fsp.readFile(path.join(inputDir, input.file), 'utf8').then(contents => | ||
input.sha === createHash(contents) | ||
) | ||
)) | ||
)).then(equalShaBoolArr => { | ||
var filterBools = equalShaBoolArr.map( | ||
// i.e.. [true, true, false] => false | ||
x => x.reduce((prev, curr) => prev && curr, true) | ||
); | ||
return filtered.filter((el, i) => filterBools[i]); | ||
}) | ||
) | ||
.then(filtered => { | ||
return filtered.filter(sha => { | ||
if (!sha.sourceChildren.length) { return sha; } | ||
var allSourcesAreUnchanged = true; | ||
sha.sourceChildren.forEach(source => { | ||
var sourceRelativePath = path.join(path.dirname(sha.input), source); | ||
var sourceExists = filtered.findIndex(x => sourceRelativePath === x.input) !== -1; | ||
if (!sourceExists) { allSourcesAreUnchanged = false; } | ||
}); | ||
return allSourcesAreUnchanged; | ||
}); | ||
}) | ||
.then(filtered => { | ||
if (!Array.isArray(filtered)) { return; } | ||
@@ -152,2 +151,3 @@ return { | ||
var compileAndCopy = function(reusableFiles) { | ||
babyTolk.reload(); | ||
return when.promise(function(resolve, reject) { | ||
@@ -209,8 +209,11 @@ options.root = inputDir; | ||
var sources = []; | ||
if (compiled.sourcemap) { | ||
var sourcemapStr = 'sourceMappingURL=' + fileName + '.map'; | ||
sources = compiled.sourcemap.sources.map(source => path.basename(source)); | ||
compiled.sourcemap.sources = | ||
sources.map(source => extensionChanged ? source : addSrcExtension(source)); | ||
compiled.sourcemap.sources = compiled.sourcemap.sources | ||
.map(source => path.resolve(process.cwd(), source)) | ||
.map(source => source.replace(inputDir, outputDir)) | ||
.map(source => path.relative(path.dirname(compiledOutputFullPath), source)) | ||
.map(source => extensionChanged ? source : addSrcExtension(source)); | ||
var srcMapFileName = compiledOutputFullPath + '.map'; | ||
@@ -233,7 +236,9 @@ writeFiles.push(fsp.writeFile(srcMapFileName, JSON.stringify(compiled.sourcemap))); | ||
type: compiled.transformId, | ||
inputSha: compiled.inputSha, | ||
inputSha: compiled.inputSha.map(x => ({ | ||
file: path.relative(inputDir, x.file), | ||
sha: x.sha | ||
})), | ||
outputSha: createHash(compiled.result), | ||
input: relativePath, | ||
output: fileNames, | ||
sourceChildren: sources | ||
}); | ||
@@ -258,22 +263,7 @@ eventEmitter.emit('compile-done', file); | ||
// compile | ||
compile().then(function() { | ||
if (options.sourcemaps) { | ||
copy(); | ||
} else { | ||
fileDone(); | ||
} | ||
}, reject); | ||
compile().then(() => options.sourcemaps ? copy() : fileDone(), reject); | ||
} else if (babyTolk.isMinifiable(ext) && options.minify && doCompile) { | ||
// minify | ||
compile().then(function() { | ||
if (options.sourcemaps) { | ||
copy(true); | ||
} else { | ||
fileDone(); | ||
} | ||
}, reject); | ||
} else { | ||
// copy | ||
copy(); | ||
} | ||
compile().then(() => options.sourcemaps ? copy(true) : fileDone(), reject); | ||
} else { copy(); } | ||
}; | ||
@@ -280,0 +270,0 @@ |
{ | ||
"name": "baconize", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "Compile static site for production (with sourcemaps), auto-compiles files like `app.coffee -> app.js`", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -57,9 +57,9 @@ 'use strict'; | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
expect(compiledFiles, 'to contain', | ||
'index.jade', 'scripts/main.coffee', 'styles/main.styl', 'styles/_inner.styl', 'scripts/log.babel.js' | ||
'index.jade', 'scripts/main.coffee', 'styles/main.styl', 'scripts/log.babel.js' | ||
) | ||
.and('not to contain', 'about.html', 'styles/typography.css') | ||
.and('to have length', 5) | ||
.and('to have length', 4) | ||
]); | ||
@@ -157,9 +157,9 @@ }); | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
expect(compiledFiles, 'to contain', | ||
'index.jade', 'scripts/main.coffee', 'styles/main.styl', 'styles/_inner.styl', 'scripts/log.babel.js' | ||
'index.jade', 'scripts/main.coffee', 'styles/main.styl', 'scripts/log.babel.js' | ||
) | ||
.and('not to contain', 'about.html', 'styles/typography.css', 'styles/typography.css') | ||
.and('to have length', 5) | ||
.and('to have length', 4) | ||
]); | ||
@@ -212,3 +212,3 @@ }); | ||
expect(results[0].toString(), 'to contain', '"file":"main.css"') | ||
.and('to contain', '"sources":["main.styl","_inner.styl"]'), | ||
.and('to contain', '"sources":["main.styl","../dont-copy/_inner.styl"]'), | ||
expect(results[1].toString(), 'to contain', '"file":"main.js"') | ||
@@ -282,3 +282,3 @@ .and('to contain', '"sources":["main.coffee"]'), | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
@@ -288,3 +288,3 @@ expect(compiledFiles, 'to contain', | ||
'styles/main.styl', 'styles/typography.css', | ||
'scripts/iterate.js', 'scripts/main.coffee', 'styles/_inner.styl').and('to have length', 8), | ||
'scripts/iterate.js', 'scripts/main.coffee').and('to have length', 7), | ||
]); | ||
@@ -382,3 +382,3 @@ }); | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
@@ -388,3 +388,3 @@ expect(compiledFiles, 'to contain', | ||
'styles/main.styl', 'styles/typography.css', | ||
'scripts/iterate.js', 'scripts/main.coffee', 'styles/_inner.styl').and('to have length', 8), | ||
'scripts/iterate.js', 'scripts/main.coffee').and('to have length', 7), | ||
]); | ||
@@ -445,3 +445,3 @@ }); | ||
expect(results[0].toString(), 'to contain', '"file":"main.css"') | ||
.and('to contain', '"sources":["main.styl","_inner.styl"]'), | ||
.and('to contain', '"sources":["main.styl","../dont-copy/_inner.styl"]'), | ||
expect(results[1].toString(), 'to contain', '"file":"main.js"') | ||
@@ -506,5 +506,5 @@ .and('to contain', '"sources":["main.coffee"]'), | ||
// TODO: write a test where the input file is changed. | ||
var styl = fs.readFile(getPathIn('styles/_inner.styl'), 'utf8').then(content => { | ||
var styl = fs.readFile(getPathIn('dont-copy/_inner.styl'), 'utf8').then(content => { | ||
originalStylContents = content; | ||
return fs.writeFile(getPathIn('styles/_inner.styl'), content + ' '); | ||
return fs.writeFile(getPathIn('dont-copy/_inner.styl'), content + ' '); | ||
}); | ||
@@ -516,3 +516,3 @@ | ||
after(done => { | ||
var coffee = fs.writeFile(getPathIn('styles/_inner.styl'), originalStylContents); | ||
var coffee = fs.writeFile(getPathIn('dont-copy/_inner.styl'), originalStylContents); | ||
coffee.then(() => { clearDir(done); }); | ||
@@ -555,6 +555,6 @@ }); | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
expect(compiledFiles, 'to contain', | ||
'index.jade', 'styles/main.styl', 'styles/_inner.styl', 'scripts/main.coffee').and('to have length', 4), | ||
'index.jade', 'styles/main.styl', 'scripts/main.coffee').and('to have length', 3), | ||
expect(compilationReuseFiles, 'to contain', | ||
@@ -617,3 +617,3 @@ 'about.html', 'scripts/log.babel.js', 'styles/typography.css', 'scripts/iterate.js').and('to have length', 4), | ||
expect(results[0].toString(), 'to contain', '"file":"main.css"') | ||
.and('to contain', '"sources":["main.styl","_inner.styl"]'), | ||
.and('to contain', '"sources":["main.styl","../dont-copy/_inner.styl"]'), | ||
expect(results[1].toString(), 'to contain', '"file":"main.js"') | ||
@@ -636,3 +636,3 @@ .and('to contain', '"sources":["main.coffee"]'), | ||
fs.readFile(getPathOut('styles/main.styl')), | ||
fs.readFile(getPathOut('styles/_inner.styl')) | ||
// fs.readFile(getPathOut('dont-copy/_inner.styl')) | ||
]).then(function(results) { | ||
@@ -644,4 +644,4 @@ return expect.promise.all([ | ||
expect(results[3].toString(), 'to contain', ' font-family: arial;'), | ||
expect(results[4].toString(), 'to contain', '@import \'_inner\''), | ||
expect(results[5].toString(), 'to contain', 'h1\n color: darkgreen') | ||
expect(results[4].toString(), 'to contain', '@import \'../dont-copy/_inner\''), | ||
// expect(results[5].toString(), 'to contain', 'h1\n color: darkgreen') | ||
]); | ||
@@ -681,3 +681,3 @@ }); | ||
it('should not compile files prefixed with `_`', function() { | ||
return fs.readFile(getPathOut('styles/_inner.css')) | ||
return fs.readFile(getPathOut('dont-copy/_inner.css')) | ||
.then(function() { | ||
@@ -684,0 +684,0 @@ return expect.fail( |
@@ -65,3 +65,3 @@ 'use strict'; | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
@@ -72,3 +72,3 @@ expect(compiledFiles, 'to contain', | ||
.and('not to contain', 'about.html', 'styles/typography.css', 'styles/typography.css') | ||
.and('to have length', 5) | ||
.and('to have length', 4) | ||
]); | ||
@@ -172,3 +172,3 @@ }); | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
@@ -179,3 +179,3 @@ expect(compiledFiles, 'to contain', | ||
.and('not to contain', 'about.html', 'styles/typography.css', 'styles/typography.css') | ||
.and('to have length', 5) | ||
.and('to have length', 4) | ||
]); | ||
@@ -228,3 +228,3 @@ }); | ||
expect(results[0].toString(), 'to contain', '"file":"main.css"') | ||
.and('to contain', '"sources":["main.styl","_inner.styl"]'), | ||
.and('to contain', '"sources":["main.styl","../dont-copy/_inner.styl"]'), | ||
expect(results[1].toString(), 'to contain', '"file":"main.js"') | ||
@@ -306,3 +306,3 @@ .and('to contain', '"sources":["main.coffee"]'), | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
@@ -312,3 +312,3 @@ expect(compiledFiles, 'to contain', | ||
'styles/main.styl', 'styles/typography.css', | ||
'scripts/iterate.js', 'scripts/main.coffee', 'styles/_inner.styl').and('to have length', 8), | ||
'scripts/iterate.js', 'scripts/main.coffee').and('to have length', 7), | ||
]); | ||
@@ -414,3 +414,3 @@ }); | ||
return expect.promise.all([ | ||
expect(num, 'to be', 10), | ||
expect(num, 'to be', 9), | ||
expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4), | ||
@@ -420,3 +420,3 @@ expect(compiledFiles, 'to contain', | ||
'styles/main.styl', 'styles/typography.css', | ||
'scripts/iterate.js', 'scripts/main.coffee', 'styles/_inner.styl').and('to have length', 8), | ||
'scripts/iterate.js', 'scripts/main.coffee').and('to have length', 7), | ||
]); | ||
@@ -477,3 +477,3 @@ }); | ||
expect(results[0].toString(), 'to contain', '"file":"main.css"') | ||
.and('to contain', '"sources":["main.styl","_inner.styl"]'), | ||
.and('to contain', '"sources":["main.styl","../dont-copy/_inner.styl"]'), | ||
expect(results[1].toString(), 'to contain', '"file":"main.js"') | ||
@@ -480,0 +480,0 @@ .and('to contain', '"sources":["main.coffee"]'), |
Sorry, the diff of this file is not supported yet
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
3
72901
1423