| 1 |
module.exports = function (grunt) { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
var wpmudev = {}; |
| 5 |
|
| 6 |
wpmudev.files = require('./files')(grunt); |
| 7 |
wpmudev.environment = require('./environment')(grunt); |
| 8 |
|
| 9 |
wpmudev.loader = { |
| 10 |
dependencies: { |
| 11 |
"makepot": "grunt-wp-i18n", |
| 12 |
"clean": "grunt-contrib-clean", |
| 13 |
"compress": "grunt-contrib-compress", |
| 14 |
"copy": "grunt-contrib-copy" |
| 15 |
}, |
| 16 |
load: function () { |
| 17 |
grunt.verbose.subhead("Loading WPMU DEV tasks"); |
| 18 |
|
| 19 |
grunt.file.expand({ |
| 20 |
filter: 'isFile' |
| 21 |
}, wpmudev.files.stem_path('external', 'shared-tasks') + '/**/wpmudev_*.js').forEach(function (task) { |
| 22 |
grunt.verbose.writeln("Loading task definition file", task); |
| 23 |
require('../' + task)(grunt, wpmudev); |
| 24 |
}); |
| 25 |
}, |
| 26 |
setup: function () { |
| 27 |
grunt.verbose.subhead("Checking WPMU DEV task dependencies"); |
| 28 |
var spawn = require('child_process').spawnSync, |
| 29 |
which = require('which').sync, |
| 30 |
has_missing = false |
| 31 |
; |
| 32 |
|
| 33 |
for (var task in wpmudev.loader.dependencies) { |
| 34 |
if (wpmudev.environment.has_task(task)) continue; |
| 35 |
|
| 36 |
var dep = wpmudev.loader.dependencies[task]; |
| 37 |
|
| 38 |
has_missing = true; |
| 39 |
grunt.log.warn("Missing task dependency:", dep); |
| 40 |
|
| 41 |
spawn( |
| 42 |
which('npm'), |
| 43 |
['install', '--save-dev', dep], |
| 44 |
{ |
| 45 |
stdio: 'inherit', |
| 46 |
shell: true |
| 47 |
} |
| 48 |
); |
| 49 |
grunt.verbose.writeln("Loading npm-defined tasks for", dep); |
| 50 |
grunt.task.loadNpmTasks(dep); |
| 51 |
} |
| 52 |
|
| 53 |
if (has_missing) { |
| 54 |
grunt.log.writeln("Some missing dependencies installed, please make sure you commit your package.json".red.bold); |
| 55 |
} |
| 56 |
|
| 57 |
return wpmudev.loader.load(); |
| 58 |
}, |
| 59 |
}; |
| 60 |
|
| 61 |
wpmudev.loader.setup(); |
| 62 |
|
| 63 |
return wpmudev; |
| 64 |
|
| 65 |
}; |
| 66 |
|