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 | config.background = true;
|
62 | }
|
63 |
|
64 |
|
65 | if (mode === 'build') {
|
66 | if (config.background) {
|
67 | grunt.warn('You can\'t do a lumbar build in the background, forcing non-background execution...');
|
68 | }
|
69 | config.background = false;
|
70 | }
|
71 |
|
72 |
|
73 | var command = [
|
74 | 'node',
|
75 | path.join(__dirname, '../bin/lumbar'),
|
76 | mode
|
77 | ];
|
78 |
|
79 | if (config.package) {
|
80 | command.push('--package ' + config.package);
|
81 | }
|
82 |
|
83 | if (config.config) {
|
84 | command.push('--config');
|
85 | command.push(config.config);
|
86 | }
|
87 |
|
88 | if (config.minimize) {
|
89 | command.push('--minimize');
|
90 | }
|
91 |
|
92 | if (config.use) {
|
93 | command.push('--use');
|
94 | command.push(config.use);
|
95 | }
|
96 |
|
97 | if (config.withJson) {
|
98 | command.push('--with');
|
99 | command.push(JSON.stringify(config.withJson));
|
100 | }
|
101 |
|
102 | if (config.plugins) {
|
103 | config.plugins.forEach(function(plugin) {
|
104 | if (plugin.use) {
|
105 | command.push('--use');
|
106 | command.push(plugin.use);
|
107 | }
|
108 |
|
109 | if (plugin.withJson) {
|
110 | command.push('--with');
|
111 | command.push(JSON.stringify(plugin.withJson));
|
112 | }
|
113 | });
|
114 | }
|
115 |
|
116 | if (config.libraries) {
|
117 | config.libraries.forEach(function(library) {
|
118 | command.push('--library=' + library);
|
119 | });
|
120 | }
|
121 |
|
122 | if (config.verbose) {
|
123 | command.push('--verbose');
|
124 | }
|
125 |
|
126 | if (config.sourceMap) {
|
127 | command.push('--sourceMap');
|
128 | }
|
129 |
|
130 | command.push(lumbarFile);
|
131 | command.push(outputDir);
|
132 |
|
133 | var lumbarProcess = require('child_process').spawn(command.shift(), command);
|
134 |
|
135 | lumbarProcess.stdout.on('data', function(data) {
|
136 | process.stdout.write(data.toString());
|
137 | });
|
138 | lumbarProcess.stderr.on('data', function(data) {
|
139 | process.stdout.write(data.toString());
|
140 | });
|
141 |
|
142 | if (config.background) {
|
143 | done(true);
|
144 | } else {
|
145 | lumbarProcess.on('exit', function() {
|
146 | done(true);
|
147 | });
|
148 | }
|
149 | });
|
150 | }
|