node-gulp-4.0.2+~cs38.20.35/000077500000000000000000000000001415667007300150405ustar00rootroot00000000000000node-gulp-4.0.2+~cs38.20.35/.ci/000077500000000000000000000000001415667007300155115ustar00rootroot00000000000000node-gulp-4.0.2+~cs38.20.35/.ci/.azure-pipelines-steps.yml000066400000000000000000000020661415667007300225660ustar00rootroot00000000000000steps: - script: npm i -g npm@$(npm_version) displayName: Use legacy npm version $(npm_version) condition: ne(variables['npm_version'], '') - task: NodeTool@0 inputs: versionSpec: '$(node_version)' displayName: Use Node $(node_version) - script: npm install displayName: npm install - script: npm test displayName: Run tests - script: npm run coveralls displayName: Run coveralls env: # Pretend to be AppVeyor for now APPVEYOR: true APPVEYOR_BUILD_NUMBER: $(Build.BuildNumber) APPVEYOR_BUILD_ID: $(Agent.OS)_$(node_version) APPVEYOR_REPO_COMMIT: $(Build.SourceVersion) APPVEYOR_REPO_BRANCH: $(Build.SourceBranchName) # Overwrite the AppVeyor Service Name COVERALLS_SERVICE_NAME: Azure Pipelines COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) COVERALLS_PARALLEL: true CI_PULL_REQUEST: $(System.PullRequest.PullRequestNumber) - script: npm run azure-pipelines displayName: Write tests to xml - task: PublishTestResults@2 inputs: testResultsFiles: '**/test.xunit' condition: succeededOrFailed() node-gulp-4.0.2+~cs38.20.35/.ci/.azure-pipelines.yml000066400000000000000000000040501415667007300214250ustar00rootroot00000000000000trigger: - master - releases/* jobs: - job: Test_Linux displayName: Run Tests on Linux pool: vmImage: "Ubuntu 16.04" strategy: matrix: Node_v12: node_version: 12 Node_v10: node_version: 10 Node_v8: node_version: 8 Node_v6: node_version: 6 Node_v4: node_version: 4 Node_v0_12: node_version: 0.12 Node_v0_10: node_version: 0.10 steps: - template: .azure-pipelines-steps.yml - job: Test_Windows displayName: Run Tests on Windows pool: vmImage: vs2017-win2016 strategy: matrix: Node_v12: node_version: 12 Node_v10: node_version: 10 Node_v8: node_version: 8 Node_v6: node_version: 6 Node_v4: node_version: 4 npm_version: 2 Node_v0_12: node_version: 0.12 npm_version: 2 Node_v0_10: node_version: 0.10 npm_version: 2 steps: - template: .azure-pipelines-steps.yml - job: Test_MacOS displayName: Run Tests on MacOS pool: vmImage: macos-10.13 strategy: matrix: Node_v12: node_version: 12 Node_v10: node_version: 10 Node_v8: node_version: 8 Node_v6: node_version: 6 Node_v4: node_version: 4 Node_v0_12: node_version: 0.12 Node_v0_10: node_version: 0.10 steps: - template: .azure-pipelines-steps.yml - job: Notify_Coveralls displayName: Notify Coveralls that the parallel report is done pool: vmImage: "Ubuntu 16.04" dependsOn: - Test_Linux - Test_Windows - Test_MacOS steps: - script: curl -k https://coveralls.io/webhook?repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$BUILD_NAME&payload[status]=done" env: COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) BUILD_NAME: $(Build.BuildNumber) node-gulp-4.0.2+~cs38.20.35/.editorconfig000066400000000000000000000003261415667007300175160ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true end_of_line = lf [*.md] trim_trailing_whitespace = false node-gulp-4.0.2+~cs38.20.35/.eslintignore000066400000000000000000000000441415667007300175410ustar00rootroot00000000000000test/fixtures/out test/fixtures/tmp node-gulp-4.0.2+~cs38.20.35/.eslintrc000066400000000000000000000000301415667007300166550ustar00rootroot00000000000000{ "extends": "gulp" } node-gulp-4.0.2+~cs38.20.35/.gitattributes000066400000000000000000000000161415667007300177300ustar00rootroot00000000000000* text eol=lf node-gulp-4.0.2+~cs38.20.35/.github/000077500000000000000000000000001415667007300164005ustar00rootroot00000000000000node-gulp-4.0.2+~cs38.20.35/.github/support.yml000066400000000000000000000001421415667007300206340ustar00rootroot00000000000000# Configuration for support-requests - https://github.com/dessant/support-requests _extends: gulp node-gulp-4.0.2+~cs38.20.35/.npmrc000066400000000000000000000000231415667007300161530ustar00rootroot00000000000000package-lock=false node-gulp-4.0.2+~cs38.20.35/.travis.yml000066400000000000000000000002131415667007300171450ustar00rootroot00000000000000sudo: false language: node_js node_js: - '12' - '10' - '8' - '6' - '4' - '0.12' - '0.10' after_script: - npm run coveralls node-gulp-4.0.2+~cs38.20.35/LICENSE000066400000000000000000000021421415667007300160440ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Blaine Bublitz, Eric Schoffstall and other contributors 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. node-gulp-4.0.2+~cs38.20.35/README.md000066400000000000000000000247341415667007300163310ustar00rootroot00000000000000

# undertaker [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] ## Usage ```js var fs = require('fs'); var Undertaker = require('undertaker'); var taker = new Undertaker(); taker.task('task1', function(cb){ // do things cb(); // when everything is done }); taker.task('task2', function(){ return fs.createReadStream('./myFile.js') .pipe(fs.createWriteStream('./myFile.copy.js')); }); taker.task('task3', function(){ return new Promise(function(resolve, reject){ // do things resolve(); // when everything is done }); }); taker.task('combined', taker.series('task1', 'task2')); taker.task('all', taker.parallel('combined', 'task3')); ``` ## API __Task functions can be completed in any of the ways supported by [`async-done`][async-resolution]__ ### `new Undertaker([registryInstance])` The constructor is used to create a new instance of `Undertaker`. Each instance of `Undertaker` gets its own instance of a registry. By default, the registry is an instance of [`undertaker-registry`][undertaker-registry] but it can be an instance of any other registry that follows the [Custom Registries API][custom-registries]. To use a custom registry, pass a custom registry instance (`new CustomRegistry([options])`) when instantiating a new `Undertaker` instance. This will use the custom registry instance for that `Undertaker` instance. ### `task([taskName,] fn)` Both a `getter` and `setter` for tasks. If a string (`taskName`) is given as the only argument, it behaves as a `getter` and returns the wrapped task (not the original function). The wrapped task has a `unwrap` method that will return the original function. If a function (`fn`) and optionally a string (`taskName`) is given, it behaves as a `setter` and will register the task by the `taskName`. If `taskName` is not specified, the `name` or `displayName` property of the function is used as the `taskName`. Will throw if: * As a `getter`: `taskName` is missing or not a string. * As a `setter`: `taskName` is missing and `fn` is anonymous. * As a `setter`: `fn` is missing or not a function. ### `series(taskName || fn...)` Takes a variable amount of strings (`taskName`) and/or functions (`fn`) and returns a function of the composed tasks or functions. Any `taskNames` are retrieved from the registry using the `get` method. When the returned function is executed, the tasks or functions will be executed in series, each waiting for the prior to finish. If an error occurs, execution will stop. ### `parallel(taskName || fn...)` Takes a variable amount of strings (`taskName`) and/or functions (`fn`) and returns a function of the composed tasks or functions. Any `taskNames` are retrieved from the registry using the `get` method. When the returned function is executed, the tasks or functions will be executed in parallel, all being executed at the same time. If an error occurs, all execution will complete. ### `registry([registryInstance])` Optionally takes an instantiated registry object. If no arguments are passed, returns the current registry object. If an instance of a registry (`customRegistry`) is passed the tasks from the current registry will be transferred to it and the current registry will be replaced with the new registry. The ability to assign new registries will allow you to pre-define/share tasks or add custom functionality to your registries. See [Custom Registries][custom-registries] for more information. ### `tree([options])` Optionally takes an `options` object and returns an object representing the tree of registered tasks. The object returned is [`archy`][archy] compatible. Also, each node has a `type` property that can be used to determine if the node is a `task` or `function`. #### `options` ##### `options.deep` Whether or not the whole tree should be returned. Type: `Boolean` Default: `false` ### `lastRun(task, [precision])` Takes a string or function (`task`) and returns a timestamp of the last time the task was run successfully. The time will be the time the task started. Returns `undefined` if the task has not been run. If a task errors, the result of `lastRun` will be undefined because the task should probably be re-run from scratch to get into a good state again. The timestamp is always given in millisecond but the time resolution can be rounded using the `precision` parameter. The use case is to be able to compare a build time to a file time attribute. On node v0.10 or with file system like HFS or FAT, `fs.stat` time attributes like `mtime` precision is one second. Assuming `undertakerInst.lastRun('someTask')` returns `1426000001111`, `undertakerInst.lastRun('someTask', 1000)` returns `1426000001000`. The default time resolution is `1000` on node v0.10, `0` on node 0.11+ but it can be overwritten using `UNDERTAKER_TIME_RESOLUTION` environment variable. ## Custom Registries Custom registries are constructor functions allowing you to pre-define/share tasks or add custom functionality to your registries. A registry's prototype should define: - `init(taker)`: receives the undertaker instance to set pre-defined tasks using the `task(taskName, fn)` method. - `get(taskName)`: returns the task with that name or `undefined` if no task is registered with that name. - `set(taskName, fn)`: add task to the registry. If `set` modifies a task, it should return the new task. - `tasks()`: returns an object listing all tasks in the registry. You should not call these functions yourself; leave that to Undertaker, so it can keep its metadata consistent. The easiest way to create a custom registry is to inherit from [undertaker-registry]: ```js var util = require('util'); var DefaultRegistry = require('undertaker-registry'); function MyRegistry(){ DefaultRegistry.call(this); } util.inherits(MyRegistry, DefaultRegistry); module.exports = MyRegistry; ``` ### Sharing tasks To share common tasks with all your projects, you can expose an `init` method on the registry prototype and it will receive the `Undertaker` instance as the only argument. You can then use `undertaker.task(name, fn)` to register pre-defined tasks. For example you might want to share a `clean` task: ```js var fs = require('fs'); var util = require('util'); var DefaultRegistry = require('undertaker-registry'); var del = require('del'); function CommonRegistry(opts){ DefaultRegistry.call(this); opts = opts || {}; this.buildDir = opts.buildDir || './build'; } util.inherits(CommonRegistry, DefaultRegistry); CommonRegistry.prototype.init = function(takerInst){ var buildDir = this.buildDir; var exists = fs.existsSync(buildDir); if(exists){ throw new Error('Cannot initialize common tasks. ' + buildDir + ' directory exists.'); } takerInst.task('clean', function(){ return del([buildDir]); }); } module.exports = CommonRegistry; ``` Then to use it in a project: ```js var Undertaker = require('undertaker'); var CommonRegistry = require('myorg-common-tasks'); var taker = new Undertaker(CommonRegistry({ buildDir: '/dist' })); taker.task('build', taker.series('clean', function build(cb) { // do things cb(); })); ``` ### Sharing Functionalities By controlling how tasks are added to the registry, you can decorate them. For example if you wanted all tasks to share some data, you can use a custom registry to bind them to that data. Be sure to return the altered task, as per the description of registry methods above: ```js var util = require('util'); var Undertaker = require('undertaker'); var DefaultRegistry = require('undertaker-registry'); // Some task defined somewhere else var BuildRegistry = require('./build.js'); var ServeRegistry = require('./serve.js'); function ConfigRegistry(config){ DefaultRegistry.call(this); this.config = config; } util.inherits(ConfigRegistry, DefaultRegistry); ConfigRegistry.prototype.set = function set(name, fn) { // The `DefaultRegistry` uses `this._tasks` for storage. var task = this._tasks[name] = fn.bind(this.config); return task; }; var taker = new Undertaker(); taker.registry(new BuildRegistry()); taker.registry(new ServeRegistry()); // `taker.registry` will reset each task in the registry with // `ConfigRegistry.prototype.set` which will bind them to the config object. taker.registry(new ConfigRegistry({ src: './src', build: './build', bindTo: '0.0.0.0:8888' })); taker.task('default', taker.series('clean', 'build', 'serve', function(cb) { console.log('Server bind to ' + this.bindTo); console.log('Serving' + this.build); cb(); })); ``` ### In the wild * [undertaker-registry] - Custom registries probably want to inherit from this. * [undertaker-forward-reference] - Custom registry supporting forward referenced tasks (similar to gulp 3.x). * [undertaker-task-metadata] - Proof-of-concept custom registry that attaches metadata to each task. * [undertaker-common-tasks] - Proof-of-concept custom registry that pre-defines some tasks. * [alchemist-gulp] - A default set of tasks for building alchemist plugins. * [gulp-hub] - Custom registry to run tasks in multiple gulpfiles. (In a branch as of this writing) * [gulp-pipeline] - [RailsRegistry][rails-registry] is an ES2015 class that provides a gulp pipeline replacement for rails applications ## License MIT [downloads-image]: https://img.shields.io/npm/dm/undertaker.svg [npm-url]: https://www.npmjs.com/package/undertaker [npm-image]: https://img.shields.io/npm/v/undertaker.svg [azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=$PROJECT_ID&branchName=master [azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/undertaker?branchName=master [travis-url]: https://travis-ci.org/gulpjs/undertaker [travis-image]: https://img.shields.io/travis/gulpjs/undertaker.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/undertaker [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/undertaker.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/undertaker [coveralls-image]: https://img.shields.io/coveralls/gulpjs/undertaker/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg node-gulp-4.0.2+~cs38.20.35/appveyor.yml000066400000000000000000000012521415667007300174300ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "6" - nodejs_version: "8" - nodejs_version: "10" - nodejs_version: "12" platform: - x86 - x64 install: # https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:PLATFORM - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" node-gulp-4.0.2+~cs38.20.35/index.js000066400000000000000000000021201415667007300165000ustar00rootroot00000000000000'use strict'; var inherits = require('util').inherits; var EventEmitter = require('events').EventEmitter; var DefaultRegistry = require('undertaker-registry'); var tree = require('./lib/tree'); var task = require('./lib/task'); var series = require('./lib/series'); var lastRun = require('./lib/last-run'); var parallel = require('./lib/parallel'); var registry = require('./lib/registry'); var _getTask = require('./lib/get-task'); var _setTask = require('./lib/set-task'); function Undertaker(customRegistry) { EventEmitter.call(this); this._registry = new DefaultRegistry(); if (customRegistry) { this.registry(customRegistry); } this._settle = (process.env.UNDERTAKER_SETTLE === 'true'); } inherits(Undertaker, EventEmitter); Undertaker.prototype.tree = tree; Undertaker.prototype.task = task; Undertaker.prototype.series = series; Undertaker.prototype.lastRun = lastRun; Undertaker.prototype.parallel = parallel; Undertaker.prototype.registry = registry; Undertaker.prototype._getTask = _getTask; Undertaker.prototype._setTask = _setTask; module.exports = Undertaker; node-gulp-4.0.2+~cs38.20.35/lib/000077500000000000000000000000001415667007300156065ustar00rootroot00000000000000node-gulp-4.0.2+~cs38.20.35/lib/get-task.js000066400000000000000000000001401415667007300176560ustar00rootroot00000000000000'use strict'; function get(name) { return this._registry.get(name); } module.exports = get; node-gulp-4.0.2+~cs38.20.35/lib/helpers/000077500000000000000000000000001415667007300172505ustar00rootroot00000000000000node-gulp-4.0.2+~cs38.20.35/lib/helpers/buildTree.js000066400000000000000000000010071415667007300215230ustar00rootroot00000000000000'use strict'; var map = require('collection-map'); var metadata = require('./metadata'); function buildTree(tasks) { return map(tasks, function(task) { var meta = metadata.get(task); if (meta) { return meta.tree; } var name = task.displayName || task.name || ''; meta = { name: name, tree: { label: name, type: 'function', nodes: [], }, }; metadata.set(task, meta); return meta.tree; }); } module.exports = buildTree; node-gulp-4.0.2+~cs38.20.35/lib/helpers/createExtensions.js000066400000000000000000000032011415667007300231250ustar00rootroot00000000000000'use strict'; var captureLastRun = require('last-run').capture; var releaseLastRun = require('last-run').release; var metadata = require('./metadata'); var uid = 0; function Storage(fn) { var meta = metadata.get(fn); this.fn = meta.orig || fn; this.uid = uid++; this.name = meta.name; this.branch = meta.branch || false; this.captureTime = Date.now(); this.startHr = []; } Storage.prototype.capture = function() { captureLastRun(this.fn, this.captureTime); }; Storage.prototype.release = function() { releaseLastRun(this.fn); }; function createExtensions(ee) { return { create: function(fn) { return new Storage(fn); }, before: function(storage) { storage.startHr = process.hrtime(); ee.emit('start', { uid: storage.uid, name: storage.name, branch: storage.branch, time: Date.now(), }); }, after: function(result, storage) { if (result && result.state === 'error') { return this.error(result.value, storage); } storage.capture(); ee.emit('stop', { uid: storage.uid, name: storage.name, branch: storage.branch, duration: process.hrtime(storage.startHr), time: Date.now(), }); }, error: function(error, storage) { if (Array.isArray(error)) { error = error[0]; } storage.release(); ee.emit('error', { uid: storage.uid, name: storage.name, branch: storage.branch, error: error, duration: process.hrtime(storage.startHr), time: Date.now(), }); }, }; } module.exports = createExtensions; node-gulp-4.0.2+~cs38.20.35/lib/helpers/metadata.js000066400000000000000000000002061415667007300213640ustar00rootroot00000000000000'use strict'; // WeakMap for storing metadata var WM = require('es6-weak-map'); var metadata = new WM(); module.exports = metadata; node-gulp-4.0.2+~cs38.20.35/lib/helpers/normalizeArgs.js000066400000000000000000000024221415667007300224230ustar00rootroot00000000000000'use strict'; var assert = require('assert'); var map = require('arr-map'); var flatten = require('arr-flatten'); var levenshtein = require('fast-levenshtein'); function normalizeArgs(registry, args) { function getFunction(task) { if (typeof task === 'function') { return task; } var fn = registry.get(task); if (!fn) { var similar = similarTasks(registry, task); if (similar.length > 0) { assert(false, 'Task never defined: ' + task + ' - did you mean? ' + similar.join(', ')); } else { assert(false, 'Task never defined: ' + task); } } return fn; } var flattenArgs = flatten(args); assert(flattenArgs.length, 'One or more tasks should be combined using series or parallel'); return map(flattenArgs, getFunction); } function similarTasks(registry, queryTask) { if (typeof queryTask !== 'string') { return []; } var tasks = registry.tasks(); var similarTasks = []; for (var task in tasks) { if (tasks.hasOwnProperty(task)) { var distance = levenshtein.get(task, queryTask); var allowedDistance = Math.floor(0.4 * task.length) + 1; if (distance < allowedDistance) { similarTasks.push(task); } } } return similarTasks; } module.exports = normalizeArgs; node-gulp-4.0.2+~cs38.20.35/lib/helpers/validateRegistry.js000066400000000000000000000022241415667007300231300ustar00rootroot00000000000000'use strict'; var assert = require('assert'); function isFunction(fn) { return typeof fn === 'function'; } function isConstructor(registry) { if (!(registry && registry.prototype)) { return false; } var hasProtoGet = isFunction(registry.prototype.get); var hasProtoSet = isFunction(registry.prototype.set); var hasProtoInit = isFunction(registry.prototype.init); var hasProtoTasks = isFunction(registry.prototype.tasks); if (hasProtoGet || hasProtoSet || hasProtoInit || hasProtoTasks) { return true; } return false; } function validateRegistry(registry) { try { assert(isFunction(registry.get), 'Custom registry must have `get` function'); assert(isFunction(registry.set), 'Custom registry must have `set` function'); assert(isFunction(registry.init), 'Custom registry must have `init` function'); assert(isFunction(registry.tasks), 'Custom registry must have `tasks` function'); } catch (err) { if (isConstructor(registry)) { assert(false, 'Custom registries must be instantiated, but it looks like you passed a constructor'); } else { throw err; } } } module.exports = validateRegistry; node-gulp-4.0.2+~cs38.20.35/lib/last-run.js000066400000000000000000000007431415667007300177150ustar00rootroot00000000000000'use strict'; var retrieveLastRun = require('last-run'); var metadata = require('./helpers/metadata'); function lastRun(task, timeResolution) { if (timeResolution == null) { timeResolution = process.env.UNDERTAKER_TIME_RESOLUTION; } var fn = task; if (typeof task === 'string') { fn = this._getTask(task); } var meta = metadata.get(fn); if (meta) { fn = meta.orig || fn; } return retrieveLastRun(fn, timeResolution); } module.exports = lastRun; node-gulp-4.0.2+~cs38.20.35/lib/parallel.js000066400000000000000000000013261415667007300177420ustar00rootroot00000000000000'use strict'; var bach = require('bach'); var metadata = require('./helpers/metadata'); var buildTree = require('./helpers/buildTree'); var normalizeArgs = require('./helpers/normalizeArgs'); var createExtensions = require('./helpers/createExtensions'); function parallel() { var create = this._settle ? bach.settleParallel : bach.parallel; var args = normalizeArgs(this._registry, arguments); var extensions = createExtensions(this); var fn = create(args, extensions); var name = ''; metadata.set(fn, { name: name, branch: true, tree: { label: name, type: 'function', branch: true, nodes: buildTree(args), }, }); return fn; } module.exports = parallel; node-gulp-4.0.2+~cs38.20.35/lib/registry.js000066400000000000000000000007321415667007300200160ustar00rootroot00000000000000'use strict'; var reduce = require('object.reduce'); var validateRegistry = require('./helpers/validateRegistry'); function setTasks(inst, task, name) { inst.set(name, task); return inst; } function registry(newRegistry) { if (!newRegistry) { return this._registry; } validateRegistry(newRegistry); var tasks = this._registry.tasks(); this._registry = reduce(tasks, setTasks, newRegistry); this._registry.init(this); } module.exports = registry; node-gulp-4.0.2+~cs38.20.35/lib/series.js000066400000000000000000000013141415667007300174350ustar00rootroot00000000000000'use strict'; var bach = require('bach'); var metadata = require('./helpers/metadata'); var buildTree = require('./helpers/buildTree'); var normalizeArgs = require('./helpers/normalizeArgs'); var createExtensions = require('./helpers/createExtensions'); function series() { var create = this._settle ? bach.settleSeries : bach.series; var args = normalizeArgs(this._registry, arguments); var extensions = createExtensions(this); var fn = create(args, extensions); var name = ''; metadata.set(fn, { name: name, branch: true, tree: { label: name, type: 'function', branch: true, nodes: buildTree(args), }, }); return fn; } module.exports = series; node-gulp-4.0.2+~cs38.20.35/lib/set-task.js000066400000000000000000000014651415667007300177050ustar00rootroot00000000000000'use strict'; var assert = require('assert'); var metadata = require('./helpers/metadata'); function set(name, fn) { assert(name, 'Task name must be specified'); assert(typeof name === 'string', 'Task name must be a string'); assert(typeof fn === 'function', 'Task function must be specified'); function taskWrapper() { return fn.apply(this, arguments); } function unwrap() { return fn; } taskWrapper.unwrap = unwrap; taskWrapper.displayName = name; var meta = metadata.get(fn) || {}; var nodes = []; if (meta.branch) { nodes.push(meta.tree); } var task = this._registry.set(name, taskWrapper) || taskWrapper; metadata.set(task, { name: name, orig: fn, tree: { label: name, type: 'task', nodes: nodes, }, }); } module.exports = set; node-gulp-4.0.2+~cs38.20.35/lib/task.js000066400000000000000000000003561415667007300171120ustar00rootroot00000000000000'use strict'; function task(name, fn) { if (typeof name === 'function') { fn = name; name = fn.displayName || fn.name; } if (!fn) { return this._getTask(name); } this._setTask(name, fn); } module.exports = task; node-gulp-4.0.2+~cs38.20.35/lib/tree.js000066400000000000000000000007701415667007300171070ustar00rootroot00000000000000'use strict'; var defaults = require('object.defaults'); var map = require('collection-map'); var metadata = require('./helpers/metadata'); function tree(opts) { opts = defaults(opts || {}, { deep: false, }); var tasks = this._registry.tasks(); var nodes = map(tasks, function(task) { var meta = metadata.get(task); if (opts.deep) { return meta.tree; } return meta.tree.label; }); return { label: 'Tasks', nodes: nodes, }; } module.exports = tree; node-gulp-4.0.2+~cs38.20.35/package.json000066400000000000000000000030741415667007300173320ustar00rootroot00000000000000{ "name": "undertaker", "version": "1.3.0", "description": "Task registry that allows composition through series/parallel methods.", "author": "Gulp Team (https://gulpjs.com/)", "contributors": [ "Blaine Bublitz ", "Damien Lebrun " ], "repository": "gulpjs/undertaker", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "LICENSE", "index.js", "lib" ], "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "nyc mocha --async-only", "azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit", "coveralls": "nyc report --reporter=text-lcov | coveralls" }, "dependencies": { "arr-flatten": "^1.0.1", "arr-map": "^2.0.0", "bach": "^1.0.0", "collection-map": "^1.0.0", "es6-weak-map": "^2.0.1", "last-run": "^1.1.0", "object.defaults": "^1.0.0", "object.reduce": "^1.0.0", "undertaker-registry": "^1.0.0", "fast-levenshtein": "^1.0.0" }, "devDependencies": { "async-once": "^1.0.0", "coveralls": "github:phated/node-coveralls#2.x", "del": "^2.0.2", "eslint": "^2.13.1", "eslint-config-gulp": "^3.0.1", "expect": "^1.20.2", "gulp-jshint": "^1.8.4", "mocha": "^3.0.0", "nyc": "^10.3.2", "once": "^1.3.1", "through2": "^2.0.0", "undertaker-common-tasks": "^1.0.0", "undertaker-task-metadata": "^1.0.0", "vinyl-fs": "^2.2.0" }, "keywords": [ "registry", "runner", "task" ] } node-gulp-4.0.2+~cs38.20.35/test/000077500000000000000000000000001415667007300160175ustar00rootroot00000000000000node-gulp-4.0.2+~cs38.20.35/test/.eslintrc000066400000000000000000000000351415667007300176410ustar00rootroot00000000000000{ "extends": "gulp/test" } node-gulp-4.0.2+~cs38.20.35/test/fixtures/000077500000000000000000000000001415667007300176705ustar00rootroot00000000000000node-gulp-4.0.2+~cs38.20.35/test/fixtures/taskTree/000077500000000000000000000000001415667007300214525ustar00rootroot00000000000000node-gulp-4.0.2+~cs38.20.35/test/fixtures/taskTree/aliasNested.js000066400000000000000000000035661415667007300242560ustar00rootroot00000000000000'use strict'; module.exports = { label: 'Tasks', nodes: [ { label: 'noop', type: 'task', nodes: [], }, { label: 'fn1', type: 'task', nodes: [], }, { label: 'fn2', type: 'task', nodes: [], }, { label: 'fn3', type: 'task', nodes: [], }, { label: 'ser', type: 'task', nodes: [ { label: '', type: 'function', branch: true, nodes: [ { label: 'noop', type: 'function', nodes: [], }, { label: '', type: 'function', nodes: [], }, { label: 'fn1', type: 'task', nodes: [], }, { label: 'fn2', type: 'task', nodes: [], }, { label: 'fn3', type: 'task', nodes: [], }, ], }, ], }, { label: 'par', type: 'task', nodes: [ { label: '', type: 'function', branch: true, nodes: [ { label: 'noop', type: 'function', nodes: [], }, { label: '', type: 'function', nodes: [], }, { label: 'fn1', type: 'task', nodes: [], }, { label: 'fn2', type: 'task', nodes: [], }, { label: 'fn3', type: 'task', nodes: [], }, ], }, ], }, ], }; node-gulp-4.0.2+~cs38.20.35/test/fixtures/taskTree/aliasSimple.js000066400000000000000000000006461415667007300242610ustar00rootroot00000000000000'use strict'; module.exports = { label: 'Tasks', nodes: [ { label: 'noop', type: 'task', nodes: [], }, { label: 'fn1', type: 'task', nodes: [], }, { label: 'fn2', type: 'task', nodes: [], }, { label: 'fn3', type: 'task', nodes: [], }, { label: 'fn4', type: 'task', nodes: [], }, ], }; node-gulp-4.0.2+~cs38.20.35/test/fixtures/taskTree/doubleLevel.js000066400000000000000000000012021415667007300242450ustar00rootroot00000000000000'use strict'; module.exports = { label: 'Tasks', nodes: [ { label: 'fn1', type: 'task', nodes: [], }, { label: 'fn2', type: 'task', nodes: [], }, { label: 'fn3', type: 'task', nodes: [ { label: '', type: 'function', branch: true, nodes: [ { label: 'fn1', type: 'task', nodes: [], }, { label: 'fn2', type: 'task', nodes: [], }, ], }, ], }, ], }; node-gulp-4.0.2+~cs38.20.35/test/fixtures/taskTree/simple.js000066400000000000000000000003041415667007300232760ustar00rootroot00000000000000'use strict'; module.exports = { label: 'Tasks', nodes: [ 'test1', 'test2', 'test3', 'error', 'ser', 'par', 'serpar', 'serpar2', '', ], }; node-gulp-4.0.2+~cs38.20.35/test/fixtures/taskTree/singleLevel.js000066400000000000000000000003231415667007300242570ustar00rootroot00000000000000'use strict'; module.exports = { label: 'Tasks', nodes: [ { label: 'fn1', type: 'task', nodes: [], }, { label: 'fn2', type: 'task', nodes: [], }, ], }; node-gulp-4.0.2+~cs38.20.35/test/fixtures/taskTree/tripleLevel.js000066400000000000000000000046221415667007300243030ustar00rootroot00000000000000'use strict'; module.exports = { label: 'Tasks', nodes: [ { label: 'fn1', type: 'task', nodes: [ { label: '', type: 'function', branch: true, nodes: [ { label: '', type: 'function', nodes: [], }, { label: 'noop', type: 'function', nodes: [], }, ], }, ], }, { label: 'fn2', type: 'task', nodes: [ { label: '', type: 'function', branch: true, nodes: [ { label: '', type: 'function', nodes: [], }, { label: 'noop', type: 'function', nodes: [], }, ], }, ], }, { label: 'fn3', type: 'task', nodes: [ { label: '', type: 'function', branch: true, nodes: [ { label: 'fn1', type: 'task', nodes: [ { label: '', type: 'function', branch: true, nodes: [ { label: '', type: 'function', nodes: [], }, { label: 'noop', type: 'function', nodes: [], }, ], }, ], }, { label: 'fn2', type: 'task', nodes: [ { label: '', type: 'function', branch: true, nodes: [ { label: '', type: 'function', nodes: [], }, { label: 'noop', type: 'function', nodes: [], }, ], }, ], }, ], }, ], }, ], }; node-gulp-4.0.2+~cs38.20.35/test/fixtures/test.js000066400000000000000000000001101415667007300211750ustar00rootroot00000000000000'use strict'; function helloWorld() { } module.exports = helloWorld; node-gulp-4.0.2+~cs38.20.35/test/fixtures/testMore.js000066400000000000000000000001101415667007300220200ustar00rootroot00000000000000'use strict'; function helloWorld() { } module.exports = helloWorld; node-gulp-4.0.2+~cs38.20.35/test/integration.js000066400000000000000000000077051415667007300207110ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var os = require('os'); var fs = require('fs'); var path = require('path'); var vinyl = require('vinyl-fs'); var jshint = require('gulp-jshint'); var spawn = require('child_process').spawn; var once = require('once'); var aOnce = require('async-once'); var del = require('del'); var through = require('through2'); var Undertaker = require('../'); var isWindows = (os.platform() === 'win32'); function cleanup() { return del([ path.join(__dirname, './fixtures/out/'), path.join(__dirname, './fixtures/tmp/'), ]); } function noop() { } describe('integrations', function() { var taker; beforeEach(function(done) { taker = new Undertaker(); done(); }); beforeEach(cleanup); afterEach(cleanup); it('should handle vinyl streams', function(done) { taker.task('test', function() { return vinyl.src('./fixtures/test.js', { cwd: __dirname }) .pipe(vinyl.dest('./fixtures/out', { cwd: __dirname })); }); taker.parallel('test')(done); }); it('should exhaust vinyl streams', function(done) { taker.task('test', function() { return vinyl.src('./fixtures/test.js', { cwd: __dirname }); }); taker.parallel('test')(done); }); it('should lints all piped files', function(done) { taker.task('test', function() { return vinyl.src('./fixtures/test.js', { cwd: __dirname }) .pipe(jshint()); }); taker.parallel('test')(done); }); it('should handle a child process return', function(done) { taker.task('test', function() { if (isWindows) { return spawn('cmd', ['/c', 'dir']).on('error', noop); } return spawn('ls', ['-lh', __dirname]); }); taker.parallel('test')(done); }); it('should run dependencies once', function(done) { var count = 0; taker.task('clean', once(function() { count++; return del(['./fixtures/some-build.txt'], { cwd: __dirname }); })); taker.task('build-this', taker.series('clean', function(cb) { cb(); })); taker.task('build-that', taker.series('clean', function(cb) { cb(); })); taker.task('build', taker.series( 'clean', taker.parallel(['build-this', 'build-that']) )); taker.parallel('build')(function(err) { expect(count).toEqual(1); done(err); }); }); it('should run dependencies once', function(done) { var count = 0; taker.task('clean', aOnce(function(cb) { cb(); count++; del(['./fixtures/some-build.txt'], { cwd: __dirname }, cb); })); taker.task('build-this', taker.series('clean', function(cb) { cb(); })); taker.task('build-that', taker.series('clean', function(cb) { cb(); })); taker.task('build', taker.series( 'clean', taker.parallel(['build-this', 'build-that']) )); taker.parallel('build')(function(err) { expect(count).toEqual(1); done(err); }); }); it('can use lastRun with vinyl.src `since` option', function(done) { this.timeout(5000); var count = 0; function setup() { return vinyl.src('./fixtures/test*.js', { cwd: __dirname }) .pipe(vinyl.dest('./fixtures/tmp', { cwd: __dirname })); } function delay(cb) { setTimeout(cb, 2000); } // Some built taker.task('build', function() { return vinyl.src('./fixtures/tmp/*.js', { cwd: __dirname }) .pipe(vinyl.dest('./fixtures/out', { cwd: __dirname })); }); function userEdit(cb) { fs.appendFile(path.join(__dirname, './fixtures/tmp/testMore.js'), ' ', cb); } function countEditedFiles() { return vinyl.src('./fixtures/tmp/*.js', { cwd: __dirname, since: taker.lastRun('build') }) .pipe(through.obj(function(file, enc, cb) { count++; cb(); })); } taker.series(setup, delay, 'build', delay, userEdit, countEditedFiles)(function(err) { expect(count).toEqual(1); done(err); }); }); }); node-gulp-4.0.2+~cs38.20.35/test/last-run.js000066400000000000000000000057021415667007300201260ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var Undertaker = require('../'); describe('lastRun', function() { var taker, test1, test2, error, alias; var defaultResolution = process.env.UNDERTAKER_TIME_RESOLUTION; beforeEach(function(done) { process.env.UNDERTAKER_TIME_RESOLUTION = '0'; taker = new Undertaker(); test1 = function(cb) { cb(); }; taker.task('test1', test1); test2 = function(cb) { cb(); }; test2.displayName = 'test2'; taker.task(test2); error = function(cb) { cb(new Error()); }; taker.task('error', error); alias = test1; taker.task('alias', alias); done(); }); afterEach(function(done) { process.env.UNDERTAKER_TIME_RESOLUTION = defaultResolution; done(); }); it('should only record time when task has completed', function(done) { var ts; var test = function(cb) { ts = taker.lastRun('test'); cb(); }; taker.task('test', test); taker.parallel('test')(function(err) { expect(ts).toEqual(undefined); done(err); }); }); it('should record tasks time execution', function(done) { taker.parallel('test1')(function(err) { expect(taker.lastRun('test1')).toExist(); expect(taker.lastRun('test1')).toBeLessThanOrEqualTo(Date.now()); expect(taker.lastRun(test2)).toNotExist(); expect(taker.lastRun(function() {})).toNotExist(); expect(taker.lastRun.bind(taker, 'notexists')).toThrow(Error); done(err); }); }); it('should record all tasks time execution', function(done) { taker.parallel('test1', test2)(function(err) { expect(taker.lastRun('test1')).toExist(); expect(taker.lastRun('test1')).toBeLessThanOrEqualTo(Date.now()); expect(taker.lastRun(test2)).toExist(); expect(taker.lastRun(test2)).toBeLessThanOrEqualTo(Date.now()); done(err); }); }); it('should record same tasks time execution for a string task and its original', function(done) { taker.series(test2)(function(err) { expect(taker.lastRun(test2)).toEqual(taker.lastRun('test2')); done(err); }); }); it('should record tasks time execution for an aliased task', function(done) { taker.series('alias')(function(err) { expect(taker.lastRun('alias')).toEqual(taker.lastRun('test1')); done(err); }); }); it('should give time with 1s resolution', function(done) { var resolution = 1000; // 1s var since = Date.now(); var expected = since - (since % resolution); taker.series('test1')(function() { expect(taker.lastRun('test1', resolution)).toEqual(expected); done(); }); }); it('should not record task start time on error', function(done) { taker.on('error', function() { // To keep the test from catching the emitted errors }); taker.series('error')(function(err) { expect(err).toExist(); expect(taker.lastRun('error')).toNotExist(); done(); }); }); }); node-gulp-4.0.2+~cs38.20.35/test/parallel.js000066400000000000000000000075301415667007300201560ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var Undertaker = require('../'); function fn1(done) { done(null, 1); } function fn2(done) { setTimeout(function() { done(null, 2); }, 500); } function fn3(done) { done(null, 3); } function fnError(done) { done(new Error('An Error Occurred')); } describe('parallel', function() { var taker; beforeEach(function(done) { taker = new Undertaker(); taker.task('test1', fn1); taker.task('test2', fn2); taker.task('test3', fn3); taker.task('error', fnError); done(); }); it('should throw on non-valid tasks combined with valid tasks', function(done) { function fail() { taker.parallel('test1', 'test2', 'test3', {}); } expect(fail).toThrow(/Task never defined:/); done(); }); it('should throw on tasks array with both valid and non-valid tasks', function(done) { function fail() { taker.parallel(['test1', 'test2', 'test3', {}]); } expect(fail).toThrow(/Task never defined:/); done(); }); it('should throw on non-valid task', function(done) { function fail() { taker.parallel({}); } expect(fail).toThrow(/Task never defined:/); done(); }); it('should throw when no tasks specified', function(done) { function fail() { taker.parallel(); } expect(fail).toThrow(/One or more tasks should be combined using series or parallel/); done(); }); it('should throw on empty array of registered tasks', function(done) { function fail() { taker.parallel([]); } expect(fail).toThrow(/One or more tasks should be combined using series or parallel/); done(); }); it('should take only one array of registered tasks', function(done) { taker.parallel(['test1', 'test2', 'test3'])(function(err, results) { expect(results).toEqual([1, 2, 3]); done(err); }); }); it('should take all string names', function(done) { taker.parallel('test1', 'test2', 'test3')(function(err, results) { expect(results).toEqual([1, 2, 3]); done(err); }); }); it('should take all functions', function(done) { taker.parallel(fn1, fn2, fn3)(function(err, results) { expect(results).toEqual([1, 2, 3]); done(err); }); }); it('should take string names and functions', function(done) { taker.parallel('test1', fn2, 'test3')(function(err, results) { expect(results).toEqual([1, 2, 3]); done(err); }); }); it('should take nested parallel', function(done) { var parallel1 = taker.parallel('test1', 'test2', 'test3'); taker.parallel('test1', parallel1, 'test3')(function(err, results) { expect(results).toEqual([1, [1, 2, 3], 3]); done(err); }); }); it('should stop processing on error', function(done) { taker.on('error', function() { // To keep the test from catching the emitted errors }); taker.parallel('test1', 'error', 'test3')(function(err, results) { expect(err).toBeAn(Error); expect(results).toEqual([1, undefined, undefined]); done(); }); }); it('should throw on unregistered task', function(done) { function unregistered() { taker.parallel('unregistered'); } expect(unregistered).toThrow('Task never defined: unregistered'); done(); }); it('should process all functions if settle flag is true', function(done) { taker.on('error', function() { // To keep the test from catching the emitted errors }); taker._settle = true; taker.parallel(taker.parallel('test1', 'error'), 'test3')(function(err, results) { expect(err[0][0]).toBeAn(Error); expect(results).toEqual([3]); done(); }); }); it('should not register a displayName on the returned function by default', function(done) { var task = taker.parallel(fn1); expect(task.displayName).toEqual(undefined); done(); }); }); node-gulp-4.0.2+~cs38.20.35/test/registry.js000066400000000000000000000142031415667007300202250ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var Undertaker = require('../'); var DefaultRegistry = require('undertaker-registry'); var CommonRegistry = require('undertaker-common-tasks'); var MetadataRegistry = require('undertaker-task-metadata'); function noop() {} function CustomRegistry() {} CustomRegistry.prototype.init = noop; CustomRegistry.prototype.get = noop; CustomRegistry.prototype.set = noop; CustomRegistry.prototype.tasks = noop; function SetNoReturnRegistry() { this._tasks = {}; } SetNoReturnRegistry.prototype.init = noop; SetNoReturnRegistry.prototype.get = function(name) { return this.tasks[name]; }; SetNoReturnRegistry.prototype.set = function(name, fn) { this.tasks[name] = fn; }; SetNoReturnRegistry.prototype.tasks = noop; function InvalidRegistry() {} describe('registry', function() { describe('method', function() { it('should return the current registry when no arguments are given', function(done) { var taker = new Undertaker(); expect(taker.registry()).toEqual(taker._registry); done(); }); it('should set the registry to the given registry instance argument', function(done) { var taker = new Undertaker(); var customRegistry = new CustomRegistry(); taker.registry(customRegistry); expect(taker.registry()).toEqual(customRegistry); done(); }); it('should validate the custom registry instance', function(done) { var taker = new Undertaker(); var invalid = new InvalidRegistry(); function invalidSet() { taker.registry(invalid); } expect(invalidSet).toThrow('Custom registry must have `get` function'); done(); }); it('should transfer all tasks from old registry to new', function(done) { var taker = new Undertaker(new CommonRegistry()); var customRegistry = new DefaultRegistry(); taker.registry(customRegistry); expect(taker.task('clean')).toBeA('function'); expect(taker.task('serve')).toBeA('function'); done(); }); it('allows multiple custom registries to used', function(done) { var taker = new Undertaker(); taker.registry(new CommonRegistry()); expect(taker.task('clean')).toBeA('function'); expect(taker.task('serve')).toBeA('function'); taker.registry(new MetadataRegistry()); taker.task('context', function(cb) { expect(this).toEqual({ name: 'context' }); cb(); done(); }); taker.registry(new DefaultRegistry()); expect(taker.task('clean')).toBeA('function'); expect(taker.task('serve')).toBeA('function'); expect(taker.task('context')).toBeA('function'); taker.series('context')(); }); it('throws with a descriptive method when constructor is passed', function(done) { var taker = new Undertaker(); function ctor() { taker.registry(CommonRegistry); } expect(ctor).toThrow('Custom registries must be instantiated, but it looks like you passed a constructor'); done(); }); it('calls into the init function after tasks are transferred', function(done) { var taker = new Undertaker(new CommonRegistry()); var ogInit = DefaultRegistry.prototype.init; DefaultRegistry.prototype.init = function(inst) { expect(inst).toEqual(taker); expect(inst.task('clean')).toBeA('function'); expect(inst.task('serve')).toBeA('function'); }; taker.registry(new DefaultRegistry()); DefaultRegistry.prototype.init = ogInit; done(); }); }); describe('constructor', function() { it('should take a custom registry on instantiation', function(done) { var taker = new Undertaker(new CustomRegistry()); expect(taker.registry()).toBeA(CustomRegistry); expect(taker.registry()).toNotBeA(DefaultRegistry); done(); }); it('should default to undertaker-registry if not constructed with custom registry', function(done) { var taker = new Undertaker(); expect(taker.registry()).toBeA(DefaultRegistry); expect(taker.registry()).toNotBeA(CustomRegistry); done(); }); it('should take a registry that pre-defines tasks', function(done) { var taker = new Undertaker(new CommonRegistry()); expect(taker.registry()).toBeA(CommonRegistry); expect(taker.registry()).toBeA(DefaultRegistry); expect(taker.task('clean')).toBeA('function'); expect(taker.task('serve')).toBeA('function'); done(); }); it('should throw upon invalid registry', function(done) { /* eslint no-unused-vars: 0 */ var taker; function noGet() { taker = new Undertaker(new InvalidRegistry()); } expect(noGet).toThrow('Custom registry must have `get` function'); InvalidRegistry.prototype.get = noop; function noSet() { taker = new Undertaker(new InvalidRegistry()); } expect(noSet).toThrow('Custom registry must have `set` function'); InvalidRegistry.prototype.set = noop; function noInit() { taker = new Undertaker(new InvalidRegistry()); } expect(noInit).toThrow('Custom registry must have `init` function'); InvalidRegistry.prototype.init = noop; function noTasks() { taker = new Undertaker(new InvalidRegistry()); } expect(noTasks).toThrow('Custom registry must have `tasks` function'); InvalidRegistry.prototype.tasks = noop; taker = new Undertaker(new InvalidRegistry()); done(); }); }); it('does not require the `set` method to return a task', function(done) { var taker = new Undertaker(); taker.registry(new SetNoReturnRegistry()); taker.task('test', noop); taker.on('start', function(data) { expect(data.name).toEqual('test'); done(); }); taker.series('test')(); }); it('should fail and offer tasks which are close in name', function(done) { var taker = new Undertaker(new CommonRegistry()); var customRegistry = new DefaultRegistry(); taker.registry(customRegistry); function fail() { taker.series('clear'); } expect(fail).toThrow(/Task never defined: clear - did you mean\? clean/); done(); }); }); node-gulp-4.0.2+~cs38.20.35/test/series.js000066400000000000000000000074601415667007300176560ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var Undertaker = require('../'); function fn1(done) { done(null, 1); } function fn2(done) { setTimeout(function() { done(null, 2); }, 500); } function fn3(done) { done(null, 3); } function fnError(done) { done(new Error('An Error Occurred')); } describe('series', function() { var taker; beforeEach(function(done) { taker = new Undertaker(); taker.task('test1', fn1); taker.task('test2', fn2); taker.task('test3', fn3); taker.task('error', fnError); done(); }); it('should throw on non-valid tasks combined with valid tasks', function(done) { function fail() { taker.series('test1', 'test2', 'test3', {}); } expect(fail).toThrow(/Task never defined:/); done(); }); it('should throw on tasks array with both valid and non-valid tasks', function(done) { function fail() { taker.series(['test1', 'test2', 'test3', {}]); } expect(fail).toThrow(/Task never defined:/); done(); }); it('should throw on non-valid task', function(done) { function fail() { taker.series({}); } expect(fail).toThrow(/Task never defined:/); done(); }); it('should throw when no tasks specified', function(done) { function fail() { taker.series(); } expect(fail).toThrow(/One or more tasks should be combined using series or parallel/); done(); }); it('should throw on empty array of registered tasks', function(done) { function fail() { taker.series([]); } expect(fail).toThrow(/One or more tasks should be combined using series or parallel/); done(); }); it('should take only one array of registered tasks', function(done) { taker.series(['test1', 'test2', 'test3'])(function(err, results) { expect(results).toEqual([1, 2, 3]); done(err); }); }); it('should take all string names', function(done) { taker.series('test1', 'test2', 'test3')(function(err, results) { expect(results).toEqual([1, 2, 3]); done(err); }); }); it('should take all functions', function(done) { taker.series(fn1, fn2, fn3)(function(err, results) { expect(results).toEqual([1, 2, 3]); done(err); }); }); it('should take string names and functions', function(done) { taker.series('test1', fn2, 'test3')(function(err, results) { expect(results).toEqual([1, 2, 3]); done(err); }); }); it('should take nested series', function(done) { var series1 = taker.series('test1', 'test2', 'test3'); taker.series('test1', series1, 'test3')(function(err, results) { expect(results).toEqual([1, [1, 2, 3], 3]); done(err); }); }); it('should stop processing on error', function(done) { taker.on('error', function() { // To keep the test from catching the emitted errors }); taker.series('test1', 'error', 'test3')(function(err, results) { expect(err).toBeAn(Error); expect(results).toEqual([1, undefined, undefined]); done(); }); }); it('should throw on unregistered task', function(done) { function unregistered() { taker.series('unregistered'); } expect(unregistered).toThrow('Task never defined: unregistered'); done(); }); it('should process all functions if settle flag is true', function(done) { taker.on('error', function() { // To keep the test from catching the emitted errors }); taker._settle = true; taker.series(taker.series('test1', 'error'), 'test3')(function(err, results) { expect(err[0][0]).toBeAn(Error); expect(results).toEqual([3]); done(); }); }); it('should not register a displayName on the returned function by default', function(done) { var task = taker.series(fn1); expect(task.displayName).toEqual(undefined); done(); }); }); node-gulp-4.0.2+~cs38.20.35/test/task.js000066400000000000000000000077321415667007300173300ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var Undertaker = require('../'); function noop(done) { done(); } var anon = function() {}; describe('task', function() { var taker; beforeEach(function(done) { taker = new Undertaker(); done(); }); it('should register a named function', function(done) { taker.task(noop); expect(taker.task('noop').unwrap()).toEqual(noop); done(); }); it('should register an anonymous function by string name', function(done) { taker.task('test1', anon); expect(taker.task('test1').unwrap()).toEqual(anon); done(); }); it('should register an anonymous function by displayName property', function(done) { anon.displayName = ''; taker.task(anon); expect(taker.task('').unwrap()).toEqual(anon); delete anon.displayName; done(); }); it('should throw on register an anonymous function without string name', function(done) { function noName() { taker.task(function() {}); } expect(noName).toThrow('Task name must be specified'); done(); }); it('should register a named function by string name', function(done) { taker.task('test1', noop); expect(taker.task('test1').unwrap()).toEqual(noop); done(); }); it('should not get a task that was not registered', function(done) { expect(taker.task('test1')).toEqual(undefined); done(); }); it('should get a task that was registered', function(done) { taker.task('test1', noop); expect(taker.task('test1').unwrap()).toEqual(noop); done(); }); it('should get the wrapped task, not original function', function(done) { var registry = taker.registry(); taker.task('test1', noop); expect(taker.task('test1').unwrap).toBeA('function'); expect(taker.task('test1')).toEqual(registry.get('test1')); done(); }); it('provides an `unwrap` method to get the original function', function(done) { taker.task('test1', noop); expect(taker.task('test1').unwrap).toBeA('function'); expect(taker.task('test1').unwrap()).toEqual(noop); done(); }); it('should return a function that was registered in some other way', function(done) { taker.registry()._tasks.test1 = noop; expect(taker.task('test1')).toEqual(noop); done(); }); it('should prefer displayName instead of name when both properties are defined', function(done) { function fn() {} fn.displayName = 'test1'; taker.task(fn); expect(taker.task('test1').unwrap()).toEqual(fn); done(); }); it('should allow different tasks to refer to the same function', function(done) { function fn() {} taker.task('foo', fn); taker.task('bar', fn); expect(taker.task('foo').unwrap()).toEqual(taker.task('bar').unwrap()); done(); }); it('should allow using aliased tasks in composite tasks', function(done) { var count = 0; function fn(cb) { count++; cb(); } taker.task('foo', fn); taker.task('bar', fn); var series = taker.series('foo', 'bar', function(cb) { expect(count).toEqual(2); cb(); }); var parallel = taker.parallel('foo', 'bar', function(cb) { setTimeout(function() { expect(count).toEqual(4); cb(); }, 500); }); taker.series(series, parallel)(done); }); it('should allow composite tasks tasks to be aliased', function(done) { var count = 0; function fn1(cb) { count += 1; cb(); } function fn2(cb) { count += 2; cb(); } taker.task('ser', taker.series(fn1, fn2)); taker.task('foo', taker.task('ser')); taker.task('par', taker.parallel(fn1, fn2)); taker.task('bar', taker.task('par')); var series = taker.series('foo', function(cb) { expect(count).toEqual(3); cb(); }); var parallel = taker.series('bar', function(cb) { setTimeout(function() { expect(count).toEqual(6); cb(); }, 500); }); taker.series(series, parallel)(done); }); }); node-gulp-4.0.2+~cs38.20.35/test/tree.js000066400000000000000000000063151415667007300173210ustar00rootroot00000000000000'use strict'; var expect = require('expect'); var Undertaker = require('../'); var simple = require('./fixtures/taskTree/simple'); var singleLevel = require('./fixtures/taskTree/singleLevel'); var doubleLevel = require('./fixtures/taskTree/doubleLevel'); var tripleLevel = require('./fixtures/taskTree/tripleLevel'); var aliasSimple = require('./fixtures/taskTree/aliasSimple'); var aliasNested = require('./fixtures/taskTree/aliasNested'); function noop(done) { done(); } describe('tree', function() { var taker; beforeEach(function(done) { taker = new Undertaker(); done(); }); it('should return a simple tree by default', function(done) { taker.task('test1', function(cb) { cb(); }); taker.task('test2', function(cb) { cb(); }); taker.task('test3', function(cb) { cb(); }); taker.task('error', function(cb) { cb(); }); var ser = taker.series('test1', 'test2'); var anon = function(cb) { cb(); }; anon.displayName = ''; taker.task('ser', taker.series('test1', 'test2')); taker.task('par', taker.parallel('test1', 'test2', 'test3')); taker.task('serpar', taker.series('ser', 'par')); taker.task('serpar2', taker.series(ser, anon)); taker.task(anon); var tree = taker.tree(); expect(tree).toEqual(simple); done(); }); it('should form a 1 level tree', function(done) { taker.task('fn1', function(cb) { cb(); }); taker.task('fn2', function(cb) { cb(); }); var tree = taker.tree({ deep: true }); expect(tree).toEqual(singleLevel); done(); }); it('should form a 2 level nested tree', function(done) { taker.task('fn1', function(cb) { cb(); }); taker.task('fn2', function(cb) { cb(); }); taker.task('fn3', taker.series('fn1', 'fn2')); var tree = taker.tree({ deep: true }); expect(tree).toEqual(doubleLevel); done(); }); it('should form a 3 level nested tree', function(done) { taker.task('fn1', taker.parallel(function(cb) { cb(); }, noop)); taker.task('fn2', taker.parallel(function(cb) { cb(); }, noop)); taker.task('fn3', taker.series('fn1', 'fn2')); var tree = taker.tree({ deep: true }); expect(tree).toEqual(tripleLevel); done(); }); it('should use the proper labels for aliased tasks (simple)', function(done) { var anon = function(cb) { cb(); }; taker.task(noop); taker.task('fn1', noop); taker.task('fn2', taker.task('noop')); taker.task('fn3', anon); taker.task('fn4', taker.task('fn3')); var tree = taker.tree({ deep: true }); expect(tree).toEqual(aliasSimple); done(); }); it('should use the proper labels for aliased tasks (nested)', function(done) { taker.task(noop); taker.task('fn1', noop); taker.task('fn2', taker.task('noop')); taker.task('fn3', function(cb) { cb(); }); taker.task('ser', taker.series(noop, function(cb) { cb(); }, 'fn1', 'fn2', 'fn3')); taker.task('par', taker.parallel(noop, function(cb) { cb(); }, 'fn1', 'fn2', 'fn3')); var tree = taker.tree({ deep: true }); expect(tree).toEqual(aliasNested); done(); }); });