{"id":20551473,"url":"https://github.com/generate/generate-file","last_synced_at":"2025-07-18T11:11:39.294Z","repository":{"id":93328415,"uuid":"60216762","full_name":"generate/generate-file","owner":"generate","description":"Generator for generating a single file from a template.","archived":false,"fork":false,"pushed_at":"2016-06-01T23:11:21.000Z","size":13,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T00:41:32.944Z","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/generate.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-06-01T23:11:05.000Z","updated_at":"2023-06-19T16:09:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"5c23cab5-4d91-4b31-a801-deb1cfc37a10","html_url":"https://github.com/generate/generate-file","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/generate%2Fgenerate-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generate%2Fgenerate-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generate%2Fgenerate-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generate%2Fgenerate-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/generate","download_url":"https://codeload.github.com/generate/generate-file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248589983,"owners_count":21129721,"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-16T02:31:10.654Z","updated_at":"2025-04-14T11:23:05.362Z","avatar_url":"https://github.com/generate.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# generate-file [![NPM version](https://img.shields.io/npm/v/generate-file.svg?style=flat)](https://www.npmjs.com/package/generate-file) [![NPM downloads](https://img.shields.io/npm/dm/generate-file.svg?style=flat)](https://npmjs.org/package/generate-file) [![Build Status](https://img.shields.io/travis/generate/generate-file.svg?style=flat)](https://travis-ci.org/generate/generate-file)\n\nGenerator for generating a single file from a template.\n\n## What is generate?\n\nGenerate is a new, open source developer framework for rapidly initializing and scaffolding out new code projects, offering an intuitive CLI, and a powerful and expressive API that makes it easy and enjoyable to use.\n\nVisit the [getting started guide](https://github.com/generate/getting-started-guide) or the [generate](https://github.com/generate/generate) project and documentation to learn more.\n\n## Quickstart\n\ngenerate-file is a [node.js](https://nodejs.org/en/) application that is installed using [npm](https://www.npmjs.com/). If you're unfamiliar with generate, it might help to visit the [generate](https://github.com/generate/generate) readme, or visit the [getting started guide](https://github.com/generate/getting-started-guide) before continuing on.\n\n**Usage**\n\n* [CLI usage](#cli)\n* [API usage](#api)\n\n***\n\n### CLI\n\n**Installing the CLI**\n\nTo run the `file` generator from the command line, you'll need to install [generate](https://github.com/generate/generate) globally first. You can do that now with the following command:\n\n```sh\n$ npm i -g generate\n```\n\nThis adds the `gen` command to your system path, allowing it to be run from any directory.\n\n**Help**\n\nGet general help and a menu of available commands:\n\n```sh\n$ gen help\n```\n\n**Running the `file` generator**\n\nOnce both [generate](https://github.com/generate/generate) and `generate-file` are installed globally, you can run the generator with the following command:\n\n```sh\n$ gen file\n```\n\nIf completed successfully, you should see both `starting` and `finished` events in the terminal, like the following:\n\n```sh\n[00:44:21] starting ...\n...\n[00:44:22] finished ✔\n```\n\nIf you do not see one or both of those events, please [let us know about it](../../issues).\n\n### Tasks\n\n#### [generate file](generator.js#L46)\n\nCreates a task for generating a single file for each `view` passed on `options.views`. If `options.views` is undefined, the `templates` collection is used.\n\n**Params**\n\n* `options` **{Object}**\n\n**Example**\n\n```js\nvar file = require('generate-file');\n\n// use as a plugin\nvar generate = require('generate');\nvar app = generate();\napp.template('license', {contents: fs.readFileSync('LICENSE')});\napp.use(file());\n\napp.generate('license', function(err) {\n  if (err) return console.error(err);\n});\n\n// use as a plugin in your generator\nmodule.exports = function(app) {\n  app.use(file());\n  // do other generator stuff\n};\n\n// use as a sub-generator\nmodule.exports = function(app) {\n  app.register('foo', file());\n  // do other generator stuff\n\n  app.task('default', function(cb) {\n    // run task `bar` on sub-generator `foo`\n    app.generate('foo:bar', cb);\n  });\n};\n```\n\n***\n\n### API\n\n**Use as a plugin in your generator**\n\nUse as a plugin if you want to extend your own generator with the features, settings and tasks of generate-file, as if they were created on your generator.\n\nIn your [generator.js](#overview):\n\n```js\nmodule.exports = function(app) {\n  app.use(require('generate-file'));\n\n  // specify any tasks from generate-file. Example:\n  app.task('default', ['file']);\n};\n```\n\n**Use as a sub-generator**\n\nUse as a sub-generator if you want expose the features, settings and tasks from generate-file on a _namespace_ in your generator.\n\nIn your [generator.js](#overview):\n\n```js\nmodule.exports = function(app) {\n  // register the generate-file generator (as a sub-generator with an arbitrary name)\n  app.register('foo', require('generate-file'));\n\n  app.task('minify', function(cb) {\n    // minify some stuff\n    cb();\n  });\n\n  // run the \"default\" task on generate-file (aliased as `foo`), \n  // then run the `minify` task defined in our generator\n  app.task('default', function(cb) {\n    app.generate(['foo:default', 'minify'], cb);\n  });\n};\n```\n\nTasks from `generate-file` will be available on the `foo` namespace from the API and the command line. Continuing with the previous code example, to run the `default` task on `generate-file`, you would run `gen foo:default` (or just `gen foo` if `foo` does not conflict with an existing task on your generator).\n\nTo learn more about namespaces and sub-generators, and how they work, [visit the getting started guide](https://github.com/generate/getting-started-guide).\n\n***\n\n## Examples\n\nThis generator returns a function that needs to be called, so you can pass an options object if you need to customize anything.\n\n```js\nvar file = require('generate-file');\nvar generate = require('generate');\nvar app = generate();\n\n// create an arbitrary template collection, or use\n// the built-in generic collection `templates`\napp.create('docs');\n\n// add some views (a task will be created using the filename\n// of each view, so you can run `foo` to generate the `foo` file)\napp.doc('foo', {content: 'this is an example template'});\napp.doc('bar', {content: 'another example template'});\n\n// pass the collection on `options.views`, or if nothing\n// is passed the `templates` view collection will be used\napp.use(file({views: app.views.docs}));\n```\n\n**Defaults**\n\nThe following example shows how to use a custom collection. See the [API docs](#api) below for an example of how to use the built-in generic `templates` collection.\n\n```js\nvar file = require('generate-file');\nvar generate = require('generate');\nvar app = generate();\n\n// create an arbitrary template collection, or use\n// the built-in generic collection `templates`\napp.create('docs');\n\n// add some views (a task will be created using the filename\n// of each view, so you can run `foo` to generate the `foo` file)\napp.doc('foo', {content: 'this is an example template'});\napp.doc('bar', {content: 'another example template'});\n\n// pass the collection on `options.views`, or if nothing\n// is passed the `templates` view collection will be used\napp.use(file({views: app.views.docs}));\n```\n\n## Related projects\n\nYou might also be interested in these projects:\n\n* [generate-dest](https://www.npmjs.com/package/generate-dest): `Generate` generator that prompts the user for the destination directory to use. Can be used… [more](https://www.npmjs.com/package/generate-dest) | [homepage](https://github.com/generate/generate-dest)\n* [generate-node](https://www.npmjs.com/package/generate-node): Generate a node.js project, with everything you need to begin writing code and easily publish… [more](https://www.npmjs.com/package/generate-node) | [homepage](https://github.com/generate/generate-node)\n* [generate](https://www.npmjs.com/package/generate): Fast, composable, highly pluggable project generator with a user-friendly and expressive API. | [homepage](https://github.com/generate/generate)\n\n## Contributing\n\nThis document was generated by [verb](https://github.com/verbose/verb), please don't edit directly. Any changes to the readme must be made in [.verb.md](.verb.md). See [Building Docs](#building-docs).\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/generate/generate-file/issues/new).\n\n## Building docs\n\nGenerate readme and API documentation with [verb](https://github.com/verbose/verb):\n\n```sh\n$ npm install -g verb verb-readme-generator \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](https://github.com/generate/generate-file/blob/master/LICENSE).\n\n***\n\n_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on June 01, 2016._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenerate%2Fgenerate-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenerate%2Fgenerate-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenerate%2Fgenerate-file/lists"}