development-core
Advanced tools
Comparing version 0.3.1 to 0.4.0
// DynamicTask | ||
import * as gulp from 'gulp'; | ||
import { bindingConfig, currentOperation, generateTask, runSequence, toSequence, EnvOption, TaskOption, Src, Operation, DynamicTask } from './src/TaskConfig'; | ||
import { bindingConfig, currentOperation, generateTask, runTaskSequence, IEnvOption, Operation } from './src'; | ||
import * as mocha from 'gulp-mocha'; | ||
@@ -17,3 +17,3 @@ import * as minimist from 'minimist'; | ||
gulp.task('build', () => { | ||
var options: EnvOption = minimist(process.argv.slice(2), { | ||
var options: IEnvOption = minimist(process.argv.slice(2), { | ||
string: 'env', | ||
@@ -25,6 +25,2 @@ default: { env: process.env.NODE_ENV || 'development' } | ||
gulp.task('default', () => { | ||
gulp.start('build'); | ||
}); | ||
let createTask = (env) => { | ||
@@ -35,7 +31,6 @@ let oper: Operation = currentOperation(env); | ||
oper: oper, | ||
option: { src: 'src', dist: 'lib', loader: [] } | ||
option: { src: 'src', dist: 'lib' } | ||
}); | ||
let taskseq = _.map(generateTask([ | ||
let tasks = generateTask([ | ||
{ | ||
@@ -58,3 +53,3 @@ name: 'tscompile', src: 'src/**/*.ts', dist: 'lib', | ||
{ | ||
name: 'test', src: 'test/**/*spec.ts', order:1, | ||
name: 'test', src: 'test/**/*spec.ts', order: 1, | ||
oper: Operation.test | Operation.release | Operation.deploy, | ||
@@ -70,8 +65,5 @@ pipe(src) { | ||
{ name: 'clean', order: 0, src: 'src', dist: 'lib', task: (config) => del(config.getDist()) } | ||
], oper, env), tk => { | ||
return tk(gulp, config); | ||
}); | ||
let seqs = toSequence(taskseq, oper); | ||
console.log(seqs) | ||
return runSequence(gulp, seqs); | ||
], oper, env); | ||
return runTaskSequence(gulp, tasks, config); | ||
} |
@@ -16,11 +16,16 @@ /// <reference types="gulp" /> | ||
export declare type Src = string | string[]; | ||
export interface ITaskResult { | ||
name?: Src; | ||
export interface ITaskInfo { | ||
oper?: Operation; | ||
order?: number; | ||
name?: Src; | ||
watch?: boolean; | ||
} | ||
export declare type TaskResult = Src | ITaskResult; | ||
export declare type Task = (gulp: Gulp, config: TaskConfig) => TaskResult | TaskResult[] | void; | ||
export declare function task(constructor: Function): void; | ||
export interface LoaderOption { | ||
export declare type TaskResult = Src | void; | ||
export declare type TaskSource = Src | ((oper?: Operation) => Src); | ||
export declare type TaskString = string | ((oper?: Operation) => string); | ||
export interface ITask { | ||
decorator: ITaskInfo; | ||
setup(config: ITaskConfig, gulp?: Gulp): TaskResult; | ||
} | ||
export interface ILoaderOption { | ||
type?: string; | ||
@@ -34,4 +39,4 @@ module?: string | Object; | ||
} | ||
export interface DirLoaderOption extends LoaderOption { | ||
dir?: Src; | ||
export interface IDirLoaderOption extends ILoaderOption { | ||
dir?: TaskSource; | ||
dirConfigFile?: string; | ||
@@ -42,11 +47,11 @@ } | ||
} | ||
export interface Output extends ITransform { | ||
export interface IOutput extends ITransform { | ||
dts?: ITransform; | ||
js?: ITransform; | ||
} | ||
export declare type Pipe = (config?: TaskConfig, dt?: DynamicTask, gulp?: Gulp) => ITransform | Promise<ITransform>; | ||
export declare type OutputPipe = (map: Output, config?: TaskConfig, dt?: DynamicTask, gulp?: Gulp) => ITransform | Promise<ITransform>; | ||
export interface OutputDist { | ||
src?: Src; | ||
dist?: string; | ||
export declare type Pipe = (config?: ITaskConfig, dt?: IDynamicTask, gulp?: Gulp) => ITransform | Promise<ITransform>; | ||
export declare type OutputPipe = (map: IOutput, config?: ITaskConfig, dt?: IDynamicTask, gulp?: Gulp) => ITransform | Promise<ITransform>; | ||
export interface IOutputDist { | ||
src?: TaskSource; | ||
dist?: TaskString; | ||
build?: string; | ||
@@ -58,52 +63,52 @@ test?: string; | ||
} | ||
export interface DynamicTask extends OutputDist { | ||
name: string; | ||
export interface IDynamicTask extends IOutputDist { | ||
name: TaskString; | ||
order?: number; | ||
oper?: Operation; | ||
watch?: Array<string | WatchCallback> | ((config?: TaskConfig, dt?: DynamicTask) => Array<string | WatchCallback>); | ||
watchChanged?(event: WatchEvent, config: TaskConfig): any; | ||
pipe?(gulpsrc: ITransform, config: TaskConfig, dt?: DynamicTask): ITransform | Promise<ITransform>; | ||
pipes?: Pipe[] | ((config?: TaskConfig, dt?: DynamicTask) => Pipe[]); | ||
output?: OutputPipe[] | ((config?: TaskConfig, dt?: DynamicTask) => OutputPipe[]); | ||
task?(config: TaskConfig, dt?: DynamicTask, gulp?: Gulp): void | ITransform | Promise<any>; | ||
watch?: Array<string | WatchCallback> | ((config?: ITaskConfig, dt?: IDynamicTask) => Array<string | WatchCallback>); | ||
watchChanged?(event: WatchEvent, config: ITaskConfig): any; | ||
pipe?(gulpsrc: ITransform, config: ITaskConfig, dt?: IDynamicTask): ITransform | Promise<ITransform>; | ||
pipes?: Pipe[] | ((config?: ITaskConfig, dt?: IDynamicTask) => Pipe[]); | ||
output?: OutputPipe[] | ((config?: ITaskConfig, dt?: IDynamicTask) => OutputPipe[]); | ||
task?(config: ITaskConfig, dt?: IDynamicTask, gulp?: Gulp): void | ITransform | Promise<any>; | ||
} | ||
export interface DynamicLoaderOption extends LoaderOption { | ||
dynamicTasks?: DynamicTask | DynamicTask[]; | ||
export interface IDynamicLoaderOption extends ILoaderOption { | ||
dynamicTasks?: IDynamicTask | IDynamicTask[]; | ||
} | ||
export interface TaskLoaderOption { | ||
loader: string | LoaderOption | DynamicTask | DynamicTask[]; | ||
externalTask?: Task; | ||
export interface ITaskLoaderOption { | ||
loader: string | ILoaderOption | IDynamicTask | IDynamicTask[]; | ||
runTasks?: Src[] | ((oper: Operation, tasks: Src[], subGroupTask?: TaskResult, assertsTask?: TaskResult) => Src[]); | ||
tasks?: TaskOption | TaskOption[]; | ||
tasks?: ITaskOption | ITaskOption[]; | ||
subTaskOrder?: number; | ||
} | ||
export interface Asserts extends OutputDist, TaskLoaderOption { | ||
name?: string; | ||
asserts?: IMap<Src | Asserts | DynamicTask[]>; | ||
export interface IAsserts extends IOutputDist { | ||
name?: TaskString; | ||
IAsserts?: IMap<Src | IAsserts | IDynamicTask[]>; | ||
assertsOrder?: number; | ||
} | ||
export interface TaskOption extends Asserts { | ||
src: Src; | ||
export interface ITaskOption extends IAsserts, ITaskLoaderOption { | ||
src: TaskSource; | ||
} | ||
export interface ITaskDefine { | ||
moduleTaskConfig(oper: Operation, option: TaskOption, env: EnvOption): TaskConfig; | ||
moduleTaskLoader?(config: TaskConfig): Promise<Task[]>; | ||
loadConfig(oper: Operation, option: ITaskOption, env: IEnvOption): ITaskConfig; | ||
loadTasks?(config: ITaskConfig): Promise<ITask[]>; | ||
} | ||
export interface TaskConfig { | ||
export interface ITaskConfig { | ||
globals?: any; | ||
env: EnvOption; | ||
env: IEnvOption; | ||
oper: Operation; | ||
option: TaskOption; | ||
option: IAsserts | ITaskOption; | ||
getSrc?(assert?: IAsserts): Src; | ||
getDist?(dist?: IOutputDist): string; | ||
runTasks?(subGroupTask?: TaskResult, tasks?: Src[], assertTasks?: TaskResult): Src[]; | ||
printHelp?(lang: string): void; | ||
findTasksInModule?(module: string): Promise<Task[]>; | ||
findTasksInDir?(dirs: Src): Promise<Task[]>; | ||
getDist?(dist?: OutputDist): string; | ||
findTasksInModule?(module: string): Promise<ITask[]>; | ||
findTasksInDir?(dirs: Src): Promise<ITask[]>; | ||
fileFilter?(directory: string, express?: ((fileName: string) => boolean)): string[]; | ||
runSequence?(gulp: Gulp, tasks: Src[]): Promise<any>; | ||
generateTask?(tasks: DynamicTask | DynamicTask[]): Task[]; | ||
addTask?(sequence: Src[], taskResult: TaskResult): Src[]; | ||
subTaskName?(name: string, defaultName?: string): any; | ||
generateTask?(tasks: IDynamicTask | IDynamicTask[]): ITask[]; | ||
addToSequence?(sequence: Src[], task: ITaskInfo): Src[]; | ||
subTaskName?(assert: string | IAsserts, defaultName?: string): any; | ||
} | ||
export interface EnvOption { | ||
export interface IEnvOption { | ||
root?: string; | ||
@@ -122,7 +127,1 @@ help?: boolean | string; | ||
} | ||
export declare function bindingConfig(cfg: TaskConfig): TaskConfig; | ||
export declare function currentOperation(env: EnvOption): Operation; | ||
export declare function toSequence(tasks: Array<TaskResult | TaskResult[] | void>, oper: Operation): Src[]; | ||
export declare function runSequence(gulp: Gulp, tasks: Src[]): Promise<any>; | ||
export declare function files(directory: string, express?: ((fileName: string) => boolean)): string[]; | ||
export declare function generateTask(tasks: DynamicTask | DynamicTask[], oper: Operation, env: EnvOption): Task[]; |
@@ -1,2 +0,2 @@ | ||
"use strict";function task(e){Object.seal(e),Object.seal(e.prototype)}function bindingConfig(e){return e.fileFilter=e.fileFilter||files,e.runSequence=e.runSequence||runSequence,e.addTask=e.addTask||addTask,e.generateTask=e.generateTask||function(r){return generateTask(r,e.oper,e.env)},e.subTaskName=e.subTaskName||function(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return e.option.name?e.option.name+"-"+(r||n):r},e.getDist=e.getDist||function(r){if(r){var n=getCurrentDist(r,e.oper);if(n)return n}return getCurrentDist(e.option,e.oper)},e}function currentOperation(e){var r=void 0;return r=e.deploy?Operation.deploy:e.release?Operation.release:e.e2e?Operation.e2e:e.test?Operation.test:Operation.build}function toSequence(e,r){var n=[];e=_.filter(e,function(e){return e});var t=e.length;return e=_.orderBy(e,function(e){return e?_.isString(e)?t:_.isArray(e)?t:e.order:t}),_.each(e,function(e){e&&(_.isString(e)?n.push(e):_.isArray(e)?n.push(_.flatten(toSequence(e,r))):e.name&&(e.oper?(e.oper&r)>0&&n.push(e.name):n.push(e.name)))}),n}function runSequence(e,r){var n=Promise.resolve();return r&&r.length>0&&_.each(r,function(r){n=n.then(function(){var n=null,t=null;return new Promise(function(i,o){var a={};_.each(_.isArray(r)?r:[r],function(e){a[e]=!1}),n=function(e){o(e)},t=function(e){a[e.task]=!0,_.some(_.values(a),function(e){return!e})||i()},e.on("task_stop",t).on("task_err",n),e.start(r)}).then(function(){e.removeListener&&(e.removeListener("task_stop",t),e.removeListener("task_err",n))},function(r){e.removeListener&&(e.removeListener("task_stop",t),e.removeListener("task_err",n)),console.error(r)})})}),n}function files(e,r){var n=[];return r=r||function(e){return!0},_.each(fs_1.readdirSync(e),function(t){var i=e+"/"+t,o=fs_1.lstatSync(i);o.isDirectory()?n=n.concat(files(i,r)):r(i)&&n.push(i)}),n}function generateTask(e,r,n){var t=[];return _.each(_.isArray(e)?e:[e],function(e){if(!(e.oper&&(e.oper&r)<=0))if(e.watch){if(!n.watch)return;console.log("register watch dynamic task:",chalk.cyan(e.name)),t.push(createWatchTask(e))}else _.isFunction(e.task)?(console.log("register custom dynamic task:",chalk.cyan(e.name)),t.push(createTask(e))):(console.log("register pipes dynamic task:",chalk.cyan(e.name)),t.push(createPipesTask(e)))}),t}function getCurrentDist(e,r){var n=void 0;switch(r){case Operation.build:n=e.build||e.dist;break;case Operation.test:n=e.test||e.build||e.dist;break;case Operation.e2e:n=e.e2e||e.build||e.dist;break;case Operation.release:n=e.release||e.dist;break;case Operation.deploy:n=e.deploy||e.dist;break;default:n=""}return n}function addTask(e,r){if(!r)return e;if(_.isString(r)||_.isArray(r))e.push(r);else if(r.name){if(_.isNumber(r.order)&&r.order>=0&&r.order<e.length)return e.splice(r.order,0,r.name),e;e.push(r.name)}return e}function createTask(e){return function(r,n){var t=n.subTaskName(e.name);return r.task(t,function(){return e.task(n,e,r)}),_.isNumber(e.order)?{name:t,order:e.order}:t}}function createWatchTask(e){return function(r,n){var t=_.isFunction(e.watch)?e.watch(n):e.watch;_.isFunction(_.last(t))||t.push(function(r){e.watchChanged&&e.watchChanged(r,n)}),t=_.map(t,function(e){return _.isString(e)?n.subTaskName(e):e});var i=n.subTaskName(e.name);return r.task(i,function(){console.log("watch, src:",chalk.cyan.call(chalk,n.option.src)),r.watch(n.option.src,t)}),_.isNumber(e.order)?{name:i,order:e.order}:i}}function createPipesTask(e){return function(r,n){var t=n.subTaskName(e.name);return r.task(t,function(){var t=Promise.resolve(r.src(e.src||n.option.src));if(e.pipes){var i=_.isFunction(e.pipes)?e.pipes(n,e):e.pipes;_.each(i,function(i){t=t.then(function(t){return Promise.resolve(_.isFunction(i)?i(n,e,r):i).then(function(e){return t.pipe(e)})})})}else e.pipe&&(t=t.then(function(r){return e.pipe(r,n,e)}));return t.then(function(t){if(e.output){var i=_.isFunction(e.output)?e.output(n,e):e.output;return Promise.all(_.map(i,function(i){return new Promise(function(o,a){Promise.resolve(_.isFunction(i)?i(t,n,e,r):i).then(function(e){t.pipe(e).once("end",o).once("error",a)})})}))}return new Promise(function(i,o){t.pipe(r.dest(n.getDist(e))).once("end",i).once("error",o)})}),t.catch(function(e){console.log(chalk.red(e))})}),_.isNumber(e.order)?{name:t,order:e.order}:t}}var _=require("lodash"),chalk=require("chalk"),fs_1=require("fs");!function(e){e[e.build=1]="build",e[e.test=2]="test",e[e.e2e=4]="e2e",e[e.release=8]="release",e[e.deploy=16]="deploy"}(exports.Operation||(exports.Operation={}));var Operation=exports.Operation;exports.task=task,exports.bindingConfig=bindingConfig,exports.currentOperation=currentOperation,exports.toSequence=toSequence,exports.runSequence=runSequence,exports.files=files,exports.generateTask=generateTask; | ||
"use strict";!function(e){e[e.build=1]="build",e[e.test=2]="test",e[e.e2e=4]="e2e",e[e.release=8]="release",e[e.deploy=16]="deploy"}(exports.Operation||(exports.Operation={}));var Operation=exports.Operation; | ||
//# sourceMappingURL=sourcemaps/TaskConfig.js.map |
{ | ||
"name": "development-core", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "development build tools.", | ||
"main": "./lib/TaskConfig.js", | ||
"typings": "./lib/TaskConfig", | ||
"main": "./lib/index.js", | ||
"typings": "./lib/index", | ||
"scripts": { | ||
@@ -41,3 +41,4 @@ "gulp": "gulp", | ||
"gulp": "^3.9.1", | ||
"lodash": "^4.13.1" | ||
"lodash": "^4.13.1", | ||
"reflect-metadata": "^0.1.8" | ||
}, | ||
@@ -44,0 +45,0 @@ "devDependencies": { |
@@ -30,3 +30,3 @@ # packaged development-core | ||
import * as gulp from 'gulp'; | ||
import { generateTask, runSequence } from 'development-core'; | ||
import { generateTask, runTaskSequence, runSequence } from 'development-core'; | ||
@@ -43,8 +43,64 @@ ``` | ||
## define task and taskdefine. | ||
decorator not support function now, so refactor ITask interface. | ||
```ts | ||
// module A | ||
import { taskdefine, bindingConfig, Operation, ITaskOption, IEnvOption, ITaskConfig, ITaskDefine, ITask, ITaskInfo, TaskResult, task } from 'development-core'; | ||
@task({ | ||
oper: Operation.build | Operation.test | ||
}) | ||
export class TestTaskC implements ITask { | ||
public decorator: ITaskInfo = {}; | ||
constructor() { | ||
} | ||
setup(config: ITaskConfig, gulp): TaskResult { | ||
// todo... | ||
let taskname = config.subTaskName('TestTaskC'); | ||
gulp.task(taskname, ()=>{ | ||
gulp.src(config.getSrc()) | ||
.pipe(...) | ||
... | ||
.pipe(gulp.dest(config.getDist())) | ||
}); | ||
// return task name, enable this task to add in run sequence. | ||
// or just set to decorator. | ||
// this.decorator.name = taskname; | ||
return taskname | ||
} | ||
} | ||
@taskdefine() | ||
export class TaskDefine implements ITaskDefine { | ||
loadConfig(oper: Operation, option: ITaskOption, env: IEnvOption): ITaskConfig { | ||
return bindingConfig({ | ||
oper: oper, | ||
option: option, | ||
env: env | ||
}); | ||
} | ||
} | ||
// module B | ||
import { findTasks, Operation, runTaskSequence, findTaskDefine } from 'development-core'; | ||
let moduleA = require('module a'); | ||
let tasks = findTasks(moduleA); | ||
let tdfs = findTaskDefine(moduleA); | ||
// run task; | ||
runTaskSequence(tasks, tdfs.loadConfig(Operation.build, {src:'src', dist:'lib'}, {watch:true})); | ||
``` | ||
## Create development tool with dynamic tasks via Promise | ||
```ts | ||
// DynamicTask | ||
import * as gulp from 'gulp'; | ||
import { bindingConfig, currentOperation, generateTask, runSequence, toSequence, EnvOption, TaskOption, Src, Operation, DynamicTask } from './src/TaskConfig'; | ||
import { bindingConfig, currentOperation, generateTask, runTaskSequence, IEnvOption, Operation } from 'development-core'; | ||
import * as mocha from 'gulp-mocha'; | ||
@@ -63,3 +119,3 @@ import * as minimist from 'minimist'; | ||
gulp.task('build', () => { | ||
var options: EnvOption = minimist(process.argv.slice(2), { | ||
var options: IEnvOption = minimist(process.argv.slice(2), { | ||
string: 'env', | ||
@@ -71,6 +127,2 @@ default: { env: process.env.NODE_ENV || 'development' } | ||
gulp.task('default', () => { | ||
gulp.start('build'); | ||
}); | ||
let createTask = (env) => { | ||
@@ -81,7 +133,6 @@ let oper: Operation = currentOperation(env); | ||
oper: oper, | ||
option: { src: 'src', dist: 'lib', loader: [] } | ||
option: { src: 'src', dist: 'lib' } | ||
}); | ||
let taskseq = _.map(generateTask([ | ||
{ name: 'clean', src: 'src', dist: 'lib', task: (config) => del(config.getDist()) }, | ||
let tasks = generateTask([ | ||
{ | ||
@@ -94,3 +145,3 @@ name: 'tscompile', src: 'src/**/*.ts', dist: 'lib', | ||
if (config.oper === Operation.release || config.oper === Operation.deploy) { | ||
return tsmap.js.pipe(babel({presets: ['es2015']})) | ||
return tsmap.js.pipe(babel({ presets: ['es2015'] })) | ||
.pipe(uglify()).pipe(sourcemaps.write('./sourcemaps')) | ||
@@ -105,3 +156,3 @@ .pipe(gulp.dest(config.getDist(dt))); | ||
{ | ||
name: 'test', src: 'test/**/*spec.ts', | ||
name: 'test', src: 'test/**/*spec.ts', order: 1, | ||
oper: Operation.test | Operation.release | Operation.deploy, | ||
@@ -115,8 +166,7 @@ pipe(src) { | ||
}, | ||
{ src: 'src/**/*.ts', name: 'watch', watch: ['tscompile'] } | ||
], oper, env), tk => { | ||
return tk(gulp, config); | ||
}); | ||
{ src: 'src/**/*.ts', name: 'watch', watch: ['tscompile'] }, | ||
{ name: 'clean', order: 0, src: 'src', dist: 'lib', task: (config) => del(config.getDist()) } | ||
], oper, env); | ||
return runSequence(gulp, toSequence(taskseq, oper)); | ||
return runTaskSequence(gulp, tasks, config); | ||
} | ||
@@ -123,0 +173,0 @@ |
@@ -1,5 +0,2 @@ | ||
import * as _ from 'lodash'; | ||
import { Gulp, WatchEvent, WatchCallback } from 'gulp'; | ||
import * as chalk from 'chalk'; | ||
import { readdirSync, lstatSync } from 'fs'; | ||
@@ -52,44 +49,73 @@ /** | ||
/** | ||
* Task return type. | ||
* task decorator data. | ||
* | ||
* @export | ||
* @interface ITaskResult | ||
* @interface ITaskInfo | ||
*/ | ||
export interface ITaskResult { | ||
export interface ITaskInfo { | ||
/** | ||
* task name for task sequence. | ||
* operation | ||
* | ||
* @type {Src} | ||
* @memberOf ITaskResult | ||
*/ | ||
name?: Src; | ||
/** | ||
* task Operation type. default all pperation. | ||
* | ||
* enmu flags. | ||
* @type {Operation} | ||
* @memberOf ITaskResult | ||
* @memberOf ITaskInfo | ||
*/ | ||
oper?: Operation; | ||
/** | ||
* task sequence order. | ||
* task sequence index. | ||
* | ||
* @type {number} | ||
* @memberOf ITaskResult | ||
* @memberOf ITaskInfo | ||
*/ | ||
order?: number; | ||
/** | ||
* name. | ||
* | ||
* @type {Src} | ||
* @memberOf ITaskInfo | ||
*/ | ||
name?: Src; | ||
/** | ||
* is watch task or not. | ||
* | ||
* @type {boolean} | ||
* @memberOf ITaskInfo | ||
*/ | ||
watch?: boolean; | ||
} | ||
export type TaskResult = Src | ITaskResult; | ||
export type Task = (gulp: Gulp, config: TaskConfig) => TaskResult | TaskResult[] | void; | ||
export type TaskResult = Src | void; | ||
export type TaskSource = Src | ((oper?: Operation) => Src); | ||
export type TaskString = string | ((oper?: Operation) => string); | ||
// function not support deforator. | ||
// export type Task = (gulp: Gulp, config: ITaskConfig) => TaskSequence; | ||
/** | ||
* task decorator annations. | ||
* task interface. | ||
* | ||
* @export | ||
* @param {Function} constructor | ||
* @interface ITask | ||
*/ | ||
export function task(constructor: Function) { | ||
Object.seal(constructor); | ||
Object.seal(constructor.prototype); | ||
export interface ITask { | ||
/** | ||
* decorator of task. | ||
* | ||
* @type {ITaskInfo} | ||
* @memberOf ITask | ||
*/ | ||
decorator: ITaskInfo | ||
/** | ||
* setup task. | ||
* | ||
* @param {ITaskConfig} config | ||
* @param {Gulp} [gulp] | ||
* @returns {TaskResult} | ||
* | ||
* @memberOf ITask | ||
*/ | ||
setup(config: ITaskConfig, gulp?: Gulp): TaskResult; | ||
} | ||
/** | ||
@@ -99,5 +125,5 @@ * task loader option. | ||
* @export | ||
* @interface LoaderOption | ||
* @interface ILoaderOption | ||
*/ | ||
export interface LoaderOption { | ||
export interface ILoaderOption { | ||
/** | ||
@@ -107,3 +133,3 @@ * loader type, default module. | ||
* @type {string} | ||
* @memberOf LoaderOption | ||
* @memberOf ILoaderOption | ||
*/ | ||
@@ -115,3 +141,3 @@ type?: string; | ||
* @type {string | Object} | ||
* @memberOf LoaderOption | ||
* @memberOf ILoaderOption | ||
*/ | ||
@@ -124,3 +150,3 @@ module?: string | Object; | ||
* @type {string | Object} | ||
* @memberOf LoaderOption | ||
* @memberOf ILoaderOption | ||
*/ | ||
@@ -133,3 +159,3 @@ configModule?: string | Object; | ||
* @type {string | Object} | ||
* @memberOf LoaderOption | ||
* @memberOf ILoaderOption | ||
*/ | ||
@@ -142,3 +168,3 @@ taskModule?: string | Object; | ||
* @type {ITaskDefine} | ||
* @memberOf LoaderOption | ||
* @memberOf ILoaderOption | ||
*/ | ||
@@ -154,3 +180,3 @@ taskDefine?: ITaskDefine; | ||
* | ||
* @memberOf LoaderOption | ||
* @memberOf ILoaderOption | ||
*/ | ||
@@ -164,3 +190,3 @@ isTaskFunc?(mdl: any): boolean; | ||
* | ||
* @memberOf LoaderOption | ||
* @memberOf ILoaderOption | ||
*/ | ||
@@ -175,12 +201,12 @@ isTaskDefine?(mdl: any): boolean; | ||
* @interface DirLoaderOption | ||
* @extends {LoaderOption} | ||
* @extends {ILoaderOption} | ||
*/ | ||
export interface DirLoaderOption extends LoaderOption { | ||
export interface IDirLoaderOption extends ILoaderOption { | ||
/** | ||
* loader dir | ||
* | ||
* @type {Src} | ||
* @memberOf LoaderOption | ||
* @type {TaskSource} | ||
* @memberOf ILoaderOption | ||
*/ | ||
dir?: Src; | ||
dir?: TaskSource | ||
/** | ||
@@ -219,6 +245,6 @@ * config in directory. | ||
* @export | ||
* @interface Output | ||
* @interface IOutput | ||
* @extends {ITransform} | ||
*/ | ||
export interface Output extends ITransform { | ||
export interface IOutput extends ITransform { | ||
dts?: ITransform; | ||
@@ -228,14 +254,14 @@ js?: ITransform | ||
export type Pipe = (config?: TaskConfig, dt?: DynamicTask, gulp?: Gulp) => ITransform | Promise<ITransform>; | ||
export type Pipe = (config?: ITaskConfig, dt?: IDynamicTask, gulp?: Gulp) => ITransform | Promise<ITransform>; | ||
export type OutputPipe = (map: Output, config?: TaskConfig, dt?: DynamicTask, gulp?: Gulp) => ITransform | Promise<ITransform>; | ||
export type OutputPipe = (map: IOutput, config?: ITaskConfig, dt?: IDynamicTask, gulp?: Gulp) => ITransform | Promise<ITransform>; | ||
export interface OutputDist { | ||
export interface IOutputDist { | ||
/** | ||
* the src file filter string. default 'src'. | ||
* | ||
* @type {string} | ||
* @memberOf OutputDist | ||
* @type {TaskSource} | ||
* @memberOf IOutputDist | ||
*/ | ||
src?: Src; | ||
src?: TaskSource | ||
@@ -245,3 +271,3 @@ /** | ||
*/ | ||
dist?: string; | ||
dist?: TaskString; | ||
/** | ||
@@ -289,13 +315,13 @@ * build output folder. if empty use parent setting, or ues 'dist'. | ||
* @export | ||
* @interface DynamicTask | ||
* @extends {OutputDist} | ||
* @interface IDynamicTask | ||
* @extends {IOutputDist} | ||
*/ | ||
export interface DynamicTask extends OutputDist { | ||
export interface IDynamicTask extends IOutputDist { | ||
/** | ||
* task name | ||
* | ||
* @type {string} | ||
* @memberOf DynamicTask | ||
* @type {TaskName} | ||
* @memberOf IDynamicTask | ||
*/ | ||
name: string; | ||
name: TaskString; | ||
/** | ||
@@ -305,3 +331,3 @@ * task order. | ||
* @type {number} | ||
* @memberOf DynamicTask | ||
* @memberOf IDynamicTask | ||
*/ | ||
@@ -313,3 +339,3 @@ order?: number; | ||
* @type {Operation} | ||
* @memberOf DynamicTask | ||
* @memberOf IDynamicTask | ||
*/ | ||
@@ -322,5 +348,5 @@ oper?: Operation; | ||
* | ||
* @memberOf DynamicTask | ||
* @memberOf IDynamicTask | ||
*/ | ||
watch?: Array<string | WatchCallback> | ((config?: TaskConfig, dt?: DynamicTask) => Array<string | WatchCallback>); | ||
watch?: Array<string | WatchCallback> | ((config?: ITaskConfig, dt?: IDynamicTask) => Array<string | WatchCallback>); | ||
/** | ||
@@ -330,7 +356,7 @@ * watch changed. | ||
* @param {WatchEvent} event | ||
* @param {TaskConfig} config | ||
* @param {ITaskConfig} config | ||
* | ||
* @memberOf DynamicTask | ||
* @memberOf IDynamicTask | ||
*/ | ||
watchChanged?(event: WatchEvent, config: TaskConfig); | ||
watchChanged?(event: WatchEvent, config: ITaskConfig); | ||
/** | ||
@@ -340,8 +366,8 @@ * stream pipe. | ||
* @param {ITransform} gulpsrc | ||
* @param {TaskConfig} config | ||
* @param {ITaskConfig} config | ||
* @returns {(ITransform | Promise<ITransform>)} | ||
* | ||
* @memberOf DynamicTask | ||
* @memberOf IDynamicTask | ||
*/ | ||
pipe?(gulpsrc: ITransform, config: TaskConfig, dt?: DynamicTask): ITransform | Promise<ITransform>; | ||
pipe?(gulpsrc: ITransform, config: ITaskConfig, dt?: IDynamicTask): ITransform | Promise<ITransform>; | ||
@@ -352,5 +378,5 @@ /** | ||
* | ||
* @memberOf DynamicTask | ||
* @memberOf IDynamicTask | ||
*/ | ||
pipes?: Pipe[] | ((config?: TaskConfig, dt?: DynamicTask) => Pipe[]); | ||
pipes?: Pipe[] | ((config?: ITaskConfig, dt?: IDynamicTask) => Pipe[]); | ||
@@ -361,5 +387,5 @@ /** | ||
* | ||
* @memberOf DynamicTask | ||
* @memberOf IDynamicTask | ||
*/ | ||
output?: OutputPipe[] | ((config?: TaskConfig, dt?: DynamicTask) => OutputPipe[]); | ||
output?: OutputPipe[] | ((config?: ITaskConfig, dt?: IDynamicTask) => OutputPipe[]); | ||
@@ -369,10 +395,10 @@ /** | ||
* | ||
* @param {TaskConfig} config | ||
* @param {DynamicTask} [dt] | ||
* @param {ITaskConfig} config | ||
* @param {IDynamicTask} [dt] | ||
* @param {Gulp} [gulp] | ||
* @returns {(void | ITransform | Promise<any>)} | ||
* | ||
* @memberOf DynamicTask | ||
* @memberOf IDynamicTask | ||
*/ | ||
task?(config: TaskConfig, dt?: DynamicTask, gulp?: Gulp): void | ITransform | Promise<any>; | ||
task?(config: ITaskConfig, dt?: IDynamicTask, gulp?: Gulp): void | ITransform | Promise<any>; | ||
@@ -385,13 +411,13 @@ } | ||
* @export | ||
* @interface DynamicLoaderOption | ||
* @extends {LoaderOption} | ||
* @interface IDynamicLoaderOption | ||
* @extends {ILoaderOption} | ||
*/ | ||
export interface DynamicLoaderOption extends LoaderOption { | ||
export interface IDynamicLoaderOption extends ILoaderOption { | ||
/** | ||
* dynamic task | ||
* | ||
* @type {(DynamicTask | DynamicTask[])} | ||
* @memberOf DynamicLoaderOption | ||
* @type {(IDynamicTask | IDynamicTask[])} | ||
* @memberOf IDynamicLoaderOption | ||
*/ | ||
dynamicTasks?: DynamicTask | DynamicTask[]; | ||
dynamicTasks?: IDynamicTask | IDynamicTask[]; | ||
} | ||
@@ -406,22 +432,16 @@ | ||
*/ | ||
export interface TaskLoaderOption { | ||
export interface ITaskLoaderOption { | ||
/** | ||
* task loader | ||
* | ||
* @type {(string | LoaderOption | DynamicTask | DynamicTask[])} | ||
* @memberOf TaskOption | ||
* @type {(string | ILoaderOption | IDynamicTask | IDynamicTask[])} | ||
* @memberOf ITaskOption | ||
*/ | ||
loader: string | LoaderOption | DynamicTask | DynamicTask[]; | ||
loader: string | ILoaderOption | IDynamicTask | IDynamicTask[]; | ||
/** | ||
* external task for | ||
* | ||
* @memberOf TaskConfig | ||
*/ | ||
externalTask?: Task; | ||
/** | ||
* custom set run tasks sequence. | ||
* | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
@@ -433,6 +453,6 @@ runTasks?: Src[] | ((oper: Operation, tasks: Src[], subGroupTask?: TaskResult, assertsTask?: TaskResult) => Src[]); | ||
* | ||
* @type {(TaskOption | TaskOption[])} | ||
* @memberOf TaskOption | ||
* @type {(ITaskOption | ITaskOption[])} | ||
* @memberOf ITaskOption | ||
*/ | ||
tasks?: TaskOption | TaskOption[]; | ||
tasks?: ITaskOption | ITaskOption[]; | ||
@@ -450,29 +470,30 @@ /** | ||
/** | ||
* asserts to be dealt with. | ||
* IAsserts to be dealt with. | ||
* | ||
* @export | ||
* @interface Asserts | ||
* @interface IAsserts | ||
* @extends {IOutputDist} | ||
*/ | ||
export interface Asserts extends OutputDist, TaskLoaderOption { | ||
export interface IAsserts extends IOutputDist { | ||
/** | ||
* asserts extends name. for register dynamic task. | ||
* IAsserts extends name. for register dynamic task. | ||
* | ||
* @type {string} | ||
* @memberOf Asserts | ||
* @type {TaskName} | ||
* @memberOf IAsserts | ||
*/ | ||
name?: string; | ||
name?: TaskString; | ||
/** | ||
* tasks to deal with asserts. | ||
* tasks to deal with IAsserts. | ||
* | ||
* @type {IMap<Src | Asserts, DynamicTask[]>} | ||
* @memberOf Asserts | ||
* @type {IMap<Src | IAsserts, IDynamicTask[]>} | ||
* @memberOf IAsserts | ||
*/ | ||
asserts?: IMap<Src | Asserts | DynamicTask[]>; | ||
IAsserts?: IMap<Src | IAsserts | IDynamicTask[]>; | ||
/** | ||
* set asserts task order in this task sequence. | ||
* set IAsserts task order in this task sequence. | ||
* | ||
* @type {number} | ||
* @memberOf Asserts | ||
* @memberOf IAsserts | ||
*/ | ||
@@ -487,12 +508,14 @@ assertsOrder?: number; | ||
* @export | ||
* @interface TaskOption | ||
* @interface ITaskOption | ||
* @extends {IAsserts} | ||
* @extends {ITaskLoaderOption} | ||
*/ | ||
export interface TaskOption extends Asserts { | ||
export interface ITaskOption extends IAsserts, ITaskLoaderOption { | ||
/** | ||
* the src file filter string. default 'src'. | ||
* | ||
* @type {string} | ||
* @memberOf TaskOption | ||
* @type {TaskSource} | ||
* @memberOf ITaskOption | ||
*/ | ||
src: Src; | ||
src: TaskSource; | ||
} | ||
@@ -511,8 +534,8 @@ | ||
* @param {Operation} oper | ||
* @param {TaskOption} option | ||
* @returns {TaskConfig} | ||
* @param {ITaskOption} option | ||
* @returns {ITaskConfig} | ||
* | ||
* @memberOf ITaskDefine | ||
*/ | ||
moduleTaskConfig(oper: Operation, option: TaskOption, env: EnvOption): TaskConfig | ||
loadConfig(oper: Operation, option: ITaskOption, env: IEnvOption): ITaskConfig | ||
@@ -522,3 +545,3 @@ /** | ||
* | ||
* @param {TaskConfig} config | ||
* @param {ITaskConfig} config | ||
* @param {tasksInModule} findInModule | ||
@@ -530,3 +553,3 @@ * @param {tasksInDir} findInDir | ||
*/ | ||
moduleTaskLoader?(config: TaskConfig): Promise<Task[]>; | ||
loadTasks?(config: ITaskConfig): Promise<ITask[]>; | ||
} | ||
@@ -538,5 +561,5 @@ | ||
* @export | ||
* @interface TaskConfig | ||
* @interface ITaskConfig | ||
*/ | ||
export interface TaskConfig { | ||
export interface ITaskConfig { | ||
/** | ||
@@ -550,5 +573,5 @@ * custom global data cache. | ||
* @type {EnvOption} | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
env: EnvOption; | ||
env: IEnvOption; | ||
/** | ||
@@ -558,3 +581,3 @@ * run operation | ||
* @type {Operation} | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
@@ -565,8 +588,28 @@ oper: Operation; | ||
* | ||
* @type {TaskOption} | ||
* @memberOf TaskConfig | ||
* @type {IAsserts} | ||
* @memberOf ITaskConfig | ||
*/ | ||
option: TaskOption; | ||
option: IAsserts | ITaskOption; | ||
/** | ||
* get Src of current state. default implement in bindingConfig. | ||
* | ||
* @param {IAsserts} [assert] | ||
* @returns {Src} | ||
* | ||
* @memberOf ITaskConfig | ||
*/ | ||
getSrc?(assert?: IAsserts): Src; | ||
/** | ||
* get dist of current state. default implement in bindingConfig. | ||
* | ||
* @param {IOutputDist} dist | ||
* @returns {string} | ||
* | ||
* @memberOf ITaskConfig | ||
*/ | ||
getDist?(dist?: IOutputDist): string; | ||
/** | ||
* custom config run tasks sequence in. | ||
@@ -579,3 +622,3 @@ * | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
@@ -588,3 +631,3 @@ runTasks?(subGroupTask?: TaskResult, tasks?: Src[], assertTasks?: TaskResult): Src[]; | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
@@ -597,7 +640,7 @@ printHelp?(lang: string): void; | ||
* @param {string} module | ||
* @returns {Promise<Task[]>} | ||
* @returns {Promise<ITask[]>} | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
findTasksInModule?(module: string): Promise<Task[]>; | ||
findTasksInModule?(module: string): Promise<ITask[]>; | ||
/** | ||
@@ -607,18 +650,9 @@ * find task in directories. default implement by loader. | ||
* @param {Src} dirs | ||
* @returns {Promise<Task[]>} | ||
* @returns {Promise<ITask[]>} | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
findTasksInDir?(dirs: Src): Promise<Task[]>; | ||
findTasksInDir?(dirs: Src): Promise<ITask[]>; | ||
/** | ||
* get dist of current state. default implement in bindingConfig. | ||
* | ||
* @param {OutputDist} dist | ||
* @returns {string} | ||
* | ||
* @memberOf TaskConfig | ||
*/ | ||
getDist?(dist?: OutputDist): string; | ||
/** | ||
* filter file in directory. default implement in bindingConfig. | ||
@@ -630,3 +664,3 @@ * | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
@@ -641,3 +675,3 @@ fileFilter?(directory: string, express?: ((fileName: string) => boolean)): string[]; | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
@@ -649,8 +683,8 @@ runSequence?(gulp: Gulp, tasks: Src[]): Promise<any>; | ||
* | ||
* @param {(DynamicTask | DynamicTask[])} tasks | ||
* @param {(IDynamicTask | IDynamicTask[])} tasks | ||
* @returns {Task[]} | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
generateTask?(tasks: DynamicTask | DynamicTask[]): Task[]; | ||
generateTask?(tasks: IDynamicTask | IDynamicTask[]): ITask[]; | ||
@@ -661,17 +695,17 @@ /** | ||
* @param {Src[]} sequence task sequence. | ||
* @param {TaskResult} taskResult | ||
* @param {ITaskInfo} task | ||
* @returns {Src[]} | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
addTask?(sequence: Src[], taskResult: TaskResult): Src[]; | ||
addToSequence?(sequence: Src[], task: ITaskInfo): Src[]; | ||
/** | ||
* generate sub task name | ||
* | ||
* @param {string} name | ||
* @param {IAsserts | string} assert | ||
* @param {string} [defaultName] | ||
* | ||
* @memberOf TaskConfig | ||
* @memberOf ITaskConfig | ||
*/ | ||
subTaskName?(name: string, defaultName?: string); | ||
subTaskName?(assert: string | IAsserts, defaultName?: string); | ||
} | ||
@@ -683,5 +717,5 @@ | ||
* @export | ||
* @interface EnvOption | ||
* @interface IEnvOption | ||
*/ | ||
export interface EnvOption { | ||
export interface IEnvOption { | ||
/** | ||
@@ -691,3 +725,3 @@ * project root. | ||
* @type {string} | ||
* @memberOf EnvOption | ||
* @memberOf IEnvOption | ||
*/ | ||
@@ -699,3 +733,3 @@ root?: string; | ||
* @type {(boolean | string)} | ||
* @memberOf EnvOption | ||
* @memberOf IEnvOption | ||
*/ | ||
@@ -718,3 +752,3 @@ help?: boolean | string; | ||
* @type {string} | ||
* @memberOf EnvOption | ||
* @memberOf IEnvOption | ||
*/ | ||
@@ -735,386 +769,5 @@ config?: string; | ||
* @type {Src} | ||
* @memberOf EnvOption | ||
* @memberOf IEnvOption | ||
*/ | ||
grp?: Src; | ||
} | ||
/** | ||
* binding Config to implement default func. | ||
* | ||
* @export | ||
* @param {TaskConfig} cfg | ||
* @returns {TaskConfig} | ||
*/ | ||
export function bindingConfig(cfg: TaskConfig): TaskConfig { | ||
cfg.fileFilter = cfg.fileFilter || files; | ||
cfg.runSequence = cfg.runSequence || runSequence; | ||
cfg.addTask = cfg.addTask || addTask; | ||
cfg.generateTask = cfg.generateTask || ((tasks: DynamicTask | DynamicTask[]) => { | ||
return generateTask(tasks, cfg.oper, cfg.env); | ||
}); | ||
cfg.subTaskName = cfg.subTaskName || ((name, deft = '') => { | ||
return cfg.option.name ? `${cfg.option.name}-${name || deft}` : name; | ||
}); | ||
cfg.getDist = cfg.getDist || ((ds?: OutputDist) => { | ||
if (ds) { | ||
let dist = getCurrentDist(ds, cfg.oper); | ||
if (dist) { | ||
return dist; | ||
} | ||
} | ||
return getCurrentDist(cfg.option, cfg.oper); | ||
}); | ||
return cfg; | ||
} | ||
/** | ||
* get current env Operation. | ||
* | ||
* @export | ||
* @param {EnvOption} env | ||
* @returns | ||
*/ | ||
export function currentOperation(env: EnvOption) { | ||
let oper: Operation; | ||
if (env.deploy) { | ||
oper = Operation.deploy; | ||
} else if (env.release) { | ||
oper = Operation.release; | ||
} else if (env.e2e) { | ||
oper = Operation.e2e; | ||
} else if (env.test) { | ||
oper = Operation.test; | ||
} else { | ||
oper = Operation.build; | ||
} | ||
return oper; | ||
} | ||
/** | ||
* convert setup task result to run sequence src. | ||
* | ||
* @export | ||
* @param {(Array<TaskResult | TaskResult[] | void>)} tasks | ||
* @param {Operation} oper | ||
* @returns {Src[]} | ||
*/ | ||
export function toSequence(tasks: Array<TaskResult | TaskResult[] | void>, oper: Operation): Src[] { | ||
let seq: Src[] = []; | ||
tasks = _.filter(tasks, it => it); | ||
let len = tasks.length; | ||
tasks = _.orderBy(tasks, t => { | ||
if (t) { | ||
if (_.isString(t)) { | ||
return len; | ||
} else if (_.isArray(t)) { | ||
return len; | ||
} else { | ||
return (<ITaskResult>t).order | ||
} | ||
} | ||
return len; | ||
}); | ||
_.each(tasks, t => { | ||
if (!t) { | ||
return; | ||
} | ||
if (_.isString(t)) { | ||
seq.push(t); | ||
} else if (_.isArray(t)) { | ||
seq.push(_.flatten(toSequence(t, oper))); | ||
} else { | ||
if (t.name) { | ||
if (t.oper) { | ||
if ((t.oper & oper) > 0) { | ||
seq.push(t.name); | ||
} | ||
} else { | ||
seq.push(t.name); | ||
} | ||
} | ||
} | ||
}); | ||
return seq; | ||
} | ||
/** | ||
* run task sequence. | ||
* | ||
* @protected | ||
* @param {Gulp} gulp | ||
* @param {Src[]} tasks | ||
* @returns {Promise<any>} | ||
* | ||
* @memberOf Development | ||
*/ | ||
export function runSequence(gulp: Gulp, tasks: Src[]): Promise<any> { | ||
let ps = Promise.resolve(); | ||
if (tasks && tasks.length > 0) { | ||
_.each(tasks, task => { | ||
ps = ps.then(() => { | ||
let taskErr = null, taskStop = null; | ||
return new Promise((reslove, reject) => { | ||
let tskmap: any = {}; | ||
_.each(_.isArray(task) ? task : [task], t => { | ||
tskmap[t] = false; | ||
}); | ||
taskErr = (err) => { | ||
reject(err); | ||
}; | ||
taskStop = (e: any) => { | ||
tskmap[e.task] = true; | ||
if (!_.some(_.values(tskmap), it => !it)) { | ||
reslove(); | ||
} | ||
} | ||
gulp.on('task_stop', taskStop) | ||
.on('task_err', taskErr); | ||
gulp.start(task); | ||
}) | ||
.then(() => { | ||
if (gulp['removeListener']) { | ||
gulp['removeListener']('task_stop', taskStop); | ||
gulp['removeListener']('task_err', taskErr); | ||
} | ||
}, err => { | ||
if (gulp['removeListener']) { | ||
gulp['removeListener']('task_stop', taskStop); | ||
gulp['removeListener']('task_err', taskErr); | ||
} | ||
console.error(err); | ||
}); | ||
}); | ||
}); | ||
} | ||
return ps; | ||
} | ||
/** | ||
* filter fileName in directory. | ||
* | ||
* @export | ||
* @param {string} directory | ||
* @param {((fileName: string) => boolean)} [express] | ||
* @returns {string[]} | ||
*/ | ||
export function files(directory: string, express?: ((fileName: string) => boolean)): string[] { | ||
let res: string[] = []; | ||
express = express || ((fn) => true); | ||
_.each(readdirSync(directory), fname => { | ||
let filePn = directory + '/' + fname; | ||
var fst = lstatSync(filePn); | ||
if (!fst.isDirectory()) { | ||
if (express(filePn)) { | ||
res.push(filePn) | ||
} | ||
} else { | ||
res = res.concat(files(filePn, express)) | ||
} | ||
}); | ||
return res; | ||
} | ||
/** | ||
* dynamic build tasks. | ||
* | ||
* @export | ||
* @param {(DynamicTask | DynamicTask[])} tasks | ||
* @param {Operation} oper | ||
* @returns {Task[]} | ||
*/ | ||
export function generateTask(tasks: DynamicTask | DynamicTask[], oper: Operation, env: EnvOption): Task[] { | ||
let taskseq: Task[] = []; | ||
_.each(_.isArray(tasks) ? tasks : [tasks], dt => { | ||
if (dt.oper && (dt.oper & oper) <= 0) { | ||
return; | ||
} | ||
if (dt.watch) { | ||
if (!env.watch) { | ||
return; | ||
} | ||
console.log('register watch dynamic task:', chalk.cyan(dt.name)); | ||
taskseq.push(createWatchTask(dt)); | ||
} else if (_.isFunction(dt.task)) { // custom task | ||
console.log('register custom dynamic task:', chalk.cyan(dt.name)); | ||
taskseq.push(createTask(dt)); | ||
} else { | ||
console.log('register pipes dynamic task:', chalk.cyan(dt.name)); | ||
// pipe stream task. | ||
taskseq.push(createPipesTask(dt)); | ||
} | ||
}); | ||
return taskseq; | ||
} | ||
/** | ||
* get dist. | ||
* | ||
* @param {OutputDist} ds | ||
* @param {Operation} oper | ||
* @returns | ||
*/ | ||
function getCurrentDist(ds: OutputDist, oper: Operation) { | ||
let dist: string; | ||
switch (oper) { | ||
case Operation.build: | ||
dist = ds.build || ds.dist; | ||
break; | ||
case Operation.test: | ||
dist = ds.test || ds.build || ds.dist; | ||
break; | ||
case Operation.e2e: | ||
dist = ds.e2e || ds.build || ds.dist; | ||
break; | ||
case Operation.release: | ||
dist = ds.release || ds.dist; | ||
break; | ||
case Operation.deploy: | ||
dist = ds.deploy || ds.dist; | ||
break; | ||
default: | ||
dist = ''; | ||
break; | ||
} | ||
return dist; | ||
} | ||
function addTask(taskSequence: Src[], rst: TaskResult) { | ||
if (!rst) { | ||
return taskSequence; | ||
} | ||
if (_.isString(rst) || _.isArray(rst)) { | ||
taskSequence.push(rst); | ||
} else if (rst.name) { | ||
if (_.isNumber(rst.order) && rst.order >= 0 && rst.order < taskSequence.length) { | ||
taskSequence.splice(rst.order, 0, rst.name); | ||
return taskSequence; | ||
} | ||
taskSequence.push(rst.name); | ||
} | ||
return taskSequence; | ||
} | ||
/** | ||
* promise task. | ||
* | ||
* @param {DynamicTask} dt | ||
* @returns | ||
*/ | ||
function createTask(dt: DynamicTask) { | ||
return (gulp: Gulp, cfg: TaskConfig): TaskResult => { | ||
let tk = cfg.subTaskName(dt.name); | ||
gulp.task(tk, () => { | ||
return dt.task(cfg, dt, gulp); | ||
}); | ||
if (_.isNumber(dt.order)) { | ||
return <ITaskResult>{ | ||
name: tk, | ||
order: dt.order | ||
}; | ||
} | ||
return tk | ||
}; | ||
} | ||
/** | ||
* create dynamic watch task. | ||
* | ||
* @param {DynamicTask} dt | ||
* @returns | ||
*/ | ||
function createWatchTask(dt: DynamicTask) { | ||
return (gulp: Gulp, cfg: TaskConfig): TaskResult => { | ||
let watchs = _.isFunction(dt.watch) ? dt.watch(cfg) : dt.watch; | ||
if (!_.isFunction(_.last(watchs))) { | ||
watchs.push(<WatchCallback>(event: WatchEvent) => { | ||
dt.watchChanged && dt.watchChanged(event, cfg); | ||
}); | ||
} | ||
watchs = _.map(watchs, w => { | ||
if (_.isString(w)) { | ||
return cfg.subTaskName(w); | ||
} | ||
return w; | ||
}) | ||
let tk = cfg.subTaskName(dt.name); | ||
gulp.task(tk, () => { | ||
console.log('watch, src:', chalk.cyan.call(chalk, cfg.option.src)); | ||
gulp.watch(cfg.option.src, watchs) | ||
}); | ||
if (_.isNumber(dt.order)) { | ||
return <ITaskResult>{ | ||
name: tk, | ||
order: dt.order | ||
}; | ||
} | ||
return tk; | ||
}; | ||
} | ||
function createPipesTask(dt: DynamicTask) { | ||
return (gulp: Gulp, cfg: TaskConfig): TaskResult => { | ||
let tk = cfg.subTaskName(dt.name); | ||
gulp.task(tk, () => { | ||
let src = Promise.resolve(gulp.src(dt.src || cfg.option.src)); | ||
if (dt.pipes) { | ||
let pipes = _.isFunction(dt.pipes) ? dt.pipes(cfg, dt) : dt.pipes; | ||
_.each(pipes, (p: Pipe) => { | ||
src = src.then(psrc => { | ||
return Promise.resolve((_.isFunction(p) ? p(cfg, dt, gulp) : p)) | ||
.then(stram => { | ||
return psrc.pipe(stram) | ||
}); | ||
}); | ||
}) | ||
} else if (dt.pipe) { | ||
src = src.then((stream => { | ||
return dt.pipe(stream, cfg, dt); | ||
})); | ||
} | ||
src.then(stream => { | ||
if (dt.output) { | ||
let outputs = _.isFunction(dt.output) ? dt.output(cfg, dt) : dt.output; | ||
return Promise.all(_.map(outputs, output => { | ||
return new Promise((resolve, reject) => { | ||
Promise.resolve<NodeJS.ReadWriteStream>((_.isFunction(output) ? output(stream, cfg, dt, gulp) : output)) | ||
.then(output => { | ||
stream.pipe(output) | ||
.once('end', resolve) | ||
.once('error', reject); | ||
}); | ||
}); | ||
})); | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
stream.pipe(gulp.dest(cfg.getDist(dt))) | ||
.once('end', resolve) | ||
.once('error', reject); | ||
}); | ||
} | ||
}); | ||
return src.catch(err => { | ||
console.log(chalk.red(err)); | ||
}); | ||
}); | ||
if (_.isNumber(dt.order)) { | ||
return <ITaskResult>{ | ||
name: tk, | ||
order: dt.order | ||
}; | ||
} | ||
return tk; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
130749
39
1880
179
9
6
1
+ Addedreflect-metadata@^0.1.8
+ Addedreflect-metadata@0.1.14(transitive)