Skip to content
Find files and process their paths in a template.
CoffeeScript JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
tasks
test
.editorconfig
.gitattributes
.gitignore
.jshintrc
.npmignore
.travis.yml
Gruntfile.coffee
LICENSE-MIT
README.md
package.json

README.md

grunt-pathfinder Build Status

Find files and process their paths in a template.

Getting Started

If you haven't used grunt before, be sure to check out the Getting Started guide.

From the same directory as your project's Gruntfile and package.json, install this plugin with the following command:

npm install grunt-pathfinder --save-dev

Once that's done, add this line to your project's Gruntfile:

grunt.loadNpmTasks('grunt-pathfinder');

If the plugin has been installed correctly, running grunt --help at the command line should list the newly-installed plugin's task or tasks. In addition, the plugin should be listed in package.json as a devDependency, which ensures that it will be installed whenever the npm install command is run.

The "importjs" task

Overview

In your project's Gruntfile, add a section named pathfinder to the data object passed into grunt.initConfig().

grunt.initConfig({
  pathfinder: {
    main: {
      files:
        'path/to/output.js': ['some/**/*.js', 'other/whatever.js'],
      template: 'path/to/template.js'
    }
  }
});

The pathfinder task

Overview

Inside your Gruntfile, add a section named pathfinder. This section specifies the possible locations of files, the template which the found filepaths are passed to and the output file (compiled template).

Settings

There are a number of options available. Please review the minimatch options here. As well as some additional options as follows:

files

Type: object

key:value pair that describes outputFile:filesToImport. This defines where the compiled template output will be saved to (key) where files are being looked for (value). Value can be a string or an array of files and/or minimatch patterns.

template

Type: String

The template file will be parsed using grunt.template and the found file paths will be passed as data. The paths array is available in your template file.

Events

grunt-pathfinder emits and events using grunt.event.emit called pathfinder-paths. If you listen on this event, you can manipulate the paths array (e.g. filter it) and save it before it gets passed to the template. A use case of this is the [importless][] example config in the Gruntfile.

Something went wrong with that request. Please try again.