Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ function addAssetsToStream(paths, files) {
concat = require('gulp-concat'),
isRelativeUrl = require('is-relative-url'),
vfs = require('vinyl-fs'),
extend = require('extend'),
src,
globs,
name = paths.name,
basePath = paths.basePath,
filepaths = files[name].assets,
options = pluginOptions,
type = paths.type,
options = extend({}, pluginOptions),
gulpConcatOptions = {};

if (!filepaths.length) {
Expand Down Expand Up @@ -75,6 +77,9 @@ function addAssetsToStream(paths, files) {

// option for newLine in gulp-concat
if (options.hasOwnProperty('newLine')) {
if (options.newLine === ';' && type === 'css') {
options.newLine = null;
}
gulpConcatOptions.newLine = options.newLine;
}

Expand Down Expand Up @@ -121,7 +126,8 @@ function processAssets(file, basePath, data) {
basePath: basePath,
searchPath: pluginOptions.searchPath,
cwd: file.cwd,
transformPath: pluginOptions.transformPath
transformPath: pluginOptions.transformPath,
type: type
}, files);
}
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"event-stream": "^3.3.4",
"extend": "^3.0.1",
"glob": "^7.1.2",
"gulp-concat": "^2.6.1",
"gulp-if": "^2.0.2",
Expand Down
99 changes: 99 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,72 @@ describe('useref()', function() {
stream.end();
});

it('should concat CSS assets with newLine option', function (done) {
var a = 0,

testFile = getFixture('01.html'),
separator = '\r\n',

stream = useref({newLine: separator}),

buffer1 = new Buffer(fs.readFileSync(path.join('test', 'fixtures', 'css', 'one.css'))),
buffer2 = new Buffer(separator),
buffer3 = new Buffer(fs.readFileSync(path.join('test', 'fixtures', 'css', 'two.css'))),
bufferFinal = Buffer.concat([buffer1, buffer2, buffer3]),

fileFinal = new Vinyl({ contents: bufferFinal });

stream.on('data', function(newFile){
if (a === 1) {
newFile.path.should.equal(path.normalize('./test/fixtures/css/combined.css'));
newFile.contents.toString().should.equal(fileFinal.contents.toString());
}
++a;
});

stream.once('end', function () {
a.should.equal(2);
done();
});

stream.write(testFile);

stream.end();
});

it('should concat CSS assets but skip newLine option if semicolon', function (done) {
var a = 0,

testFile = getFixture('01.html'),
separator = ';',

stream = useref({newLine: separator}),

buffer1 = new Buffer(fs.readFileSync(path.join('test', 'fixtures', 'css', 'one.css'))),
buffer2 = new Buffer('\n'),
buffer3 = new Buffer(fs.readFileSync(path.join('test', 'fixtures', 'css', 'two.css'))),
bufferFinal = Buffer.concat([buffer1, buffer2, buffer3]),

fileFinal = new Vinyl({ contents: bufferFinal });

stream.on('data', function(newFile){
if (a === 1) {
newFile.path.should.equal(path.normalize('./test/fixtures/css/combined.css'));
newFile.contents.toString().should.equal(fileFinal.contents.toString());
}
++a;
});

stream.once('end', function () {
a.should.equal(2);
done();
});

stream.write(testFile);

stream.end();
});

it('should skip concatenation and pass CSS assets through with noconcat option', function(done) {
var a = 0;

Expand Down Expand Up @@ -253,6 +319,39 @@ describe('useref()', function() {
stream.end();
});

it('should concat JS assets with newLine option if semicolon', function(done) {
var a = 0,

testFile = getFixture('02.html'),
separator = ';',

stream = useref({newLine: separator}),

buffer1 = new Buffer(fs.readFileSync(path.join('test', 'fixtures', 'scripts', 'this.js'))),
buffer2 = new Buffer(separator),
buffer3 = new Buffer(fs.readFileSync(path.join('test', 'fixtures', 'scripts', 'that.js'))),
bufferFinal = Buffer.concat([buffer1, buffer2, buffer3]),

fileFinal = new Vinyl({ contents: bufferFinal });

stream.on('data', function(newFile){
if (a === 1) {
newFile.path.should.equal(path.normalize('./test/fixtures/scripts/combined.js'));
newFile.contents.toString().should.equal(fileFinal.contents.toString());
}
++a;
});

stream.once('end', function () {
a.should.equal(2);
done();
});

stream.write(testFile);

stream.end();
});

it('should skip concatenation and pass JS assets through with noconcat option', function(done) {
var a = 0;

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ extend-shallow@^3.0.2:
assign-symbols "^1.0.0"
is-extendable "^1.0.1"

extend@^3.0.0, extend@~3.0.1:
extend@^3.0.0, extend@^3.0.1, extend@~3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"

Expand Down