1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | var path = require('path');
|
38 |
|
39 | module.exports = function(grunt) {
|
40 | grunt.registerMultiTask('lumbar', 'Starts a lumbar process', function() {
|
41 |
|
42 | var done = this.async();
|
43 |
|
44 | var config = this.data,
|
45 | lumbarFile = config.watch || config.build || './lumbar.json',
|
46 | outputDir = config.output || './public',
|
47 | mode;
|
48 |
|
49 | if (config.build) {
|
50 | mode = 'build';
|
51 | }
|
52 | if (config.watch) {
|
53 | mode = 'watch';
|
54 | }
|
55 |
|
56 | if (mode !== 'watch' && mode !== 'build') {
|
57 | grunt.fatal('Arguments to lumbar task must be watch: {}, or build: {}');
|
58 | }
|
59 |
|
60 | if (!('background' in config)) {
|
61 |
|
62 | config.background = mode !== 'build';
|
63 | }
|
64 |
|
65 |
|
66 | if (mode === 'build') {
|
67 | if (config.background) {
|
68 | grunt.warn('You can\'t do a lumbar build in the background, forcing non-background execution...');
|
69 | }
|
70 | config.background = false;
|
71 | }
|
72 |
|
73 |
|
74 | var command = [
|
75 | 'node',
|
76 | path.join(__dirname, '../bin/lumbar'),
|
77 | mode
|
78 | ];
|
79 |
|
80 | if (config.package) {
|
81 | command.push('--package');
|
82 | command.push(config.package);
|
83 | }
|
84 |
|
85 | if (config.config) {
|
86 | command.push('--config');
|
87 | command.push(config.config);
|
88 | }
|
89 |
|
90 | if (config.minimize) {
|
91 | command.push('--minimize');
|
92 | }
|
93 |
|
94 | if (config.use) {
|
95 | command.push('--use');
|
96 | command.push(config.use);
|
97 | }
|
98 |
|
99 | if (config.withJson) {
|
100 | command.push('--with');
|
101 | command.push(JSON.stringify(config.withJson));
|
102 | }
|
103 |
|
104 | if (config.plugins) {
|
105 | config.plugins.forEach(function(plugin) {
|
106 | if (plugin.use) {
|
107 | command.push('--use');
|
108 | command.push(plugin.use);
|
109 | }
|
110 |
|
111 | if (plugin.withJson) {
|
112 | command.push('--with');
|
113 | command.push(JSON.stringify(plugin.withJson));
|
114 | }
|
115 | });
|
116 | }
|
117 |
|
118 | if (config.libraries) {
|
119 | config.libraries.forEach(function(library) {
|
120 | command.push('--library=' + library);
|
121 | });
|
122 | }
|
123 |
|
124 | if (config.verbose) {
|
125 | command.push('--verbose');
|
126 | }
|
127 |
|
128 | if (config.sourceMap) {
|
129 | command.push('--sourceMap' + (config.sourceMap !== true ? '=' + config.sourceMap : ''));
|
130 | }
|
131 |
|
132 | command.push(lumbarFile);
|
133 | command.push(outputDir);
|
134 |
|
135 | var lumbarProcess = require('child_process').spawn(command.shift(), command, { stdio: 'inherit', cwd: config.cwd });
|
136 | if (config.background) {
|
137 | done(true);
|
138 | } else {
|
139 | lumbarProcess.on('exit', function() {
|
140 | done(lumbarProcess.exitCode);
|
141 | });
|
142 | }
|
143 | });
|
144 | }
|