Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-assign

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-assign - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

README.md

14

finish.js
'use strict';
module.exports = function(
OUTPUT, output, index, outputs,
output, index, outputs,
count, length,

@@ -9,10 +9,12 @@ snippets,

) {
outputs[index] = OUTPUT.replace('${output}', output);
outputs[index] = output;
if (count === length) {
var source = snippets.reduce(function(source, snippet, index) {
return source.concat(snippet, outputs[index]);
}, []).join('');
file.contents = new Buffer(source);
if (length) {
var source = snippets.reduce(function(source, snippet, index) {
return source.concat(snippet, outputs[index]);
}, []).join('');
file.contents = new Buffer(source);
}
callback(null, file);
}
};

@@ -20,4 +20,4 @@ 'use strict';

SPLITS = /<!--\s*build:(?:styles|scripts)(?::[\w-]*)?\s*(?:\s+\S+|"[^"]+"|'[^']+')\s*-->[^]*?<!--\s*endbuild\s*-->/,
BLOCKS = /<!--\s*build:(styles|scripts)(?::([\w-]*))?\s*(\s+\S+|"[^"]+"|'[^']+')\s*-->([^]*?)<!--\s*endbuild\s*-->/g,
SPLITS = /<!--\s*build:(?:styles|scripts)(?::[\w-]*)?\s*(?:\s+\S+?|"[^"]+"|'[^']+')\s*-->[^]*?<!--\s*endbuild\s*-->/,
BLOCKS = /<!--\s*build:(styles|scripts)(?::([\w-]*))?\s*(\s+\S+?|"[^"]+"|'[^']+')\s*-->([^]*?)<!--\s*endbuild\s*-->/g,
INPUTS = {

@@ -60,3 +60,3 @@ styles: /<\s*link\b[^>]*\bhref\s*=\s*("[^"]+"|'[^']+'|[^\s>]+)[^>]*>/gi,

var SOURCE = new String(file.contents),
var SOURCE = String(file.contents),
DIRECTORY = pathDirname(file.path),

@@ -81,5 +81,8 @@ snippets = SOURCE.split(SPLITS),

if (!exist(assignees, type, name)) {
length --;
outputs[index] = source;
return;
return finish(
source, index, outputs,
count, -- length,
snippets,
file, callback
);
}

@@ -92,11 +95,13 @@

assignee(inputs, outputRelative)
assignee(inputs, {
original: outputOriginal,
relative: outputRelative
})
.on('error', function(error) {
callback(new PluginError(PLUGIN_NAME, error));
})
.on('error', callback)
.on('end', function() {
var output = OUTPUTS[type].replace('${output}', outputOriginal);
finish(
OUTPUTS[type], outputOriginal, index, outputs,
output, index, outputs,
++ count, length,

@@ -116,7 +121,8 @@ snippets,

if (error) {
return callback(new PluginError(PLUGIN_NAME, error));
return callback(error);
}
output = OUTPUTS[type].replace('${output}', output);
finish(
OUTPUTS[type], output, index, outputs,
output, index, outputs,
++ count, length,

@@ -129,11 +135,11 @@ snippets,

} else {
length --;
outputs[index] = source;
finish(
source, index, outputs,
count, -- length,
snippets,
file, callback
);
}
});
if (length === 0) {
callback(null, file);
}
});
};
{
"name": "gulp-assign",
"version": "0.1.0",
"version": "0.2.0",
"main": "index.js",

@@ -14,3 +14,4 @@ "dependencies": {

"gulp-concat": "^2.6.0",
"mocha": "^2.3.3"
"mocha": "^2.3.3",
"sinon": "^1.17.2"
},

@@ -33,3 +34,3 @@ "scripts": {

"author": "",
"description": ""
"description": "Detects JavaScript/CSS references in HTML and passes to others plugins"
}
'use strict';
process.chdir(__dirname);
var gulp = require('gulp'),

@@ -8,51 +8,181 @@ del = require('del'),

assign = require('..'),
expect = require('chai').expect;
expect = require('chai').expect,
sinon = require('sinon'),
through = require('through2'),
gutil = require('gulp-util');
describe('gulp-assign', function() {
process.chdir(__dirname);
let src = 'src',
dst = 'dist';
before(function() {
return del(dst);
});
describe('gulp-assign', function() {
it('quirky', function(done) {
it('default', function(done) {
let assignees = {
main: function(inputs, output, callback) {
expect(inputs).to.have.length(6);
expect(output.relative).not.to.match(/^\//);
callback(null, output.original);
},
void: function(inputs, output) {
expect(inputs).to.have.length(3);
expect(output.relative).not.to.match(/^\//);
let spy = sinon.spy(function(file, encoding, callback) {
expect(file.isNull()).to.be.true;
callback(null, file);
});
return gulp.src(inputs, {base: src})
.pipe(through.obj(spy))
.pipe(concat(output.relative))
.pipe(gulp.dest(dst))
.on('end', function() {
expect(spy.called).to.be.false;
});
},
mutational: function(inputs, output, callback) {
expect(inputs).to.be.empty;
expect(output.relative).to.equal('outline');
callback(null, output.original);
}
};
let src = 'src',
dst = 'dist';
gulp.src(`${src}/quirky.*.html`)
.pipe(assign({
styles: assignees,
scripts: assignees
}))
.pipe(gulp.dest(dst))
.on('end', done);
});
del(dst).then(function() {
it('available', function(done) {
// let results = [];
let assignees = sinon.spy(function(inputs, output, callback) {
let outputOriginal = output.original,
outputRelative = output.relative;
counters[outputOriginal] = counters[outputOriginal] || 0;
counters[outputOriginal] ++;
expect(inputs).to.be.empty;
expect(outputRelative).not.to.match(/^\//);
callback(null, outputOriginal);
});
gulp.src(`${src}/**/*.html`)
.pipe(assign({
styles: {
default: function(inputs, output, callback) {
gulp.src(inputs, {base: src})
.pipe(concat(output.relative))
.pipe(gulp.dest(dst));
callback(null, output.original);
},
vendor: function(inputs, output) {
return gulp.src(inputs, {base: src})
.pipe(concat(output))
.pipe(gulp.dest(dst));
}
},
scripts: function(inputs, output, callback) {
gulp.src(inputs, {base: src})
.pipe(concat(output.relative))
.pipe(gulp.dest(dst));
callback(null, output.original);
}
}))
.pipe(gulp.dest(dst))
.on('end', function() {
// let result = results[0];
// for (let i = 1, len = results.length; i < len; i ++) {
// expect(result).to.deep.equal(results[i]);
// }
done();
let counters = {};
gulp.src(`${src}/available.*.html`)
.pipe(assign({
styles: assignees,
scripts: assignees
}))
.pipe(gulp.dest(dst))
.on('end', function() {
expect(counters).to.have.all.keys([
'/aaa.css',
'/aaa.js',
'/bbb.css',
'/bbb.js',
'/ccc.css',
'/ccc.js',
'/ddd.css',
'/ddd.js'
]);
expect(counters).property('/aaa.css').to.equal(12);
expect(counters).property('/aaa.js').to.equal(12);
expect(counters).property('/bbb.css').to.equal(6);
expect(counters).property('/bbb.js').to.equal(6);
expect(counters).property('/ccc.css').to.equal(12);
expect(counters).property('/ccc.js').to.equal(12);
expect(counters).property('/ddd.css').to.equal(18);
expect(counters).property('/ddd.js').to.equal(18);
expect(assignees.callCount).to.equal((12 + 6 + 12 + 18) * 2);
done();
});
});
it('working', function(done) {
let assignees = {
default: function(inputs, output) {
let spy = sinon.spy(function(file, encoding, callback) {
expect(file.isNull()).to.be.false;
callback(null, file);
});
expect(inputs).to.have.length(4);
expect(output.relative).not.to.match(/^\//);
return gulp.src(inputs, {base: src})
.pipe(through.obj(spy))
.pipe(concat(output.relative))
.pipe(gulp.dest(dst))
.on('end', function() {
expect(spy.callCount).to.equal(3);
});
},
vendor: function(inputs, output) {
expect(inputs).to.have.length(2);
expect(output.relative).not.to.match(/^\//);
return gulp.src(inputs, {base: src})
.pipe(concat(output.relative))
.pipe(gulp.dest(dst));
}
};
gulp.src(`${src}/*/*.html`)
.pipe(assign({
styles: assignees,
scripts: assignees
}))
.pipe(gulp.dest(dst))
.on('end', done);
});
it('wrong callback', function(done) {
let message = 'bad callback';
let spy = sinon.spy(function(error) {
expect(error).to.have.property('message').and.equal(message);
// gutil.log(gutil.colors.red(`Error: ${error.message}`));
this.emit('end');
});
gulp.src(`${src}/wrong.html`)
.pipe(assign({
styles: function(inputs, output, callback) {
callback(new Error(message));
}
}))
.on('error', spy)
.on('end', function() {
expect(spy.called).to.be.true;
done();
});
});
it('wrong stream', function(done) {
let message = 'bad stream';
let spy = sinon.spy(function(error) {
expect(error).to.have.property('message').and.equal(message);
// gutil.log(gutil.colors.red(`Error: ${error.message}`));
this.emit('end');
});
gulp.src(`${src}/wrong.html`)
.pipe(assign({
scripts: function(inputs, output) {
return gulp.src(inputs, {base: src})
.pipe(through.obj(function() {
this.emit('error', new Error(message));
}));
}
}))
.on('error', spy)
.on('end', function() {
expect(spy.called).to.be.true;
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc