development-core
Advanced tools
Comparing version 0.7.4 to 0.7.8
@@ -1,2 +0,2 @@ | ||
"use strict";function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function generateTask(t,e){var r=[];return _.each(_.isArray(t)?t:[t],function(t){t.watchTasks&&(t.oper=(t.oper||TaskConfig_1.Operation.default)|TaskConfig_1.Operation.watch),utils_1.matchTaskInfo(t,e)&&utils_1.matchTaskGroup(t,e)&&((t.oper&TaskConfig_1.Operation.watch)>0?r.push(createWatchTask(t)):_.isFunction(t.task)?r.push(createTask(t)):r.push(createPipesTask(t)))}),r}function createTask(t){var e=function(e,r){var o=e.subTaskName(t.name);return console.log("register custom dynamic task:",chalk.cyan(o)),r.task(o,function(){return t.task(e,t,r)}),o};return new DynamicTask({order:t.order,oper:t.oper,watch:t.watch,group:t.group},e)}function createWatchTask(t){var e=function(e,r){var o=_.isFunction(t.watchTasks)?t.watchTasks(e):t.watchTasks;_.isFunction(_.last(o))||o.push(function(r){t.watchChanged&&t.watchChanged(r,e)}),o=_.map(o,function(t){return _.isString(t)?e.subTaskName(t):t});var n=e.subTaskName(t);return console.log("register watch dynamic task:",chalk.cyan(n)),r.task(n,function(){var n=e.getSrc(t,t);console.log("watch, src:",chalk.cyan.call(chalk,n)),r.watch(n,o)}),n};return new DynamicTask({order:t.order,oper:t.oper,watch:t.watch,group:t.group},e)}function createPipesTask(t){return new DynamicPipeTask(t)}var _get=function t(e,r,o){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,r);if(void 0===n){var a=Object.getPrototypeOf(e);return null===a?void 0:t(a,r,o)}if("value"in n)return n.value;var i=n.get;if(void 0!==i)return i.call(o)},_createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,r,o){return r&&t(e.prototype,r),o&&t(e,o),e}}(),_=require("lodash"),coregulp=require("gulp"),chalk=require("chalk"),TaskConfig_1=require("./TaskConfig"),utils_1=require("./utils"),PipeTask_1=require("./PipeTask"),DynamicTask=function(){function t(e,r){_classCallCheck(this,t),this.decorator=e,this.factory=r}return _createClass(t,[{key:"setup",value:function(t,e){var r=this.factory(t,e||coregulp);return r&&(this.decorator.taskName=r),r}}]),t}(),DynamicPipeTask=function(t){function e(t,r){_classCallCheck(this,e);var o=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,r));return o.dt=t,o.decorator=r||t,o}return _inherits(e,t),_createClass(e,[{key:"getOption",value:function(t){return this.dt||t.option}},{key:"sourceStream",value:function(t,r,o){var n=this;return this.dt.pipe?Promise.resolve(_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"sourceStream",this).call(this,t,r,o)).then(function(e){return new Promise(function(r,o){n.dt.pipe(e,t,n.dt,function(t){t?o(t):r(e)})})}):_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"sourceStream",this).call(this,t,r,o)}},{key:"pipes",value:function t(r,o,n){var t=_.isFunction(this.dt.pipes)?this.dt.pipes(r,o,n):this.dt.pipes;return t=t||[],t.concat(_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"pipes",this).call(this,r,o,n))}},{key:"output",value:function(t,r,o){if(null===this.dt.output)return[function(t){return t}];var n=_.isFunction(this.dt.output)?this.dt.output(t,r,o):this.dt.output;return n=n||[],n.concat(_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"output",this).call(this,t,r,o))}}]),e}(PipeTask_1.PipeTask);exports.generateTask=generateTask; | ||
"use strict";function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function generateTask(t,e){var r=[];return _.each(_.isArray(t)?t:[t],function(t){t.watchTasks&&(t.oper=(t.oper||TaskConfig_1.Operation.default)|TaskConfig_1.Operation.watch),utils_1.matchTaskInfo(t,e)&&utils_1.matchTaskGroup(t,e)&&((t.oper&TaskConfig_1.Operation.watch)>0?r.push(createWatchTask(t)):_.isFunction(t.task)?r.push(createTask(t)):r.push(createPipesTask(t)))}),r}function createTask(t){var e=function(e,r){var o=e.subTaskName(t.name);return console.log("register custom dynamic task:",chalk.cyan(o)),r.task(o,function(){return t.task(e,t,r)}),o};return new DynamicTask({order:t.order,oper:t.oper,watch:t.watch,group:t.group},e)}function createWatchTask(t){var e=function(e,r){var o=_.isFunction(t.watchTasks)?t.watchTasks(e):t.watchTasks;_.isFunction(_.last(o))||o.push(function(r){t.watchChanged&&t.watchChanged(r,e)}),o=_.map(o,function(t){return _.isString(t)?e.subTaskName(t):t});var n=e.subTaskName(t);return console.log("register watch dynamic task:",chalk.cyan(n)),r.task(n,function(){var n=e.getSrc(t,t);console.log("watch, src:",chalk.cyan.call(chalk,n)),r.watch(n,o)}),n};return new DynamicTask({order:t.order,oper:t.oper,watch:t.watch,group:t.group},e)}function createPipesTask(t){return new DynamicPipeTask(t)}var _get=function t(e,r,o){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,r);if(void 0===n){var a=Object.getPrototypeOf(e);return null===a?void 0:t(a,r,o)}if("value"in n)return n.value;var i=n.get;if(void 0!==i)return i.call(o)},_createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,r,o){return r&&t(e.prototype,r),o&&t(e,o),e}}(),_=require("lodash"),coregulp=require("gulp"),chalk=require("chalk"),TaskConfig_1=require("./TaskConfig"),utils_1=require("./utils"),PipeTask_1=require("./PipeTask"),DynamicTask=function(){function t(e,r){_classCallCheck(this,t),this.decorator=e,this.factory=r}return _createClass(t,[{key:"setup",value:function(t,e){var r=this.factory(t,e||coregulp);return r&&(this.decorator.taskName=r),r}}]),t}(),DynamicPipeTask=function(t){function e(t,r){_classCallCheck(this,e);var o=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,r));return o.dt=t,o.decorator=r||t,o}return _inherits(e,t),_createClass(e,[{key:"getOption",value:function(t){return this.dt||t.option}},{key:"sourceStream",value:function(t,r,o){var n=this;return this.dt.pipe?Promise.resolve(_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"sourceStream",this).call(this,t,r,o)).then(function(e){return _.isArray(e)?Promise.all(_.map(e,function(r){return new Promise(function(o,a){n.dt.pipe(r,t,n.dt,function(t){t?a(t):o(e)})})})):new Promise(function(r,o){n.dt.pipe(e,t,n.dt,function(t){t?o(t):r(e)})})}):_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"sourceStream",this).call(this,t,r,o)}},{key:"pipes",value:function t(r,o,n){var t=_.isFunction(this.dt.pipes)?this.dt.pipes(r,o,n):this.dt.pipes;return t=t||[],t.concat(_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"pipes",this).call(this,r,o,n))}},{key:"output",value:function(t,r,o){if(null===this.dt.output)return[function(t){return t}];var n=_.isFunction(this.dt.output)?this.dt.output(t,r,o):this.dt.output;return n=n||[],n.concat(_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"output",this).call(this,t,r,o))}}]),e}(PipeTask_1.PipeTask);exports.generateTask=generateTask; | ||
//# sourceMappingURL=sourcemaps/generateTask.js.map |
/// <reference types="gulp" /> | ||
import { Gulp } from 'gulp'; | ||
import { IAssertDist, ITaskInfo, TaskResult, ITaskConfig, IPipeOperate, Pipe, OutputPipe, ITask, ITransform } from './TaskConfig'; | ||
import { TransformSource, IAssertDist, ITaskInfo, TaskResult, ITaskConfig, IPipeOperate, Pipe, OutputPipe, ITask, ITransform } from './TaskConfig'; | ||
/** | ||
@@ -24,7 +24,7 @@ * pipe task. | ||
* @param {Gulp} gulp | ||
* @returns {(ITransform | Promise<ITransform>)} | ||
* @returns {(TransformSource | Promise<TransformSource>)} | ||
* | ||
* @memberOf IPipeTask | ||
*/ | ||
sourceStream(config: ITaskConfig, dist: IAssertDist, gulp: Gulp): ITransform | Promise<ITransform>; | ||
sourceStream(config: ITaskConfig, dist: IAssertDist, gulp: Gulp): TransformSource | Promise<TransformSource>; | ||
/** | ||
@@ -51,4 +51,30 @@ * task pipe works. | ||
output(config: ITaskConfig, dist: IAssertDist, gulp?: Gulp): OutputPipe[]; | ||
/** | ||
* execute task works. | ||
* | ||
* @param {ITaskConfig} config | ||
* @param {Gulp} gulp | ||
* @returns {Promise<any>} | ||
* | ||
* @memberOf IPipeTask | ||
*/ | ||
execute(config: ITaskConfig, gulp: Gulp): Promise<any>; | ||
} | ||
/** | ||
* mutil source stream pipe task run way. | ||
* | ||
* @export | ||
* @enum {number} | ||
*/ | ||
export declare enum RunWay { | ||
/** | ||
* run mutil source stream by sequence. | ||
*/ | ||
sequence = 1, | ||
/** | ||
* run mutil source stream by parallel. | ||
*/ | ||
parallel = 2, | ||
} | ||
/** | ||
* Task base class. | ||
@@ -62,2 +88,9 @@ * | ||
/** | ||
* run mutil source stream way. default parallel. | ||
* | ||
* | ||
* @memberOf PipeTask | ||
*/ | ||
runWay: RunWay; | ||
/** | ||
* task default name. | ||
@@ -80,3 +113,3 @@ * | ||
protected getOption(config: ITaskConfig): IAssertDist; | ||
sourceStream(config: ITaskConfig, option: IAssertDist, gulp: Gulp): ITransform | Promise<ITransform>; | ||
sourceStream(config: ITaskConfig, option: IAssertDist, gulp: Gulp): TransformSource | Promise<TransformSource>; | ||
/** | ||
@@ -93,3 +126,23 @@ * match pipe Operate | ||
protected match(p: IPipeOperate, name: string, config: ITaskConfig): boolean; | ||
protected working(source: ITransform, config: ITaskConfig, option: IAssertDist, gulp: Gulp): Promise<void | {}[]>; | ||
/** | ||
* execute task working | ||
* | ||
* @param {ITaskConfig} config | ||
* @param {Gulp} gulp | ||
* @returns {Promise<any>} | ||
* | ||
* @memberOf PipeTask | ||
*/ | ||
execute(config: ITaskConfig, gulp: Gulp): Promise<any>; | ||
/** | ||
* setup task works. | ||
* | ||
* @param {ITaskConfig} config | ||
* @param {Gulp} [gulp] | ||
* @returns {TaskResult} | ||
* | ||
* @memberOf PipeTask | ||
*/ | ||
setup(config: ITaskConfig, gulp?: Gulp): TaskResult; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(n,r,t){return r&&e(n.prototype,r),t&&e(n,t),n}}(),coregulp=require("gulp"),chalk=require("chalk"),_=require("lodash"),PipeTask=function(){function e(n){_classCallCheck(this,e),this.decorator=n||{}}return _createClass(e,[{key:"pipes",value:function(e,n,r){var t=e.option,o=t.loader;return o&&_.isFunction(o.pipes)?_.isFunction(o.pipes)?o.pipes(e,t,r):_.filter(o.pipes,function(e){return _.isFunction(e)||e.name&&e.name===n.name}):[]}},{key:"output",value:function(e,n,r){var t=e.option,o=t.loader;if(o&&!_.isString(o)&&!_.isArray(o)){if(o.output)return _.isFunction(o.output)?o.output(e,t,r):_.filter(o.pipes,function(e){return _.isFunction(e)||e.name&&e.name===n.name});if(null===o.output)return[function(e){return e}]}return[function(t){return t.pipe(r.dest(e.getDist(n)))}]}},{key:"getOption",value:function(e){return e.option}},{key:"sourceStream",value:function(e,n,r){return r.src(e.getSrc(n,this.decorator))}},{key:"match",value:function(e,n,r){return!!e&&(!(e.name&&!n.endsWith(n))&&!(e.oper&&(e.oper&r.oper)<=0))}},{key:"setup",value:function(e,n){var r=this;n=n||coregulp;var t=this.getOption(e),o=e.subTaskName(t,this.name);return console.log("register "+this.name+" task:",chalk.cyan(o)),n.task(o,function(){return Promise.resolve(r.sourceStream(e,t,n)).then(function(i){return Promise.all(_.map(r.pipes(e,t,n),function(i){return _.isFunction(i)?i(e,t,n):r.match(i,o,e)?Promise.resolve(i.toTransform(e,t,n)).then(function(e){return e.order=i.order,e}):null})).then(function(n){var t=n.length;return n=_.orderBy(_.filter(n,function(e){return e}),function(e){return _.isArray(e)?t:_.isNumber(e.order)?e.order:t}),_.each(n,function(n){r.match(n,o,e)&&(i=_.isFunction(n.transformSourcePipe)?n.transformSourcePipe(i):_.isFunction(i.transformPipe)?i.transformPipe(n):i.pipe(n))}),i})}).then(function(i){var u=r.output(e,t,n);return Promise.all(_.map(u,function(u){return _.isFunction(u)?u(i,e,t,n):r.match(u,o,e)?u.toTransform(i,e,t,n):null}))}).then(function(e){return Promise.all(_.map(e,function(e){return new Promise(function(n,r){e?e.once("end",function(){n(e)}).once("error",r):n()})}))}).catch(function(e){console.log(chalk.red(e)),process.exit(0)})}),this.decorator.taskName=o,o}}]),e}();exports.PipeTask=PipeTask; | ||
"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(n,r,t){return r&&e(n.prototype,r),t&&e(n,t),n}}(),coregulp=require("gulp"),chalk=require("chalk"),_=require("lodash");!function(e){e[e.sequence=1]="sequence",e[e.parallel=2]="parallel"}(exports.RunWay||(exports.RunWay={}));var RunWay=exports.RunWay,PipeTask=function(){function e(n){_classCallCheck(this,e),this.runWay=RunWay.parallel,this.decorator=n||{}}return _createClass(e,[{key:"pipes",value:function(e,n,r){var t=e.option,o=t.loader;return o&&_.isFunction(o.pipes)?_.isFunction(o.pipes)?o.pipes(e,t,r):_.filter(o.pipes,function(e){return _.isFunction(e)||e.name&&e.name===n.name}):[]}},{key:"output",value:function(e,n,r){var t=e.option,o=t.loader;if(o&&!_.isString(o)&&!_.isArray(o)){if(o.output)return _.isFunction(o.output)?o.output(e,t,r):_.filter(o.pipes,function(e){return _.isFunction(e)||e.name&&e.name===n.name});if(null===o.output)return[function(e){return e}]}return[function(t){return t.pipe(r.dest(e.getDist(n)))}]}},{key:"getOption",value:function(e){return e.option}},{key:"sourceStream",value:function(e,n,r){return r.src(e.getSrc(n,this.decorator))}},{key:"match",value:function(e,n,r){return!!e&&(!(e.name&&!n.endsWith(n))&&!(e.oper&&(e.oper&r.oper)<=0))}},{key:"working",value:function(e,n,r,t){var o=this,u=n.subTaskName(r,this.name);return Promise.resolve(e).then(function(e){return Promise.all(_.map(o.pipes(n,r,t),function(e){return _.isFunction(e)?e(n,r,t):o.match(e,u,n)?Promise.resolve(e.toTransform(n,r,t)).then(function(n){return n.order=e.order,n}):null})).then(function(r){var t=r.length;return r=_.orderBy(_.filter(r,function(e){return e}),function(e){return _.isArray(e)?t:_.isNumber(e.order)?e.order:t}),_.each(r,function(r){o.match(r,u,n)&&(e=_.isFunction(r.transformSourcePipe)?r.transformSourcePipe(e):_.isFunction(e.transformPipe)?e.transformPipe(r):e.pipe(r))}),e})}).then(function(e){var i=o.output(n,r,t);return Promise.all(_.map(i,function(i){return _.isFunction(i)?i(e,n,r,t):o.match(i,u,n)?i.toTransform(e,n,r,t):null}))}).then(function(e){return Promise.all(_.map(e,function(e){return new Promise(function(n,r){e?e.once("end",function(){n(e)}).once("error",r):n()})}))}).catch(function(e){console.log(chalk.red(e)),process.exit(0)})}},{key:"execute",value:function(e,n){var r=this,t=this.getOption(e);return Promise.resolve(this.sourceStream(e,t,n)).then(function(o){if(!_.isArray(o))return r.working(o,e,t,n);if(r.runWay===RunWay.parallel)return Promise.all(_.map(o,function(o){return r.working(o,e,t,n)}));if(r.runWay!==RunWay.sequence)return Promise.reject("runWay setting error.");var u=function(){var u=void 0;return _.each(o,function(o){u=u?u.then(function(){return r.working(o,e,t,n)}):r.working(o,e,t,n)}),{v:u}}();return"object"===("undefined"==typeof u?"undefined":_typeof(u))?u.v:void 0})}},{key:"setup",value:function(e,n){var r=this;n=n||coregulp;var t=this.getOption(e),o=e.subTaskName(t,this.name);return console.log("register "+this.name+" task:",chalk.cyan(o)),n.task(o,function(){return r.execute(e,n)}),this.decorator.taskName=o,o}}]),e}();exports.PipeTask=PipeTask; | ||
//# sourceMappingURL=sourcemaps/PipeTask.js.map |
@@ -178,2 +178,6 @@ /// <reference types="node" /> | ||
/** | ||
* transform source. | ||
*/ | ||
export declare type TransformSource = ITransform | ITransform[]; | ||
/** | ||
* output transform. support typescript output. | ||
@@ -180,0 +184,0 @@ * |
{ | ||
"name": "development-core", | ||
"version": "0.7.4", | ||
"version": "0.7.8", | ||
"description": "development build tools.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -90,3 +90,3 @@ # packaged development-core | ||
(tsmap, config, dt) => { | ||
if (config.oper === Operation.release || config.oper === Operation.deploy) { | ||
if (config.oper & Operation.release || config.oper & Operation.deploy) { | ||
return tsmap.js.pipe(babel({ presets: ['es2015'] })) | ||
@@ -230,3 +230,3 @@ .pipe(uglify()).pipe(sourcemaps.write('./sourcemaps')) | ||
(tsmap, config, dt) => { | ||
if (config.oper === Operation.release || config.oper === Operation.deploy) { | ||
if (config.oper & Operation.release || config.oper & Operation.deploy) { | ||
return tsmap.js.pipe(babel({ presets: ['es2015'] })) | ||
@@ -233,0 +233,0 @@ .pipe(uglify()).pipe(sourcemaps.write('./sourcemaps')) |
@@ -6,3 +6,3 @@ import * as _ from 'lodash'; | ||
import { IAssertDist, IOutputPipe, Operation, ITaskInfo, ITransform, TaskResult, IPipe, IDynamicTaskOption, ITaskConfig, ITask } from './TaskConfig'; | ||
import { IAssertDist, IOutputPipe, Operation, ITaskInfo, TransformSource, TaskResult, IPipe, IDynamicTaskOption, ITaskConfig, ITask } from './TaskConfig'; | ||
import { matchTaskGroup, matchTaskInfo } from './utils'; | ||
@@ -34,15 +34,29 @@ import { PipeTask } from './PipeTask'; | ||
sourceStream(config: ITaskConfig, dist: IAssertDist, gulp?: Gulp): ITransform | Promise<ITransform> { | ||
sourceStream(config: ITaskConfig, dist: IAssertDist, gulp?: Gulp): TransformSource | Promise<TransformSource> { | ||
if (this.dt.pipe) { | ||
return Promise.resolve(super.sourceStream(config, dist, gulp)) | ||
.then(stream => { | ||
return new Promise((resolve, reject) => { | ||
this.dt.pipe(stream, config, this.dt, (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(stream); | ||
} | ||
if (!_.isArray(stream)) { | ||
return new Promise((resolve, reject) => { | ||
this.dt.pipe(stream, config, this.dt, (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(stream); | ||
} | ||
}); | ||
}); | ||
}); | ||
} else { | ||
return Promise.all(_.map(stream, it => { | ||
return new Promise((resolve, reject) => { | ||
this.dt.pipe(it, config, this.dt, (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(stream); | ||
} | ||
}); | ||
}); | ||
})); | ||
} | ||
}); | ||
@@ -49,0 +63,0 @@ } else { |
import { Gulp } from 'gulp'; | ||
import { IAssertDist, ITaskInfo, TaskResult, ITaskConfig, IPipeOperate, Pipe, OutputPipe, ITask, ITransform, ILoaderOption } from './TaskConfig'; | ||
import { TransformSource, IAssertDist, ITaskInfo, TaskResult, ITaskConfig, IPipeOperate, Pipe, OutputPipe, ITask, ITransform, ILoaderOption } from './TaskConfig'; | ||
import * as coregulp from 'gulp'; | ||
@@ -21,3 +21,2 @@ import * as chalk from 'chalk'; | ||
name: string; | ||
/** | ||
@@ -29,8 +28,7 @@ * gulp src stream. | ||
* @param {Gulp} gulp | ||
* @returns {(ITransform | Promise<ITransform>)} | ||
* @returns {(TransformSource | Promise<TransformSource>)} | ||
* | ||
* @memberOf IPipeTask | ||
*/ | ||
sourceStream(config: ITaskConfig, dist: IAssertDist, gulp: Gulp): ITransform | Promise<ITransform>; | ||
sourceStream(config: ITaskConfig, dist: IAssertDist, gulp: Gulp): TransformSource | Promise<TransformSource>; | ||
/** | ||
@@ -57,6 +55,33 @@ * task pipe works. | ||
*/ | ||
output(config: ITaskConfig, dist: IAssertDist, gulp?: Gulp): OutputPipe[] | ||
output(config: ITaskConfig, dist: IAssertDist, gulp?: Gulp): OutputPipe[]; | ||
/** | ||
* execute task works. | ||
* | ||
* @param {ITaskConfig} config | ||
* @param {Gulp} gulp | ||
* @returns {Promise<any>} | ||
* | ||
* @memberOf IPipeTask | ||
*/ | ||
execute(config: ITaskConfig, gulp: Gulp): Promise<any>; | ||
} | ||
/** | ||
* mutil source stream pipe task run way. | ||
* | ||
* @export | ||
* @enum {number} | ||
*/ | ||
export enum RunWay { | ||
/** | ||
* run mutil source stream by sequence. | ||
*/ | ||
sequence = 1, | ||
/** | ||
* run mutil source stream by parallel. | ||
*/ | ||
parallel = 2 | ||
} | ||
/** | ||
* Task base class. | ||
@@ -70,2 +95,9 @@ * | ||
/** | ||
* run mutil source stream way. default parallel. | ||
* | ||
* | ||
* @memberOf PipeTask | ||
*/ | ||
public runWay = RunWay.parallel; | ||
/** | ||
* task default name. | ||
@@ -116,3 +148,3 @@ * | ||
sourceStream(config: ITaskConfig, option: IAssertDist, gulp: Gulp): ITransform | Promise<ITransform> { | ||
sourceStream(config: ITaskConfig, option: IAssertDist, gulp: Gulp): TransformSource | Promise<TransformSource> { | ||
return gulp.src(config.getSrc(option, this.decorator)); | ||
@@ -146,89 +178,139 @@ } | ||
setup(config: ITaskConfig, gulp?: Gulp): TaskResult { | ||
gulp = gulp || coregulp; | ||
let option = this.getOption(config); | ||
let tk = config.subTaskName(option, this.name); | ||
console.log(`register ${this.name} task:`, chalk.cyan(tk)); | ||
gulp.task(tk, () => { | ||
return Promise.resolve(this.sourceStream(config, option, gulp)) | ||
.then(psrc => { | ||
return Promise.all(_.map(this.pipes(config, option, gulp), (p: Pipe) => { | ||
if (_.isFunction(p)) { | ||
return p(config, option, gulp); | ||
protected working(source: ITransform, config: ITaskConfig, option: IAssertDist, gulp: Gulp) { | ||
let name = config.subTaskName(option, this.name); | ||
return Promise.resolve(source) | ||
.then(psrc => { | ||
return Promise.all(_.map(this.pipes(config, option, gulp), (p: Pipe) => { | ||
if (_.isFunction(p)) { | ||
return p(config, option, gulp); | ||
} else { | ||
if (!this.match(p, name, config)) { | ||
return null; | ||
} else { | ||
if (!this.match(p, tk, config)) { | ||
return null; | ||
return Promise.resolve(p.toTransform(config, option, gulp)) | ||
.then(trs => { | ||
trs.order = p.order; | ||
// trs.oper = p.order; | ||
return trs; | ||
}); | ||
} | ||
} | ||
})) | ||
.then(tans => { | ||
let len = tans.length; | ||
tans = _.orderBy(_.filter(tans, t => t), t => { | ||
if (_.isArray(t)) { | ||
return len; | ||
} else { | ||
return Promise.resolve(p.toTransform(config, option, gulp)) | ||
.then(trs => { | ||
trs.order = p.order; | ||
// trs.oper = p.order; | ||
return trs; | ||
}); | ||
if (_.isNumber(t.order)) { | ||
return t.order; | ||
} | ||
return len; | ||
} | ||
} | ||
})) | ||
.then(tans => { | ||
let len = tans.length; | ||
tans = _.orderBy(_.filter(tans, t => t), t => { | ||
if (_.isArray(t)) { | ||
return len; | ||
} else { | ||
if (_.isNumber(t.order)) { | ||
return t.order; | ||
} | ||
return len; | ||
} | ||
}); | ||
}); | ||
_.each(tans, stream => { | ||
if (!this.match(stream, tk, config)) { | ||
return; | ||
} | ||
_.each(tans, stream => { | ||
if (!this.match(stream, name, config)) { | ||
return; | ||
} | ||
if (_.isFunction(stream.transformSourcePipe)) { | ||
psrc = stream.transformSourcePipe(psrc); | ||
} else if (_.isFunction(psrc.transformPipe)) { | ||
psrc = psrc.transformPipe(stream); | ||
} else { | ||
psrc = psrc.pipe(stream); | ||
} | ||
}); | ||
return psrc; | ||
}) | ||
}) | ||
.then(stream => { | ||
let outputs = this.output(config, option, gulp); | ||
return Promise.all(_.map(outputs, output => { | ||
if (_.isFunction(output)) { | ||
return output(stream, config, option, gulp); | ||
} else { | ||
if (!this.match(output, tk, config)) { | ||
return null; | ||
if (_.isFunction(stream.transformSourcePipe)) { | ||
psrc = stream.transformSourcePipe(psrc); | ||
} else if (_.isFunction(psrc.transformPipe)) { | ||
psrc = psrc.transformPipe(stream); | ||
} else { | ||
return output.toTransform(stream, config, option, gulp); | ||
psrc = psrc.pipe(stream); | ||
} | ||
}); | ||
return psrc; | ||
}) | ||
}) | ||
.then(stream => { | ||
let outputs = this.output(config, option, gulp); | ||
return Promise.all(_.map(outputs, output => { | ||
if (_.isFunction(output)) { | ||
return output(stream, config, option, gulp); | ||
} else { | ||
if (!this.match(output, name, config)) { | ||
return null; | ||
} else { | ||
return output.toTransform(stream, config, option, gulp); | ||
} | ||
})) | ||
}).then(outputs => { | ||
return Promise.all(_.map(outputs, output => { | ||
return new Promise((resolve, reject) => { | ||
if (output) { | ||
output | ||
.once('end', () => { | ||
resolve(output); | ||
}) | ||
.once('error', reject); | ||
} | ||
})) | ||
}).then(outputs => { | ||
return Promise.all(_.map(outputs, output => { | ||
return new Promise((resolve, reject) => { | ||
if (output) { | ||
output | ||
.once('end', () => { | ||
resolve(output); | ||
}) | ||
.once('error', reject); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
})); | ||
}) | ||
.catch(err => { | ||
console.log(chalk.red(err)); | ||
process.exit(0); | ||
}); | ||
} | ||
/** | ||
* execute task working | ||
* | ||
* @param {ITaskConfig} config | ||
* @param {Gulp} gulp | ||
* @returns {Promise<any>} | ||
* | ||
* @memberOf PipeTask | ||
*/ | ||
execute(config: ITaskConfig, gulp: Gulp): Promise<any> { | ||
let option = this.getOption(config); | ||
return Promise.resolve(this.sourceStream(config, option, gulp)) | ||
.then(stream => { | ||
if (_.isArray(stream)) { | ||
if (this.runWay === RunWay.parallel) { | ||
return Promise.all(_.map(stream, st => this.working(st, config, option, gulp))); | ||
} else if (this.runWay === RunWay.sequence) { | ||
let pthen: Promise<any>; | ||
_.each(stream, st => { | ||
if (!pthen) { | ||
pthen = this.working(st, config, option, gulp); | ||
} else { | ||
resolve(); | ||
pthen = pthen.then(() => { | ||
return this.working(st, config, option, gulp); | ||
}); | ||
} | ||
}); | ||
})); | ||
}) | ||
.catch(err => { | ||
console.log(chalk.red(err)); | ||
process.exit(0); | ||
}); | ||
return pthen; | ||
} else { | ||
return Promise.reject('runWay setting error.'); | ||
} | ||
} else { | ||
return this.working(stream, config, option, gulp); | ||
} | ||
}); | ||
} | ||
/** | ||
* setup task works. | ||
* | ||
* @param {ITaskConfig} config | ||
* @param {Gulp} [gulp] | ||
* @returns {TaskResult} | ||
* | ||
* @memberOf PipeTask | ||
*/ | ||
setup(config: ITaskConfig, gulp?: Gulp): TaskResult { | ||
gulp = gulp || coregulp; | ||
let option = this.getOption(config); | ||
let tk = config.subTaskName(option, this.name); | ||
console.log(`register ${this.name} task:`, chalk.cyan(tk)); | ||
gulp.task(tk, () => { | ||
return this.execute(config, gulp); | ||
}); | ||
@@ -235,0 +317,0 @@ |
@@ -195,2 +195,6 @@ import { Gulp, WatchEvent, WatchCallback, TaskCallback } from 'gulp'; | ||
/** | ||
* transform source. | ||
*/ | ||
export type TransformSource = ITransform | ITransform[]; | ||
/** | ||
* output transform. support typescript output. | ||
@@ -197,0 +201,0 @@ * |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
266891
3926