Skip to content
Pascal Hartig edited this page Apr 11, 2013 · 4 revisions

actions#sourceRoot

Stores and return the source root for this class. The source root is used to prefix filepath with .read() or .template().

  • root - A string to resolve sourceRoot against.

Returns the source root value.

actions#destinationRoot

Sets the destination root for this class, the working directory.

Relatives path are added to the directory where the script was invoked and expanded.

This automatically creates the working directory if it doensn't exists and cd into it.

  • root - A string to resolve destinationRoot against.

Returns the destinatio root value.

actions#copy

Make some of the file API aware of our source / destination root paths. copy, template (only when could be applied/required by legacy code), write and alike consider:

  • source - the source path to be relative to generator's templates/ directory.
  • destination - the destination path to be relative to application Gruntfile's directory (most likely cwd)

actions#read

A simple method to read the content of the a file.

The encoding is utf8 by default, to read binary files, pass the proper encoding or null.

Non absolute path are prefixed by the source root.

  • source - A filepath String to read from
  • encoding - An optional encoding value to use (default: utf8)

Returns the file content

actions#write

Writes a chunk of data to a given filepath, checking for collision prior to the file write.

  • filepath - Path to write to
  • conent - File content to write

Returns the generator instance

actions#checkForCollision

File collision checked. Takes a filepath (the file about to be written) and the actual content. A basic check is done to see if the file exists, it it does:

  1. read its content from FS
  2. compare it with content provided
  3. if identical, mark it as is and skip the check
  4. if diverged, prepare and show up the file collision menu

The menu has the following options:

  • Y - yes, overwrite
  • n - no, do not overwrite
  • a - all, overwrite this and all others
  • q - quit, abort
  • d - diff, show the differences between the old and the new
  • h - help, show this help

actions#template

Use configured engine to render the provided source template at the given destination. data is an optional hash to pass to the template, if undefined, executes the template in the generator instance context.

actions#engine

The engine method is the function used whenever a template needs to be rendered.

It uses the configured engine (default: underscore) to render the body template with the provided data.

  • body - Template content
  • data - Data to render the template with

Returns the rendered string

actions#directory

Copies recursively the files from source directory to root directory.

  • source - Filepath of the directory to read from (relative to sourceRoot)
  • destination - Filepath to copy to (relative to destinationRoot) Returns the generator instance

actions#remote

Remotely fetch a package on github, store this into a _cache folder, and provide a "remote" object as a facade API to ourself (part of genrator API, copy, template, directory)

Example:

this.remote('user', 'repo', function(err, remote) {
  remote.copy('.', 'vendors/user-repo');
});

Returns the generator instance

remote#copy

Simple proxy to .copy(source, destination)

remote#template

same as .template(source, destination, data)

remote#directory

same as .template(source, destination)

actions#installDependencies

Runs npm and bower in the generated directory concurrently and prints a message to let the user know.

Options:

  • npm: bool, whether to run npm install, default: true
  • bower: bool, whether to run bower install, defaulkt: true
  • skipInstall: bool, whether to skip automatic installation and just print a message to the user how to do it, default: false

Example:

this.installDependencies({ bower: true, npm: true, skipInstall: false });

Returns the generator instance.

Clone this wiki locally