Skip to content

Commit

Permalink
grunt.spm.loadTasks only load tasks from NODE_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsiaoming Yang committed Mar 12, 2013
1 parent 9037e60 commit 217783d
Showing 1 changed file with 30 additions and 45 deletions.
75 changes: 30 additions & 45 deletions lib/sdk/grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,55 +83,40 @@ grunt.file.writeJSON = function(filepath, contents, options) {
grunt.spm = {};

// load all spm tasks and its plugins' tasks
grunt.spm.loadTasks = function(tasks) {
grunt.spm.loadTasks = function(name) {
var NODE_PATH = process.env.NODE_PATH;
if (!tasks) {
// load built-in tasks
// 1. grunt-spm-build
tasks = [];
tasks.push(path.dirname(require.resolve('grunt-spm-build')));
tasks.forEach(function(task) {
grunt.loadTasks(path.join(task, 'tasks'));
});
} else if (NODE_PATH) {
// load global tasks
if (!Array.isArray(tasks)) {
tasks = [tasks];
}
tasks.forEach(function(task) {
var rootdir = path.join(NODE_PATH, task);
var pkgfile = path.join(rootdir, 'package.json');
var pkg = grunt.file.exists(pkgfile) ? grunt.file.readJSON(pkgfile): {keywords: []};

var taskdir = path.join(rootdir, 'tasks');
// Process collection plugins
if (pkg.keywords && pkg.keywords.indexOf('gruntcollection') !== -1) {

Object.keys(pkg.dependencies).forEach(function(depName) {
var filepath = grunt.file.findup(path.join(rootdir, 'node_modules', depName), {
cwd: rootdir,
nocase: true
});
if (filepath) {
// Load this task plugin recursively
grunt.spm.loadTasks(path.relative(NODE_PATH, filepath));
}
});
// Load the tasks of itself
if (grunt.file.exists(taskdir)) {
grunt.loadTasks(taskdir);
}
return;
}
if (grunt.file.exists(taskdir)) {
grunt.loadTasks(taskdir);
} else {
grunt.log.error('Global task ' + task + ' not found.');
if (!NODE_PATH) {
grunt.log.error('Environment variable required: "NODE_PATH"');
process.exit(1);
}

log.info('load', name + ' from NODE_PATH');

var rootdir = path.join(NODE_PATH, name);
var pkgfile = path.join(rootdir, 'package.json');
var pkg = grunt.file.exists(pkgfile) ? grunt.file.readJSON(pkgfile): {keywords: []};

var taskdir = path.join(rootdir, 'tasks');
// Process collection plugins
if (pkg.keywords && pkg.keywords.indexOf('gruntcollection') !== -1) {

Object.keys(pkg.dependencies).forEach(function(depName) {
var filepath = path.join(rootdir, 'node_modules', depName);
if (grunt.file.exists(filepath)) {
// Load this task plugin recursively
grunt.spm.loadTasks(path.relative(NODE_PATH, filepath));
}
});
// Load the tasks of itself
if (grunt.file.exists(taskdir)) {
grunt.loadTasks(taskdir);
}
return;
}
if (grunt.file.exists(taskdir)) {
grunt.loadTasks(taskdir);
} else {
grunt.log.error('Environment variable required: "NODE_PATH"');
process.exit(1);
grunt.log.error('Global task ' + name + ' not found.');
}
};

Expand Down

0 comments on commit 217783d

Please sign in to comment.