broccoli-rename-files

Rename files


Keywords
broccoli, broccoli-plugin, rename, prepend, append, file
License
MIT
Install
npm install broccoli-rename-files@1.0.1

Documentation

broccoli-rename-files Build Status

Deprecated

This project has been deprecated in favor of broccoli-funnel. Please see getDestinationPath for a corresponding API.


Rename files in a tree. Currently only prepend/append is supported and doesn't touch file extensions, but will eventually add more features.

Install

$ npm install broccoli-rename-files

Simple Usage

You can easily add text around a filename using the prepend and append options. The following example renames path/to/file.txt to path/to/wow-file-new.txt

var BroccoliRenameFiles = require('broccoli-rename-files');

tree = new BroccoliRenameFiles(tree, {
  prepend: 'wow-',
  append: '-new'
});

Complex Usage

To achieve more complex renames, override the filter's transformFilename function. It receives the full filename, the basename, and the extension name (as calculated by node's native path module). These arguments are somewhat redundant, but they allow you to easily construct the filename you want.

For reference, here is the default implementation. Note that you can access options on the filter:

function(filename, basename, extname) {
  var prepend = this.options.prepend || '';
  var append = this.options.append || '';

  return prepend + basename + append + extname;
};

And here is a version that renames foo.module.js to foo.js.

var BroccoliRenameFiles = require('broccoli-rename-files');

tree = new BroccoliRenameFiles(tree, {
  transformFilename: function(filename, basename, extname) {
    return filename.replace('.module', '');
  }
});

This filter is not intended to move files between directories. There are other filters that do that well.

API

renameFiles(tree, options)

Options

options.prepend {String} Optional. The string to be prepended to the filename.

options.append {String} Optional. The string to be appended to the filename.

options.keepOriginal {Boolean} Optional. Whether to keep the original file as well.

License

MIT © Gabor Babicz