{"id":16773846,"url":"https://github.com/ziflex/gulp-tasks-monorepo","last_synced_at":"2025-04-10T20:04:09.601Z","repository":{"id":11516397,"uuid":"69915983","full_name":"ziflex/gulp-tasks-monorepo","owner":"ziflex","description":"Tool for running gulp tasks against multiple packages","archived":false,"fork":false,"pushed_at":"2023-01-06T02:23:10.000Z","size":1728,"stargazers_count":6,"open_issues_count":8,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T11:20:05.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ziflex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-03T22:24:16.000Z","updated_at":"2021-11-15T07:20:49.000Z","dependencies_parsed_at":"2023-01-13T16:32:51.755Z","dependency_job_id":null,"html_url":"https://github.com/ziflex/gulp-tasks-monorepo","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fgulp-tasks-monorepo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fgulp-tasks-monorepo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fgulp-tasks-monorepo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fgulp-tasks-monorepo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ziflex","download_url":"https://codeload.github.com/ziflex/gulp-tasks-monorepo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248287961,"owners_count":21078817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T06:47:11.056Z","updated_at":"2025-04-10T20:04:09.577Z","avatar_url":"https://github.com/ziflex.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-tasks-monorepo\n\n\u003e Write once, apply to all\n\nTool for running gulp tasks against multiple packages\n\n[![npm version](https://badge.fury.io/js/gulp-tasks-monorepo.svg)](https://www.npmjs.com/package/gulp-tasks-monorepo)\n[![Build Status](https://secure.travis-ci.org/ziflex/gulp-tasks-monorepo.svg?branch=master)](http://travis-ci.org/ziflex/gulp-tasks-monorepo)\n[![Coverage Status](https://coveralls.io/repos/github/ziflex/gulp-tasks-monorepo/badge.svg?branch=master)](https://coveralls.io/github/ziflex/gulp-tasks-monorepo)\n\n## Motivation\n\nBasic idea of the package is reusing gulp tasks for multiple projects that have similar build pipelines.\nPackage iterates over a given folder with packages and run gulp tasks against each package.\nIn its turn, each gulp task receives a current package metadata that contains some information about the package which can be extended via package initializers (they are covered below).\n\n## Usage\n\n### Quick start\n\nImagine, that we have a following project structure\n\n```sh\n\n    packages/\n        common/\n            src/\n            package.json\n        api/\n            src/\n            package.json\n    gulpfile.js\n    package.json\n\n```\n\nBoth packages are written in ES6 and needed to be transpiled into ES5.\nHere is our task in gulp file:\n\n```javascript\nvar rimraf = require('rimraf');\nvar path = require('path');\nvar gulp = require('gulp');\nvar babel = require('gulp-babel');\nvar gutil = require('gulp-util');\nvar MonorepoTasks = require('gulp-tasks-monorepo');\n\nvar repo = MonorepoTasks({\n    dir: path.join(__dirname, '/packages'),\n});\n\nrepo.task('clean', function clean(pkg, done) {\n    gutil.log('Cleaning', pkg.name(), 'package');\n\n    rimraf(path.join(pkg.location(), '/dist'), done);\n});\n\nrepo.task('build', ['clean'], function build(pkg) {\n    gutil.log('Building', pkg.name(), 'package');\n\n    return gulp\n        .src(path.join(pkg.location(), '/src/**/*.js'))\n        .pipe(babel())\n        .pipe(gulp.dest(path.join(pkg.location(), '/dist')));\n});\n```\n\nAs we can see, pretty much the same as with regular vanilla gulp, but with one exception - every task receives a package metadata with its name and location.\n\n#### Sequential execution flow\n\nSince the package executes all tasks in parallel, there is a way how to force it to run them sequentially.\n\n```javascript\nvar repo = MonorepoTasks({\n    dir: path.join(__dirname, '/packages'),\n});\n\nrepo.task('a', function() {});\n\nrepo.task('b', function() {});\n\nrepo.task('c', [['a', 'b']], function() {});\n```\n\nIt needs to put those tasks that are needed to be executed sequentially in a nested array.\n\n### Metadata\n\nOf course, in real world, our build tasks are more complicated and we need to give some more information to these tasks in order to let them know how to handle each package more precisely .\nIn order to do that, we can create `package.js` in a root directory of each package that should export one single function which accepts a package metadata:\n\n```javascript\nmodule.exports = function init(pkg) {\n    pkg.options('build.scripts.minify', true);\n};\n```\n\nThe package will load this module and run initializer before running any tasks.\nAfter that, any task can get the information:\n\n```javascript\nvar gif = require('gulp-if');\nvar uglify = require('gulp-uglify');\n\nrepo.task('build', ['clean'], function build(pkg) {\n    gutil.log('Building', pkg.name(), 'package');\n\n    var minify = pkg.options('build.scripts.minify') || false;\n\n    return gulp\n        .src(path.join(pkg.location(), '/src/**/*.js'))\n        .pipe(babel())\n        .pipe(gif(minify, uglify()))\n        .pipe(gulp.dest(path.join(pkg.location(), '/dist')));\n});\n```\n\n#### Async metadata initializer\n\nMetadata initializer also can be async:\n\n```javascript\nvar fs = require('fs');\nvar path = require('path');\n\nmodule.exports = function init(pkg, done) {\n    fs.readFile(path.join(pkg.location(), 'package.json'), 'utf8', function(\n        err,\n        content,\n    ) {\n        if (err) {\n            return done(err);\n        }\n\n        const info = JSON.parse(content);\n\n        pkg.options('dependencies.production', info.dependencies);\n        pkg.options('dependencies.development', info.devDependencies);\n\n        done();\n    });\n};\n```\n\n### Bonus\n\nAs a bonus, we can drastically minimize amount of code and organize it better.\nWe can use [`gulp-tasks-registrator`](https://github.com/ziflex/gulp-tasks-registrator) for loading external gulp tasks:\n\n```javascript\nvar gulp = require('gulp');\nvar RegisterTasks = require('gulp-tasks-registrator');\nvar MonorepoTasks = require('gulp-tasks-monorepo');\nvar loadPlugins = require('gulp-load-plugins');\n\nvar $ = loadPlugins({\n    replaceString: /^gulp(-|\\.)/,\n    pattern: ['gulp', 'gulp-*', 'gulp.*', 'rimraf'],\n});\n\nRegisterTasks({\n    gulp: MonorepoTasks({\n        dir: path.join(__dirname, 'packages'),\n    }),\n    dir: path.join(__dirname, 'tasks'),\n    args: [$],\n    verbose: true,\n    panic: true,\n    group: true,\n});\n```\n\n```javascript\n// tasks/clean.js\n\nvar path = require('path');\n\nmodule.exports = function factory($) {\n    return function task(pkg, done) {\n        $.rimraf(path.join(pkg.location(), '/dist'), done);\n    };\n};\n```\n\n```javascript\n// tasks/build.js\n\nvar path = require('path');\n\nmodule.exports = function factory($) {\n    function task(pkg) {\n        return $.gulp\n            .src(path.join(pkg.location(), '/src/**/*.js'))\n            .pipe($.babel())\n            .pipe($.if(minify, uglify()))\n            .pipe($.gulp.dest(path.join(pkg.location(), '/dist')));\n    }\n\n    task.dependencies = ['clean'];\n\n    return task;\n};\n```\n\n## API\n\n#### Monorepo(options)\n\n#### options.dir\n\nType: `string`.  \nFull path to a directory that contains packages.\n\n#### options.file\n\nType: `string`.  \nFile name for initialization module.  \nOptional.  \nDefault `package.js`.\n\n#### options.package\n\nType: `string` | `array\u003cstring\u003e`.  \nArray of string or comma-separated string that represent a package(s) to run tasks against.  \nOptional.\n\n#### options.gulp\n\nType: `object`.  \nAlternative gulp instance.  \nOptional.\n\n#### options.quiet\n\nType: `boolean`.  \nTurns off logging.  \nOptional.  \nDefault `false`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziflex%2Fgulp-tasks-monorepo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziflex%2Fgulp-tasks-monorepo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziflex%2Fgulp-tasks-monorepo/lists"}