gulp-less-precompiler
Advanced tools
Comparing version
@@ -0,0 +0,0 @@ /* global require */ |
@@ -0,0 +0,0 @@ /* global require, module */ |
{ | ||
"name": "gulp-less-precompiler", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A gulp plugin that replaces imports with the imported file content.", | ||
@@ -26,3 +26,4 @@ "main": "index.js", | ||
"through2": "^2.0.0", | ||
"vinyl": "^1.1.0" | ||
"vinyl": "^1.1.0", | ||
"vinyl-sourcemaps-apply": "^0.2.0" | ||
}, | ||
@@ -29,0 +30,0 @@ "devDependencies": { |
@@ -11,2 +11,3 @@ /* global require */ | ||
var File = require('vinyl'); | ||
var sourcemaps = require('vinyl-sourcemaps-apply'); | ||
@@ -20,5 +21,6 @@ var REGEX_IMPORT = new RegExp('@import [\'"](.+?)[\'"];'); | ||
* @param {Object} context | ||
* @param {Boolean} debug Whether to display debug messages during work. | ||
* @returns {Promise<Buffer>} | ||
*/ | ||
function scanFile(file, promise, context) { | ||
function scanFile(file, promise, context, debug) { | ||
return new Promise(function(resolve, reject) { | ||
@@ -48,4 +50,9 @@ | ||
if (!matches) { | ||
gutil.log('=> ' + line); | ||
if (debug) { | ||
gutil.log('=> ' + line); | ||
} | ||
return builder.appendLine(line); | ||
} | ||
@@ -62,3 +69,3 @@ | ||
return scanFile(targetFile, promise, context); | ||
return scanFile(targetFile, promise, context, debug); | ||
@@ -82,7 +89,8 @@ }); | ||
* @param {File} file | ||
* @param {Boolean} debug Whether to display debug messages during work. | ||
* @returns {Promise<Buffer>} | ||
**/ | ||
function startScan(file) { | ||
function startScan(file, debug) { | ||
gutil.log('Starting style precompilation with ' + file.path); | ||
return scanFile(file, Promise.resolve(new StringBuilder()), []); | ||
return scanFile(file, Promise.resolve(new StringBuilder()), [], debug); | ||
} | ||
@@ -92,7 +100,23 @@ | ||
* Creates a new precompiler for use in a gulp workflow. | ||
* @param {Object} [options] Never actually used. | ||
* @param {Object} [options] The plugin options. | ||
* @param {Boolean} [options.debug] Whether to log debug messages. | ||
*/ | ||
module.exports = function lessPrecompiler(options) { | ||
var config = { | ||
debug: options | ||
&& options.debug, | ||
sourceMaps: options | ||
? options.sourceMaps !== false | ||
: true, | ||
push: options | ||
&& options.push | ||
}; | ||
return through2.obj(function(file, encoding, done) { | ||
var self = this; | ||
@@ -103,3 +127,3 @@ if (file.isNull()) { | ||
startScan(file).then(function(builder) { | ||
startScan(file, config.debug).then(function(builder) { | ||
@@ -114,2 +138,11 @@ if (file.isBuffer()) { | ||
file.contents = new Buffer(result); | ||
if (config.sourceMaps && file.sourceMap) { | ||
sourcemaps(file, result.map); | ||
} | ||
if (config.push) { | ||
self.push(file); | ||
} | ||
done(null, file); | ||
@@ -122,5 +155,23 @@ | ||
if (file.isStream()) { | ||
file.contents = new Stream(); | ||
return builder.writeStream(file.contents, done); | ||
return builder.writeStream(file.contents, function(error, result) { | ||
if (error) { | ||
return done(error); | ||
} | ||
if (config.sourceMaps && file.sourceMap) { | ||
sourcemaps(file, result.map); | ||
} | ||
if (config.push) { | ||
self.push(file); | ||
} | ||
done(null, file); | ||
}); | ||
} | ||
@@ -127,0 +178,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
183
22%7397
-81.74%5
25%11
-50%+ Added
+ Added