New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

development-tool

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

development-tool - npm Package Compare versions

Comparing version 0.9.6 to 0.9.8

build/Context.js

19

lib/DevelopConfig.d.ts

@@ -1,2 +0,2 @@

import { IEnvOption, RunWay } from 'development-core';
import { IEnvOption, RunWay, ITaskConfig, ITaskContext } from 'development-core';
import { IAssertOption, TaskOption } from './TaskOption';

@@ -40,9 +40,2 @@ import { ITaskLoader } from './ITaskLoader';

/**
* compose context.
*
* @type {boolean}
* @memberOf DevelopConfig
*/
compose?: boolean;
/**
* custom loader factory.

@@ -57,2 +50,12 @@ *

loaderFactory?(option: TaskOption, env?: IEnvOption): ITaskLoader;
/**
* custom context factory.
*
* @param {ITaskConfig} cfg
* @param {ITaskContext} [parent]
* @returns {ITaskContext}
*
* @memberOf DevelopConfig
*/
contextFactory?(cfg: ITaskConfig, parent?: ITaskContext): ITaskContext;
}
import { ITask, IEnvOption, ITaskContext } from 'development-core';
import { IContext } from './TaskOption';
import { IContext } from './IContext';
/**

@@ -4,0 +4,0 @@ * task loader.

import { ITaskLoader } from './ITaskLoader';
import { IEnvOption } from 'development-core';
import { ITaskOption } from './TaskOption';
import { ITaskOption, contextFactory } from './TaskOption';
/**

@@ -16,2 +16,3 @@ * loader factory.

* @param {IEnvOption} [env]
* @param {contextFactory} [factory]
* @returns {ITaskLoader}

@@ -21,3 +22,3 @@ *

*/
create(option: ITaskOption, env?: IEnvOption): ITaskLoader;
create(option: ITaskOption, env?: IEnvOption, factory?: contextFactory): ITaskLoader;
}

@@ -33,3 +34,3 @@ /**

constructor();
create(option: ITaskOption, env?: IEnvOption): ITaskLoader;
create(option: ITaskOption, env?: IEnvOption, factory?: contextFactory): ITaskLoader;
}

@@ -1,2 +0,2 @@

"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,r){for(var a=0;a<r.length;a++){var o=r[a];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(r,a,o){return a&&e(r.prototype,a),o&&e(r,o),r}}(),DirLoader_1=require("./loaders/DirLoader"),ModuleLoader_1=require("./loaders/ModuleLoader"),DynamicLoader_1=require("./loaders/DynamicLoader"),CustomLoader_1=require("./loaders/CustomLoader"),_=require("lodash"),chalk=require("chalk"),LoaderFactory=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"create",value:function(e,r){if(_.isString(e.loader))return e.loader={module:e.loader},new ModuleLoader_1.ModuleLoader(e);if(_.isFunction(e.loader))return new CustomLoader_1.CustomLoader(e,e.loader);if(_.isArray(e.loader))return e.loader={dynamicTasks:e.loader||[]},new DynamicLoader_1.DynamicLoader(e);if(e.loader){if(e.loader.dir)return new DirLoader_1.DirLoader(e,r);if(_.isString(e.loader.name))return e.loader={dynamicTasks:e.loader},new DynamicLoader_1.DynamicLoader(e);if(e.loader.dynamicTasks)return new DynamicLoader_1.DynamicLoader(e);var a=null,o=e.loader;switch(o.type){case"dir":a=new DirLoader_1.DirLoader(e,r);break;case"dynamic":a=new DynamicLoader_1.DynamicLoader(e);break;case"module":default:a=new ModuleLoader_1.ModuleLoader(e,r)}return a}return console.log(chalk.cyan(e.name),chalk.yellow("loader not setting, use dynamic loader.")),e.loader={dynamicTasks:[]},new DynamicLoader_1.DynamicLoader(e)}}]),e}();exports.LoaderFactory=LoaderFactory;
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,r){for(var a=0;a<r.length;a++){var o=r[a];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(r,a,o){return a&&e(r.prototype,a),o&&e(r,o),r}}(),DirLoader_1=require("./loaders/DirLoader"),ModuleLoader_1=require("./loaders/ModuleLoader"),DynamicLoader_1=require("./loaders/DynamicLoader"),CustomLoader_1=require("./loaders/CustomLoader"),_=require("lodash"),chalk=require("chalk"),LoaderFactory=function(){function e(){_classCallCheck(this,e)}return _createClass(e,[{key:"create",value:function(e,r,a){if(_.isString(e.loader))return e.loader={module:e.loader},new ModuleLoader_1.ModuleLoader(e,r,a);if(_.isFunction(e.loader))return new CustomLoader_1.CustomLoader(e,e.loader,a);if(_.isArray(e.loader))return e.loader={dynamicTasks:e.loader||[]},new DynamicLoader_1.DynamicLoader(e,r,a);if(e.loader){if(e.loader.dir)return new DirLoader_1.DirLoader(e,r);if(_.isString(e.loader.name))return e.loader={dynamicTasks:e.loader},new DynamicLoader_1.DynamicLoader(e,r,a);if(e.loader.dynamicTasks)return new DynamicLoader_1.DynamicLoader(e);var o=null,n=e.loader;switch(n.type){case"dir":o=new DirLoader_1.DirLoader(e,r,a);break;case"dynamic":o=new DynamicLoader_1.DynamicLoader(e,r,a);break;case"module":default:o=new ModuleLoader_1.ModuleLoader(e,r,a)}return o}return console.log(chalk.cyan(e.name),chalk.yellow("loader not setting, use dynamic loader.")),e.loader={dynamicTasks:[]},new DynamicLoader_1.DynamicLoader(e,r,a)}}]),e}();exports.LoaderFactory=LoaderFactory;
//# sourceMappingURL=sourcemaps/loaderFactory.js.map
/// <reference types="chai" />
import { ITask, IEnvOption, IContextDefine, ITaskContext } from 'development-core';
import { ITaskOption, IContext } from '../TaskOption';
import { ITask, IEnvOption, IContextDefine, ITaskContext, ITaskConfig } from 'development-core';
import { ITaskOption } from '../TaskOption';
import { IContext } from '../IContext';
import { ITaskLoader } from '../ITaskLoader';

@@ -8,3 +9,4 @@ export declare abstract class BaseLoader implements ITaskLoader {

protected env: IEnvOption;
constructor(option: ITaskOption, env?: IEnvOption);
protected factory: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext;
constructor(option: ITaskOption, env?: IEnvOption, factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext);
load(context: IContext): Promise<ITask[]>;

@@ -11,0 +13,0 @@ loadContext(env: IEnvOption): Promise<IContext>;

@@ -1,2 +0,2 @@

"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _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}}(),BaseLoader=function(){function e(t,n){_classCallCheck(this,e),this.option=t,this.env=n}return _createClass(e,[{key:"load",value:function(e){var t=this;return this.contextDef.then(function(n){return t.loadTasks(e,n)}).catch(function(e){console.error(e)})}},{key:"loadContext",value:function(e){this.env=e;var t=this;return this.contextDef.then(function(n){return n.getContext({option:t.option,env:e})}).catch(function(e){console.error(e)})}},{key:"loadTasks",value:function(e,t){if(t.tasks)return t.tasks(e);var n=this.getTaskModule();return e.findTasks(n)}},{key:"getConfigModule",value:function(){var e=this.option.loader;return e.configModule||e.module}},{key:"getTaskModule",value:function(){var e=this.option.loader;return e.taskModule||e.module}},{key:"contextDef",get:function(){return this._contextDef||(this._contextDef=Promise.resolve(this.getContextDefine())),this._contextDef}}]),e}();exports.BaseLoader=BaseLoader;
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _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}}(),BaseLoader=function(){function e(t,n,o){_classCallCheck(this,e),this.option=t,this.env=n,this.factory=o}return _createClass(e,[{key:"load",value:function(e){var t=this;return this.contextDef.then(function(n){return t.loadTasks(e,n)}).catch(function(e){console.error(e)})}},{key:"loadContext",value:function(e){this.env=e;var t=this;return this.contextDef.then(function(n){return n.getContext({option:t.option,env:e,createContext:t.factory})}).catch(function(e){console.error(e)})}},{key:"loadTasks",value:function(e,t){if(t.tasks)return t.tasks(e);var n=this.getTaskModule();return e.findTasks(n)}},{key:"getConfigModule",value:function(){var e=this.option.loader;return e.configModule||e.module}},{key:"getTaskModule",value:function(){var e=this.option.loader;return e.taskModule||e.module}},{key:"contextDef",get:function(){return this._contextDef||(this._contextDef=Promise.resolve(this.getContextDefine())),this._contextDef}}]),e}();exports.BaseLoader=BaseLoader;
//# sourceMappingURL=../sourcemaps/loaders/BaseLoader.js.map

@@ -1,3 +0,4 @@

import { ITask, IEnvOption, ITaskContext } from 'development-core';
import { ITaskOption, customLoader, IContext } from '../TaskOption';
import { ITask, IEnvOption, ITaskContext, ITaskConfig } from 'development-core';
import { ITaskOption, customLoader } from '../TaskOption';
import { IContext } from '../IContext';
import { ITaskLoader } from '../ITaskLoader';

@@ -7,3 +8,4 @@ export declare class CustomLoader implements ITaskLoader {

private loader;
constructor(option: ITaskOption, loader: customLoader);
private factory;
constructor(option: ITaskOption, loader: customLoader, factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext);
load(context: ITaskContext): Promise<ITask[]>;

@@ -10,0 +12,0 @@ private condef;

@@ -1,2 +0,2 @@

"use strict";function _classCallCheck(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,o){for(var n=0;n<o.length;n++){var t=o[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(o,n,t){return n&&e(o.prototype,n),t&&e(o,t),o}}(),development_core_1=require("development-core"),CustomLoader=function(){function e(o,n){_classCallCheck(this,e),this.option=o,this.loader=n}return _createClass(e,[{key:"load",value:function(e){return Promise.resolve(this.loader(e))}},{key:"loadContext",value:function(e){var o=this;return this.condef=this.condef||Promise.resolve(development_core_1.bindingConfig({option:o.option,env:e})),this.condef}}]),e}();exports.CustomLoader=CustomLoader;
"use strict";function _classCallCheck(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,o){for(var t=0;t<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(o,t,n){return t&&e(o.prototype,t),n&&e(o,n),o}}(),development_core_1=require("development-core"),CustomLoader=function(){function e(o,t,n){_classCallCheck(this,e),this.option=o,this.loader=t,this.factory=n}return _createClass(e,[{key:"load",value:function(e){return Promise.resolve(this.loader(e))}},{key:"loadContext",value:function(e){var o=this;return this.condef=this.condef||Promise.resolve(development_core_1.bindingConfig({option:o.option,env:e,createContext:o.factory})),this.condef}}]),e}();exports.CustomLoader=CustomLoader;
//# sourceMappingURL=../sourcemaps/loaders/CustomLoader.js.map

@@ -1,8 +0,8 @@

import { ITask, IContextDefine, ITaskContext, IEnvOption } from 'development-core';
import { ITask, IContextDefine, ITaskContext, ITaskConfig, IEnvOption } from 'development-core';
import { ITaskOption } from '../TaskOption';
import { ModuleLoader } from './ModuleLoader';
export declare class DirLoader extends ModuleLoader {
constructor(option: ITaskOption, env: IEnvOption);
constructor(option: ITaskOption, env: IEnvOption, factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext);
loadTasks(context: ITaskContext, def: IContextDefine): Promise<ITask[]>;
protected getContextDefine(): IContextDefine | Promise<IContextDefine>;
}

@@ -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 _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,o,r){return o&&e(t.prototype,o),r&&e(t,r),t}}(),_get=function e(t,o,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,o);if(void 0===n){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,o,r)}if("value"in n)return n.value;var a=n.get;if(void 0!==a)return a.call(r)},development_core_1=require("development-core"),ModuleLoader_1=require("./ModuleLoader"),DirLoader=function(e){function t(e,o){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,o))}return _inherits(t,e),_createClass(t,[{key:"loadTasks",value:function(e,o){var r=this.option.loader;return r.dir?e.findTasksInDir(development_core_1.taskSourceVal(r.dir,e)):_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"loadTasks",this).call(this,e,o)}},{key:"getContextDefine",value:function(){var e=this.option.loader,o=this;return e.configModule||e.module||!e.dir?_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"getContextDefine",this).call(this):development_core_1.findTaskDefineInDir(development_core_1.taskSourceVal(e.dir,development_core_1.bindingConfig({env:o.env,option:{}})))}}]),t}(ModuleLoader_1.ModuleLoader);exports.DirLoader=DirLoader;
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,o,r){return o&&e(t.prototype,o),r&&e(t,r),t}}(),_get=function e(t,o,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,o);if(void 0===n){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,o,r)}if("value"in n)return n.value;var a=n.get;if(void 0!==a)return a.call(r)},development_core_1=require("development-core"),ModuleLoader_1=require("./ModuleLoader"),DirLoader=function(e){function t(e,o,r){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,o))}return _inherits(t,e),_createClass(t,[{key:"loadTasks",value:function(e,o){var r=this.option.loader;return r.dir?e.findTasksInDir(development_core_1.taskSourceVal(r.dir,e)):_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"loadTasks",this).call(this,e,o)}},{key:"getContextDefine",value:function(){var e=this.option.loader,o=this;return e.configModule||e.module||!e.dir?_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"getContextDefine",this).call(this):development_core_1.findTaskDefineInDir(development_core_1.taskSourceVal(e.dir,development_core_1.bindingConfig({env:o.env,option:{},createContext:o.factory})))}}]),t}(ModuleLoader_1.ModuleLoader);exports.DirLoader=DirLoader;
//# sourceMappingURL=../sourcemaps/loaders/DirLoader.js.map

@@ -1,7 +0,7 @@

import { IContextDefine, IEnvOption } from 'development-core';
import { IContextDefine, IEnvOption, ITaskConfig, ITaskContext } from 'development-core';
import { ITaskOption } from '../TaskOption';
import { BaseLoader } from './BaseLoader';
export declare class DynamicLoader extends BaseLoader {
constructor(option: ITaskOption, env?: IEnvOption);
constructor(option: ITaskOption, env?: IEnvOption, factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext);
protected getContextDefine(): IContextDefine | Promise<IContextDefine>;
}

@@ -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 _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),contextDefine_1=require("../utils/contextDefine"),BaseLoader_1=require("./BaseLoader"),DynamicLoader=function(e){function t(e,r){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r))}return _inherits(t,e),_createClass(t,[{key:"getContextDefine",value:function(){return contextDefine_1.default(this.getTaskModule())}}]),t}(BaseLoader_1.BaseLoader);exports.DynamicLoader=DynamicLoader;
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),contextDefine_1=require("../utils/contextDefine"),BaseLoader_1=require("./BaseLoader"),DynamicLoader=function(e){function t(e,r,n){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r,n))}return _inherits(t,e),_createClass(t,[{key:"getContextDefine",value:function(){return contextDefine_1.default(this.getTaskModule())}}]),t}(BaseLoader_1.BaseLoader);exports.DynamicLoader=DynamicLoader;
//# sourceMappingURL=../sourcemaps/loaders/DynamicLoader.js.map

@@ -1,7 +0,7 @@

import { IContextDefine, IEnvOption } from 'development-core';
import { IContextDefine, IEnvOption, ITaskConfig, ITaskContext } from 'development-core';
import { ITaskOption } from '../TaskOption';
import { BaseLoader } from './BaseLoader';
export declare class ModuleLoader extends BaseLoader {
constructor(option: ITaskOption, env?: IEnvOption);
constructor(option: ITaskOption, env?: IEnvOption, factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext);
protected getContextDefine(): IContextDefine | Promise<IContextDefine>;
}

@@ -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 _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _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}}(),development_core_1=require("development-core"),BaseLoader_1=require("./BaseLoader"),contextDefine_1=require("../utils/contextDefine"),chalk=require("chalk"),ModuleLoader=function(e){function t(e,n){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n))}return _inherits(t,e),_createClass(t,[{key:"getContextDefine",value:function(){var e=this;return new Promise(function(t,n){var o=e.option.loader;if(o)if(o.contextDefine)t(o.contextDefine);else if(o.taskDefine)t(development_core_1.taskDefine2Context(o.taskDefine));else{var r=e.getConfigModule();development_core_1.findTaskDefineInModule(r).then(function(n){t(n?n:contextDefine_1.default(e.getTaskModule()))}).catch(function(n){console.error(chalk.red(n)),t(contextDefine_1.default(e.getTaskModule()))})}else n("loader not found.")})}}]),t}(BaseLoader_1.BaseLoader);exports.ModuleLoader=ModuleLoader;
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _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}}(),development_core_1=require("development-core"),BaseLoader_1=require("./BaseLoader"),contextDefine_1=require("../utils/contextDefine"),chalk=require("chalk"),ModuleLoader=function(e){function t(e,n,o){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n,o))}return _inherits(t,e),_createClass(t,[{key:"getContextDefine",value:function(){var e=this;return new Promise(function(t,n){var o=e.option.loader;if(o)if(o.contextDefine)t(o.contextDefine);else if(o.taskDefine)t(development_core_1.taskDefine2Context(o.taskDefine));else{var r=e.getConfigModule();development_core_1.findTaskDefineInModule(r).then(function(n){t(n?n:contextDefine_1.default(e.getTaskModule()))}).catch(function(n){console.error(chalk.red(n)),t(contextDefine_1.default(e.getTaskModule()))})}else n("loader not found.")})}}]),t}(BaseLoader_1.BaseLoader);exports.ModuleLoader=ModuleLoader;
//# sourceMappingURL=../sourcemaps/loaders/ModuleLoader.js.map
/// <reference types="chai" />
import { Order, IPipeOption, ICustomPipe, ITaskDefine, ITask, IAsserts, RunWay, IContextDefine, TaskSource, IDynamicTaskOption, ITaskContext } from 'development-core';
import { Order, IPipeOption, ICustomPipe, ITaskDefine, ITask, IAsserts, RunWay, IContextDefine, TaskSource, IDynamicTaskOption, ITaskContext, ITaskConfig } from 'development-core';
export declare type contextFactory = (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext;
/**
* development context
*
* @export
* @interface IContext
* @extends {ITaskContext}
*/
export interface IContext extends ITaskContext {
parent?: IContext;
}
/**
* task loader option.

@@ -15,0 +6,0 @@ *

@@ -1,85 +0,8 @@

/// <reference types="gulp" />
import { Gulp } from 'gulp';
import { ITaskLoader } from './ITaskLoader';
import { Src, ITaskContext, ITaskInfo, ITask, IEnvOption, IDynamicTaskOption, RunWay } from 'development-core';
import { TaskOption, ITaskOption, IAssertOption, IContext } from './TaskOption';
import { DevelopConfig } from './DevelopConfig';
export * from './DevelopConfig';
export * from './TaskOption';
export * from './IContext';
export * from './Context';
export * from './Development';
export * from './ITaskLoader';
export * from './LoaderFactory';
export * from './loaders/BaseLoader';
export declare class Development {
private dirname;
protected config: DevelopConfig;
/**
* global data.
*
*
* @private
* @type {*}
* @memberOf Development
*/
private globals;
/**
* create development tool.
*
* @static
* @param {Gulp} gulp
* @param {string} dirname
* @param {(DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>)} setting
* @param {any} [runWay=RunWay.sequence]
* @returns {Development}
*
* @memberOf Development
*/
static create(gulp: Gulp, dirname: string, setting: DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>, runWay?: RunWay, compose?: boolean): Development;
/**
* Creates an instance of Development.
*
* @param {string} dirname
* @param {DevelopConfig} config
*
* @memberOf Development
*/
private constructor(dirname, config);
/**
* run task.
*
* @param {Gulp} gulp
* @param {IEnvOption} env
* @returns {Promise<any>}
*
* @memberOf Development
*/
run(gulp: Gulp, env: IEnvOption): Promise<any>;
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[]>;
/**
* load sub tasks as group task.
*
* @protected
* @param {Gulp} gulp
* @param {IContext} ctx
* @returns {Promise<ITaskInfo>}
*
* @memberOf Development
*/
protected loadSubTask(gulp: Gulp, ctx: IContext): Promise<ITaskInfo>;
/**
* load asserts tasks.
*
* @protected
* @param {Gulp} gulp
* @param {ITaskContext} ctx
* @returns {Promise<Src>}
*
* @memberOf Development
*/
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,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function __export(e){for(var n in e)exports.hasOwnProperty(n)||(exports[n]=e[n])}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 t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(n,t,o){return t&&e(n.prototype,t),o&&e(n,o),n}}(),_=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(n,t){_classCallCheck(this,e),this.dirname=n,this.config=t,this.globals={}}return _createClass(e,[{key:"run",value:function(e,n){var t=this;n.root||(n.root=this.dirname),n.help&&(console.log(chalk.grey("... main help ...")),this.printHelp(n.help));var o=this.getContext(n);return this.loadTasks(e,this.config.tasks,o).then(function(n){return t.config.runWay===development_core_1.RunWay.parallel?development_core_1.runSequence(e,[development_core_1.flattenSequence(e,n,o)]):development_core_1.runSequence(e,n)}).catch(function(e){console.error(e),process.exit(1)})}},{key:"getContext",value:function(e){if(!this.globalctx||this.globalctx.env!==e){var n=this.config.option||{};this.globalctx=this.bindingContext(development_core_1.bindingConfig({env:e,option:n}),null)}return this.globalctx}},{key:"bindingContext",value:function(e,n){var t=e;return t.globals=this.globals,this.config.compose&&(t.parent=_.isUndefined(n)?this.getContext(t.env):n),t}},{key:"loadTasks",value:function(e,n,t){var o=this;return Promise.all(_.map(_.isArray(n)?n:[n],function(n){n.dist=n.dist||"dist";var r=o.createLoader(n,t.env);return r.loadContext(t.env).then(function(n){return o.bindingContext(n,t),console.log(chalk.green("task context loaded.")),n.env.help?(n.printHelp&&(console.log(chalk.grey("...development default help...")),n.printHelp(_.isString(n.env.help)?n.env.help:"")),[]):Promise.all([r.load(n),o.loadAssertTasks(e,n),o.loadSubTask(e,n)]).then(function(t){return console.log(chalk.green("tasks loaded.")),o.setup(e,n,t[0],t[1],t[2])})})})).then(function(n){var o=[];return _.each(n,function(n){var r=development_core_1.zipSequence(e,n,t);r&&o.push(r)}),o})}},{key:"setup",value:function(e,n,t,o,r){return Promise.resolve(development_core_1.toSequence(e,t,n)).then(function(e){return n.runTasks?n.runTasks(e,o,r):(n.addToSequence(e,o),n.addToSequence(e,r),e)})}},{key:"loadSubTask",value:function(e,n){var t=this;if(!n.option.tasks)return Promise.resolve(null);var o=function(){var o=n.option;return _.each(_.isArray(o.tasks)?o.tasks:[o.tasks],function(e){e.name=n.subTaskName(e.name),e.src=e.src||o.src,e.dist=e.dist||o.dist}),{v:t.loadTasks(e,o.tasks,n).then(function(t){var r=void 0;return r=o.subTaskRunWay===development_core_1.RunWay.parallel?[development_core_1.flattenSequence(e,t,n,function(e,t){return n.subTaskName(e,t===development_core_1.RunWay.sequence?"-subs":"-subp")})]:development_core_1.zipSequence(e,t,n,function(e,t){return n.subTaskName(e,t===development_core_1.RunWay.sequence?"-subs":"-subp")}),r?{order:o.subTaskOrder,taskName:r}:null})}}();return"object"===("undefined"==typeof o?"undefined":_typeof(o))?o.v:void 0}},{key:"loadAssertTasks",value:function(e,n){var t=this,o=n.option;if(!o.asserts)return Promise.resolve(null);var r=function(){var r=[];return _.each(_.keys(o.asserts),function(e){var t=void 0,a=o.asserts[e];_.isString(a)?t={src:a,loader:[{name:e,pipes:[],watch:!0}]}:_.isNumber(a)?t={loader:[{oper:a,name:e,pipes:[]}]}:_.isFunction(a)?t={loader:a}:_.isArray(a)?a.length>0&&(t=_.isString(_.first(a))?{src:a,loader:[{name:e,pipes:[],watch:!0}]}:{loader:a,watch:!0}):t=a,_.isNull(t)||_.isUndefined(t)||(t.name=t.name||n.subTaskName(e),t.src=t.src||n.getSrc({oper:development_core_1.Operation.build})+"/**/*."+e,t.dist=t.dist||n.getDist({oper:development_core_1.Operation.build}),r.push(t))}),{v:Promise.all(_.map(r,function(o){return t.loadTasks(e,o,n).then(function(e){return{task:o,sq:e}})})).then(function(t){var r=_.map(t,function(t){return development_core_1.zipSequence(e,t.sq,n,function(e,o){return n.subTaskName(t.task.name,o===development_core_1.RunWay.sequence?"-asserts":"-assertp")})}),a=void 0;return a=o.assertsRunWay===development_core_1.RunWay.sequence?r:development_core_1.zipSequence(e,[r],n,function(e,n){return e+(n===development_core_1.RunWay.sequence?"-asserts":"-assertp")}),{order:o.assertsOrder,taskName:a}})}}();return"object"===("undefined"==typeof r?"undefined":_typeof(r))?r.v:void 0}},{key:"createLoader",value:function(e,n){var t=this,o=null;return _.isFunction(this.config.loaderFactory)||!function(){var e=new LoaderFactory_1.LoaderFactory;t.config.loaderFactory=function(t){return e.create(t,n)}}(),o=this.config.loaderFactory(e,n)}},{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(n,t,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:development_core_1.RunWay.sequence,a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=_.isArray(o)?{tasks:o,runWay:r}:o;_.isUndefined(s.runWay)||(s.runWay=r,s.compose=a);var i=new e(t,s);return s.setupTask=s.setupTask||"build",n.task(s.setupTask,function(e){var t=minimist(process.argv.slice(2),{string:"env",default:{env:process.env.NODE_ENV||"development"}});return i.run(n,t)}),n.task("default",function(){n.start(s.setupTask)}),i}}]),e}();exports.Development=Development;
"use strict";function __export(e){for(var r in e)exports.hasOwnProperty(r)||(exports[r]=e[r])}__export(require("./Context")),__export(require("./Development")),__export(require("./LoaderFactory")),__export(require("./loaders/BaseLoader"));
//# sourceMappingURL=sourcemaps/tools.js.map
{
"name": "development-tool",
"version": "0.9.6",
"version": "0.9.8",
"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.",

@@ -47,3 +47,4 @@ "main": "./lib/tools.js",

"checksum": "^0.1.1",
"development-core": "^0.9.8",
"development-core": "^0.9.10",
"gulp": "^3.9.1"

@@ -50,0 +51,0 @@ },

@@ -1,2 +0,2 @@

import { IEnvOption, RunWay } from 'development-core';
import { IEnvOption, RunWay, ITaskConfig, ITaskContext } from 'development-core';
import { IAssertOption, TaskOption } from './TaskOption';

@@ -46,19 +46,22 @@ import { ITaskLoader } from './ITaskLoader';

/**
* compose context.
* custom loader factory.
*
* @type {boolean}
* @param {TaskOption} option
* @param {IEnvOption} [env]
* @returns {ITaskLoader}
*
* @memberOf DevelopConfig
*/
compose?: boolean;
loaderFactory?(option: TaskOption, env?: IEnvOption): ITaskLoader;
/**
* custom loader factory.
* custom context factory.
*
* @param {TaskOption} option
* @param {IEnvOption} [env]
* @returns {ITaskLoader}
* @param {ITaskConfig} cfg
* @param {ITaskContext} [parent]
* @returns {ITaskContext}
*
* @memberOf DevelopConfig
*/
loaderFactory?(option: TaskOption, env?: IEnvOption): ITaskLoader;
contextFactory?(cfg: ITaskConfig, parent?: ITaskContext): ITaskContext;
}
import { ITask, IEnvOption, ITaskContext } from 'development-core';
import { IContext } from './TaskOption';
import { IContext } from './IContext';

@@ -4,0 +4,0 @@ /**

import { ITaskLoader } from './ITaskLoader';
import { DirLoader } from './loaders/DirLoader';
import { IEnvOption } from 'development-core';
import { IEnvOption } from 'development-core';
import { ITaskOption, ILoaderOption, IDynamicLoaderOption } from './TaskOption'
import { ITaskOption, ILoaderOption, IDynamicLoaderOption, contextFactory } from './TaskOption'
import { ModuleLoader } from './loaders/ModuleLoader';

@@ -24,2 +24,3 @@ import { DynamicLoader } from './loaders/DynamicLoader';

* @param {IEnvOption} [env]
* @param {contextFactory} [factory]
* @returns {ITaskLoader}

@@ -29,3 +30,3 @@ *

*/
create(option: ITaskOption, env?: IEnvOption): ITaskLoader;
create(option: ITaskOption, env?: IEnvOption, factory?: contextFactory): ITaskLoader;
}

@@ -45,3 +46,3 @@

}
create(option: ITaskOption, env?: IEnvOption): ITaskLoader {
create(option: ITaskOption, env?: IEnvOption, factory?: contextFactory): ITaskLoader {

@@ -52,5 +53,5 @@ if (_.isString(option.loader)) {

};
return new ModuleLoader(option);
return new ModuleLoader(option, env, factory);
} else if (_.isFunction(option.loader)) {
return new CustomLoader(option, option.loader);
return new CustomLoader(option, option.loader, factory);
} else if (_.isArray(option.loader)) {

@@ -60,3 +61,3 @@ option.loader = <IDynamicLoaderOption>{

};
return new DynamicLoader(option);
return new DynamicLoader(option, env, factory);
} else if (option.loader) {

@@ -73,3 +74,3 @@ // if config dir.

};
return new DynamicLoader(option);
return new DynamicLoader(option, env, factory);
}

@@ -86,7 +87,7 @@

case 'dir':
loader = new DirLoader(option, env);
loader = new DirLoader(option, env, factory);
break;
case 'dynamic':
loader = new DynamicLoader(option);
loader = new DynamicLoader(option, env, factory);
break;

@@ -96,3 +97,3 @@

default:
loader = new ModuleLoader(option, env);
loader = new ModuleLoader(option, env, factory);
break;

@@ -106,5 +107,5 @@ }

};
return new DynamicLoader(option);
return new DynamicLoader(option, env, factory);
}
}
}

@@ -1,3 +0,4 @@

import { ITask, IEnvOption, IContextDefine, ITaskContext } from 'development-core';
import { ITaskOption, ILoaderOption, IContext } from '../TaskOption';
import { ITask, IEnvOption, IContextDefine, ITaskContext, ITaskConfig } from 'development-core';
import { ITaskOption, ILoaderOption } from '../TaskOption';
import { IContext } from '../IContext';
import { ITaskLoader } from '../ITaskLoader';

@@ -8,7 +9,4 @@

protected option: ITaskOption;
protected env: IEnvOption;
constructor(option: ITaskOption, env?: IEnvOption) {
this.option = option;
this.env = env;
constructor(protected option: ITaskOption, protected env?: IEnvOption, protected factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext) {
}

@@ -33,3 +31,4 @@

option: self.option,
env: env
env: env,
createContext: self.factory
});

@@ -36,0 +35,0 @@ })

@@ -1,3 +0,4 @@

import { ITask, IEnvOption, ITaskContext, bindingConfig } from 'development-core';
import { ITaskOption, customLoader, IContext } from '../TaskOption';
import { ITask, IEnvOption, ITaskContext, bindingConfig, ITaskConfig } from 'development-core';
import { ITaskOption, customLoader } from '../TaskOption';
import { IContext } from '../IContext';
import { ITaskLoader } from '../ITaskLoader';

@@ -7,3 +8,3 @@

constructor(private option: ITaskOption, private loader: customLoader) {
constructor(private option: ITaskOption, private loader: customLoader, private factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext) {

@@ -22,3 +23,4 @@ }

option: self.option,
env: env
env: env,
createContext: self.factory
}));

@@ -25,0 +27,0 @@

import * as _ from 'lodash';
import { ITask, IContextDefine, ITaskContext, bindingConfig, findTaskDefineInDir, taskSourceVal, IEnvOption } from 'development-core';
import { ITask, IContextDefine, ITaskContext, bindingConfig, findTaskDefineInDir, ITaskConfig, taskSourceVal, IEnvOption } from 'development-core';
import { ITaskOption, IDirLoaderOption } from '../TaskOption';

@@ -8,3 +8,3 @@ import { ModuleLoader } from './ModuleLoader';

constructor(option: ITaskOption, env: IEnvOption) {
constructor(option: ITaskOption, env: IEnvOption, factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext) {
super(option, env);

@@ -27,3 +27,3 @@ }

&& !loader.module && loader.dir) {
return findTaskDefineInDir(taskSourceVal(loader.dir, bindingConfig({ env: self.env, option: {} })));
return findTaskDefineInDir(taskSourceVal(loader.dir, bindingConfig({ env: self.env, option: {}, createContext: self.factory })));
} else {

@@ -30,0 +30,0 @@ return super.getContextDefine();

@@ -1,2 +0,2 @@

import { IContextDefine, IEnvOption } from 'development-core';
import { IContextDefine, IEnvOption, ITaskConfig, ITaskContext } from 'development-core';
import { ITaskOption } from '../TaskOption';

@@ -8,4 +8,4 @@ import contextDefine from '../utils/contextDefine';

constructor(option: ITaskOption, env?: IEnvOption) {
super(option, env);
constructor(option: ITaskOption, env?: IEnvOption, factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext) {
super(option, env, factory);
}

@@ -12,0 +12,0 @@

@@ -1,2 +0,2 @@

import { IContextDefine, findTaskDefineInModule, IEnvOption, taskDefine2Context } from 'development-core';
import { IContextDefine, findTaskDefineInModule, IEnvOption, ITaskConfig, ITaskContext, taskDefine2Context } from 'development-core';
import { ITaskOption, ILoaderOption } from '../TaskOption';

@@ -9,4 +9,4 @@ import { BaseLoader } from './BaseLoader';

constructor(option: ITaskOption, env?: IEnvOption) {
super(option, env);
constructor(option: ITaskOption, env?: IEnvOption, factory?: (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext) {
super(option, env, factory);
}

@@ -13,0 +13,0 @@

import {
Order, IPipeOption, ICustomPipe, ITaskDefine, ITask, IAsserts, RunWay
, IContextDefine, TaskSource, IDynamicTaskOption, ITaskContext
, IContextDefine, TaskSource, IDynamicTaskOption, ITaskContext, ITaskConfig
} from 'development-core'
export type contextFactory = (cfg: ITaskConfig, parent?: ITaskContext) => ITaskContext;
/**
* development context
*
* @export
* @interface IContext
* @extends {ITaskContext}
*/
export interface IContext extends ITaskContext {
parent?: IContext;
}
/**
* task loader option.

@@ -19,0 +10,0 @@ *

@@ -1,14 +0,6 @@

import * as _ from 'lodash';
import { Gulp, TaskCallback } from 'gulp';
import * as minimist from 'minimist';
import { ITaskLoader } from './ITaskLoader';
import { LoaderFactory } from './LoaderFactory';
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';
import * as chalk from 'chalk';
export * from './DevelopConfig';
export * from './TaskOption';
export * from './IContext';
export * from './Context';
export * from './Development';
export * from './ITaskLoader';

@@ -18,350 +10,4 @@ export * from './LoaderFactory';

export class Development {
/**
* global data.
*
*
* @private
* @type {*}
* @memberOf Development
*/
private globals: any = {};
/**
* create development tool.
*
* @static
* @param {Gulp} gulp
* @param {string} dirname
* @param {(DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>)} setting
* @param {any} [runWay=RunWay.sequence]
* @returns {Development}
*
* @memberOf Development
*/
static create(gulp: Gulp, dirname: string, setting: DevelopConfig | Array<ITaskOption | IAssertOption | IDynamicTaskOption>, runWay = RunWay.sequence, compose = false): Development {
let option = _.isArray(setting) ? { tasks: setting, runWay: runWay } : setting;
if (!_.isUndefined(option.runWay)) {
option.runWay = runWay;
option.compose = compose;
}
let devtool = new Development(dirname, option);
option.setupTask = option.setupTask || 'build';
gulp.task(option.setupTask, (callback: TaskCallback) => {
var options: IEnvOption = minimist(process.argv.slice(2), {
string: 'env',
default: { env: process.env.NODE_ENV || 'development' }
});
return devtool.run(gulp, options);
});
gulp.task('default', () => {
gulp.start(option.setupTask);
});
return devtool;
}
/**
* Creates an instance of Development.
*
* @param {string} dirname
* @param {DevelopConfig} config
*
* @memberOf Development
*/
private constructor(private dirname: string, protected config: DevelopConfig) {
}
/**
* run task.
*
* @param {Gulp} gulp
* @param {IEnvOption} env
* @returns {Promise<any>}
*
* @memberOf Development
*/
run(gulp: Gulp, env: IEnvOption): Promise<any> {
if (!env.root) {
env.root = this.dirname;
}
if (env.help) {
console.log(chalk.grey('... main help ...'));
this.printHelp(env.help);
}
let gbctx = this.getContext(env);
return this.loadTasks(gulp, this.config.tasks, gbctx)
.then(tseq => {
// console.log(chalk.grey('run sequenec tasks:'), tseq);
if (this.config.runWay === RunWay.parallel) {
return runSequence(gulp, [flattenSequence(gulp, tseq, gbctx)]);
} else {
return runSequence(gulp, tseq);
}
})
.catch(err => {
console.error(err);
process.exit(1);
});
}
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;
if (this.config.compose) {
ctx.parent = _.isUndefined(parent) ? this.getContext(ctx.env) : parent;
}
return ctx;
}
protected loadTasks(gulp: Gulp, tasks: TaskOption, parent: IContext): Promise<Src[]> {
return Promise.all<Src[]>(
_.map(_.isArray(tasks) ? <ITaskOption[]>tasks : [<ITaskOption>tasks], optask => {
optask.dist = optask.dist || 'dist';
// console.log(chalk.grey('begin load task via loader:'), optask.loader);
let loader = this.createLoader(optask, parent.env);
return loader.loadContext(parent.env)
.then(ctx => {
this.bindingContext(ctx, parent);
console.log(chalk.green('task context loaded.'));
if (ctx.env.help) {
if (ctx.printHelp) {
console.log(chalk.grey('...development default help...'));
ctx.printHelp(_.isString(ctx.env.help) ? ctx.env.help : '');
}
return [];
} else {
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]);
});
}
});
})
)
.then(tsq => {
let rst: Src[] = [];
_.each(tsq, t => {
let tk = zipSequence(gulp, t, parent);
if (tk) {
rst.push(tk);
}
});
return rst;
});
}
protected setup(gulp: Gulp, ctx: ITaskContext, tasks: ITask[], assertsTask: ITaskInfo, subGroupTask: ITaskInfo): Promise<Src[]> {
return Promise.resolve(toSequence(gulp, tasks, ctx))
.then(tsqs => {
// if (_.isFunction(context.option['runTasks'])) {
// return context.option['runTasks'](context.oper, tsqs, subGroupTask, assertsTask);
// } else if (_.isArray(context.option['runTasks'])) {
// tsqs = context.option['runTasks'];
// } else
if (ctx.runTasks) {
return ctx.runTasks(tsqs, assertsTask, subGroupTask);
}
// console.log(assertsTask);
ctx.addToSequence(tsqs, assertsTask);
ctx.addToSequence(tsqs, subGroupTask);
return tsqs;
});
}
/**
* load sub tasks as group task.
*
* @protected
* @param {Gulp} gulp
* @param {IContext} ctx
* @returns {Promise<ITaskInfo>}
*
* @memberOf Development
*/
protected loadSubTask(gulp: Gulp, ctx: IContext): Promise<ITaskInfo> {
if (ctx.option['tasks']) {
let optask = <ITaskOption>ctx.option;
_.each(_.isArray(optask.tasks) ? optask.tasks : [optask.tasks], subopt => {
subopt.name = ctx.subTaskName(subopt.name);
subopt.src = subopt.src || optask.src;
subopt.dist = subopt.dist || optask.dist;
});
return this.loadTasks(gulp, optask.tasks, ctx)
.then(subseq => {
let taskname;
if (optask.subTaskRunWay === RunWay.parallel) {
taskname = [flattenSequence(gulp, subseq, ctx, (name, runway) => ctx.subTaskName(name, (runway === RunWay.sequence ? '-subs' : '-subp')))]
} else {
taskname = zipSequence(gulp, subseq, ctx, (name, runway) => ctx.subTaskName(name, (runway === RunWay.sequence ? '-subs' : '-subp')));
}
if (taskname) {
return <ITaskInfo>{
order: optask.subTaskOrder,
taskName: taskname
};
} else {
return null;
}
});
} else {
return Promise.resolve(null);
}
}
/**
* load asserts tasks.
*
* @protected
* @param {Gulp} gulp
* @param {ITaskContext} ctx
* @returns {Promise<Src>}
*
* @memberOf Development
*/
protected loadAssertTasks(gulp: Gulp, ctx: IContext): Promise<ITaskInfo> {
let optask = <IAssertOption>ctx.option;
if (optask.asserts) {
let tasks: IAssertOption[] = [];
_.each(_.keys(optask.asserts), name => {
let op: IAssertOption;
let sr = optask.asserts[name];
if (_.isString(sr)) {
op = <IAssertOption>{ src: sr, loader: [{ name: name, pipes: [], watch: true }] };
} else if (_.isNumber(sr)) {
// watch with Operation.autoWatch.
op = <IAssertOption>{ loader: [{ oper: sr, name: name, pipes: [] }] };
} else if (_.isFunction(sr)) {
op = { loader: sr };
} else if (_.isArray(sr)) {
if (sr.length > 0) {
if (_.isString(_.first(<string[]>sr))) {
op = <IAssertOption>{ src: <string[]>sr, loader: [{ name: name, pipes: [], watch: true }] };
} else {
op = <IAssertOption>{ loader: <IDynamicTaskOption[]>sr, watch: true };
}
}
} else {
op = sr;
}
if (_.isNull(op) || _.isUndefined(op)) {
return;
}
op.name = op.name || ctx.subTaskName(name);
op.src = op.src || (ctx.getSrc({ oper: Operation.build }) + '/**/*.' + name);
op.dist = op.dist || ctx.getDist({ oper: Operation.build });
tasks.push(op);
});
return Promise.all(_.map(tasks, task => {
return this.loadTasks(gulp, <ITaskOption>task, ctx)
.then(sq => {
return {
task: task,
sq: sq
}
});
}))
.then(tseq => {
// asserts tasks run mutil.
let assertSeq = _.map(tseq, t => {
return zipSequence(gulp, t.sq, ctx, (name, runway) => ctx.subTaskName(t.task.name, runway === RunWay.sequence ? '-asserts' : '-assertp')); // ctx.subTaskName(name + (runway === RunWay.sequence ? '-assert-seq' : '-assert-par')));
});
let taskname;
if (optask.assertsRunWay === RunWay.sequence) {
taskname = assertSeq;
} else {
taskname = zipSequence(gulp, [assertSeq], ctx, (name, runway) => name + (runway === RunWay.sequence ? '-asserts' : '-assertp'));
}
return <ITaskInfo>{
order: optask.assertsOrder,
taskName: taskname
}
});
} else {
return Promise.resolve(null);
}
}
protected createLoader(option: TaskOption, env: IEnvOption): ITaskLoader {
let loader = null;
if (!_.isFunction(this.config.loaderFactory)) {
let factory = new LoaderFactory();
this.config.loaderFactory = (opt: ITaskOption) => {
return factory.create(opt, env);
}
}
loader = this.config.loaderFactory(option, env);
return loader;
}
protected printHelp(help: boolean | string) {
if (help === 'en') {
console.log(`
/**
* gulp [build] [--env production|development] [--context name] [--root path] [--watch] [--test] [--serve] [--release] [--task taskname]
* @params
* --env development or production;
* --context app setting
* --root path, set relative path of the development tool root.
* --watch watch src file change or not. if changed will auto update to node service.
* --release release web app or not. if [--env production], default to release.
* --test need auto load test file to node service.
* --deploy run deploy tasks to deploy project.
* --serve start node web service or not.
* --task taskname spruce task taskname
**/`);
} else {
console.log(`
/**
* gulp [build] [--env production|development] [--context name] [--root path] [--watch] [--test] [--serve] [--release] [--task taskname]
* @params
* --env 发布环境 默认开发环境development;
* --context 设置配置文件;
* --root path, 设置编译环境相对路径
* --watch 是否需要动态监听文件变化
* --release 是否release编译, [--env production] 默认release
* --test 启动自动化测试
* --deploy 运行加载deploy tasks, 编译发布项目。
* --serve 是否在开发模式下 开启node web服务
* --task taskname 运行单独任务taskname
**/`);
}
}
}

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc