npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generate-file

v0.1.0

Published

Generator for generating a single file from a template.

Downloads

4

Readme

generate-file NPM version NPM downloads Build Status

Generator for generating a single file from a template.

What is generate?

Generate 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.

Visit the getting started guide or the generate project and documentation to learn more.

Quickstart

generate-file is a node.js application that is installed using npm. If you're unfamiliar with generate, it might help to visit the generate readme, or visit the getting started guide before continuing on.

Usage


CLI

Installing the CLI

To run the file generator from the command line, you'll need to install generate globally first. You can do that now with the following command:

$ npm i -g generate

This adds the gen command to your system path, allowing it to be run from any directory.

Help

Get general help and a menu of available commands:

$ gen help

Running the file generator

Once both generate and generate-file are installed globally, you can run the generator with the following command:

$ gen file

If completed successfully, you should see both starting and finished events in the terminal, like the following:

[00:44:21] starting ...
...
[00:44:22] finished ✔

If you do not see one or both of those events, please let us know about it.

Tasks

generate file

Creates a task for generating a single file for each view passed on options.views. If options.views is undefined, the templates collection is used.

Params

  • options {Object}

Example

var file = require('generate-file');

// use as a plugin
var generate = require('generate');
var app = generate();
app.template('license', {contents: fs.readFileSync('LICENSE')});
app.use(file());

app.generate('license', function(err) {
  if (err) return console.error(err);
});

// use as a plugin in your generator
module.exports = function(app) {
  app.use(file());
  // do other generator stuff
};

// use as a sub-generator
module.exports = function(app) {
  app.register('foo', file());
  // do other generator stuff

  app.task('default', function(cb) {
    // run task `bar` on sub-generator `foo`
    app.generate('foo:bar', cb);
  });
};

API

Use as a plugin in your generator

Use 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.

In your generator.js:

module.exports = function(app) {
  app.use(require('generate-file'));

  // specify any tasks from generate-file. Example:
  app.task('default', ['file']);
};

Use as a sub-generator

Use as a sub-generator if you want expose the features, settings and tasks from generate-file on a namespace in your generator.

In your generator.js:

module.exports = function(app) {
  // register the generate-file generator (as a sub-generator with an arbitrary name)
  app.register('foo', require('generate-file'));

  app.task('minify', function(cb) {
    // minify some stuff
    cb();
  });

  // run the "default" task on generate-file (aliased as `foo`), 
  // then run the `minify` task defined in our generator
  app.task('default', function(cb) {
    app.generate(['foo:default', 'minify'], cb);
  });
};

Tasks 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).

To learn more about namespaces and sub-generators, and how they work, visit the getting started guide.


Examples

This generator returns a function that needs to be called, so you can pass an options object if you need to customize anything.

var file = require('generate-file');
var generate = require('generate');
var app = generate();

// create an arbitrary template collection, or use
// the built-in generic collection `templates`
app.create('docs');

// add some views (a task will be created using the filename
// of each view, so you can run `foo` to generate the `foo` file)
app.doc('foo', {content: 'this is an example template'});
app.doc('bar', {content: 'another example template'});

// pass the collection on `options.views`, or if nothing
// is passed the `templates` view collection will be used
app.use(file({views: app.views.docs}));

Defaults

The following example shows how to use a custom collection. See the API docs below for an example of how to use the built-in generic templates collection.

var file = require('generate-file');
var generate = require('generate');
var app = generate();

// create an arbitrary template collection, or use
// the built-in generic collection `templates`
app.create('docs');

// add some views (a task will be created using the filename
// of each view, so you can run `foo` to generate the `foo` file)
app.doc('foo', {content: 'this is an example template'});
app.doc('bar', {content: 'another example template'});

// pass the collection on `options.views`, or if nothing
// is passed the `templates` view collection will be used
app.use(file({views: app.views.docs}));

Related projects

You might also be interested in these projects:

  • generate-dest: Generate generator that prompts the user for the destination directory to use. Can be used… more | homepage
  • generate-node: Generate a node.js project, with everything you need to begin writing code and easily publish… more | homepage
  • generate: Fast, composable, highly pluggable project generator with a user-friendly and expressive API. | homepage

Contributing

This document was generated by verb, please don't edit directly. Any changes to the readme must be made in .verb.md. See Building Docs.

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install -g verb verb-readme-generator && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on June 01, 2016.