development-tool
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -1,3 +0,3 @@ | ||
import { IEnvOption } from 'development-core'; | ||
import { TaskOption } from './TaskOption'; | ||
import { IEnvOption, RunWay } from 'development-core'; | ||
import { IAssertOption, TaskOption } from './TaskOption'; | ||
import { ITaskLoader } from './ITaskLoader'; | ||
@@ -26,2 +26,16 @@ /** | ||
/** | ||
* development tool option. | ||
* | ||
* @type {IAssertOption} | ||
* @memberOf DevelopConfig | ||
*/ | ||
option?: IAssertOption; | ||
/** | ||
* tasks runWay | ||
* | ||
* @type {RunWay} | ||
* @memberOf DevelopConfig | ||
*/ | ||
runWay?: RunWay; | ||
/** | ||
* custom loader factory. | ||
@@ -28,0 +42,0 @@ * |
import { ITask, IEnvOption, ITaskContext } from 'development-core'; | ||
import { IContext } from './TaskOption'; | ||
/** | ||
@@ -21,3 +22,3 @@ * task loader. | ||
* | ||
* @param {ITaskContext} context | ||
* @param {IContext} context | ||
* @returns {Promise<ITask[]>} | ||
@@ -27,3 +28,3 @@ * | ||
*/ | ||
loadContext(env: IEnvOption): Promise<ITaskContext>; | ||
loadContext(env: IEnvOption): Promise<IContext>; | ||
} |
/// <reference types="chai" /> | ||
import { ITask, IEnvOption, IContextDefine, ITaskContext } from 'development-core'; | ||
import { ITaskOption } from '../TaskOption'; | ||
import { ITaskOption, IContext } from '../TaskOption'; | ||
import { ITaskLoader } from '../ITaskLoader'; | ||
@@ -9,4 +9,4 @@ export declare abstract class BaseLoader implements ITaskLoader { | ||
constructor(option: ITaskOption, env?: IEnvOption); | ||
load(context: ITaskContext): Promise<ITask[]>; | ||
loadContext(env: IEnvOption): Promise<ITaskContext>; | ||
load(context: IContext): Promise<ITask[]>; | ||
loadContext(env: IEnvOption): Promise<IContext>; | ||
private _contextDef; | ||
@@ -13,0 +13,0 @@ protected readonly contextDef: Promise<IContextDefine>; |
import { ITask, IEnvOption, ITaskContext } from 'development-core'; | ||
import { ITaskOption, customLoader } from '../TaskOption'; | ||
import { ITaskOption, customLoader, IContext } from '../TaskOption'; | ||
import { ITaskLoader } from '../ITaskLoader'; | ||
@@ -10,3 +10,3 @@ export declare class CustomLoader implements ITaskLoader { | ||
private condef; | ||
loadContext(env: IEnvOption): Promise<ITaskContext>; | ||
loadContext(env: IEnvOption): Promise<IContext>; | ||
} |
/// <reference types="chai" /> | ||
import { Order, IPipeOption, ICustomPipe, ITaskDefine, ITask, IAsserts, IContextDefine, TaskSource, IDynamicTaskOption, ITaskContext } from 'development-core'; | ||
/** | ||
* development context | ||
* | ||
* @export | ||
* @interface IContext | ||
* @extends {ITaskContext} | ||
*/ | ||
export interface IContext extends ITaskContext { | ||
parent?: IContext; | ||
} | ||
/** | ||
* task loader option. | ||
@@ -5,0 +15,0 @@ * |
/// <reference types="gulp" /> | ||
import { Gulp } from 'gulp'; | ||
import { ITaskLoader } from './ITaskLoader'; | ||
import { Src, ITaskContext, ITaskInfo, ITask, IEnvOption, IDynamicTaskOption } from 'development-core'; | ||
import { TaskOption, ITaskOption, IAssertOption } from './TaskOption'; | ||
import { Src, ITaskContext, ITaskInfo, ITask, IEnvOption, IDynamicTaskOption, RunWay } from 'development-core'; | ||
import { TaskOption, ITaskOption, IAssertOption, IContext } from './TaskOption'; | ||
import { DevelopConfig } from './DevelopConfig'; | ||
@@ -31,2 +31,3 @@ export * from './DevelopConfig'; | ||
* @param {(DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>)} setting | ||
* @param {any} [runWay=RunWay.sequence] | ||
* @returns {Development} | ||
@@ -36,3 +37,3 @@ * | ||
*/ | ||
static create(gulp: Gulp, dirname: string, setting: DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>): Development; | ||
static create(gulp: Gulp, dirname: string, setting: DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>, runWay?: RunWay): Development; | ||
/** | ||
@@ -57,4 +58,6 @@ * Creates an instance of Development. | ||
run(gulp: Gulp, env: IEnvOption): Promise<any>; | ||
private bindingContext(ctx); | ||
protected loadTasks(gulp: Gulp, tasks: TaskOption, env: IEnvOption): Promise<Src[]>; | ||
private globalctx; | ||
getContext(env: any): IContext; | ||
private bindingContext(context, parent); | ||
protected loadTasks(gulp: Gulp, tasks: TaskOption, parent: IContext): Promise<Src[]>; | ||
protected setup(gulp: Gulp, ctx: ITaskContext, tasks: ITask[], assertsTask: ITaskInfo, subGroupTask: ITaskInfo): Promise<Src[]>; | ||
@@ -66,8 +69,8 @@ /** | ||
* @param {Gulp} gulp | ||
* @param {ITaskContext} ctx | ||
* @returns {Promise<Src>} | ||
* @param {IContext} ctx | ||
* @returns {Promise<ITaskInfo>} | ||
* | ||
* @memberOf Development | ||
*/ | ||
protected loadSubTask(gulp: Gulp, ctx: ITaskContext): Promise<ITaskInfo>; | ||
protected loadSubTask(gulp: Gulp, ctx: IContext): Promise<ITaskInfo>; | ||
/** | ||
@@ -83,5 +86,5 @@ * load asserts tasks. | ||
*/ | ||
protected loadAssertTasks(gulp: Gulp, ctx: ITaskContext): Promise<ITaskInfo>; | ||
protected loadAssertTasks(gulp: Gulp, ctx: IContext): Promise<ITaskInfo>; | ||
protected createLoader(option: TaskOption, env: IEnvOption): ITaskLoader; | ||
protected printHelp(help: boolean | string): void; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function __export(e){for(var t in e)exports.hasOwnProperty(t)||(exports[t]=e[t])}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,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),_=require("lodash"),minimist=require("minimist"),LoaderFactory_1=require("./LoaderFactory"),development_core_1=require("development-core"),chalk=require("chalk");__export(require("./LoaderFactory")),__export(require("./loaders/BaseLoader"));var Development=function(){function e(t,n){_classCallCheck(this,e),this.dirname=t,this.config=n,this.globals={}}return _createClass(e,[{key:"run",value:function(e,t){return t.root||(t.root=this.dirname),t.help&&(console.log(chalk.grey("... main help ...")),this.printHelp(t.help)),this.loadTasks(e,this.config.tasks,t).then(function(t){return development_core_1.runSequence(e,t)}).catch(function(e){console.error(e),process.exit(1)})}},{key:"bindingContext",value:function(e){return e.globals=this.globals,e}},{key:"loadTasks",value:function(e,t,n){var r=this;return Promise.all(_.map(_.isArray(t)?t:[t],function(t){t.dist=t.dist||"dist";var o=r.createLoader(t,n);return o.loadContext(n).then(function(t){return r.bindingContext(t),console.log(chalk.green("task context loaded.")),t.env.help?(t.printHelp&&(console.log(chalk.grey("...development default help...")),t.printHelp(_.isString(t.env.help)?t.env.help:"")),[]):r.loadSubTask(e,t).then(function(n){return Promise.all([o.load(t),r.loadAssertTasks(e,t)]).then(function(o){return console.log(chalk.green("tasks loaded.")),r.setup(e,t,o[0],o[1],n)})})})})).then(function(e){return _.flatten(e)})}},{key:"setup",value:function(e,t,n,r,o){return Promise.resolve(development_core_1.toSequence(e,n,t)).then(function(e){return t.runTasks?t.runTasks(e,r,o):(t.addToSequence(e,r),t.addToSequence(e,o),e)})}},{key:"loadSubTask",value:function(e,t){var n=this;if(!t.tasks)return Promise.resolve(null);var r=function(){var r=t.option;return _.each(_.isArray(r.tasks)?r.tasks:[r.tasks],function(e){e.name=t.subTaskName(e.name),e.src=e.src||r.src,e.dist=e.dist||r.dist}),{v:n.loadTasks(e,r.tasks,t.env).then(function(n){if(n&&n.length>0){var o=_.first(n),a=_.last(n),s=_.isArray(o)?_.first(o):o,i=_.isArray(a)?_.last(a):a,l=t.subTaskName(s+"-"+i,"-sub");return e.task(l,function(){return development_core_1.runSequence(e,n)}),{order:r.subTaskOrder,taskName:l}}return null})}}();return"object"===("undefined"==typeof r?"undefined":_typeof(r))?r.v:void 0}},{key:"loadAssertTasks",value:function(e,t){var n=this,r=t.option;if(!r.asserts)return Promise.resolve(null);var o=function(){var o=[];return _.each(_.keys(r.asserts),function(e){var n=void 0,a=r.asserts[e];_.isString(a)?n={src:a,loader:[{name:e,pipes:[],watch:!0}]}:_.isArray(a)?a.length>0&&(n=_.isString(_.first(a))?{src:a,loader:[{name:e,pipes:[],watch:!0}]}:{loader:a,watch:!0}):n=_.isFunction(a)?{loader:a}:a,_.isNull(n)||_.isUndefined(n)||(n.name=n.name||t.subTaskName(e),n.src=n.src||t.getSrc({oper:development_core_1.Operation.build})+"/**/*."+e,n.dist=n.dist||t.getDist({oper:development_core_1.Operation.build}),o.push(n))}),{v:Promise.all(_.map(o,function(r){return n.loadTasks(e,r,t.env).then(function(e){return{task:r,sq:e}})})).then(function(n){var r=_.map(n,function(n){var r=n.sq,o=void 0;if(r&&r.length>0){if(1===r.length)return r[0];o=t.subTaskName(n.task,"-assert"),e.task(o,function(){return development_core_1.runSequence(e,r)})}else o=t.subTaskName(n.sq);return o});return{order:t.option.assertsOrder,taskName:r}})}}();return"object"===("undefined"==typeof o?"undefined":_typeof(o))?o.v:void 0}},{key:"createLoader",value:function(e,t){var n=this,r=null;return _.isFunction(this.config.loaderFactory)||!function(){var e=new LoaderFactory_1.LoaderFactory;n.config.loaderFactory=function(n){return e.create(n,t)}}(),r=this.config.loaderFactory(e,t)}},{key:"printHelp",value:function(e){"en"===e?console.log("\n /**\n * gulp [build] [--env production|development] [--context name] [--root path] [--watch] [--test] [--serve] [--release] [--task taskname]\n * @params\n * --env development or production;\n * --context app setting\n * --root path, set relative path of the development tool root.\n * --watch watch src file change or not. if changed will auto update to node service. \n * --release release web app or not. if [--env production], default to release. \n * --test need auto load test file to node service.\n * --deploy run deploy tasks to deploy project. \n * --serve start node web service or not.\n * --task taskname spruce task taskname\n **/"):console.log("\n /**\n * gulp [build] [--env production|development] [--context name] [--root path] [--watch] [--test] [--serve] [--release] [--task taskname]\n * @params\n * --env 发布环境 默认开发环境development;\n * --context 设置配置文件;\n * --root path, 设置编译环境相对路径\n * --watch 是否需要动态监听文件变化\n * --release 是否release编译, [--env production] 默认release \n * --test 启动自动化测试\n * --deploy 运行加载deploy tasks, 编译发布项目。 \n * --serve 是否在开发模式下 开启node web服务\n * --task taskname 运行单独任务taskname\n **/")}}],[{key:"create",value:function(t,n,r){var o=_.isArray(r)?{tasks:r}:r,a=new e(n,o);return o.setupTask=o.setupTask||"build",t.task(o.setupTask,function(e){var n=minimist(process.argv.slice(2),{string:"env",default:{env:process.env.NODE_ENV||"development"}});return a.run(t,n)}),t.task("default",function(){t.start(o.setupTask)}),a}}]),e}();exports.Development=Development; | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function __export(e){for(var t in e)exports.hasOwnProperty(t)||(exports[t]=e[t])}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,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),_=require("lodash"),minimist=require("minimist"),LoaderFactory_1=require("./LoaderFactory"),development_core_1=require("development-core"),chalk=require("chalk");__export(require("./LoaderFactory")),__export(require("./loaders/BaseLoader"));var Development=function(){function e(t,n){_classCallCheck(this,e),this.dirname=t,this.config=n,this.globals={}}return _createClass(e,[{key:"run",value:function(e,t){var n=this;t.root||(t.root=this.dirname),t.help&&(console.log(chalk.grey("... main help ...")),this.printHelp(t.help));var o=this.getContext(t);return this.loadTasks(e,this.config.tasks,o).then(function(t){return n.config.runWay===development_core_1.RunWay.parallel?development_core_1.runSequence(e,[development_core_1.flattenSequence(e,t,o)]):development_core_1.runSequence(e,t)}).catch(function(e){console.error(e),process.exit(1)})}},{key:"getContext",value:function(e){if(!this.globalctx||this.globalctx.env!==e){var t=this.config.option||{};this.globalctx=this.bindingContext(development_core_1.bindingConfig({env:e,option:t}),null)}return this.globalctx}},{key:"bindingContext",value:function(e,t){var n=e;return n.globals=this.globals,n.parent=_.isUndefined(t)?this.getContext(n.env):t,n}},{key:"loadTasks",value:function(e,t,n){var o=this;return Promise.all(_.map(_.isArray(t)?t:[t],function(t){t.dist=t.dist||"dist";var r=o.createLoader(t,n.env);return r.loadContext(n.env).then(function(t){return o.bindingContext(t,n),console.log(chalk.green("task context loaded.")),t.env.help?(t.printHelp&&(console.log(chalk.grey("...development default help...")),t.printHelp(_.isString(t.env.help)?t.env.help:"")),[]):Promise.all([r.load(t),o.loadAssertTasks(e,t),o.loadSubTask(e,t)]).then(function(n){return console.log(chalk.green("tasks loaded.")),o.setup(e,t,n[0],n[1],n[2])})})})).then(function(e){return _.flatten(e)})}},{key:"setup",value:function(e,t,n,o,r){return Promise.resolve(development_core_1.toSequence(e,n,t)).then(function(e){return t.runTasks?t.runTasks(e,o,r):(t.addToSequence(e,o),t.addToSequence(e,r),e)})}},{key:"loadSubTask",value:function(e,t){var n=this;if(!t.option.tasks)return Promise.resolve(null);var o=function(){var o=t.option;return _.each(_.isArray(o.tasks)?o.tasks:[o.tasks],function(e){e.name=t.subTaskName(e.name),e.src=e.src||o.src,e.dist=e.dist||o.dist}),{v:n.loadTasks(e,o.tasks,t).then(function(n){var r=development_core_1.zipSequence(e,n,t,function(e,t){return e+(t===development_core_1.RunWay.sequence?"-sub-seq":"-sub-par")});return r?{name:r,order:o.subTaskOrder,taskName:r}:null})}}();return"object"===("undefined"==typeof o?"undefined":_typeof(o))?o.v:void 0}},{key:"loadAssertTasks",value:function(e,t){var n=this,o=t.option;if(!o.asserts)return Promise.resolve(null);var r=function(){var r=[];return _.each(_.keys(o.asserts),function(e){var n=void 0,a=o.asserts[e];_.isString(a)?n={src:a,loader:[{name:e,pipes:[],watch:!0}]}:_.isArray(a)?a.length>0&&(n=_.isString(_.first(a))?{src:a,loader:[{name:e,pipes:[],watch:!0}]}:{loader:a,watch:!0}):n=_.isFunction(a)?{loader:a}:a,_.isNull(n)||_.isUndefined(n)||(n.name=n.name||t.subTaskName(e),n.src=n.src||t.getSrc({oper:development_core_1.Operation.build})+"/**/*."+e,n.dist=n.dist||t.getDist({oper:development_core_1.Operation.build}),r.push(n))}),{v:Promise.all(_.map(r,function(o){return n.loadTasks(e,o,t).then(function(e){return{task:o,sq:e}})})).then(function(n){var o=_.map(n,function(n){return development_core_1.zipSequence(e,n.sq,t,function(e,n){return t.subTaskName(e+(n===development_core_1.RunWay.sequence?"-assert-seq":"-assert-par"))})});return{order:t.option.assertsOrder,taskName:o}})}}();return"object"===("undefined"==typeof r?"undefined":_typeof(r))?r.v:void 0}},{key:"createLoader",value:function(e,t){var n=this,o=null;return _.isFunction(this.config.loaderFactory)||!function(){var e=new LoaderFactory_1.LoaderFactory;n.config.loaderFactory=function(n){return e.create(n,t)}}(),o=this.config.loaderFactory(e,t)}},{key:"printHelp",value:function(e){"en"===e?console.log("\n /**\n * gulp [build] [--env production|development] [--context name] [--root path] [--watch] [--test] [--serve] [--release] [--task taskname]\n * @params\n * --env development or production;\n * --context app setting\n * --root path, set relative path of the development tool root.\n * --watch watch src file change or not. if changed will auto update to node service. \n * --release release web app or not. if [--env production], default to release. \n * --test need auto load test file to node service.\n * --deploy run deploy tasks to deploy project. \n * --serve start node web service or not.\n * --task taskname spruce task taskname\n **/"):console.log("\n /**\n * gulp [build] [--env production|development] [--context name] [--root path] [--watch] [--test] [--serve] [--release] [--task taskname]\n * @params\n * --env 发布环境 默认开发环境development;\n * --context 设置配置文件;\n * --root path, 设置编译环境相对路径\n * --watch 是否需要动态监听文件变化\n * --release 是否release编译, [--env production] 默认release \n * --test 启动自动化测试\n * --deploy 运行加载deploy tasks, 编译发布项目。 \n * --serve 是否在开发模式下 开启node web服务\n * --task taskname 运行单独任务taskname\n **/")}}],[{key:"create",value:function(t,n,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:development_core_1.RunWay.sequence,a=_.isArray(o)?{tasks:o,runWay:r}:o;_.isUndefined(a.runWay)||(a.runWay=r);var s=new e(n,a);return a.setupTask=a.setupTask||"build",t.task(a.setupTask,function(e){var n=minimist(process.argv.slice(2),{string:"env",default:{env:process.env.NODE_ENV||"development"}});return s.run(t,n)}),t.task("default",function(){t.start(a.setupTask)}),s}}]),e}();exports.Development=Development; | ||
//# sourceMappingURL=sourcemaps/tools.js.map |
{ | ||
"name": "development-tool", | ||
"version": "0.9.1", | ||
"description": "development build tools, gulp task manager.", | ||
"version": "0.9.2", | ||
"description": "development tools, tasks component, gulp task manager, tasks loader, run tasks in sequence via Promise. easy to load tasks module, generate asserts task, compose tasks.", | ||
"main": "./lib/tools.js", | ||
@@ -20,5 +20,12 @@ "typings": "./lib/tools", | ||
"gulp", | ||
"promise", | ||
"front-end", | ||
"component", | ||
"generate", | ||
"tasks", | ||
"loader", | ||
"task manager", | ||
"typescript", | ||
"node", | ||
"babel" | ||
"metadata", | ||
"node" | ||
], | ||
@@ -41,3 +48,3 @@ "author": "houjun", | ||
"checksum": "^0.1.1", | ||
"development-core": "^0.9.1", | ||
"development-core": "^0.9.4", | ||
"gulp": "^3.9.1" | ||
@@ -52,3 +59,3 @@ }, | ||
"del": "^2.2.1", | ||
"development-assert-ts": "^0.3.2", | ||
"development-assert-ts": "^0.4.0", | ||
"through2": "^2.0.1", | ||
@@ -55,0 +62,0 @@ "ts-node": "^1.6.0", |
@@ -70,11 +70,34 @@ # packaged development-tool | ||
Development.create(gulp, __dirname, { | ||
tasks: <ITaskOption>{ | ||
src: 'src', | ||
dist: 'lib', | ||
buildDist: 'build', | ||
testSrc: 'test/**/*.spec.ts', | ||
loader: 'development-tool-node' | ||
} | ||
}); | ||
Development.create(gulp, __dirname, [{ | ||
src: 'src', | ||
dist: 'lib', | ||
buildDist: 'build', | ||
asserts:{ | ||
config: { | ||
src(ctx) { | ||
if (ctx.env.config) { | ||
return `src/config-${ctx.env.config}.json`; | ||
} else { | ||
return 'src/config.json'; | ||
} | ||
}, | ||
watch: true, // add watch to this assert. | ||
loader: [ | ||
{ | ||
name: 'config', | ||
oper: Operation.default, | ||
pipes: [ | ||
() => cache('config_json'), | ||
() => rename('config.json'), | ||
() => jeditor() | ||
] | ||
} | ||
] | ||
}, | ||
json: ['src/**/*.json', '!src/data/**/*.json', '!src**/jsconfig.json', '!src/config*.json'] | ||
... | ||
}, | ||
testSrc: 'test/**/*.spec.ts', | ||
loader: 'development-tool-node' | ||
}]); | ||
@@ -174,3 +197,3 @@ ``` | ||
// bundles: { | ||
// ... | ||
// } | ||
@@ -180,2 +203,4 @@ } | ||
}, { | ||
... | ||
}]); | ||
@@ -182,0 +207,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { IEnvOption } from 'development-core'; | ||
import { TaskOption } from './TaskOption'; | ||
import { IEnvOption, RunWay } from 'development-core'; | ||
import { IAssertOption, TaskOption } from './TaskOption'; | ||
import { ITaskLoader } from './ITaskLoader'; | ||
@@ -30,2 +30,18 @@ // import { Operation } from './Operation'; | ||
/** | ||
* development tool option. | ||
* | ||
* @type {IAssertOption} | ||
* @memberOf DevelopConfig | ||
*/ | ||
option?: IAssertOption; | ||
/** | ||
* tasks runWay | ||
* | ||
* @type {RunWay} | ||
* @memberOf DevelopConfig | ||
*/ | ||
runWay?: RunWay | ||
/** | ||
* custom loader factory. | ||
@@ -32,0 +48,0 @@ * |
import { ITask, IEnvOption, ITaskContext } from 'development-core'; | ||
import { IContext } from './TaskOption'; | ||
/** | ||
@@ -24,3 +24,3 @@ * task loader. | ||
* | ||
* @param {ITaskContext} context | ||
* @param {IContext} context | ||
* @returns {Promise<ITask[]>} | ||
@@ -30,4 +30,4 @@ * | ||
*/ | ||
loadContext(env: IEnvOption): Promise<ITaskContext>; | ||
loadContext(env: IEnvOption): Promise<IContext>; | ||
} |
import { ITask, IEnvOption, IContextDefine, ITaskContext } from 'development-core'; | ||
import { ITaskOption, ILoaderOption } from '../TaskOption'; | ||
import { ITaskOption, ILoaderOption, IContext } from '../TaskOption'; | ||
import { ITaskLoader } from '../ITaskLoader'; | ||
@@ -15,3 +15,3 @@ | ||
load(context: ITaskContext): Promise<ITask[]> { | ||
load(context: IContext): Promise<ITask[]> { | ||
return this.contextDef | ||
@@ -26,3 +26,3 @@ .then(def => { | ||
loadContext(env: IEnvOption): Promise<ITaskContext> { | ||
loadContext(env: IEnvOption): Promise<IContext> { | ||
this.env = env; | ||
@@ -32,3 +32,3 @@ let self = this; | ||
.then(def => { | ||
return def.getContext({ | ||
return <IContext>def.getContext({ | ||
option: self.option, | ||
@@ -35,0 +35,0 @@ env: env |
import { ITask, IEnvOption, ITaskContext, bindingConfig } from 'development-core'; | ||
import { ITaskOption, customLoader } from '../TaskOption'; | ||
import { ITaskOption, customLoader, IContext } from '../TaskOption'; | ||
import { ITaskLoader } from '../ITaskLoader'; | ||
@@ -15,7 +15,7 @@ | ||
private condef: Promise<ITaskContext>; | ||
loadContext(env: IEnvOption): Promise<ITaskContext> { | ||
private condef: Promise<IContext>; | ||
loadContext(env: IEnvOption): Promise<IContext> { | ||
let self = this; | ||
this.condef = this.condef || Promise.resolve( | ||
bindingConfig({ | ||
<IContext>bindingConfig({ | ||
option: self.option, | ||
@@ -22,0 +22,0 @@ env: env |
@@ -1,5 +0,18 @@ | ||
import { Order, IPipeOption, ICustomPipe, ITaskDefine, ITask, IAsserts | ||
, IContextDefine, TaskSource, IDynamicTaskOption, ITaskContext } from 'development-core' | ||
import { | ||
Order, IPipeOption, ICustomPipe, ITaskDefine, ITask, IAsserts | ||
, IContextDefine, TaskSource, IDynamicTaskOption, ITaskContext | ||
} from 'development-core' | ||
/** | ||
* development context | ||
* | ||
* @export | ||
* @interface IContext | ||
* @extends {ITaskContext} | ||
*/ | ||
export interface IContext extends ITaskContext { | ||
parent?: IContext; | ||
} | ||
/** | ||
* task loader option. | ||
@@ -6,0 +19,0 @@ * |
110
src/tools.ts
@@ -7,4 +7,4 @@ import * as _ from 'lodash'; | ||
import { LoaderFactory } from './LoaderFactory'; | ||
import { Operation, Src, toSequence, runSequence, ITaskContext, ITaskInfo, ITask, IEnvOption, IDynamicTaskOption } from 'development-core'; | ||
import { TaskOption, ITaskOption, IAssertOption } from './TaskOption'; | ||
import { Operation, Src, toSequence, runSequence, bindingConfig, zipSequence, flattenSequence, ITaskContext, ITaskInfo, ITask, IEnvOption, IDynamicTaskOption, RunWay } from 'development-core'; | ||
import { TaskOption, ITaskOption, IAssertOption, IContext } from './TaskOption'; | ||
import { DevelopConfig } from './DevelopConfig'; | ||
@@ -36,2 +36,3 @@ import * as chalk from 'chalk'; | ||
* @param {(DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>)} setting | ||
* @param {any} [runWay=RunWay.sequence] | ||
* @returns {Development} | ||
@@ -41,4 +42,7 @@ * | ||
*/ | ||
static create(gulp: Gulp, dirname: string, setting: DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>): Development { | ||
let option = _.isArray(setting) ? { tasks: setting } : setting; | ||
static create(gulp: Gulp, dirname: string, setting: DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>, runWay = RunWay.sequence): Development { | ||
let option = _.isArray(setting) ? { tasks: setting, runWay: runWay } : setting; | ||
if (!_.isUndefined(option.runWay)) { | ||
option.runWay = runWay; | ||
} | ||
let devtool = new Development(dirname, option); | ||
@@ -91,6 +95,11 @@ option.setupTask = option.setupTask || 'build'; | ||
return this.loadTasks(gulp, this.config.tasks, env) | ||
let gbctx = this.getContext(env); | ||
return this.loadTasks(gulp, this.config.tasks, gbctx) | ||
.then(tseq => { | ||
// console.log(chalk.grey('run sequenec tasks:'), tseq); | ||
return runSequence(gulp, tseq); | ||
if (this.config.runWay === RunWay.parallel) { | ||
return runSequence(gulp, [flattenSequence(gulp, tseq, gbctx)]); | ||
} else { | ||
return runSequence(gulp, tseq); | ||
} | ||
}) | ||
@@ -103,9 +112,24 @@ .catch(err => { | ||
private bindingContext(ctx: ITaskContext): ITaskContext { | ||
private globalctx: IContext; | ||
getContext(env) { | ||
if (!this.globalctx || this.globalctx.env !== env) { | ||
let option = this.config.option || {}; | ||
this.globalctx = <IContext>this.bindingContext(bindingConfig({ | ||
env: env, | ||
option: option | ||
}), null); | ||
} | ||
return this.globalctx; | ||
} | ||
private bindingContext(context: ITaskContext, parent: IContext): IContext { | ||
let ctx = <IContext>context; | ||
// cfg.env = cfg.env || this.env; | ||
ctx.globals = this.globals; | ||
ctx.parent = _.isUndefined(parent) ? this.getContext(ctx.env) : parent; | ||
return ctx; | ||
} | ||
protected loadTasks(gulp: Gulp, tasks: TaskOption, env: IEnvOption): Promise<Src[]> { | ||
protected loadTasks(gulp: Gulp, tasks: TaskOption, parent: IContext): Promise<Src[]> { | ||
return Promise.all<Src[]>( | ||
@@ -115,7 +139,7 @@ _.map(_.isArray(tasks) ? <ITaskOption[]>tasks : [<ITaskOption>tasks], optask => { | ||
// console.log(chalk.grey('begin load task via loader:'), optask.loader); | ||
let loader = this.createLoader(optask, env); | ||
let loader = this.createLoader(optask, parent.env); | ||
return loader.loadContext(env) | ||
return loader.loadContext(parent.env) | ||
.then(ctx => { | ||
this.bindingContext(ctx); | ||
this.bindingContext(ctx, parent); | ||
console.log(chalk.green('task context loaded.')); | ||
@@ -129,12 +153,10 @@ if (ctx.env.help) { | ||
} else { | ||
return this.loadSubTask(gulp, ctx) | ||
.then(subtask => { | ||
return Promise.all([ | ||
loader.load(ctx), | ||
this.loadAssertTasks(gulp, ctx) | ||
]) | ||
.then(tasks => { | ||
console.log(chalk.green('tasks loaded.')); | ||
return this.setup(gulp, ctx, tasks[0], tasks[1], subtask) | ||
}); | ||
return Promise.all([ | ||
loader.load(ctx), | ||
this.loadAssertTasks(gulp, ctx), | ||
this.loadSubTask(gulp, ctx) | ||
]) | ||
.then(tks => { | ||
console.log(chalk.green('tasks loaded.')); | ||
return this.setup(gulp, ctx, tks[0], tks[1], tks[2]); | ||
}); | ||
@@ -173,10 +195,9 @@ } | ||
* @param {Gulp} gulp | ||
* @param {ITaskContext} ctx | ||
* @returns {Promise<Src>} | ||
* @param {IContext} ctx | ||
* @returns {Promise<ITaskInfo>} | ||
* | ||
* @memberOf Development | ||
*/ | ||
protected loadSubTask(gulp: Gulp, ctx: ITaskContext): Promise<ITaskInfo> { | ||
if (ctx['tasks']) { | ||
protected loadSubTask(gulp: Gulp, ctx: IContext): Promise<ITaskInfo> { | ||
if (ctx.option['tasks']) { | ||
let optask = <ITaskOption>ctx.option; | ||
@@ -188,18 +209,12 @@ _.each(_.isArray(optask.tasks) ? optask.tasks : [optask.tasks], subopt => { | ||
}); | ||
return this.loadTasks(gulp, optask.tasks, ctx.env) | ||
return this.loadTasks(gulp, optask.tasks, ctx) | ||
.then(subseq => { | ||
if (subseq && subseq.length > 0) { | ||
let first = _.first(subseq); | ||
let last = _.last(subseq); | ||
let frn = _.isArray(first) ? _.first(first) : first; | ||
let lsn = _.isArray(last) ? _.last(last) : last; | ||
let subName = ctx.subTaskName(`${frn}-${lsn}`, '-sub'); | ||
gulp.task(subName, () => { | ||
return runSequence(gulp, subseq); | ||
}); | ||
let taskname = zipSequence(gulp, subseq, ctx, (name, runway) => name + (runway === RunWay.sequence ? '-sub-seq' : '-sub-par')); | ||
if (taskname) { | ||
return <ITaskInfo>{ | ||
name: taskname, | ||
order: optask.subTaskOrder, | ||
taskName: subName | ||
taskName: taskname | ||
}; | ||
@@ -225,3 +240,3 @@ } else { | ||
*/ | ||
protected loadAssertTasks(gulp: Gulp, ctx: ITaskContext): Promise<ITaskInfo> { | ||
protected loadAssertTasks(gulp: Gulp, ctx: IContext): Promise<ITaskInfo> { | ||
let optask = <IAssertOption>ctx.option; | ||
@@ -259,3 +274,3 @@ if (optask.asserts) { | ||
return Promise.all(_.map(tasks, task => { | ||
return this.loadTasks(gulp, <ITaskOption>task, ctx.env) | ||
return this.loadTasks(gulp, <ITaskOption>task, ctx) | ||
.then(sq => { | ||
@@ -271,18 +286,3 @@ return { | ||
let assertSeq = _.map(tseq, t => { | ||
let subseq = t.sq; | ||
let name; | ||
if (subseq && subseq.length > 0) { | ||
if (subseq.length === 1) { | ||
return subseq[0]; | ||
} | ||
name = ctx.subTaskName(t.task, '-assert') | ||
gulp.task(name, () => { | ||
return runSequence(gulp, subseq); | ||
}); | ||
} else { | ||
name = ctx.subTaskName(t.sq); | ||
} | ||
return name; | ||
return zipSequence(gulp, t.sq, ctx, (name, runway) => ctx.subTaskName(name + (runway === RunWay.sequence ? '-assert-seq' : '-assert-par'))); | ||
}); | ||
@@ -289,0 +289,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
157748
1882
510
Updateddevelopment-core@^0.9.4