├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── example.js ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended" 4 | ], 5 | 6 | "env": { 7 | "browser": false, 8 | "es6": true, 9 | "node": true, 10 | "mocha": true 11 | }, 12 | 13 | "parserOptions":{ 14 | "ecmaVersion": 9, 15 | "sourceType": "module", 16 | "ecmaFeatures": { 17 | "modules": true, 18 | "experimentalObjectRestSpread": true 19 | } 20 | }, 21 | 22 | "globals": { 23 | "document": false, 24 | "navigator": false, 25 | "window": false 26 | }, 27 | 28 | "rules": { 29 | "accessor-pairs": 2, 30 | "arrow-spacing": [2, { "before": true, "after": true }], 31 | "block-spacing": [2, "always"], 32 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 33 | "comma-dangle": [2, "never"], 34 | "comma-spacing": [2, { "before": false, "after": true }], 35 | "comma-style": [2, "last"], 36 | "constructor-super": 2, 37 | "curly": [2, "multi-line"], 38 | "dot-location": [2, "property"], 39 | "eol-last": 2, 40 | "eqeqeq": [2, "allow-null"], 41 | "generator-star-spacing": [2, { "before": true, "after": true }], 42 | "handle-callback-err": [2, "^(err|error)$" ], 43 | "indent": [2, 2, { "SwitchCase": 1 }], 44 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 45 | "keyword-spacing": [2, { "before": true, "after": true }], 46 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 47 | "new-parens": 2, 48 | "no-array-constructor": 2, 49 | "no-caller": 2, 50 | "no-class-assign": 2, 51 | "no-cond-assign": 2, 52 | "no-const-assign": 2, 53 | "no-control-regex": 2, 54 | "no-debugger": 2, 55 | "no-delete-var": 2, 56 | "no-dupe-args": 2, 57 | "no-dupe-class-members": 2, 58 | "no-dupe-keys": 2, 59 | "no-duplicate-case": 2, 60 | "no-empty-character-class": 2, 61 | "no-eval": 2, 62 | "no-ex-assign": 2, 63 | "no-extend-native": 2, 64 | "no-extra-bind": 2, 65 | "no-extra-boolean-cast": 2, 66 | "no-extra-parens": [2, "functions"], 67 | "no-fallthrough": 2, 68 | "no-floating-decimal": 2, 69 | "no-func-assign": 2, 70 | "no-implied-eval": 2, 71 | "no-inner-declarations": [2, "functions"], 72 | "no-invalid-regexp": 2, 73 | "no-irregular-whitespace": 2, 74 | "no-iterator": 2, 75 | "no-label-var": 2, 76 | "no-labels": 2, 77 | "no-lone-blocks": 2, 78 | "no-mixed-spaces-and-tabs": 2, 79 | "no-multi-spaces": 2, 80 | "no-multi-str": 2, 81 | "no-multiple-empty-lines": [2, { "max": 1 }], 82 | "no-native-reassign": 0, 83 | "no-negated-in-lhs": 2, 84 | "no-new": 2, 85 | "no-new-func": 2, 86 | "no-new-object": 2, 87 | "no-new-require": 2, 88 | "no-new-wrappers": 2, 89 | "no-obj-calls": 2, 90 | "no-octal": 2, 91 | "no-octal-escape": 2, 92 | "no-proto": 0, 93 | "no-redeclare": 2, 94 | "no-regex-spaces": 2, 95 | "no-return-assign": 2, 96 | "no-self-compare": 2, 97 | "no-sequences": 2, 98 | "no-shadow-restricted-names": 2, 99 | "no-spaced-func": 2, 100 | "no-sparse-arrays": 2, 101 | "no-this-before-super": 2, 102 | "no-throw-literal": 2, 103 | "no-trailing-spaces": 0, 104 | "no-undef": 2, 105 | "no-undef-init": 2, 106 | "no-unexpected-multiline": 2, 107 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 108 | "no-unreachable": 2, 109 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 110 | "no-useless-call": 0, 111 | "no-with": 2, 112 | "one-var": [0, { "initialized": "never" }], 113 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 114 | "padded-blocks": [0, "never"], 115 | "quotes": [2, "single", "avoid-escape"], 116 | "radix": 2, 117 | "semi": [2, "always"], 118 | "semi-spacing": [2, { "before": false, "after": true }], 119 | "space-before-blocks": [2, "always"], 120 | "space-before-function-paren": [2, "never"], 121 | "space-in-parens": [2, "never"], 122 | "space-infix-ops": 2, 123 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 124 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 125 | "use-isnan": 2, 126 | "valid-typeof": 2, 127 | "wrap-iife": [2, "any"], 128 | "yoda": [2, "never"] 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | .idea 4 | .vscode 5 | *.sublime-* 6 | 7 | # test related, or directories generated by tests 8 | test/actual 9 | actual 10 | coverage 11 | .nyc* 12 | 13 | # npm 14 | node_modules 15 | npm-debug.log 16 | 17 | # yarn 18 | yarn.lock 19 | yarn-error.log 20 | 21 | # misc 22 | _gh_pages 23 | _draft 24 | _drafts 25 | bower_components 26 | vendor 27 | temp 28 | tmp 29 | TODO.md 30 | package-lock.json -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | - windows 6 | language: node_js 7 | node_js: 8 | - node 9 | - '11' 10 | - '10' 11 | - '9' 12 | - '8' 13 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | const Base = require('base'); 5 | const tasks = require('base-task'); 6 | 7 | const base = new Base(); 8 | base.use(tasks()); 9 | 10 | /** 11 | * Define tasks 12 | */ 13 | 14 | base.task('foo', function(cb) { 15 | console.log('this is foo!'); 16 | cb(); 17 | }); 18 | base.task('bar', function(cb) { 19 | console.log('this is bar!'); 20 | cb(); 21 | }); 22 | 23 | /** 24 | * Build tasks 25 | */ 26 | 27 | base.build(['foo', 'bar']) 28 | .then(() => { 29 | // this is foo! 30 | // this is bar! 31 | console.log('done!'); 32 | }) 33 | .catch(console.error) 34 | ``` 35 | 36 | See the [composer][] documentation for more details, or to create bug reports related to running or registering tasks. 37 | 38 | 39 | ## API 40 | 41 | ### .task 42 | 43 | Register a task 44 | 45 | **Params** 46 | 47 | * `name` **{String}**: Task name to register (tasks are cached on `app.tasks`) 48 | * `dependencies` **{String|Array|Function}**: String, list or array of tasks. 49 | * `callback` **{Function}**: Function to be called when the task is executed. Task functions should either return a stream or call the callback to let [composer][] know when the task is finished. 50 | 51 | **Examples** 52 | 53 | Register a task. 54 | 55 | ```js 56 | app.task('default', function() { 57 | // return the stream to signal "done" 58 | return app.src('pages/*.hbs') 59 | .pipe(app.dest('dist')); 60 | }); 61 | ``` 62 | 63 | Register a task with dependencies (other tasks to run before executing the task): 64 | 65 | ```js 66 | app.task('site', ['styles'], function() { 67 | return app.src('pages/*.hbs') 68 | .pipe(app.dest('dist')); 69 | }); 70 | 71 | app.task('default', ['site']); 72 | ``` 73 | 74 | **Get a task** 75 | 76 | ```js 77 | const task = app.task('site'); 78 | ``` 79 | 80 | ### .build 81 | 82 | Run a task or array of tasks. 83 | 84 | 85 | **Promise examples** 86 | 87 | ```js 88 | // run the "default" task, if defined 89 | app.build(); 90 | app.build('default'); 91 | 92 | // run an array of tasks 93 | app.build(['foo', 'bar']) 94 | .then(() => console.log('done!')) 95 | .catch(console.error); 96 | ``` 97 | 98 | 99 | **Callback examples** 100 | 101 | ```js 102 | // run the "default" task, if defined 103 | app.build(function(err, results) { 104 | if (err) return console.error(err); 105 | console.log(results); 106 | }); 107 | 108 | app.build('default', function(err, results) { 109 | if (err) return console.error(err); 110 | console.log(results); 111 | }); 112 | 113 | app.build(['foo', 'bar'], function(err, results) { 114 | if (err) return console.error(err); 115 | console.log(results); 116 | }); 117 | ``` 118 | 119 | ### .series 120 | 121 | Compose task or list of tasks into a single function that runs the tasks in series. 122 | 123 | **Params** 124 | 125 | * `tasks` **{String|Array|Function}**: List of tasks by name, function, or array of names/functions. 126 | * `returns` **{Function}**: Composed function that may take a callback function. 127 | 128 | **Example** 129 | 130 | ```js 131 | app.task('foo', function(cb) { 132 | console.log('this is foo'); 133 | cb(); 134 | }); 135 | 136 | const build = app.series('foo', function(cb) { 137 | console.log('this is bar'); 138 | cb(); 139 | }); 140 | 141 | build(function(err) { 142 | if (err) return console.error(err); 143 | console.log('finished'); 144 | }); 145 | //=> this is foo 146 | //=> this is bar 147 | //=> finished 148 | ``` 149 | 150 | ### .parallel 151 | 152 | Compose task or list of tasks into a single function that runs the tasks in parallel. 153 | 154 | **Params** 155 | 156 | * `tasks` **{String|Array|Function}**: List of tasks by name, function, or array of names/functions. 157 | * `returns` **{Function}**: Composed function that may take a callback function. 158 | 159 | **Example** 160 | 161 | ```js 162 | app.task('foo', function(cb) { 163 | setTimeout(function() { 164 | console.log('this is foo'); 165 | cb(); 166 | }, 500); 167 | }); 168 | 169 | const build = app.parallel('foo', function(cb) { 170 | console.log('this is bar'); 171 | cb(); 172 | }); 173 | 174 | build(function(err) { 175 | if (err) return console.error(err); 176 | console.log('finished'); 177 | }); 178 | //=> this is bar 179 | //=> this is foo 180 | //=> finished 181 | ``` 182 | 183 | ## Events 184 | 185 | The following events are emitted by [composer][]. See the composer docs for more details 186 | 187 | ### on.task 188 | 189 | Emitted when a `task` is `register`, `starting` and `finished`. 190 | 191 | ```js 192 | app.on('task', function(task) { 193 | console.log(task.status); 194 | //=> 'register' 195 | }); 196 | ``` 197 | 198 | ### on.build 199 | 200 | Emitted when a `build` is `starting` and `finished`. 201 | 202 | ```js 203 | app.on('build', function(build) { 204 | console.log(build.status); 205 | //=> 'starting' 206 | }); 207 | ``` 208 | 209 | ## History 210 | 211 | ### v2.0.0 212 | 213 | - Bumped [composer][] to v2.0.0. 214 | 215 | ### v0.3.0 216 | 217 | - Bumped [composer][] to v0.11.0, so the `.watch` method is no longer included by default. To add `.watch`, use the [base-watch][] plugin. 218 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # base-task [![NPM version](https://img.shields.io/npm/v/base-task.svg?style=flat)](https://www.npmjs.com/package/base-task) [![NPM monthly downloads](https://img.shields.io/npm/dm/base-task.svg?style=flat)](https://npmjs.org/package/base-task) [![NPM total downloads](https://img.shields.io/npm/dt/base-task.svg?style=flat)](https://npmjs.org/package/base-task) [![Linux Build Status](https://img.shields.io/travis/base/base-task.svg?style=flat&label=Travis)](https://travis-ci.org/base/base-task) 2 | 3 | > Base plugin that provides a very thin wrapper around [https://github.com/doowb/composer](https://github.com/doowb/composer) for adding task methods to your Base application. 4 | 5 | Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. 6 | 7 | ## Install 8 | 9 | Install with [npm](https://www.npmjs.com/): 10 | 11 | ```sh 12 | $ npm install --save base-task 13 | ``` 14 | 15 | ## Usage 16 | 17 | ```js 18 | const Base = require('base'); 19 | const tasks = require('base-task'); 20 | const base = new Base(); 21 | 22 | base.use(tasks()); 23 | 24 | /** 25 | * Define tasks 26 | */ 27 | 28 | base.task('foo', cb => { 29 | console.log('this is foo!'); 30 | cb(); 31 | }); 32 | 33 | base.task('bar', cb => { 34 | console.log('this is bar!'); 35 | cb(); 36 | }); 37 | 38 | /** 39 | * Build tasks 40 | */ 41 | 42 | base.build(['foo', 'bar']) 43 | .then(() => { 44 | // this is foo! 45 | // this is bar! 46 | console.log('done!'); 47 | }) 48 | .catch(console.error) 49 | ``` 50 | 51 | See the [composer](https://github.com/doowb/composer) documentation for more details, or to create bug reports related to running or registering tasks. 52 | 53 | ## API 54 | 55 | ### .task 56 | 57 | Register a task 58 | 59 | **Params** 60 | 61 | * `name` **{String}**: Task name to register (tasks are cached on `app.tasks`) 62 | * `dependencies` **{String|Array|Function}**: String, list or array of tasks. 63 | * `callback` **{Function}**: Function to be called when the task is executed. Task functions should either return a stream or call the callback to let [composer](https://github.com/doowb/composer) know when the task is finished. 64 | 65 | **Examples** 66 | 67 | Register a task. 68 | 69 | ```js 70 | app.task('default', function() { 71 | // return the stream to signal "done" 72 | return app.src('pages/*.hbs') 73 | .pipe(app.dest('dist')); 74 | }); 75 | ``` 76 | 77 | Register a task with dependencies (other tasks to run before executing the task): 78 | 79 | ```js 80 | app.task('site', ['styles'], function() { 81 | return app.src('pages/*.hbs') 82 | .pipe(app.dest('dist')); 83 | }); 84 | 85 | app.task('default', ['site']); 86 | ``` 87 | 88 | **Get a task** 89 | 90 | ```js 91 | const task = app.task('site'); 92 | ``` 93 | 94 | ### .build 95 | 96 | Run a task or array of tasks. 97 | 98 | **Promise examples** 99 | 100 | ```js 101 | // run the "default" task, if defined 102 | app.build(); 103 | app.build('default'); 104 | 105 | // run an array of tasks 106 | app.build(['foo', 'bar']) 107 | .then(() => console.log('done!')) 108 | .catch(console.error); 109 | ``` 110 | 111 | **Callback examples** 112 | 113 | ```js 114 | // run the "default" task, if defined 115 | app.build(function(err, results) { 116 | if (err) return console.error(err); 117 | console.log(results); 118 | }); 119 | 120 | app.build('default', function(err, results) { 121 | if (err) return console.error(err); 122 | console.log(results); 123 | }); 124 | 125 | app.build(['foo', 'bar'], function(err, results) { 126 | if (err) return console.error(err); 127 | console.log(results); 128 | }); 129 | ``` 130 | 131 | ### .series 132 | 133 | Compose task or list of tasks into a single function that runs the tasks in series. 134 | 135 | **Params** 136 | 137 | * `tasks` **{String|Array|Function}**: List of tasks by name, function, or array of names/functions. 138 | * `returns` **{Function}**: Composed function that may take a callback function. 139 | 140 | **Example** 141 | 142 | ```js 143 | app.task('foo', cb => { 144 | console.log('this is foo'); 145 | cb(); 146 | }); 147 | 148 | const build = app.series('foo', cb => { 149 | console.log('this is bar'); 150 | cb(); 151 | }); 152 | 153 | build(function(err) { 154 | if (err) return console.error(err); 155 | console.log('finished'); 156 | }); 157 | //=> this is foo 158 | //=> this is bar 159 | //=> finished 160 | ``` 161 | 162 | ### .parallel 163 | 164 | Compose task or list of tasks into a single function that runs the tasks in parallel. 165 | 166 | **Params** 167 | 168 | * `tasks` **{String|Array|Function}**: List of tasks by name, function, or array of names/functions. 169 | * `returns` **{Function}**: Composed function that may take a callback function. 170 | 171 | **Example** 172 | 173 | ```js 174 | app.task('foo', cb => { 175 | setTimeout(function() { 176 | console.log('this is foo'); 177 | cb(); 178 | }, 500); 179 | }); 180 | 181 | const build = app.parallel('foo', cb => { 182 | console.log('this is bar'); 183 | cb(); 184 | }); 185 | 186 | build(function(err) { 187 | if (err) return console.error(err); 188 | console.log('finished'); 189 | }); 190 | //=> this is bar 191 | //=> this is foo 192 | //=> finished 193 | ``` 194 | 195 | ## Events 196 | 197 | The following events are emitted by [composer](https://github.com/doowb/composer). See the composer docs for more details 198 | 199 | ### on.task 200 | 201 | Emitted when a `task` is `register`, `starting` and `finished`. 202 | 203 | ```js 204 | app.on('task', function(task) { 205 | console.log(task.status); 206 | //=> 'register' 207 | }); 208 | ``` 209 | 210 | ### on.build 211 | 212 | Emitted when a `build` is `starting` and `finished`. 213 | 214 | ```js 215 | app.on('build', function(build) { 216 | console.log(build.status); 217 | //=> 'starting' 218 | }); 219 | ``` 220 | 221 | ## History 222 | 223 | ### v2.0.0 224 | 225 | * Bumped [composer](https://github.com/doowb/composer) to v2.0.0. 226 | 227 | ### v0.3.0 228 | 229 | * Bumped [composer](https://github.com/doowb/composer) to v0.11.0, so the `.watch` method is no longer included by default. To add `.watch`, use the [base-watch](https://github.com/node-base/base-watch) plugin. 230 | 231 | ## About 232 | 233 |
234 | Contributing 235 | 236 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 237 | 238 |
239 | 240 |
241 | Running Tests 242 | 243 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 244 | 245 | ```sh 246 | $ npm install && npm test 247 | ``` 248 | 249 |
250 | 251 |
252 | Building docs 253 | 254 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 255 | 256 | To generate the readme, run the following command: 257 | 258 | ```sh 259 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 260 | ``` 261 | 262 |
263 | 264 | ### Related projects 265 | 266 | Other base plugins you might be interested in: 267 | 268 | * [base-cli](https://www.npmjs.com/package/base-cli): Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a… [more](https://github.com/node-base/base-cli) | [homepage](https://github.com/node-base/base-cli "Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a few plugins, like 'base-store', 'base-options' and 'base-data'.") 269 | * [base-generators](https://www.npmjs.com/package/base-generators): Adds project-generator support to your `base` application. | [homepage](https://github.com/node-base/base-generators "Adds project-generator support to your `base` application.") 270 | * [base-option](https://www.npmjs.com/package/base-option): Adds a few options methods to base, like `option`, `enable` and `disable`. See the readme… [more](https://github.com/node-base/base-option) | [homepage](https://github.com/node-base/base-option "Adds a few options methods to base, like `option`, `enable` and `disable`. See the readme for the full API.") 271 | * [base-plugins](https://www.npmjs.com/package/base-plugins): Adds 'smart plugin' support to your base application. | [homepage](https://github.com/node-base/base-plugins "Adds 'smart plugin' support to your base application.") 272 | * [base-store](https://www.npmjs.com/package/base-store): Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object… [more](https://github.com/node-base/base-store) | [homepage](https://github.com/node-base/base-store "Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object that exposes all of the methods from the data-store library. Also now supports sub-stores!") 273 | * [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks") 274 | 275 | ### Contributors 276 | 277 | | **Commits** | **Contributor** | 278 | | --- | --- | 279 | | 60 | [jonschlinkert](https://github.com/jonschlinkert) | 280 | | 6 | [doowb](https://github.com/doowb) | 281 | | 2 | [davequick](https://github.com/davequick) | 282 | 283 | ### Author 284 | 285 | **Jon Schlinkert** 286 | 287 | * [GitHub Profile](https://github.com/jonschlinkert) 288 | * [Twitter Profile](https://twitter.com/jonschlinkert) 289 | * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) 290 | 291 | ### License 292 | 293 | Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). 294 | Released under the [MIT License](LICENSE). 295 | 296 | *** 297 | 298 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 22, 2018._ 299 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | const Base = require('base'); 2 | const tasks = require('./'); 3 | 4 | const base = new Base(); 5 | base.use(tasks()); 6 | 7 | /** 8 | * Define tasks 9 | */ 10 | 11 | base.task('foo', function(cb) { 12 | console.log('this is foo!'); 13 | cb(); 14 | }); 15 | base.task('bar', function(cb) { 16 | console.log('this is bar!'); 17 | cb(); 18 | }); 19 | 20 | /** 21 | * Build tasks 22 | */ 23 | 24 | base.build(['foo', 'bar']) 25 | .then(() => { 26 | // this is foo! 27 | // this is bar! 28 | console.log('done!'); 29 | }) 30 | .catch(console.error) 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * base-task 3 | * 4 | * Copyright (c) 2015-2018, Jon Schlinkert. 5 | * Released under the MIT License. 6 | */ 7 | 8 | const define = require('define-property'); 9 | const Composer = require('composer'); 10 | 11 | module.exports = function(options) { 12 | return function(app) { 13 | this.composer = new Composer(options); 14 | this.tasks = this.composer.tasks; 15 | define(this, 'build', this.composer.build.bind(this.composer)); 16 | define(this, 'task', this.composer.task.bind(this.composer)); 17 | define(this, 'parallel', this.composer.parallel.bind(this.composer)); 18 | define(this, 'series', this.composer.series.bind(this.composer)); 19 | this.composer.on('build', this.emit.bind(this, 'build')); 20 | this.composer.on('task', this.emit.bind(this, 'task')); 21 | }; 22 | }; 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "base-task", 3 | "description": "Base plugin that provides a very thin wrapper around for adding task methods to your Base application.", 4 | "version": "3.0.0", 5 | "homepage": "https://github.com/base/base-task", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "contributors": [ 8 | "Brian Woodward (https://twitter.com/doowb)", 9 | "Dave Quick (http://dq.gg)", 10 | "Jon Schlinkert (http://twitter.com/jonschlinkert)" 11 | ], 12 | "repository": "base/base-task", 13 | "bugs": { 14 | "url": "https://github.com/base/base-task/issues" 15 | }, 16 | "license": "MIT", 17 | "files": [ 18 | "index.js" 19 | ], 20 | "main": "index.js", 21 | "engines": { 22 | "node": ">=8" 23 | }, 24 | "scripts": { 25 | "test": "mocha" 26 | }, 27 | "dependencies": { 28 | "composer": "^4.1.0", 29 | "define-property": "^2.0.2" 30 | }, 31 | "devDependencies": { 32 | "base": "^3.0.0", 33 | "gulp-format-md": "^2.0.0", 34 | "mocha": "^5.2.0" 35 | }, 36 | "keywords": [ 37 | "api", 38 | "app", 39 | "application", 40 | "base", 41 | "base-plugin", 42 | "baseplugin", 43 | "build", 44 | "building-blocks", 45 | "composer", 46 | "control", 47 | "create", 48 | "flow", 49 | "framework", 50 | "generate", 51 | "plugin", 52 | "plugins", 53 | "run", 54 | "task", 55 | "tasks", 56 | "tool", 57 | "toolkit", 58 | "tools" 59 | ], 60 | "verb": { 61 | "toc": false, 62 | "layout": "default", 63 | "tasks": [ 64 | "readme" 65 | ], 66 | "plugins": [ 67 | "gulp-format-md" 68 | ], 69 | "related": { 70 | "description": "Other base plugins you might be interested in:", 71 | "list": [ 72 | "base", 73 | "base-cli", 74 | "base-generators", 75 | "base-option", 76 | "base-plugins", 77 | "base-store" 78 | ] 79 | }, 80 | "reflinks": [ 81 | "base-watch", 82 | "composer" 83 | ] 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var Base = require('base'); 5 | var assert = require('assert'); 6 | var tasks = require('./'); 7 | var base; 8 | 9 | describe('tasks', function() { 10 | beforeEach(function() { 11 | base = new Base(); 12 | base.use('base-task', tasks()); 13 | }); 14 | 15 | it('should register the plugin', function() { 16 | assert(base.isRegistered('base-task')); 17 | }); 18 | 19 | it('should not register the plugin more than once', function() { 20 | let count = 0; 21 | base = new Base(); 22 | base.on('plugin', () => (count++)); 23 | base.use('task', tasks()); 24 | base.use('task', tasks()); 25 | base.use('task', tasks()); 26 | base.use('task', tasks()); 27 | assert.equal(count, 1); 28 | }); 29 | 30 | it('should decorate a `tasks` property', function() { 31 | assert(base.tasks); 32 | assert.equal(typeof base.tasks, 'object'); 33 | }); 34 | 35 | it('should decorate a `task` method', function() { 36 | assert.equal(typeof base.task, 'function'); 37 | }); 38 | 39 | it('should decorate a `build` method', function() { 40 | assert.equal(typeof base.build, 'function'); 41 | }); 42 | 43 | it('should run a task', function(cb) { 44 | let count = 0; 45 | base.task('a', function(next) { 46 | count++; 47 | next(); 48 | }); 49 | base.build('a', function(err) { 50 | assert.equal(count, 1); 51 | cb(); 52 | }); 53 | }); 54 | 55 | it('should run multiple tasks', function(cb) { 56 | let count = 0; 57 | base.task('a', function(next) { 58 | count++; 59 | next(); 60 | }); 61 | 62 | base.task('b', function(next) { 63 | count++; 64 | next(); 65 | }); 66 | 67 | base.build(['a', 'b'], function(err) { 68 | assert.equal(count, 2); 69 | cb(); 70 | }); 71 | }); 72 | 73 | it('should return a promise', function() { 74 | let count = 0; 75 | base.task('a', function(next) { 76 | count++; 77 | next(); 78 | }); 79 | 80 | base.task('b', function(next) { 81 | count++; 82 | next(); 83 | }); 84 | 85 | return base.build(['a', 'b']) 86 | .then(() => { 87 | assert.equal(count, 2); 88 | }); 89 | }); 90 | 91 | it('should emit task events', async() => { 92 | let count = 0; 93 | 94 | base.on('task', task => { 95 | switch (task.status) { 96 | case 'starting': 97 | case 'finished': { 98 | count++; 99 | } 100 | } 101 | }); 102 | 103 | base.task('a', next => next()); 104 | base.task('b', next => next()); 105 | 106 | await base.build(['a', 'b']); 107 | assert.equal(count, 4); 108 | }); 109 | }); 110 | --------------------------------------------------------------------------------