Parser.prototype._include = function(filename, cb) { debug('[include] %s', filename) this._getProp('files').push(filename) var self = this , origStream = this._stream , origFile = this.file , origLines = this.lines , stream = fs.createReadStream(filename) self._stream = es.pause() self.file = filename self.lines = 0 setupPipeline(stream, self) function cleanup(err) { self._stream = origStream self.file = origFile self.lines = origLines cb(err) } self._stream.on('end', cleanup) stream.on('error', cleanup) }
gulp.task('test16', ['clean'], function () { var ps = es.pause(); var one = gulp.src('src/s1/*.ts') .pipe(ps.pause()) // Pausing stream for 1 sec .pipe(typescript()).on('error', abort) .pipe(gulp.dest('build/test16/s1')); var two = gulp.src('src/s2/*.ts') .pipe(typescript()).on('error', abort) .pipe(gulp.dest('build/test16/s2')); setTimeout(function () { ps.resume() }, 1000); return es.merge(one, two) .pipe(expect([ 'build/test16/s1/a.js', 'build/test16/s2/b.js' ])) .on('end', function () { if (glob.sync('gulp-tsc-tmp-*').length > 0) { throw "Temporary directory is left behind"; } }); });
function promiseToStream(promise) { var stream = es.pause(); promise.then(function(result) { stream.resume(); stream.end(result); }, function(err) { throw err; }); return stream; }
module.exports = function(opts) { 'use strict'; if (!opts) { throw new PluginError(PLUGIN_NAME, 'Missing options array!'); } if (!opts.out && typeof opts.out !== 'string') { throw new PluginError(PLUGIN_NAME, 'Only single file outputs are supported right now, please pass a valid output file name!'); } if (!opts.baseUrl) { throw new PluginError(PLUGIN_NAME, 'Pipeing dirs/files is not supported right now, please specify the base path for your script.'); } // create the stream and save the file name (opts.out will be replaced by a callback function later) var _s = es.pause(), _fName = opts.out; // just a small wrapper around the r.js optimizer, we write a new gutil.File (vinyl) to the Stream, mocking a file, which can be handled // regular gulp plugins (i hope...). // try { optimize(opts, function(text) { _s.resume(); _s.end(new File({ path: _fName, contents: new Buffer(text) })); }); // } catch (err) { // _s.emit('error', err); // } // return the stream for chain .pipe()ing return _s; }
createStream: function(ourGlob, negatives, opt) { if (!negatives) negatives = []; if (!opt) opt = {}; if (typeof opt.cwd !== 'string') opt.cwd = process.cwd(); if (typeof opt.silent !== 'boolean') opt.silent = true; if (typeof opt.nonull !== 'boolean') opt.nonull = false; // create globbing stuff var globber = new glob.Glob(ourGlob, opt); // extract base path because we are too lazy lol var rules = globber.minimatch.set[0]; var basePath = path.normalize(flatten2d(rules).join(path.sep)); // create stream and map events from globber to it var stream = es.pause(); globber.on('error', stream.emit.bind(stream, 'error')); globber.on('end', function(){ stream.end(); }); globber.on('match', function(filename) { stream.write({ cwd: opt.cwd, base: basePath, path: path.resolve(opt.cwd, filename) }); }); if (negatives.length === 0) return stream; // no filtering needed // stream to check against negatives var filterStream = es.map(function(filename, cb) { var matcha = isMatch.bind(null, filename); if (!negatives.every(matcha)) return cb(null, filename); // pass cb(); // ignore }); return stream.pipe(filterStream); },
module.exports = function(filename, options, cb) { if (arguments.length == 2) { cb = options options = {} } var stream = fs.createReadStream(filename) , parser = new Parser() parser.serverRoot = options.serverRoot || '/usr/local/apache' parser.file = filename parser._stream = es.pause() parser.files = [ filename ] parser.name = 'global' parser._stream.on('end', function() { parser.end() }) stream.on('error', function(err) { parser.emit('error', err) }) if (cb) { parser.on('error', cb) parser.on('end', function() { cb(null, parser.config, parser) }) } setupPipeline(stream, parser) return parser }
module.exports = function gulpDurandaljs(userOptions){ var _s = es.pause(), options = _.defaults(userOptions || {}, defOptions), baseDir = options.baseDir, mainFile = path.join(baseDir, options.main), almondWrapper = (function(){ var almond = options.almond, almondPath = typeof(almond) === 'string' ? almond : path.join(__dirname, 'res/custom-almond.js'); if(!almond){ return undefined; } return { start: '(function() {\n' + fs.readFileSync(almondPath, {encoding: 'utf-8'}), end: '}());' }; })(), dynamicModules = (function(){ var mainFileContent = fs.readFileSync(mainFile, {encoding: 'utf-8'}), plugins = mainFileContent.match(/['"]?plugins['"]?\s*:/) ? durandalDynamicPlugins : [], transitions = mainFileContent.match(/['"]?transitions['"]?\s*:/) ? durandalDynamicTransitions : []; return [].concat(plugins, transitions); })(), scannedModules = (function(){ var stripExtension = function(p){ return p.substr(0, p.length - path.extname(p).length); }, expand = function(p){ return glob.sync(path.normalize(path.join(baseDir, p))); }, relativeToBaseDir = path.relative.bind(path, baseDir), jsFiles = _.unique( _.flatten([ mainFile, expand('/**/*.js') ])), jsModules = jsFiles.map(relativeToBaseDir).map(stripExtension), textFiles = _.flatten(_.map(options.textModuleExtensions, function(ext){return expand('/**/*'+ext);})), textModules = textFiles.map(relativeToBaseDir).map(function(m){ return 'text!' + m; }), scannedModules = {js: jsModules, text: textModules}; return scannedModules; })(), allModules = (function(){ var fixSlashes = function(p){ return p.replace(new RegExp('\\\\','g'),'/');}, modules = _.flatten([scannedModules.js, options.extraModules || [], dynamicModules, scannedModules.text]) .map(fixSlashes) .filter(options.moduleFilter); return _.unique(modules); })(), insertRequireModules = (function(){ if(typeof(options.require) === 'string' || _.isArray(options.require)){ return _.flatten([options.require]); } else if(options.require === true || (options.almond && options.require !== false)){ return [allModules[0]]; } return undefined; })(), rjsCb = function(text, sourceMapText){ var output = options.output || path.basename(mainFile), mapOutput = output + '.map'; _s.resume(); text += '//# sourceMappingURL=' + path.basename(mapOutput); _s.write(new gutil.File({ path: output, contents: new Buffer(text) })); if(sourceMapText){ _s.write(new gutil.File({ path: mapOutput, contents: new Buffer(sourceMapText) })); } _s.end(); }, errCb = function(err){ _s.resume(); _s.emit('error', new gutil.PluginError(PLUGIN_NAME, err)); _s.end(); }; var rjsConfig = { logLevel: options.verbose ? 0 : 4, baseUrl : baseDir, mainConfigFile: mainFile, include : allModules, out: rjsCb, optimize: options.minify ? 'uglify2' : 'none', preserveLicenseComments: !options.minify, generateSourceMaps : true, insertRequire : insertRequireModules, wrap: almondWrapper }; rjsConfig = _.defaults(options.requirejs, rjsConfig); requirejs.optimize(rjsConfig, null, errCb); _s.on('error', function(e){ gutil.log('Durandal ' + gutil.colors.red(e.message)); }); return _s; };