Skip to content

Commit

Permalink
Merge pull request #41 from schmod/cwd
Browse files Browse the repository at this point in the history
Allow user to specify working directory
  • Loading branch information
shootaroo committed Jan 5, 2016
2 parents 72e379f + 87f9c3e commit 6f7e63e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,19 @@ require('jit-grunt')(grunt, {

### Options

#### cwd

Type: `Strong`
Default: `process.cwd()`

All plugins and tasks are resolved relative to this path.

#### pluginsRoot

Type: `String`
Default: `'node_modules'`

Root directory of grunt plugins.
Root directory of grunt plugins, relative to the working directory.

```js
require('jit-grunt')(grunt)({
Expand All @@ -122,7 +129,7 @@ require('jit-grunt')(grunt)({
Type: `String`
Default: `null`

JIT Loading for custom tasks dir (replacement of [grunt.loadTasks]).
JIT Loading for custom tasks dir (replacement of [grunt.loadTasks]), relative to the working directory..

```js
require('jit-grunt')(grunt)({
Expand Down
5 changes: 5 additions & 0 deletions jit-grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ module.exports = function (grunt, mappings) {
if (options.pluginsRoot) {
jit.pluginsRoot = options.pluginsRoot;
}

if (options.cwd) {
jit.cwd = options.cwd;
}

};
};
9 changes: 5 additions & 4 deletions src/jit-grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const EXTENSIONS = ['.coffee', '.js'];

const jit = {
pluginsRoot: 'node_modules',
mappings: {}
mappings: {},
cwd: process.cwd()
};


Expand All @@ -28,13 +29,13 @@ jit.findPlugin = function (taskName) {
if (this.mappings.hasOwnProperty(taskName)) {
pluginName = this.mappings[taskName];
if (pluginName.indexOf('/') >= 0 && pluginName.indexOf('@') !== 0) {
taskPath = path.resolve(pluginName);
taskPath = path.resolve(this.cwd, pluginName);
if (fs.existsSync(taskPath)) {
return this.loadPlugin(taskName, taskPath, true);
}
} else {
let dir = path.join(this.pluginsRoot, pluginName, 'tasks');
taskPath = this.findUp(path.resolve(), function (cwd) {
taskPath = this.findUp(this.cwd, function (cwd) {
let findPath = path.join(cwd, dir);
return fs.existsSync(findPath) ? findPath : null;
});
Expand All @@ -56,7 +57,7 @@ jit.findPlugin = function (taskName) {

// Auto Mappings
let dashedName = taskName.replace(/([A-Z])/g, '-$1').replace(/_+/g, '-').toLowerCase();
taskPath = this.findUp(path.resolve(), cwd => {
taskPath = this.findUp(this.cwd, cwd => {
for (let p = PREFIXES.length; p--;) {
pluginName = PREFIXES[p] + dashedName;
let findPath = path.join(cwd, this.pluginsRoot, pluginName, 'tasks');
Expand Down

0 comments on commit 6f7e63e

Please sign in to comment.