gulp-strip-code
Advanced tools
Comparing version 0.1.2 to 0.1.3
11
index.js
@@ -10,4 +10,6 @@ var es = require('event-stream'); | ||
options.end_comment = (typeof options.end_comment === 'undefined') ? 'end-test-code' : options.end_comment; | ||
var pattern = options.pattern || new RegExp("[\\t ]*\\/\\* ?" + options.start_comment + " ?\\*\\/[\\s\\S]*?\\/\\* ?" + options.end_comment + " ?\\*\\/[\\t ]*\\n?", "g"); | ||
options.keep_comments = typeof options.keep_comments !== 'undefined'; | ||
var pattern = options.pattern || new RegExp("([\\t ]*\\/\\* ?" + options.start_comment + " ?\\*\\/)[\\s\\S]*?(\\/\\* ?" + options.end_comment + " ?\\*\\/[\\t ]*\\n?)", "g"); | ||
if (isStream) { | ||
@@ -18,3 +20,8 @@ return callback(new Error('gulp-strip-code: Streaming not supported'), file); | ||
if (isBuffer) { | ||
file.contents = new Buffer(String(file.contents).replace(pattern, "")); | ||
if(options.keep_comments){ | ||
file.contents = new Buffer(String(file.contents).replace(pattern, "$1\n$2")); | ||
} | ||
else{ | ||
file.contents = new Buffer(String(file.contents).replace(pattern, "")); | ||
} | ||
return callback(null, file); | ||
@@ -21,0 +28,0 @@ } |
{ | ||
"name": "gulp-strip-code", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A gulp plugin to remove parts of code based on regular expressions.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -69,2 +69,9 @@ gulp-strip-code | ||
#### options.keep_comments | ||
Type: `Boolean` | ||
Default value: `false` | ||
Sets the behaviour to keep the identifying comments or not. | ||
Setting a truthy value for keep_comments will enable it. | ||
#### options.pattern | ||
@@ -89,2 +96,4 @@ Type: `RegExp` | ||
* 0.1.3 keep comments option added | ||
* 0.1.2 default values added | ||
* 0.1.0 Initial release | ||
@@ -91,0 +100,0 @@ |
@@ -59,2 +59,23 @@ var stripCode = require('../'); | ||
}); | ||
it('should remove code from start_comment to end_comment on a buffer but keep comments', function(done) { | ||
var file = new gutil.File({ | ||
path: 'test/fixtures/originalkeepcomments.css', | ||
cwd: 'test/', | ||
base: 'test/fixtures', | ||
contents: fs.readFileSync('test/fixtures/originalkeepcomments.css') | ||
}); | ||
var stream = stripCode({ | ||
start_comment: "keepcomments", | ||
end_comment: "end-keepcomments", | ||
keep_comments: true | ||
}); | ||
stream.on('data', function(newFile) { | ||
should.exist(newFile); | ||
should.exist(newFile.contents); | ||
String(newFile.contents).should.equal(fs.readFileSync('test/expected/modifiedkeepcomments.css', 'utf8')); | ||
done(); | ||
}); | ||
stream.write(file); | ||
stream.end(); | ||
}); | ||
it('should error on a stream', function(done) { | ||
@@ -61,0 +82,0 @@ var file = new gutil.File({ |
Sorry, the diff of this file is not supported yet
10079
12
153
102