# type-task

> type-task is task manager via AOP, IOC.

Latest version **0.5.5** (published 2018-06-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install type-task
pnpm add type-task
yarn add type-task
bun add type-task
```

Provides the command `type-task`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.5 |
| Published | 2018-06-05 |
| First published | 2018-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 210.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 1 |
| Author | houjun |
| Maintainers | houjun |
| Keywords | task, task manager, pipe, ioc, aop, shell, develop, tool |

## Links

- npm: https://www.npmjs.com/package/type-task
- Repository: https://github.com/zhouhoujun/type-task
- Homepage: https://github.com/zhouhoujun/type-task#readme
- Issues: https://github.com/zhouhoujun/type-task/issues
- npm.io page: https://npm.io/package/type-task

## Dependencies (11)

- [rxjs](https://npm.io/package/rxjs.md) ^5.5.7
- [chalk](https://npm.io/package/chalk.md) ^2.3.1
- [liftoff](https://npm.io/package/liftoff.md) ^2.5.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [vinyl-fs](https://npm.io/package/vinyl-fs.md) ^3.0.2
- [interpret](https://npm.io/package/interpret.md) ^1.1.0
- [time-stamp](https://npm.io/package/time-stamp.md) ^2.0.0
- [@types/chalk](https://npm.io/package/@types/chalk.md) ^2.2.0
- [pretty-hrtime](https://npm.io/package/pretty-hrtime.md) ^1.0.3
- [@types/vinyl-fs](https://npm.io/package/@types/vinyl-fs.md) ^2.4.8
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.8

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.5.5 (latest) — 2018-06-05
- 0.5.3 — 2018-05-23
- 0.5.2 — 2018-05-22
- 0.5.1 — 2018-05-22
- 0.5.0 — 2018-05-21
- 0.4.0 — 2018-05-16
- 0.3.1 — 2018-04-12
- 0.3.0 — 2018-04-11
- 0.2.5 — 2018-04-05
- 0.2.4 — 2018-03-28
- 0.2.3 — 2018-03-27
- 0.2.2 — 2018-03-15
- 0.2.1 — 2018-03-15
- 0.1.6 — 2018-03-14
- 0.1.5 — 2018-03-13
- … 8 more at https://npm.io/package/type-task/versions

## README

# packaged type-task

This repo is for distribution on `npm`. The source for this module is in the
[main repo](https://github.com/zhouhoujun/type-task).
Please file issues and pull requests against that repo.

`type-task` is task manager via AOP, IOC.

## Install

1. install modules:

```shell
npm install -g type-task
```

2. install cil:

```shell
npm install type-task
```

use command: `type-task [task names] [--param param]`

taskname: decorator class with `@Task('taskname')` or `@TaskModule({name:'taskname'})`.


You can `import` modules:


## Doc

### Define Task

* Single task

```ts
@Task('test')
class SimpleTask extends AbstractTask implements ITask {

    constructor(name: string) {
        super(name);
    }

    run(): Promise<any> {
        // console.log('before simple task:', this.name);
        return Promise.resolve('simple task')
            .then(val => {
                console.log('return simple task:', val);
                return val;
            });
    }
}

```

* Component task

```ts
@Task
class DelComponentTask extends TaskElement {
    execute(data?: any): Promise<any> {
        return del(['lib/**']);
    }
}

```

* Task module

```ts
@TaskModule({
    providers: <IPipeElementProvider>{
        name: 'tscomplie',
        src: 'src/**/*.ts',
        dest: 'lib',
        pipes: [
            (ctx) => cache('typescript'),
            (ctx) => classAnnotations(),
            sourcemaps.init,
            (ctx) => tsProject()
        ]
    },
    task: PipeElement
})
class TsCompile extends TaskElement {
}

```

### Run task

see [interface](https://github.com/zhouhoujun/type-task/blob/master/src/ITaskContainer.ts)

```ts
1.
let container = new TaskContainer(__dirname, moudles)
2.
TaskContainer.create(__dirname, moudles)
    .bootstrap(<IConfigure>{
        ...
        task:...
    });
3.
TaskContainer.create(__dirname, moudles)
    .bootstrap(TestTask);
4.
TaskContainer.create(__dirname)
    .bootstrap([TestTask, TsCompile, <IConfigure>{
        ...
        task: ...
    }]);

```

## Simples

more simples [see](https://github.com/zhouhoujun/type-task/blob/master/test/simples.task.ts)

```ts
import { Task, ITask, taskSymbols, TaskContainer, AbstractTask, TaskElement, PipeElement, ITaskComponent, IConfigure, PipeComponent, IPipeElementProvider, TaskModule, ITransform, Src, PipeExpress, RunWay, TransformExpress, TransformType } from 'type-task';
import * as mocha from 'gulp-mocha';

const del = require('del');
const cache = require('gulp-cached');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
import { classAnnotations } from 'typescript-class-annotations';
import { isFunction, isBoolean, ObjectMap } from 'tsioc';


@TaskModule({
    providers: <IPipeElementProvider>{
        pipes: [
            () => cache('typescript'),
            sourcemaps.init,
            () => classAnnotations(),
            (ctx, config) => {
                let target = config.moduleTarget as TsCompile;
                if (target.tsconfig) {
                    return ts(target.tsconfig);
                } else {
                    let tsProject = ts.createProject(ctx.toRootPath(target.tsconfigFile || './tsconfig.json'));
                    return tsProject();
                }
            }
        ],
        destPipes: {
            js: [
                (ctx, config, transform) => {
                    let trans: ITransform = transform.js;
                    trans.changeAsOrigin = true;
                    return trans;
                },
                (ctx, config) => {
                    let target = config.moduleTarget as TsCompile;
                    if (target.uglify) {
                        return isBoolean(target.uglify) ? uglify() : uglify(target.uglify);
                    }
                    return null;
                },
                (ctx) => sourcemaps.write('./sourcemaps')
            ],
            dts: [
                (ctx, config, transform) => {
                    let tans: ITransform = transform.dts;
                    tans.changeAsOrigin = true;
                    return tans;
                }
            ]
        }
    },
    task: PipeElement
})
export class TsCompile extends TaskElement {

    constructor(name: string, runWay?: RunWay, public src?: Src, public dest?: Src,
        private tsPipes?: TransformExpress, private jsPipes?: TransformExpress,
        public tsconfigFile?: string, public tsconfig?: ObjectMap<any>, public uglify?: boolean | ObjectMap<any>) {
        super(name, runWay);
    }

    onInit() {
        let providers = this.config.providers as IPipeElementProvider;

        console.log('src:', this.src, 'dest:', this.dest, 'providers:', providers);

        if (this.src) {
            providers.src = this.src;
        }

        if (this.dest) {
            providers.dest = this.dest;
        }

        if (this.tsPipes) {
            let pipes: TransformType[] = isFunction(providers.pipes) ? providers.pipes(this.context, this.config) : providers.pipes;
            let tsPipes: TransformType[] = isFunction(this.tsPipes) ? this.tsPipes(this.context, this.config) : this.tsPipes;
            pipes.splice(1, 0, ...tsPipes);
            providers.pipes = pipes;
        }

        if (this.jsPipes) {
            let destPipes: any = isFunction(providers.destPipes) ? providers.destPipes(this.context, this.config) : providers.destPipes;
            destPipes.js = isFunction(destPipes.js) ? destPipes.js(this.context, this.config) : destPipes.js;
            let jsPipes: TransformType[] = isFunction(this.jsPipes) ? this.jsPipes(this.context, this.config) : this.jsPipes;
            destPipes.js.splice(1, 0, ...jsPipes);
            providers.destPipes = destPipes;
        }
        this.config.providers = providers;
    }
}

@TaskModule({
    providers: {
        name: 'test',
        src: 'test/**/*.spec.ts',
        awaitPiped: true,
        pipes: [() => mocha()]
    },
    task: PipeElement
})
class TestTask extends TaskElement {
    execute(data?: any): Promise<any> {
        return del(['lib/**', 'bin/**']);
    }
}

TaskContainer.create(__dirname)
    .bootstrap([
        TestTask,
        {
            providers: {
                name: 'tscompLIB',
                src: ['src/**/*.ts', '!src/cli/**'],
                dest: 'lib',
                uglify: true
            },
            task: TsCompile
        },
        {
            providers: {
                name: 'tscompCLI',
                src: 'src/cli/*.ts',
                dest: 'bin',
                uglify: true
            },
            task: TsCompile
        }]);


```

## Documentation [github](https://github.com/zhouhoujun/type-task.git)

Documentation is available on the
[type-task docs site](https://github.com/zhouhoujun/type-task).

## License

MIT © [Houjun](https://github.com/zhouhoujun/)

---
_Source: https://npm.io/package/type-task · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
