diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 09e661e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: node_js -node_js: - - "node" - - "iojs" - - "7" - - "6" - - "5" - - "4" -script: - npm test diff --git a/README.md b/README.md index 9758045..95ccaf9 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,20 @@ # [gulp](http://gulpjs.com)-strip-comments -[![Build Status](https://img.shields.io/travis/RnbWd/gulp-strip-comments.svg?style=flat-square)](https://travis-ci.org/RnbWd/gulp-strip-comments) [![Coverage Status](https://coveralls.io/repos/RnbWd/gulp-strip-comments/badge.svg?branch=master&service=github)](https://coveralls.io/github/RnbWd/gulp-strip-comments?branch=master) [![downloads](https://img.shields.io/npm/dt/gulp-strip-comments.svg?style=flat-square)](https://www.npmjs.com/package/gulp-strip-comments) -[![decomment](https://img.shields.io/badge/decomment-v0.9.0-blue.svg?style=flat-square)](https://github.com/vitaly-t/decomment) -[![David](https://david-dm.org/rnbwd/gulp-strip-comments.svg?style=flat-square)](https://david-dm.org/rnbwd/gulp-strip-comments) +[![decomment](https://img.shields.io/badge/decomment-v0.9.5-blue.svg?style=flat-square)](https://github.com/vitaly-t/decomment) > [decomment](https://github.com/vitaly-t/decomment) - removes comments from JSON, JavaScript, CSS, HTML, etc. [![NPM](https://nodei.co/npm/gulp-strip-comments.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/gulp-strip-comments/) - ## Features -* Removes both single and multi-line comments from JSON, JavaScript and CSS/Text -* Automatically recognizes HTML and removes all `` from it -* Does not change layout / formatting of the original document -* Removes lines that have only comments on them -* Compatible with CSS3, JSON5 and ECMAScript 6 +- Removes both single and multi-line comments from JSON, JavaScript and CSS/Text +- Automatically recognizes HTML and removes all `` from it +- Does not change layout / formatting of the original document +- Removes lines that have only comments on them +- Compatible with CSS3, JSON5 and ECMAScript 6 The library does not support mixed content - HTML with JavaScript or CSS in it. Once the input code is recognized as HTML, only the HTML comments will be removed from it. @@ -29,7 +26,6 @@ For JSON and JavaScript this library uses [esprima] to guarantee correct process As an example, it can process [AngularJS 1.5 Core](https://code.angularjs.org/1.5.0/angular.js) in under 100ms, which is 1.1MB ~ 30,000 lines of JavaScript. - ## Install ```sh @@ -39,13 +35,11 @@ $ npm install --save-dev gulp-strip-comments ## Usage ```js -var gulp = require('gulp'); -var strip = require('gulp-strip-comments'); +var gulp = require("gulp"); +var strip = require("gulp-strip-comments"); -gulp.task('default', function () { - return gulp.src('template.js') - .pipe(strip()) - .pipe(gulp.dest('dist')); +gulp.task("default", function () { + return gulp.src("template.js").pipe(strip()).pipe(gulp.dest("dist")); }); ``` @@ -70,10 +64,10 @@ If [esprima] fails to validate the code, it will throw a parsing error. When suc ##### options.safe ⇒ Boolean -* `false (default)` - remove all multi-line comments -* `true` - keep special multi-line comments that begin with: - - `
test
'); - var stream = strip.html(); - stream.once('data', function (newFile) { - var data = newFile.contents; - expect(data).toBeTruthy(); - expect(data.toString()).toBe("\
test
"); - }); - stream.once('end', done); - stream.write(fakeFile); - stream.end(); + it("should strip html", function (done) { + var fakeFile = getBuffer( + "
test
", + ); + var stream = strip.html(); + stream.once("data", function (newFile) { + var data = newFile.contents; + expect(data).toBeTruthy(); + expect(data.toString()).toBe("
test
"); }); - + stream.once("end", done); + stream.write(fakeFile); + stream.end(); + }); }); //////////////////////// // Negative tests; describe("Negative:", function () { - describe("with null buffer", function () { - it('must return null data', function (done) { - var fakeFile = getNull(); - var stream = strip(); - stream.once('data', function (newFile) { - expect(newFile.contents).toBeNull(); - }); - stream.once('end', done); - stream.write(fakeFile); - stream.end(); - }); + describe("with null buffer", function () { + it("must return null data", function (done) { + var fakeFile = getNull(); + var stream = strip(); + stream.once("data", function (newFile) { + expect(newFile.contents).toBeNull(); + }); + stream.once("end", done); + stream.write(fakeFile); + stream.end(); }); + }); - describe("with a stream", function () { - var err; - it('must throw an error', function (done) { - try { - var fakeFile = getStream(); - var stream = strip(); - stream.write(fakeFile); // this will throw an error; - } catch (e) { - err = e; - done(); - } - expect(err instanceof PluginError); - expect(err.message).toBe("Streaming not supported."); - }); + describe("with a stream", function () { + var err; + it("must throw an error", function (done) { + try { + var fakeFile = getStream(); + var stream = strip(); + stream.write(fakeFile); // this will throw an error; + } catch (e) { + err = e; + done(); + } + expect(err instanceof PluginError); + expect(err.message).toBe("Streaming not supported."); }); + }); + + describe("with a bad data", function () { + var err; + it("must throw an error", function (done) { + try { + var fakeFile = getBuffer("/*! special */ js code /* normal */"); + var stream = strip("help"); + stream.write(fakeFile); + } catch (e) { + err = e; + done(); + } + expect(err instanceof PluginError); + expect(err.message).toBe("Parameter 'options' must be an object."); + }); + }); }); function getFakeDest(content) { - return new Vinyl({ - path: './test/fixture/test.js', - cwd: './test/', - base: './test/fixture/', - contents: content - }); + return new Vinyl({ + path: "./test/fixture/test.js", + cwd: "./test/", + base: "./test/fixture/", + contents: content, + }); } function getBuffer(bufferContent) { - return getFakeDest(new Buffer(bufferContent)); + return getFakeDest(Buffer.from(bufferContent)); } function getNull() { - return getFakeDest(null); + return getFakeDest(null); } function getStream() { - return getFakeDest(stream.PassThrough()); + return getFakeDest(stream.PassThrough()); }