pax_global_header00006660000000000000000000000064130121332200014475gustar00rootroot0000000000000052 comment=c179a8c491047eb980459fea6d0e2fd65d6d0ad1 gulp-concat-2.6.1/000077500000000000000000000000001301213322000137175ustar00rootroot00000000000000gulp-concat-2.6.1/.editorconfig000066400000000000000000000002561301213322000163770ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = false gulp-concat-2.6.1/.gitignore000066400000000000000000000001041301213322000157020ustar00rootroot00000000000000.DS_Store *.log node_modules build *.node components coverage *.swp gulp-concat-2.6.1/.travis.yml000066400000000000000000000001151301213322000160250ustar00rootroot00000000000000sudo: false language: node_js node_js: - "5" - "4" - "0.12" - "0.10" gulp-concat-2.6.1/LICENSE000077500000000000000000000020511301213322000147250ustar00rootroot00000000000000Copyright (c) 2016 Contra Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gulp-concat-2.6.1/README.md000066400000000000000000000043511301213322000152010ustar00rootroot00000000000000![status](https://secure.travis-ci.org/contra/gulp-concat.svg?branch=master) ## Installation Install package with NPM and add it to your development dependencies: `npm install --save-dev gulp-concat` ## Information
Packagegulp-concat
Description Concatenates files
Node Version >= 0.10
## Usage ```js var concat = require('gulp-concat'); gulp.task('scripts', function() { return gulp.src('./lib/*.js') .pipe(concat('all.js')) .pipe(gulp.dest('./dist/')); }); ``` This will concat files by your operating systems newLine. It will take the base directory from the first file that passes through it. Files will be concatenated in the order that they are specified in the `gulp.src` function. For example, to concat `./lib/file3.js`, `./lib/file1.js` and `./lib/file2.js` in that order, the following code will create a task to do that: ```js var concat = require('gulp-concat'); gulp.task('scripts', function() { return gulp.src(['./lib/file3.js', './lib/file1.js', './lib/file2.js']) .pipe(concat('all.js')) .pipe(gulp.dest('./dist/')); }); ``` To change the newLine simply pass an object as the second argument to concat with newLine being whatever (\r\n if you want to support any OS to look at it) For instance: ```js .pipe(concat('main.js', {newLine: ';'})) ``` To specify `cwd`, `path` and other [vinyl](https://github.com/wearefractal/vinyl) properties, gulp-concat accepts `Object` as first argument: ```js var concat = require('gulp-concat'); gulp.task('scripts', function() { return gulp.src(['./lib/file3.js', './lib/file1.js', './lib/file2.js']) .pipe(concat({ path: 'new.js', stat: { mode: 0666 }})) .pipe(gulp.dest('./dist')); }); ``` This will concat files into `./dist/new.js`. ### Source maps Source maps can be generated by using [gulp-sourcemaps](https://www.npmjs.org/package/gulp-sourcemaps): ```js var gulp = require('gulp'); var concat = require('gulp-concat'); var sourcemaps = require('gulp-sourcemaps'); gulp.task('javascript', function() { return gulp.src('src/**/*.js') .pipe(sourcemaps.init()) .pipe(concat('all.js')) .pipe(sourcemaps.write()) .pipe(gulp.dest('dist')); }); ``` gulp-concat-2.6.1/index.js000066400000000000000000000047261301213322000153750ustar00rootroot00000000000000'use strict'; var through = require('through2'); var path = require('path'); var File = require('vinyl'); var Concat = require('concat-with-sourcemaps'); // file can be a vinyl file object or a string // when a string it will construct a new one module.exports = function(file, opt) { if (!file) { throw new Error('gulp-concat: Missing file option'); } opt = opt || {}; // to preserve existing |undefined| behaviour and to introduce |newLine: ""| for binaries if (typeof opt.newLine !== 'string') { opt.newLine = '\n'; } var isUsingSourceMaps = false; var latestFile; var latestMod; var fileName; var concat; if (typeof file === 'string') { fileName = file; } else if (typeof file.path === 'string') { fileName = path.basename(file.path); } else { throw new Error('gulp-concat: Missing path in file options'); } function bufferContents(file, enc, cb) { // ignore empty files if (file.isNull()) { cb(); return; } // we don't do streams (yet) if (file.isStream()) { this.emit('error', new Error('gulp-concat: Streaming not supported')); cb(); return; } // enable sourcemap support for concat // if a sourcemap initialized file comes in if (file.sourceMap && isUsingSourceMaps === false) { isUsingSourceMaps = true; } // set latest file if not already set, // or if the current file was modified more recently. if (!latestMod || file.stat && file.stat.mtime > latestMod) { latestFile = file; latestMod = file.stat && file.stat.mtime; } // construct concat instance if (!concat) { concat = new Concat(isUsingSourceMaps, fileName, opt.newLine); } // add file to concat instance concat.add(file.relative, file.contents, file.sourceMap); cb(); } function endStream(cb) { // no files passed in, no file goes out if (!latestFile || !concat) { cb(); return; } var joinedFile; // if file opt was a file path // clone everything from the latest file if (typeof file === 'string') { joinedFile = latestFile.clone({contents: false}); joinedFile.path = path.join(latestFile.base, file); } else { joinedFile = new File(file); } joinedFile.contents = concat.content; if (concat.sourceMapping) { joinedFile.sourceMap = JSON.parse(concat.sourceMap); } this.push(joinedFile); cb(); } return through.obj(bufferContents, endStream); }; gulp-concat-2.6.1/package.json000066400000000000000000000013751301213322000162130ustar00rootroot00000000000000{ "name": "gulp-concat", "description": "Concatenates files", "version": "2.6.1", "repository": "contra/gulp-concat", "author": "Contra (http://contra.io/)", "files": [ "index.js" ], "keywords": [ "gulpplugin" ], "dependencies": { "concat-with-sourcemaps": "^1.0.0", "through2": "^2.0.0", "vinyl": "^2.0.0" }, "devDependencies": { "gulp": "^3.8.7", "gulp-sourcemaps": "^2.2.0", "istanbul": "^0.4.5", "mocha": "^3.0.0", "mocha-lcov-reporter": "^1.2.0", "should": "^11.0.0", "stream-array": "^1.0.1", "stream-assert": "^2.0.1" }, "scripts": { "test": "mocha", "coverage": "istanbul cover _mocha" }, "engines": { "node": ">= 0.10" }, "license": "MIT" } gulp-concat-2.6.1/test/000077500000000000000000000000001301213322000146765ustar00rootroot00000000000000gulp-concat-2.6.1/test/fixtures/000077500000000000000000000000001301213322000165475ustar00rootroot00000000000000gulp-concat-2.6.1/test/fixtures/first.js000066400000000000000000000000261301213322000202320ustar00rootroot00000000000000console.log('first'); gulp-concat-2.6.1/test/fixtures/second.js000066400000000000000000000000271301213322000203570ustar00rootroot00000000000000console.log('second'); gulp-concat-2.6.1/test/main.js000066400000000000000000000134101301213322000161570ustar00rootroot00000000000000var concat = require('../'); var should = require('should'); var fs = require('fs'); var path = require('path'); var assert = require('stream-assert'); var test = require('./test-stream'); var File = require('vinyl'); var gulp = require('gulp'); var sourcemaps = require('gulp-sourcemaps'); require('mocha'); var fixtures = function (glob) { return path.join(__dirname, 'fixtures', glob); } var thirdBase = __dirname, thirdFile = 'third.js', thirdPath = path.join(thirdBase, thirdFile); describe('gulp-concat', function() { // Create a third fixture, so we'll know it has the latest modified stamp. // It must not live in the test/fixtures directory, otherwise the test // 'should take path from latest file' will be meaningless. before(function(done){ fs.writeFile(thirdPath, 'console.log(\'third\');\n', done); }); // We'll delete it when we're done. after(function(done){ fs.unlink(thirdPath, done); }); describe('concat()', function() { it('should throw, when arguments is missing', function () { concat.should.throw('gulp-concat: Missing file option'); }); it('should ignore null files', function (done) { var stream = concat('test.js'); stream .pipe(assert.length(0)) .pipe(assert.end(done)); stream.write(new File()); stream.end(); }); it('should emit error on streamed file', function (done) { gulp.src(fixtures('*'), { buffer: false }) .pipe(concat('test.js')) .once('error', function (err) { err.message.should.eql('gulp-concat: Streaming not supported'); done(); }); }); it('should concat one file', function (done) { test('wadap') .pipe(concat('test.js')) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.contents.toString().should.eql('wadap'); })) .pipe(assert.end(done)); }); it('should concat multiple files', function (done) { test('wadap', 'doe') .pipe(concat('test.js')) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.contents.toString().should.eql('wadap\ndoe'); })) .pipe(assert.end(done)); }); it('should concat buffers', function (done) { test([65, 66], [67, 68], [69, 70]) .pipe(concat('test.js')) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.contents.toString().should.eql('AB\nCD\nEF'); })) .pipe(assert.end(done)); }); it('should preserve mode from files', function (done) { test('wadaup') .pipe(concat('test.js')) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.stat.mode.should.eql(0666); })) .pipe(assert.end(done)); }); it('should take path from latest file', function (done) { gulp.src([fixtures('*'), thirdPath]) .pipe(concat('test.js')) .pipe(assert.length(1)) .pipe(assert.first(function (newFile) { var newFilePath = path.resolve(newFile.path); var expectedFilePath = path.resolve(path.join(thirdBase, 'test.js')); newFilePath.should.equal(expectedFilePath); })) .pipe(assert.end(done)); }); it('should preserve relative path from files', function (done) { test('wadap', 'doe') .pipe(concat('test.js')) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.relative.should.eql('test.js'); })) .pipe(assert.end(done)); }); it('should support source maps', function (done) { gulp.src(fixtures('*')) .pipe(sourcemaps.init()) .pipe(concat('all.js')) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.sourceMap.sources.should.have.length(2); d.sourceMap.file.should.eql('all.js'); })) .pipe(assert.end(done)); }); describe('should not fail if no files were input', function () { it('when argument is a string', function(done) { var stream = concat('test.js'); stream.end(); done(); }); it('when argument is an object', function(done) { var stream = concat({path: 'new.txt'}); stream.end(); done(); }); }); describe('options', function () { it('should support newLine', function (done) { test('wadap', 'doe') .pipe(concat('test.js', {newLine: '\r\n'})) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.contents.toString().should.eql('wadap\r\ndoe'); })) .pipe(assert.end(done)); }) it('should support empty newLine', function (done) { test('wadap', 'doe') .pipe(concat('test.js', {newLine: ''})) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.contents.toString().should.eql('wadapdoe'); })) .pipe(assert.end(done)); }) }); describe('with object as argument', function () { it('should throw without path', function () { (function() { concat({ path: undefined }); }).should.throw('gulp-concat: Missing path in file options'); }); it('should create file based on path property', function (done) { test('wadap') .pipe(concat({path: 'new.txt'})) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.path.should.eql('new.txt'); })) .pipe(assert.end(done)); }); it('should calculate relative path from cwd and path in arguments', function (done) { test('wadap') .pipe(concat({cwd: path.normalize('/home/contra'), path: path.normalize('/home/contra/test/new.txt')})) .pipe(assert.length(1)) .pipe(assert.first(function (d) { d.relative.should.eql(path.normalize('test/new.txt')); })) .pipe(assert.end(done)); }); }); }); }); gulp-concat-2.6.1/test/test-stream.js000066400000000000000000000007071301213322000175100ustar00rootroot00000000000000var array = require('stream-array'); var File = require('vinyl'); module.exports = function () { var args = Array.prototype.slice.call(arguments); var i = 0; function create(contents) { return new File({ cwd: '/home/contra/', base: '/home/contra/test', path: '/home/contra/test/file' + (i++).toString() + '.js', contents: new Buffer(contents), stat: {mode: 0666} }); } return array(args.map(create)) };