# gulp-apps

> running same tasks template for multiple apps

Latest version **1.1.3** (published 2018-04-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-apps
pnpm add gulp-apps
yarn add gulp-apps
bun add gulp-apps
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2018-04-20 |
| First published | 2016-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 97.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | iBaryo |
| Maintainers | baryo |

## Links

- npm: https://www.npmjs.com/package/gulp-apps
- Repository: https://github.com/iBaryo/gulp-apps
- Homepage: https://github.com/iBaryo/gulp-apps#readme
- Issues: https://github.com/iBaryo/gulp-apps/issues
- npm.io page: https://npm.io/package/gulp-apps

## Dependencies (2)

- [gulp](https://npm.io/package/gulp.md) ^3.9.1
- [run-sequence](https://npm.io/package/run-sequence.md) ^1.2.2

## Recent versions

- 1.1.3 (latest) — 2018-04-20
- 1.1.2 — 2016-12-02
- 1.1.1 — 2016-12-02
- 1.1.0 — 2016-12-02
- 1.0.8 — 2016-11-22
- 1.0.7 — 2016-11-21
- 1.0.6 — 2016-11-21
- 1.0.5 — 2016-11-20
- 1.0.4 — 2016-11-20
- 1.0.3 — 2016-11-19
- 1.0.2 — 2016-11-19
- 1.0.1 — 2016-11-19
- 1.0.0 — 2016-11-19

## README

# gulp-apps
Do you have several apps or components but you want to expose the same build process?
Then this is the package for you.

##To install:
``npm i gulp-apps --save-dev``

##Usage

gulpfile.ts :


### Defining tasks template
```
import {IApp, gulpApps, IAppContext} from "gulp-apps";
const gulp = require('gulp');
const apps = require('gulp-apps').gulpApps;

// The structure of my apps
interface IMyApp extends IApp {
    dir: string;
    enabled: boolean;
}

// Initializing tasks template
const tasks =
    apps.use(gulp).initTasks<IMyApp>([
        {
            name: 'task-1',
            fn: () => {
                console.log('hello from task-1');
            }
        },
        {
            name: 'task-2',
            dependencies: ['task-1'],
            fn: (done) => {
                console.log('task-2 has dependencies');
                Promise.resolve().then(done);
            }
        },
        {
            name: 'task-3',
            dependencies: ['task-1', 'task-2'],
            fn: function(this : IAppContext<IMyApp>) => {
                console.log('accessing relevant app on task run-time');
                console.log(this.app.name);
            }
        }
    ]);
```

### Creating tasks for apps

```
// Initializing tasks for a given app to get a runner.
const runner = tasks.for({
    name: 'firstApp',
    dir: './app1',
    enabled: true
});

// or initialize for multiple apps to get a group runner 
const groupRunner = tasks.forAll([
    {
        name: 'secondApp',
        enabled: true,
        dir: './app2'
    },
    {
        name: 'thirdApp',
        enabled: false,
        dir: './app3'
    }
]);

```

Result in defined tasks:

```
[22:37:25] Tasks for ~\projects\tmp\gulpfile.js
[22:37:25] ├── firstApp-task-1
[22:37:25] ├─┬ firstApp-task-2
[22:37:25] │ └── firstApp-task-1
[22:37:25] ├─┬ firstApp-task-3
[22:37:25] │ ├── firstApp-task-1
[22:37:25] │ └── firstApp-task-2
[22:37:25] ├── secondApp-task-1
[22:37:25] ├─┬ secondApp-task-2
[22:37:25] │ └── secondApp-task-1
[22:37:25] ├─┬ secondApp-task-3
[22:37:25] │ ├── secondApp-task-1
[22:37:25] │ └── secondApp-task-2
[22:37:25] ├── thirdApp-task-1
[22:37:25] ├─┬ thirdApp-task-2
[22:37:25] │ └── thirdApp-task-1
[22:37:25] └─┬ thirdApp-task-3
[22:37:25]   ├── thirdApp-task-1
[22:37:25]   └── thirdApp-task-2

```

### Running tasks
And now that we have the runners for the apps, we can invoke tasks:

```
// invoking task for our single app runner
runner.run('task-3');

// run for group in parallal.
groupRunner.run('task-3');

// or in sequence
groupRunner.runInSequence('task-3');
```

###Example
It's useful to expose base tasks and set more down the road:

```
gulp.task('build-enabled', (done) => {
    const myApps = require('./myApps.json') as IMyApp[];
    tasks.forAll(myApps.filter(app => app.enabled)).run('my-build-task').then(done);
});
```


##Class Decorator
`gulp-apps` also has decorator support!

```
const GulpApp = gulpApps.use(gulp).getDecorator<IMyApp>();

@GulpApp()
class Tasks implements IAppContext<IMyApp> {
    constructor(public app : IMyApp) {}

    @GulpApp.task()
    public myTask() {}

    @GulpApp.task(['myTask'])
    public secondTask() {}

    @GulpApp.task(['secondTask'], 'diff-name')
    public thirdTask() {}

    @GulpApp.task(['diff-name'])
    public accessApp() {
        console.log(this.app.name);
    }

    @GulpApp.task(['accessApp', 'diff-name'])
    public accessPrivateMethods() {
        this.privateMethod();
    }

    private privateMethod() {
        console.log('this is not a gulp task');
        console.log(this.app.name);
    }

    @GulpApp.task(['accessPrivateMethods'])
    public default() {

    }
}


gulp.task('do-it', ()=> {
    GulpApp.getTasks().for({
        name: 'my-cool-app',
        dir: './',
        enabled: true
    })
        .run('default');
});
```

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