# gulp-module

> Gulp submodules with namespaces and direct execution support.

Latest version **0.0.6** (published 2015-08-30) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2015-08-30 |
| First published | 2015-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Maciej Zasada |
| Maintainers | maciejzasada |
| Keywords | gulp, module, submodule, namespace, ns |

## Links

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

## Dependencies (4)

- [glob](https://npm.io/package/glob.md) ^5.0.14
- [gulp](https://npm.io/package/gulp.md) ^3.9.0
- [minimatch](https://npm.io/package/minimatch.md) ^2.0.10
- [run-sequence](https://npm.io/package/run-sequence.md) ^1.1.2

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [stockfish](https://npm.io/package/stockfish.md) — 27.0K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2015-08-30
- 0.0.5 — 2015-08-30
- 0.0.4 — 2015-08-30
- 0.0.3 — 2015-08-29
- 0.0.2 — 2015-08-29
- 0.0.1 — 2015-08-29

## README

# gulp-module
Gulp support for submodules with namespaces and direct submodule execution.

## Installation
`npm install --save-dev gulp-module`

IMPORTANT: gulp-module needs to be installed locally for each module.

## Example project structure
```
project/ -
  gulpfile.js
  (...)
  module/ -
    gulpfile.js
    (...)
```

## Module definition
```javascript
module.exports = require('gulp-module').define('moduleName', function (gulp, runSequence) {
  // Regular gulpfile here.
  // Do not re-import gulp or runSequence, use the arguments instead.
  // Use regular task names, e.g. default, build, coffee.
};
```

*Returns:* {String} module name (namespace).

## Task namespacing
All tasks are being automatically namespaced with the module name.
E.g. task `build` becomes `moduleName:build`.


## Importing modules
Modules can be imported in parent gulpfiles using the `gulpModule.load` to load a specific gulpfile.js or `gulpModule.loadAll` to recursively load all modules in a specific directory.
Both need to be passed a reference to the parent's `gulp` instance.

```javascript
var gulp = require('gulp'),
  gulpModule = require('gulp-module');

gulpModule.loadAll('modules', gulp);
// or
gulpModule.load('modules/desktop/gulpfile.js', gulp);
```

Then, tasks can be introduced in the parent's tasks as dependencies or in `runSequence` calls.

## Getting submodule task names
Tasks from within the submodules are namespaced with the module name and the separator between the namespace and the task name being a `:`.

However, it is safer to query a child task using the provided `gulpModule.tasks` function.

The `gulpModule.tasks` function also provides a `minimatch` filter so you can even query a group of all loaded tasks.

E.g.
```javascript
gulpModule.tasks('build', 'desktop');  // returns ['desktop:build']
gulpModule.tasks('clean', '*');  // returns clean task in all loaded namespaces, e.g. ['desktop:clean', 'mobile:clean']
gulpModule.tasks(['coffee', 'sass'], 'mobile');  // returns ['mobile:coffee', 'mobile:sass']
```


## Direct module execution
Modules can be still executed directly with gulp. E.g.

```
$ cd project/module
gulp module:build
```
When executed directly, gulp-module adds a non-namespaced `default` task so you can still run a module with simply `gulp`. All other tasks need to be run with a correct namespace, i.e. a defined `clean` task becomes `moduleName:clean` no matter if the module is run directly or if it is imported.


### Example module definition
I.e. `project/module/gulpfile.js` above.
```javascript
module.exports = require('gulp-module').define('module', function (gulp, runSequence) {

  gulp.task('coffee', function () {
    // Becomes 'module:coffe'
  });

  gulp.task('compass', function () {
    // Becomes 'module:compass'
  });

  gulp.task('test', function () {
    // Becomes 'module:test'
  });

  gulp.task('build', function (cb) {
    // Becomes 'module:build'
    // runSequence can still use non-namespaced tasks within module definition
    // and will namespace them automatically at runtime.
    runSequence('clean', ['coffee', 'compass'], 'test', cb);
  });

  gulp.task('default', ['build']);  // Becomes 'module:default'.
  // In direct execution additional task 'default' is defined that runs a
  // 'module:default' task as a dependency.

};
```

## License
MIT

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