{"id":21432080,"url":"https://github.com/lookfirst/gulp-helpers","last_synced_at":"2025-07-14T12:32:44.686Z","repository":{"id":27474252,"uuid":"30953635","full_name":"lookfirst/gulp-helpers","owner":"lookfirst","description":"A set of tasks and helpers for gulp","archived":false,"fork":false,"pushed_at":"2018-01-17T06:25:15.000Z","size":205,"stargazers_count":35,"open_issues_count":22,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-13T17:13:41.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/lookfirst.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-18T05:36:51.000Z","updated_at":"2023-11-03T09:45:44.000Z","dependencies_parsed_at":"2022-08-25T21:23:40.918Z","dependency_job_id":null,"html_url":"https://github.com/lookfirst/gulp-helpers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookfirst%2Fgulp-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookfirst%2Fgulp-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookfirst%2Fgulp-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookfirst%2Fgulp-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lookfirst","download_url":"https://codeload.github.com/lookfirst/gulp-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225976192,"owners_count":17554197,"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-11-22T23:16:13.792Z","updated_at":"2024-11-22T23:16:14.390Z","avatar_url":"https://github.com/lookfirst.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/gulp-helpers.svg)](https://badge.fury.io/js/gulp-helpers)\n[![npm dependencies](https://david-dm.org/lookfirst/gulp-helpers.svg)](https://david-dm.org/lookfirst/gulp-helpers)\n[![Build Status](https://travis-ci.org/lookfirst/gulp-helpers.svg)](https://travis-ci.org/lookfirst/gulp-helpers)\n[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/lookfirst/gulp-helpers)\n\n# gulp-helpers\n\nA set of tasks and helpers for gulp 3.x \n\nWhen gulp 4 is released, gulp-helpers will be rewritten to support [custom registries](https://github.com/phated/undertaker#custom-registries).\n\n# Don't repeat yourself (DRY) gulpfiles\n\nWhen writing gulpfiles, I often find myself copying entire blocks of code between files. I make mistakes and forget things. I improve one gulpfile and have a hard time upgrading old gulpfiles in other projects. \n\nIn other words, _gulpfiles are not DRY between projects_. \n\nOne way to solve this issue is by moving common task functionality into a set of external tasks that can be re-used across projects. The '[Split tasks across multiple files](split-tasks-across-multiple-files.md)' recipe breaks up your gulpfile into little files. The problem is that it doesn't solve the larger DRY issues that I've run into.\n\n## Example less task\n\nI might have a task to process my [less](http://lesscss.org/) CSS files. It is many lines tall and does a whole bunch of stuff. I've forgotten half of what it does (wtf is [plumber()](https://github.com/floatdrop/gulp-plumber))? It also necessitates adding `devDependencies` to my projects `package.json` and all the `require` lines at the top of the gulpfile. _What a mess_.\n\n```\nvar gulp = require('gulp');\nvar plumber = require('gulp-plumber');\nvar less = require('gulp-less');\nvar cache = require('gulp-cached');\nvar changed = require('gulp-changed');\nvar sourcemaps = require('gulp-sourcemaps');\nvar lessPluginCleanCSS = require('less-plugin-clean-css');\nvar cleancss = new lessPluginCleanCSS({advanced: true});\nvar browserSync = require('browser-sync');\n\ngulp.task('less', function () {\n  return gulp.src(path.less)\n    .pipe(cache('less'))\n    .pipe(plumber())\n    .pipe(changed(path.output, {extension: '.css'}))\n    .pipe(sourcemaps.init())\n    .pipe(less({\n      plugins: [ cleancss ]\n    }))\n    .pipe(sourcemaps.write('.'))\n    .pipe(gulp.dest(path.output))\n    .pipe(browserSync.reload({ stream: true }));\n});\n```\n\n## gulp-helpers to the rescue\n\n[gulp-helpers](https://github.com/lookfirst/gulp-helpers/) reduces [the less CSS task](https://github.com/lookfirst/gulp-helpers/blob/master/src/tasks/less.js) down to a single line in your gulpfile.\n\n```\nnpm install gulp-helpers --save-dev\n```\n\n```\nvar gulp = require('gulp');\nvar gulpHelpers = require('gulp-helpers');\nvar taskMaker = gulpHelpers.taskMaker(gulp);\n\ntaskMaker.defineTask('less', { src: 'src/**/*.less', dest: 'dist' });\n```\n\nA more complete example that uses [babel](http://babeljs.io/) to transpile our code on save looks like this:\n\n```\nvar gulp = require('gulp');\nvar gulpHelpers = require('gulp-helpers');\nvar taskMaker = gulpHelpers.taskMaker(gulp);\n\nvar path = {\n\tsource: 'src/**/*.js',\n\toutput: 'dist',\n\twatch: 'src/**'\n};\n\ntaskMaker.defineTask('clean', {taskName: 'clean', src: path.output});\ntaskMaker.defineTask('babel', {taskName: 'babel', src: path.source, dest: path.output, \n\t\t\t\tcompilerOptions: {modules: 'system'}, watchTask: true});\n\ngulp.task('default', ['clean', 'babel', 'watch-babel']);\n```\n\n* There is little code and a lot of configuration. It makes setting up new gulpfiles trivial because now I don't have to re-learn gulp and all of its plugins every time I want to start a new project. \n\n* Automatically generate `gulp.watch` tasks by passing `watchTask: true`.\n\n* The `package.json` `devDependencies` section is so clean! Just a dependency on gulp and gulp-helpers.\n\n* Take advantage of bug fixes and improvements in gulp-helpers automatically and more importantly, across projects.\n\n* When the next version of gulp is available, this gulpfile will work without changes.\n\n## Examples\n\n* [systemjs-seed project](https://github.com/lookfirst/systemjs-seed/)\n\n## API\n\n### defineTask\n\n```\ntaskMaker.defineTask(NAME_OF_GULPHELPERS_TASK, OPTIONS);\n```\n\nThe named gulp-helper task will be loaded via `require` and you pass options into it. There is a whole bunch of tasks already defined, [take a look](https://github.com/lookfirst/gulp-helpers/tree/master/src/tasks) at the ones you need in order to figure out the options you can pass in. I've tried to keep the naming pretty consistent between tasks. For example, `src` and `dest` will always map to the arguments to `gulp.src()` and `gulp.dest()`.\n\nThere are a couple options which are default across all tasks:\n* `taskName` - The name of the `gulp.task()` task, defaults to the first argument of `defineTask` (String)\n* `taskDeps` - Passed into `gulp.task()` as the dependent tasks (Array)\n* `chmod` - For tasks which output files (such as `sass`, `copy`, `concat`...), since version `2.0.15`, it is capable of setting `read/write` permissions (Number or Object). See [gulp-chmod](https://github.com/sindresorhus/gulp-chmod) for more details.\n\n### situation\n\n```\nexport SITUATION=production\n```\n\n```\nvar situation = gulpHelpers.situation();\nif (situation.isProduction()) {\n  // do production stuff\n} else if (situation.isDevelopment()) {\n  // do development stuff\n}\n```\n\nThis returns a `Situation` object, which is good for determining if we are running in `development`, `sandbox`, `demo` or `production` mode based on the SITUATION environment variable.\n\nSandbox and Production mode generally means that the project is bundled and minified and [browserSync](http://browsersync.io) is running without reloading turned on.\n\nThis makes it easy to build gulpfiles which can be deployed to PaaS solutions like Heroku, yet still allow you to test your app in production mode locally.\n\n### framework\n\n```\nvar _ = gulpHelpers.framework('lodash'); // '_' also works\nvar runSequence = gulpHelpers.framework('run-sequence');\n```\n\nThe idea behind `framework` is that the dependency chain is in gulp-helpers instead of being in your own project's `package.json`. \n\n* [lodash](https://lodash.com/)\n* [run-sequence](https://github.com/OverZealous/run-sequence)\n\n## Development\n\ngulp-helpers is written in ES6 and transpiled to ES5 using [babel](https://babeljs.io/). This allows us to take advantage of ES6 features while maintaining backwards compatibility. In my research, it seems like this is one of the first public [NPM projects](https://www.npmjs.com/package/gulp-helpers) to do this. Fun!\n\nPull requests to add more tasks or improve on existing ones are welcome. I'd like this to become a useful repository for lots of projects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flookfirst%2Fgulp-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flookfirst%2Fgulp-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flookfirst%2Fgulp-helpers/lists"}