{"id":18434715,"url":"https://github.com/assemble/assemble-handle","last_synced_at":"2025-04-07T19:31:56.341Z","repository":{"id":57184946,"uuid":"49528955","full_name":"assemble/assemble-handle","owner":"assemble","description":"Assemble pipeline plugin for handling middleware stages.","archived":false,"fork":false,"pushed_at":"2018-12-12T01:18:12.000Z","size":20,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-23T00:04:51.106Z","etag":null,"topics":["assemble","assemble-pipeline-plugin","assemble-plugin","middleware"],"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/assemble.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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-01-12T21:08:34.000Z","updated_at":"2019-11-05T08:04:14.000Z","dependencies_parsed_at":"2022-09-10T22:40:16.805Z","dependency_job_id":null,"html_url":"https://github.com/assemble/assemble-handle","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assemble%2Fassemble-handle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assemble%2Fassemble-handle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assemble%2Fassemble-handle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assemble%2Fassemble-handle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/assemble","download_url":"https://codeload.github.com/assemble/assemble-handle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247716362,"owners_count":20984227,"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":["assemble","assemble-pipeline-plugin","assemble-plugin","middleware"],"created_at":"2024-11-06T06:05:03.339Z","updated_at":"2025-04-07T19:31:56.056Z","avatar_url":"https://github.com/assemble.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# assemble-handle [![NPM version](https://img.shields.io/npm/v/assemble-handle.svg?style=flat)](https://www.npmjs.com/package/assemble-handle) [![NPM monthly downloads](https://img.shields.io/npm/dm/assemble-handle.svg?style=flat)](https://npmjs.org/package/assemble-handle) [![NPM total downloads](https://img.shields.io/npm/dt/assemble-handle.svg?style=flat)](https://npmjs.org/package/assemble-handle) [![Linux Build Status](https://img.shields.io/travis/assemble/assemble-handle.svg?style=flat\u0026label=Travis)](https://travis-ci.org/assemble/assemble-handle)\n\n\u003e Assemble pipeline plugin for handling custom middleware stages.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save assemble-handle\n```\n\n## Usage\n\n```js\nconst handle = require('assemble-handle');\n```\n\n### handle\n\nHandle middleware for the given middleware \"stage\".\n\n```js\napp.task('default', function() {\n  return app.src('*.js')\n    .pipe(handle(app, 'handlerName')) //\u003c= handle middleware\n    .pipe(app.dest('foo'))\n});\n```\n\n**Example**\n\n```js\nconst assemble = require('assemble');\nconst handle = require('assemble-handle');\nconst app = assemble();\n\n/**\n * create some middleware \"stages\"\n */\n\napp.handler('onStream');\napp.handler('preWrite');\napp.handler('postWrite');\n\n/**\n * Create middleware\n */\n\napp.onStream(/\\.(js|css)$/, function(file, next) {\n  // lint javascript\n  next();\n});\n\napp.preWrite(/\\.(jpg|png)$/, function(file, next) {\n  // minify images\n  next();\n});\n\napp.postWrite(/./, function(file, next) {\n  // create files tree or something\n  next();\n});\n\n/**\n * Run (handle) the middleware \n */\n\napp.task('site', function() {\n  return app.src('assets/**/*.*')\n    .pipe(handle(app, 'onStream'))  // handle onStream\n    .pipe(handle(app, 'preWrite'))  // handle preWrite\n    .pipe(app.dest('site/'));\n    .pipe(handle(app, 'postWrite')) // handle postWrite\n});\n```\n\n### handle.once\n\nA `.once` method is exposed, which has the same exact behavior as the main function, but will ensure that middleware is only handled once for a given \"stage\".\n\n**Example**\n\nFor example the given middleware will only run once.\n\n```js\nconst assemble = require('assemble-core');\nconst handle = require('assemble-handle');\nconst app = assemble();\n\napp.handler('onFoo');\n\napp.onFoo(/./, function(file, next) {\n  file.count = file.count || 0;\n  file.count++;\n  next();\n});\n\napp.task('handle-once', function(cb) {\n  let files = [];\n  app.src('test/**/*.*')\n    .pipe(handle.once(app, 'onFoo'))\n    .pipe(handle.once(app, 'onFoo'))\n    .pipe(handle.once(app, 'onFoo'))\n    .pipe(handle.once(app, 'onFoo'))\n    .pipe(handle.once(app, 'onFoo'))\n    .on('data', function(file) {\n      files.push(file);\n    })\n    .pipe(app.dest('test/actual'))\n    .on('end', function() {\n      console.log(files[0].count);\n      //=\u003e 1\n      cb();\n    });\n});\n\napp.task('handle', function(cb) {\n  let files = [];\n  app.src('test/**/*.*')\n    .pipe(handle(app, 'onFoo'))\n    .pipe(handle(app, 'onFoo'))\n    .pipe(handle(app, 'onFoo'))\n    .pipe(handle(app, 'onFoo'))\n    .pipe(handle(app, 'onFoo'))\n    .on('data', function(file) {\n      files.push(file);\n    })\n    .pipe(app.dest('test/actual'))\n    .on('end', function() {\n      console.log(files[0].count);\n      //=\u003e 5\n      cb();\n    });\n});\n```\n\n## Custom handlers\n\nCreate custom middleware handlers.\n\n```js\napp.handler('onFoo');\n```\n\nThis adds an `.onFoo` method to the instance:\n\n```js\napp.onFoo(/\\.hbs$/, function(file, next) {\n  // do stuff to file\n  next();\n});\n```\n\nAll `.onFoo` middleware will now run when the `onFoo` handler is called:\n\n```js\napp.task('default', function() {\n  return app.src('*.hbs')\n\n    // call the `onFoo` handler\n    .pipe(handle(app, 'onFoo')) \n});\n```\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [assemble-core](https://www.npmjs.com/package/assemble-core): The core assemble application with no presets or defaults. All configuration is left to the… [more](https://github.com/assemble/assemble-core) | [homepage](https://github.com/assemble/assemble-core \"The core assemble application with no presets or defaults. All configuration is left to the implementor.\")\n* [assemble-fs](https://www.npmjs.com/package/assemble-fs): Light wrapper for vinyl-fs to add streams support in a way that plays nice with… [more](https://github.com/assemble/assemble-fs) | [homepage](https://github.com/assemble/assemble-fs \"Light wrapper for vinyl-fs to add streams support in a way that plays nice with Assemble middleware.\")\n* [assemble-streams](https://www.npmjs.com/package/assemble-streams): Assemble pipeline plugin for pushing views into a vinyl stream. | [homepage](https://github.com/assemble/assemble-streams \"Assemble pipeline plugin for pushing views into a vinyl stream.\")\n* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble \"Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit\")\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 17 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 3  | [doowb](https://github.com/doowb) |  \n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on December 11, 2018._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassemble%2Fassemble-handle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fassemble%2Fassemble-handle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassemble%2Fassemble-handle/lists"}