UNPKG

1.96 kBJavaScriptView Raw
1/*
2 * grunt-dojo
3 * https://github.com/phated/grunt-dojo
4 *
5 * Copyright (c) 2013 Blaine Bublitz
6 * Licensed under the MIT license.
7 */
8
9module.exports = function(grunt) {
10
11 'use strict';
12
13 grunt.registerMultiTask('dojo', 'build dojo by spawning a child process', function(){
14
15 var done = this.async();
16
17 var options = this.options({
18 dojo: null,
19 load: 'build',
20 profile: null,
21 package: null,
22 packages: null,
23 require: null,
24 requires: null,
25 releaseDir: null,
26 cwd: null,
27 dojoConfig: null
28 });
29
30 grunt.log.subhead('Building Dojo...');
31
32 var args = [];
33 if(options.dojo){
34 args.push(options.dojo);
35 args.push('load=' + options.load);
36
37 if(options.profile){
38 args.push('--profile', options.profile);
39 }
40
41 /*
42 * Support both the singular and plural form of the 'package' and 'require' parameters
43 */
44 ['package', 'require'].forEach(function(dojoParam){
45 if(!Array.isArray(options[dojoParam+'s'])) {
46 options[dojoParam+'s'] = [];
47 }
48 if(options[dojoParam]){
49 options[dojoParam+'s'].push(options[dojoParam]);
50 }
51 options[dojoParam+'s'].forEach(function(packagePath){
52 args.push('--'+dojoParam, packagePath);
53 });
54 });
55
56
57 if(options.dojoConfig){
58 args.push('--dojoConfig', options.dojoConfig);
59 }
60
61 if(options.releaseDir){
62 args.push('--releaseDir', options.releaseDir);
63 }
64 } else {
65 grunt.log.error('No dojo specified');
66 done(false);
67 }
68
69 var opts = {};
70 if(options.cwd){
71 opts.cwd = options.cwd;
72 }
73
74 grunt.util.spawn({
75 cmd: 'node',
76 args: args,
77 opts: opts
78 }, function(err, result){
79 if(err){
80 grunt.log.error(err);
81 return done(false);
82 }
83
84 grunt.log.success('Dojo Successfully Built...');
85
86 done();
87 });
88
89 });
90
91};