@tsdi/pack
@tsdi/pack is simple build tasks, base on AOP, Ioc container, via @tsdi. dev build pack activities.
Last updated 5 days ago by houjun .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @tsdi/pack 
SYNC missed versions from official npm registry.

packaged @tsdi/pack

@tsdi/pack is project build pack tools, 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.

Install

  1. install modules:
npm install @tsdi/pack
  1. install cli | build pack:

cli in global

npm install -g '@tsdi/cli'

build pack

npm install '@tsdi/pack'

use command: tsdi run [taskfile.ts], tsdi run [taskfile.js] use command: tsdi build [options]

You can import modules:

Doc

Define Task

  • define task component or attr task item.

@Task('clean, [clean]')
export class CleanActivity extends Activity<void> {

    @Input() clean: Expression<Src>;

    async execute(ctx: NodeActivityContext): Promise<void> {
        let clean = await this.resolveExpression(this.clean, ctx);
        if (clean) {
            await ctx.del(ctx.toRootSrc(clean), {force: true});
        }
    }
}


  • control flow activities.

see control flow codes

Define component pipe

@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;
    }
}

Define component Task


/**
 * ts build option.
 *
 * @export
 * @interface TsBuildOption
 * @extends {AssetActivityOption}
 */
export interface TsBuildOption extends AssetActivityOption {
    test?: Binding<NodeExpression<Src>>;
    annotation?: Binding<NodeExpression<boolean>>;
    tsconfig?: Binding<NodeExpression<string | CompilerOptions>>;
    dts?: Binding<NodeExpression<string>>;
    uglify?: Binding<NodeExpression<boolean>>;
    uglifyOptions?: Binding<NodeExpression>;
}

@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<TsBuildActivity>();
                    let framework = scope.framework || sourcemaps;
                    return ctx.injector.get(TransformService).executePipe(ctx, ctx.getData(), framework.init())
                }
            }
        },
        {
            activity: Activities.if,
            condition: (ctx, bind) => bind.getScope<TsBuildActivity>().beforePipes?.length > 0,
            body: {
                activity: 'pipes',
                pipes: 'binding: beforePipes'
            }
        },
        {
            activity: Activities.execute,
            name: 'tscompile',
            action: async (ctx: NodeActivityContext, bind) => {
                let scope = bind.getScope<TsBuildActivity>();
                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<TsBuildActivity>().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<TsBuildActivity>();
                            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<ITransform>;
    @Input('beforePipes') beforePipes: ActivityType<ITransform>[];
    @Input('tsconfig', './tsconfig.json') tsconfig: string | ObjectMap;
    @Input() uglify: NodeExpression<boolean>;
    @Input('uglifyOptions') uglifyOptions: any;
}

Run task

  • use coustom task component.
@Task({
    deps: [
        PackModule,
        ServerActivitiesModule,
        TsBuildActivity
    ],
    baseURL: __dirname,
    template: <TsBuildOption>{
        activity: 'ts',
        annotation: true,
        dist: 'dist',
        dts: 'dist',
        sourcemap: true
    }
})
export class PackBuilder implements AfterInit {

    onAfterInit(): void | Promise<void> {
        console.log('activities build has inited...')
    }
}


  • run task.
// 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
        // }
    ]

});

Documentation

Documentation is available on the

packages

@tsdi/cli @tsdi/ioc @tsdi/aop @tsdi/core @tsdi/boot @tsdi/components @tsdi/compiler @tsdi/activities @tsdi/pack @tsdi/typeorm-adapter @tsdi/unit @tsdi/unit-console

License

MIT © Houjun

Current Tags

  • 6.0.12                                ...           latest (5 days ago)

107 Versions

  • 6.0.12                                ...           5 days ago
  • 6.0.11                                ...           6 days ago
  • 6.0.10                                ...           7 days ago
  • 6.0.9                                ...           9 days ago
  • 6.0.8                                ...           10 days ago
  • 6.0.7                                ...           12 days ago
  • 6.0.6                                ...           a month ago
  • 6.0.4                                ...           a month ago
  • 6.0.3                                ...           a month ago
  • 6.0.2                                ...           a month ago
  • 6.0.1                                ...           a month ago
  • 6.0.0                                ...           a month ago
  • 6.0.0-beta12                                ...           a month ago
  • 6.0.0-beta11                                ...           a month ago
  • 6.0.0-beta9                                ...           a month ago
  • 6.0.0-beta8                                ...           2 months ago
  • 6.0.0-beta7                                ...           2 months ago
  • 6.0.0-beta6                                ...           3 months ago
  • 6.0.0-beta5                                ...           3 months ago
  • 6.0.0-beta4                                ...           3 months ago
  • 6.0.0-beta3                                ...           3 months ago
  • 6.0.0-beta2                                ...           3 months ago
  • 6.0.0-beta1                                ...           3 months ago
  • 5.3.13                                ...           5 months ago
  • 5.3.12                                ...           6 months ago
  • 5.3.10                                ...           6 months ago
  • 5.3.9                                ...           6 months ago
  • 5.3.8                                ...           6 months ago
  • 5.3.7                                ...           6 months ago
  • 5.3.6                                ...           7 months ago
  • 5.3.5                                ...           7 months ago
  • 5.3.2                                ...           7 months ago
  • 5.3.1                                ...           7 months ago
  • 5.3.0                                ...           7 months ago
  • 5.3.0-beta4                                ...           7 months ago
  • 5.2.16                                ...           7 months ago
  • 5.2.15                                ...           8 months ago
  • 5.2.14                                ...           8 months ago
  • 5.2.13                                ...           8 months ago
  • 5.2.12                                ...           8 months ago
  • 5.2.7                                ...           8 months ago
  • 5.2.6                                ...           8 months ago
  • 5.2.5                                ...           9 months ago
  • 5.2.4                                ...           9 months ago
  • 5.2.3                                ...           9 months ago
  • 5.2.2                                ...           9 months ago
  • 5.2.1                                ...           9 months ago
  • 5.1.19                                ...           9 months ago
  • 5.1.18                                ...           9 months ago
  • 5.1.17                                ...           10 months ago
  • 5.1.16                                ...           10 months ago
  • 5.1.15                                ...           10 months ago
  • 5.1.14                                ...           10 months ago
  • 5.1.13                                ...           10 months ago
  • 5.1.12                                ...           10 months ago
  • 5.1.11                                ...           10 months ago
  • 5.1.10                                ...           10 months ago
  • 5.1.8                                ...           10 months ago
  • 5.1.7                                ...           10 months ago
  • 5.1.6                                ...           10 months ago
  • 5.1.3                                ...           10 months ago
  • 5.1.1                                ...           10 months ago
  • 5.1.0                                ...           10 months ago
  • 5.0.24                                ...           a year ago
  • 5.0.23                                ...           a year ago
  • 5.0.22                                ...           a year ago
  • 5.0.21                                ...           a year ago
  • 5.0.20                                ...           a year ago
  • 5.0.19                                ...           a year ago
  • 5.0.18                                ...           a year ago
  • 5.0.18-beta                                ...           a year ago
  • 5.0.15                                ...           a year ago
  • 5.0.13                                ...           a year ago
  • 5.0.12                                ...           a year ago
  • 5.0.11                                ...           a year ago
  • 5.0.10                                ...           a year ago
  • 5.0.8                                ...           a year ago
  • 5.0.7                                ...           a year ago
  • 5.0.5                                ...           a year ago
  • 5.0.4                                ...           a year ago
  • 5.0.3                                ...           a year ago
  • 5.0.2                                ...           a year ago
  • 5.0.1                                ...           a year ago
  • 5.0.0-beta25                                ...           a year ago
  • 5.0.0-beta24                                ...           a year ago
  • 5.0.0-beta23                                ...           a year ago
  • 5.0.0-beta22                                ...           a year ago
  • 5.0.0-beta20                                ...           a year ago
  • 5.0.0-beta19                                ...           a year ago
  • 5.0.0-beta18                                ...           a year ago
  • 5.0.0-beta17                                ...           a year ago
  • 5.0.0-beta16                                ...           a year ago
  • 5.0.0-beta15                                ...           a year ago
  • 5.0.0-beta14                                ...           a year ago
  • 5.0.0-beta12                                ...           a year ago
  • 5.0.0-beta11                                ...           a year ago
  • 5.0.0-beta10                                ...           a year ago
  • 5.0.0-beta9                                ...           a year ago
  • 5.0.0-beta8                                ...           a year ago
  • 5.0.0-beta7                                ...           a year ago
  • 5.0.0-beta6                                ...           a year ago
  • 5.0.0-beta5                                ...           a year ago
  • 5.0.0-beta4                                ...           a year ago
  • 5.0.0-beta3                                ...           a year ago
  • 5.0.0-beta2                                ...           a year ago
  • 5.0.0-beta1                                ...           a year ago
  • 5.0.0-beta                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 109
Last Day 0
Last Week 46
Last Month 171
Dependencies (26)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |