{"id":25180710,"url":"https://github.com/base-repos/base-generators","last_synced_at":"2025-06-24T22:33:07.161Z","repository":{"id":66211907,"uuid":"50559553","full_name":"base-repos/base-generators","owner":"base-repos","description":"Plugin that adds project-generator support to your `base` application.","archived":false,"fork":false,"pushed_at":"2020-04-01T00:04:48.000Z","size":279,"stargazers_count":13,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T06:04:43.011Z","etag":null,"topics":["assemble","base","generate","plugin","toolkit","update","verb"],"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/base-repos.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-28T05:55:07.000Z","updated_at":"2025-01-31T00:37:43.000Z","dependencies_parsed_at":"2023-02-24T00:00:26.870Z","dependency_job_id":null,"html_url":"https://github.com/base-repos/base-generators","commit_stats":{"total_commits":237,"total_committers":2,"mean_commits":118.5,"dds":0.04219409282700426,"last_synced_commit":"9a741117b80ed19b281177169c0f98059cb97c90"},"previous_names":["node-base/base-generators","base-repos/base-generators","base/base-generators"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base-repos%2Fbase-generators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base-repos%2Fbase-generators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base-repos%2Fbase-generators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/base-repos%2Fbase-generators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/base-repos","download_url":"https://codeload.github.com/base-repos/base-generators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823920,"owners_count":21809713,"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","base","generate","plugin","toolkit","update","verb"],"created_at":"2025-02-09T16:19:21.449Z","updated_at":"2025-05-07T06:04:49.313Z","avatar_url":"https://github.com/base-repos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# base-generators [![NPM version](https://img.shields.io/npm/v/base-generators.svg?style=flat)](https://www.npmjs.com/package/base-generators) [![NPM downloads](https://img.shields.io/npm/dm/base-generators.svg?style=flat)](https://npmjs.org/package/base-generators) [![Linux Build Status](https://img.shields.io/travis/node-base/base-generators.svg?style=flat\u0026label=Travis)](https://travis-ci.org/node-base/base-generators)\n\n\u003e Adds project-generator support to your `base` application.\n\nYou might also be interested in [base-task](https://github.com/node-base/base-task).\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [Examples](#examples)\n  * [Tasks](#tasks)\n  * [Generators](#generators)\n  * [Sub-generators](#sub-generators)\n- [In the wild](#in-the-wild)\n- [API](#api)\n- [About](#about)\n  * [Related projects](#related-projects)\n  * [Contributing](#contributing)\n  * [Contributors](#contributors)\n  * [Release history](#release-history)\n  * [Building docs](#building-docs)\n  * [Running tests](#running-tests)\n  * [Author](#author)\n  * [License](#license)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save base-generators\n```\n\n**HEADS UP!**\n\nThe `.generateEach` method has been deprecated. Use `.generate` instead.\n\n## Usage\n\n```js\nvar generators = require('base-generators');\nvar Base = require('base');\n\n// register the plugin before instantiating, to make \n// sure the plugin is called on all Generator instances \nBase.use(generators());\nvar base = new Base();\n```\n\n## Examples\n\nAll examples assume the following code is defined:\n\n```js\nvar Base = require('base');\nvar generators = require('base-generators');\n\nBase.use(generators());\nvar base = new Base();\n```\n\n### Tasks\n\nTasks are exactly the same as [gulp](http://gulpjs.com) tasks, and are powered by [bach](https://github.com/gulpjs/bach) and [composer](https://github.com/doowb/composer).\n\n**Register a task:**\n\n```js\nbase.task('default', function(cb) {\n  // do stuff\n  cb();\n});\n```\n\n**Run a task:**\n\n```js\nbase.build('default', function(err) {\n  if (err) throw err;\n});\n```\n\n### Generators\n\n\u003e I heard you liked tasks, so I put some tasks in your tasks.\n\n**What's a generator?**\n\nGenerators are functions that are registered by name, and are used to encapsulate and organize code, [tasks](#tasks), other generators, or [sub-generators](#sub-generators), in a sharable, publishable and easily re-usable way.\n\nIn case it helps, here are some [live examples](#in-the-wild).\n\n**Register a generator:**\n\n```js\nbase.register('foo', function(app, base) {\n  // `app` is the generator's \"private\" instance\n  // `base` is a \"shared\" instance, accessible by all generators\n});\n```\n\n**Get a generator:**\n\n```js\nvar foo = base.generator('foo');\n```\n\n**Register tasks in a generator:**\n\n```js\nbase.register('foo', function(app, base) {\n  app.task('default', function() {});\n  app.task('one', function() {});\n  app.task('two', function() {});\n});\n```\n\n**Run a generator's tasks:**\n\nThe `.generate` method simply calls the `.build` method on a specific generator.\n\nTo run a generator's tasks, pass the generator name as the first argument, and optionally define one or more tasks as the second argument. _(If no tasks are defined, the `default` task is run.)_\n\n```js\n// run the \"default\" task on generator \"foo\"\nbase.generate('foo', function(err) {\n  if (err) throw err;\n  console.log('done!');\n});\n\n// or specify tasks\nbase.generate('foo', ['default'], function() {});\nbase.generate('foo', ['one', 'two'], function() {});\n```\n\nAlternatively, you can call `.build` on the generator directly:\n\n```js\n// run the \"default\" task on generator \"foo\"\nbase.generator('foo')\n  .build('default', function(err) {\n    if (err) throw err;\n  });\n```\n\n### Sub-generators\n\nSub-generators are just generators that are registered on (or invoked within) another generator instance.\n\n**Register sub-generators:**\n\nRegister generators `one`, `two`, and `three` on generator `foo`:\n\n```js\nbase.register('foo', function(app, base) {\n  app.register('one', function() {});\n  app.register('two', function() {});\n  app.register('three', function() {});\n});\n```\n\n**Get a sub-generator:**\n\nUse dot-notation to get a sub-generator:\n\n```js\nvar one = base.generator('foo.one');\n```\n\nSub-generators may be nested to any level. In reality, you probably won't write code like the following example, but this only illustrates the point that generators are extremely composable, and can be built on top of or with other generators.\n\n```js\nbase.register('a', function(a, base) {\n  // do stuff\n  a.register('b', function(b) {\n    // do stuff\n    b.register('c', function(c) {\n      // do stuff\n      c.register('d', function(d) {\n        // do stuff\n        d.register('e', function(e) {\n          // arbitrary task\n          e.task('default', function(cb) {\n            console.log('e \u003e default!');\n            cb();\n          });\n        });\n      });\n    });\n  });\n});\n\nbase.getGenerator('a.b.c.d.e')\n  .build(function(err) {\n    if (err) throw err;\n    // 'e \u003e default!'\n  });\n```\n\n**Register tasks on sub-generators:**\n\n```js\nbase.register('foo', function(app, base) {\n  app.register('one', function(one) {\n    one.task('default', function() {});\n    one.task('a', function() {});\n    one.task('b', function() {});\n    one.task('c', function() {});\n  });\n\n  app.register('two', function(two) {\n    two.task('default', function() {});\n  });\n\n  app.register('three', function(three) {\n    three.task('default', function() {});\n  });\n});\n```\n\n**Run a sub-generator's tasks**\n\n```js\n// run the `default` task from sub-generator `foo.one`\nbase.generate('foo.one', function(err) {\n  if (err) throw err;\n  console.log('done!');\n});\n```\n\n**Run multiple tasks on a sub-generator:**\n\n```js\n// run tasks `a`, `b` and `c` on sub-generator `foo.one`\nbase.generate('foo.one', ['a', 'b', 'c'], function(err) {\n  if (err) throw err;\n  console.log('done!');\n});\n```\n\n## In the wild\n\nThe following applications use this library:\n\n* [generate](https://github.com/generate/generate): adds a CLI, template rendering, fs methods and generator convenience-methods to base-generators\n* [assemble](https://github.com/assemble/assemble): site generation\n* [verb](https://github.com/verbose/verb): documentation generation\n* [update](https://github.com/update/update): renames generators to \"updaters\", which are used to keep your project up-to-date\n\n## API\n\n### [.register](index.js#L60)\n\nAlias to `.setGenerator`.\n\n**Example**\n\n```js\napp.register('foo', function(app, base) {\n  // \"app\" is a private instance created for the generator\n  // \"base\" is a shared instance\n});\n```\n\n**Params**\n\n* `name` **{String}**: The generator's name\n* `options` **{Object|Function|String}**: or generator\n* `generator` **{Object|Function|String}**: Generator function, instance or filepath.\n* `returns` **{Object}**: Returns the generator instance.\n\n### [.generator](index.js#L85)\n\nGet and invoke generator `name`, or register generator `name` with the given `val` and `options`, then invoke and return the generator instance. This method differs from `.register`, which lazily invokes generator functions when `.generate` is called.\n\n**Example**\n\n```js\napp.generator('foo', function(app, base, env, options) {\n  // \"app\" - private instance created for generator \"foo\"\n  // \"base\" - instance shared by all generators\n  // \"env\" - environment object for the generator\n  // \"options\" - options passed to the generator\n});\n```\n\n**Params**\n\n* `name` **{String}**\n* `fn` **{Function|Object}**: Generator function, instance or filepath.\n* `returns` **{Object}**: Returns the generator instance or undefined if not resolved.\n\n### [.setGenerator](index.js#L116)\n\nStore a generator by file path or instance with the given `name` and `options`.\n\n**Example**\n\n```js\napp.setGenerator('foo', function(app, base) {\n  // \"app\" - private instance created for generator \"foo\"\n  // \"base\" - instance shared by all generators\n  // \"env\" - environment object for the generator\n  // \"options\" - options passed to the generator\n});\n```\n\n**Params**\n\n* `name` **{String}**: The generator's name\n* `options` **{Object|Function|String}**: or generator\n* `generator` **{Object|Function|String}**: Generator function, instance or filepath.\n* `returns` **{Object}**: Returns the generator instance.\n\n### [.getGenerator](index.js#L148)\n\nGet generator `name` from `app.generators`, same as [findGenerator], but also invokes the returned generator with the current instance. Dot-notation may be used for getting sub-generators.\n\n**Example**\n\n```js\nvar foo = app.getGenerator('foo');\n\n// get a sub-generator\nvar baz = app.getGenerator('foo.bar.baz');\n```\n\n**Params**\n\n* `name` **{String}**: Generator name.\n* `returns` **{Object|undefined}**: Returns the generator instance or undefined.\n\n### [.findGenerator](index.js#L179)\n\nFind generator `name`, by first searching the cache, then searching the cache of the `base` generator. Use this to get a generator without invoking it.\n\n**Example**\n\n```js\n// search by \"alias\"\nvar foo = app.findGenerator('foo');\n\n// search by \"full name\"\nvar foo = app.findGenerator('generate-foo');\n```\n\n**Params**\n\n* `name` **{String}**\n* `options` **{Function}**: Optionally supply a rename function on `options.toAlias`\n* `returns` **{Object|undefined}**: Returns the generator instance if found, or undefined.\n\n### [.getSubGenerator](index.js#L259)\n\nGet sub-generator `name`, optionally using dot-notation for nested generators.\n\n**Example**\n\n```js\napp.getSubGenerator('foo.bar.baz');\n```\n\n**Params**\n\n* `name` **{String}**: The property-path of the generator to get\n* `options` **{Object}**\n\nIterate over `app.generators` and call `generator.isMatch(name)`\non `name` until a match is found.\n\n**Params**\n\n* `name` **{String}**\n* `returns` **{Object|undefined}**: Returns a generator object if a match is found.\n\n**Example**\n\n```js\nconsole.log(app.hasGenerator('foo'));\n```\n\n**Params**\n\n* `name` **{String}**\n* `val` **{Object|Function}**\n* `returns` **{Boolean}**\n\nFor example, if the lookup `name` is `foo`, the function might\nreturn `[\"generator-foo\", \"foo\"]`, to ensure that the lookup happens\nin that order.\n\n**Params**\n\n* `name` **{String}**: Generator name to search for\n* `options` **{Object}**\n* `fn` **{Function}**: Lookup function that must return an array of names.\n* `returns` **{Object}**\n\n### [.extendWith](index.js#L384)\n\nExtend the generator instance with settings and features of another generator.\n\n**Example**\n\n```js\nvar foo = base.generator('foo');\napp.extendWith(foo);\n// or\napp.extendWith('foo');\n// or\napp.extendWith(['foo', 'bar', 'baz']);\n\napp.extendWith(require('generate-defaults'));\n```\n\n**Params**\n\n* `app` **{String|Object}**\n* `returns` **{Object}**: Returns the instance for chaining.\n\n### [.toAlias](index.js#L554)\n\nCreate a generator alias from the given `name`. By default the alias is the string after the last dash. Or the whole string if no dash exists.\n\n**Example**\n\n```js\nvar camelcase = require('camel-case');\nvar alias = app.toAlias('foo-bar-baz');\n//=\u003e 'baz'\n\n// custom `toAlias` function\napp.option('toAlias', function(name) {\n  return camelcase(name);\n});\nvar alias = app.toAlias('foo-bar-baz');\n//=\u003e 'fooBarBaz'\n```\n\n**Params**\n\n* `name` **{String}**\n* `options` **{Object}**\n* `returns` **{String}**: Returns the alias.\n\n## About\n\n### Related projects\n\n* [bach](https://www.npmjs.com/package/bach): Compose your async functions with elegance. | [homepage](https://github.com/gulpjs/bach#readme \"Compose your async functions with elegance.\")\n* [base-fs](https://www.npmjs.com/package/base-fs): base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file… [more](https://github.com/node-base/base-fs) | [homepage](https://github.com/node-base/base-fs \"base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file system, like src, dest, copy and symlink.\")\n* [base-pipeline](https://www.npmjs.com/package/base-pipeline): base-methods plugin that adds pipeline and plugin methods for dynamically composing streaming plugin pipelines. | [homepage](https://github.com/node-base/base-pipeline \"base-methods plugin that adds pipeline and plugin methods for dynamically composing streaming plugin pipelines.\")\n* [base-plugins](https://www.npmjs.com/package/base-plugins): Upgrade's plugin support in base applications to allow plugins to be called any time after… [more](https://github.com/node-base/base-plugins) | [homepage](https://github.com/node-base/base-plugins \"Upgrade's plugin support in base applications to allow plugins to be called any time after init.\")\n* [base-task](https://www.npmjs.com/package/base-task): base plugin that provides a very thin wrapper around [https://github.com/doowb/composer](https://github.com/doowb/composer) for adding task methods to… [more](https://github.com/node-base/base-task) | [homepage](https://github.com/node-base/base-task \"base plugin that provides a very thin wrapper around \u003chttps://github.com/doowb/composer\u003e for adding task methods to your application.\")\n* [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://github.com/node-base/base) | [homepage](https://github.com/node-base/base \"base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.\")\n* [composer](https://www.npmjs.com/package/composer): API-first task runner with three methods: task, run and watch. | [homepage](https://github.com/doowb/composer \"API-first task runner with three methods: task, run and watch.\")\n* [gulp](https://www.npmjs.com/package/gulp): The streaming build system | [homepage](http://gulpjs.com \"The streaming build system\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n### Contributors\n\n| **Commits** | **Contributor** | \n| --- | --- |\n| 227 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 6 | [doowb](https://github.com/doowb) |\n\n### Building docs\n\n_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_\n\nTo generate the readme and API documentation with [verb](https://github.com/verbose/verb):\n\n```sh\n$ npm install -g verb verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2016, [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.2.0, on November 22, 2016._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbase-repos%2Fbase-generators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbase-repos%2Fbase-generators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbase-repos%2Fbase-generators/lists"}