Type workflow frameworks, base on AOP, Ioc container, via @tsdi
npm install @tsdi/activities@tsdi/activities is an simple workflow frameworks in browser and nodejs, base on AOP, Ioc container, via @tsdi. file stream pipes activities.This repo is for distribution on npm. The source for this module is in the
main repo.
Please file issues and pull requests against that repo.
1. install modules:
``shell`
npm install @tsdi/activities
2. install cli | build activities:
shell
npm install -g '@tsdi/cli'
`
$3
`
npm install '@tsdi/activities'
`use command:
tsdi run [taskfile.ts], tsdi run [taskfile.js]
use command: tsdi build [options]You can
import modules:
Doc
$3
* define task component or attr task item.
`ts@Task('clean, [clean]')
export class CleanActivity extends Activity {
@Input() clean: Expression;
async execute(ctx: NodeActivityContext): Promise {
let clean = await this.resolveExpression(this.clean, ctx);
if (clean) {
await ctx.del(ctx.toRootSrc(clean), {force: true});
}
}
}
`* control flow activities.
$3
` ts
@Pipe('tsjs')
export class TypeScriptJsPipe implements IPipeTransform {
transform(value: any): any {
return value.js ?? value;
}
}@Pipe('dts')
export class TypeScriptDtsPipe implements IPipeTransform {
transform(value: any): any {
return value.dts;
}
}
@Pipe('path')
export class PathPipe implements IPipeTransform {
transform(value: any, defaults: string): any {
if (isString(value)) {
return value;
}
return value ? defaults : null;
}
}
`
$3
`ts/**
* ts build option.
*
* @export
* @interface TsBuildOption
* @extends {AssetActivityOption}
*/
export interface TsBuildOption extends AssetActivityOption {
test?: Binding>;
annotation?: Binding>;
tsconfig?: Binding>;
dts?: Binding>;
uglify?: Binding>;
uglifyOptions?: Binding;
}
@Task({
selector: 'ts',
template: [
{
activity: 'src',
src: 'binding: src',
},
{
activity: 'annotation',
annotationFramework: 'binding: annotationFramework',
annotation: 'binding: annotation'
},
{
activity: Activities.if,
condition: 'binding: sourcemap',
body: {
name: 'sourcemap-init',
activity: Activities.execute,
action: (ctx: NodeActivityContext, bind) => {
let scope = bind.getScope();
let framework = scope.framework || sourcemaps;
return ctx.injector.get(TransformService).executePipe(ctx, ctx.getData(), framework.init())
}
}
},
{
activity: Activities.if,
condition: (ctx, bind) => bind.getScope().beforePipes?.length > 0,
body: {
activity: 'pipes',
pipes: 'binding: beforePipes'
}
},
{
activity: Activities.execute,
name: 'tscompile',
action: async (ctx: NodeActivityContext, bind) => {
let scope = bind.getScope();
if (!scope.tsconfig) {
return;
}
let tsconfig = await ctx.resolveExpression(scope.tsconfig);
let tsCompile;
let dts = await ctx.resolveExpression(scope.dts);
if (isString(tsconfig)) {
let tsProject = ts.createProject(ctx.platform.relativeRoot(tsconfig), { declaration: !!dts });
tsCompile = tsProject();
} else {
tsconfig.declaration = !!dts;
let tsProject = ts.createProject(ctx.platform.relativeRoot('./tsconfig.json'), tsconfig);
tsCompile = tsProject();
}
return await ctx.injector.get(TransformService).executePipe(ctx, ctx.getData(), tsCompile);
}
},
{
activity: Activities.if,
// externals: async (ctx) => {
// let tds = await ctx.resolveExpression(ctx.getScope().dts);
// return tds ? {
// data: 'ctx.getData() | tsjs'
// } : null;
// },
externals: {
data: 'ctx.getData() | tsjs'
},
condition: ctx => isTransform(ctx.getData()),
body: [
{
activity: 'pipes',
pipes: 'binding: pipes'
},
{
activity: 'if',
condition: 'binding: uglify',
body: {
activity: 'uglify',
uglifyOptions: 'binding: uglifyOptions'
}
},
{
activity: Activities.if,
condition: 'binding: sourcemap',
body: {
name: 'sourcemap-write',
activity: Activities.execute,
action: async (ctx: NodeActivityContext, bind) => {
let scope = bind.getScope();
let framework = scope.framework || sourcemaps;
return await ctx.injector.get(TransformService).executePipe(ctx, ctx.getData(), framework.write(isString(scope.sourcemap) ? scope.sourcemap : './sourcemaps'));
}
}
},
{
name: 'write-js',
activity: 'dist',
dist: 'binding: dist'
}
]
},
{
activity: Activities.if,
externals: {
data: 'ctx.getData() | dts'
},
condition: 'binding: dts',
body: {
name: 'write-dts',
activity: 'dist',
dist: 'binding: dts | path:dist',
}
}
]
})
export class TsBuildActivity {
@Input() dist: string;
@Input() dts: string | bool;
@Input() annotation: boolean;
@Input('annotationFramework') annotationFramework: NodeExpression;
@Input('beforePipes') beforePipes: ActivityType[];
@Input('tsconfig', './tsconfig.json') tsconfig: string | ObjectMap;
@Input() uglify: NodeExpression;
@Input('uglifyOptions') uglifyOptions: any;
}
`
$3
* use coustom task component.
`ts
@Task({
deps: [
PackModule,
ServerActivitiesModule,
TsBuildActivity
],
baseURL: __dirname,
template: {
activity: 'ts',
annotation: true,
dist: 'dist',
dts: 'dist', // or true
sourcemap: true
}
})
export class PackBuilder implements AfterInit { onAfterInit(): void | Promise {
console.log('activities build has inited...')
}
}
`* run task.
`ts
// 1. run modue
Workflow.run(PackBuilder);
// 2. run option
Workflow.run({
name: 'test1',
template: [
{
name: 'test------1',
activity: SimpleTask
},
SimpleCTask
// {
// name: 'test------2',
// activity: SimpleCTask
// }
]
});
``MIT © Houjun