milkee 0.2.1 → 2.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +189 -59
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
2
|
(function() {
|
|
3
|
-
var CONFIG_FILE, CONFIG_PATH, CWD, argv, checkCoffee, compile, consola, exec, fs, hideBin, path, pkg, setup, yargs;
|
|
3
|
+
var CONFIG_FILE, CONFIG_PATH, CWD, argv, checkCoffee, compile, consola, exec, executePlugins, fs, getCompiledFiles, hideBin, path, pkg, runPlugins, setup, spawn, yargs;
|
|
4
4
|
|
|
5
5
|
yargs = require('yargs');
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
path = require('path');
|
|
14
14
|
|
|
15
|
-
({exec} = require('child_process'));
|
|
15
|
+
({exec, spawn} = require('child_process'));
|
|
16
16
|
|
|
17
17
|
pkg = require('../package.json');
|
|
18
18
|
|
|
@@ -80,8 +80,83 @@
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
getCompiledFiles = function(targetPath) {
|
|
84
|
+
var error, filesList, i, item, itemPath, items, len, stat;
|
|
85
|
+
filesList = [];
|
|
86
|
+
if (!fs.existsSync(targetPath)) {
|
|
87
|
+
consola.trace(`Path does not exist, skipping scan ${targetPath}`);
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
stat = fs.statSync(targetPath);
|
|
92
|
+
if (stat.isDirectory()) {
|
|
93
|
+
consola.trace(`Scanning directory: ${targetPath}`);
|
|
94
|
+
items = fs.readdirSync(targetPath);
|
|
95
|
+
for (i = 0, len = items.length; i < len; i++) {
|
|
96
|
+
item = items[i];
|
|
97
|
+
itemPath = path.join(targetPath, item);
|
|
98
|
+
filesList = filesList.concat(getCompiledFiles(itemPath));
|
|
99
|
+
}
|
|
100
|
+
} else if (stat.isFile()) {
|
|
101
|
+
if (targetPath.endsWith('.js' || targetPath.endsWith('.js.map'))) {
|
|
102
|
+
consola.trace(`Found file: ${targetPath}`);
|
|
103
|
+
filesList.push(targetPath);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (error1) {
|
|
107
|
+
error = error1;
|
|
108
|
+
consola.warn(`Could not scan output path ${targetPath}: ${error.message}`);
|
|
109
|
+
}
|
|
110
|
+
return filesList;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
executePlugins = function(config, compilationResult) {
|
|
114
|
+
var plugins, ref;
|
|
115
|
+
plugins = ((ref = config.milkee) != null ? ref.plugins : void 0) || [];
|
|
116
|
+
if (!(plugins.length > 0)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
consola.start(`Running ${plugins.length} plugin(s)...`);
|
|
120
|
+
return (async function() {
|
|
121
|
+
var error, i, len, pluginFn;
|
|
122
|
+
try {
|
|
123
|
+
for (i = 0, len = plugins.length; i < len; i++) {
|
|
124
|
+
pluginFn = plugins[i];
|
|
125
|
+
if (typeof pluginFn === 'function') {
|
|
126
|
+
await Promise.resolve(pluginFn(compilationResult));
|
|
127
|
+
} else {
|
|
128
|
+
consola.warn(`Invalid plugin definition skipped (expected a function, got ${typeof pluginFn}).`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return consola.success("Plugins executed successfully.");
|
|
132
|
+
} catch (error1) {
|
|
133
|
+
error = error1;
|
|
134
|
+
return consola.error("An error occurred during plugin execution:", error);
|
|
135
|
+
}
|
|
136
|
+
})();
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
runPlugins = function(config, options, stdout = '', stderr = '') {
|
|
140
|
+
var compilationResult, compiledFiles, mapPath, outputPath;
|
|
141
|
+
outputPath = path.join(CWD, config.output);
|
|
142
|
+
compiledFiles = getCompiledFiles(outputPath);
|
|
143
|
+
if (options.join && options.map && !options.inlineMap) {
|
|
144
|
+
mapPath = `${outputPath}.map`;
|
|
145
|
+
if (fs.existsSync(mapPath && !compiledFiles.includes(mapPath))) {
|
|
146
|
+
compiledFiles = compiledFiles.concat(getCompiledFiles(mapPath));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
compilationResult = {
|
|
150
|
+
config: config,
|
|
151
|
+
compiledFiles: compiledFiles,
|
|
152
|
+
stdout: stdout,
|
|
153
|
+
stderr: stderr
|
|
154
|
+
};
|
|
155
|
+
return executePlugins(config, compilationResult);
|
|
156
|
+
};
|
|
157
|
+
|
|
83
158
|
compile = async function() {
|
|
84
|
-
var
|
|
159
|
+
var compilerProcess, config, debounceTimeout, enabledOptions, enabledOptionsList, error, execCommand, execCommandParts, execOtherOptionStrings, i, item, itemPath, items, lastError, len, milkee, milkeeOptions, options, optionsForPlugins, spawnArgs, summary, targetDir, toContinue;
|
|
85
160
|
checkCoffee();
|
|
86
161
|
if (!fs.existsSync(CONFIG_PATH)) {
|
|
87
162
|
consola.error(`\`${CONFIG_FILE}\` not found in this directory: ${CWD}`);
|
|
@@ -97,63 +172,84 @@
|
|
|
97
172
|
options = config.options || {};
|
|
98
173
|
milkee = config.milkee || {};
|
|
99
174
|
milkeeOptions = config.milkee.options || {};
|
|
100
|
-
|
|
175
|
+
execCommandParts = ['coffee'];
|
|
101
176
|
if (options.join) {
|
|
102
|
-
|
|
103
|
-
|
|
177
|
+
execCommandParts.push('--join');
|
|
178
|
+
execCommandParts.push(`\"${config.output}\"`);
|
|
104
179
|
} else {
|
|
105
|
-
|
|
106
|
-
|
|
180
|
+
execCommandParts.push('--output');
|
|
181
|
+
execCommandParts.push(`\"${config.output}\"`);
|
|
107
182
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
183
|
+
execOtherOptionStrings = [];
|
|
184
|
+
if (options.bare) {
|
|
185
|
+
execOtherOptionStrings.push('--bare');
|
|
186
|
+
}
|
|
187
|
+
if (options.map) {
|
|
188
|
+
execOtherOptionStrings.push('--map');
|
|
189
|
+
}
|
|
190
|
+
if (options.inlineMap) {
|
|
191
|
+
execOtherOptionStrings.push('--inline-map');
|
|
192
|
+
}
|
|
193
|
+
if (options.noHeader) {
|
|
194
|
+
execOtherOptionStrings.push('--no-header');
|
|
195
|
+
}
|
|
196
|
+
if (options.transpile) {
|
|
197
|
+
execOtherOptionStrings.push('--transpile');
|
|
198
|
+
}
|
|
199
|
+
if (options.literate) {
|
|
200
|
+
execOtherOptionStrings.push('--literate');
|
|
201
|
+
}
|
|
202
|
+
if (execOtherOptionStrings.length > 0) {
|
|
203
|
+
execCommandParts.push(execOtherOptionStrings.join(' '));
|
|
204
|
+
}
|
|
205
|
+
execCommandParts.push('--compile');
|
|
206
|
+
execCommandParts.push(`\"${config.entry}\"`);
|
|
207
|
+
execCommand = execCommandParts.filter(Boolean).join(' ');
|
|
208
|
+
spawnArgs = [];
|
|
209
|
+
if (options.join) {
|
|
210
|
+
spawnArgs.push('--join');
|
|
211
|
+
spawnArgs.push(config.output);
|
|
212
|
+
} else {
|
|
213
|
+
spawnArgs.push('--output');
|
|
214
|
+
spawnArgs.push(config.output);
|
|
117
215
|
}
|
|
118
|
-
consola.box({
|
|
119
|
-
title: "Milkee Compilation Summary",
|
|
120
|
-
message: summary.join('\n')
|
|
121
|
-
});
|
|
122
|
-
otherOptionStrings = [];
|
|
123
216
|
if (options.bare) {
|
|
124
|
-
|
|
217
|
+
spawnArgs.push('--bare');
|
|
125
218
|
}
|
|
126
|
-
// consola.info "Option `bare` is selected."
|
|
127
219
|
if (options.map) {
|
|
128
|
-
|
|
220
|
+
spawnArgs.push('--map');
|
|
129
221
|
}
|
|
130
|
-
// consola.info "Option `map` is selected."
|
|
131
222
|
if (options.inlineMap) {
|
|
132
|
-
|
|
223
|
+
spawnArgs.push('--inline-map');
|
|
133
224
|
}
|
|
134
|
-
// consola.info "Option `inline-map` is selected."
|
|
135
225
|
if (options.noHeader) {
|
|
136
|
-
|
|
226
|
+
spawnArgs.push('--no-header');
|
|
137
227
|
}
|
|
138
|
-
// consola.info "Option `no-header` is selected."
|
|
139
228
|
if (options.transpile) {
|
|
140
|
-
|
|
229
|
+
spawnArgs.push('--transpile');
|
|
141
230
|
}
|
|
142
|
-
// consola.info "Option `transpile` is selected."
|
|
143
231
|
if (options.literate) {
|
|
144
|
-
|
|
232
|
+
spawnArgs.push('--literate');
|
|
145
233
|
}
|
|
146
|
-
// consola.info "Option `literate` is selected."
|
|
147
234
|
if (options.watch) {
|
|
148
|
-
|
|
235
|
+
spawnArgs.push('--watch');
|
|
149
236
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
237
|
+
spawnArgs.push('--compile');
|
|
238
|
+
spawnArgs.push(config.entry);
|
|
239
|
+
summary = [];
|
|
240
|
+
summary.push(`Entry: \`${config.entry}\``);
|
|
241
|
+
summary.push(`Output: \`${config.output}\``);
|
|
242
|
+
enabledOptions = Object.keys(options).filter(function(key) {
|
|
243
|
+
return options[key];
|
|
244
|
+
});
|
|
245
|
+
if (enabledOptions.length > 0) {
|
|
246
|
+
enabledOptionsList = enabledOptions.join(',');
|
|
247
|
+
summary.push(`Options: ${enabledOptionsList}`);
|
|
153
248
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
249
|
+
consola.box({
|
|
250
|
+
title: "Milkee Compilation Summary",
|
|
251
|
+
message: summary.join('\n')
|
|
252
|
+
});
|
|
157
253
|
if (milkeeOptions.confirm) {
|
|
158
254
|
toContinue = (await consola.prompt("Do you want to continue?", {
|
|
159
255
|
type: "confirm"
|
|
@@ -163,6 +259,7 @@
|
|
|
163
259
|
return;
|
|
164
260
|
}
|
|
165
261
|
}
|
|
262
|
+
optionsForPlugins = {...options};
|
|
166
263
|
delete options.join;
|
|
167
264
|
if (milkeeOptions.refresh) {
|
|
168
265
|
targetDir = path.join(CWD, config.output);
|
|
@@ -170,7 +267,6 @@
|
|
|
170
267
|
consola.info("Refresh skipped.");
|
|
171
268
|
} else {
|
|
172
269
|
consola.info("Executing: Refresh");
|
|
173
|
-
// Refresh
|
|
174
270
|
items = fs.readdirSync(targetDir);
|
|
175
271
|
for (i = 0, len = items.length; i < len; i++) {
|
|
176
272
|
item = items[i];
|
|
@@ -185,12 +281,51 @@
|
|
|
185
281
|
}
|
|
186
282
|
if (options.watch) {
|
|
187
283
|
consola.start(`Watching for changes in \`${config.entry}\`...`);
|
|
284
|
+
consola.info(`Executing: coffee ${spawnArgs.join(' ')}`);
|
|
285
|
+
compilerProcess = spawn('coffee', spawnArgs, {
|
|
286
|
+
shell: false
|
|
287
|
+
});
|
|
288
|
+
debounceTimeout = null;
|
|
289
|
+
lastError = null;
|
|
290
|
+
compilerProcess.stderr.on('data', function(data) {
|
|
291
|
+
var errorMsg;
|
|
292
|
+
errorMsg = data.toString().trim();
|
|
293
|
+
if (errorMsg) {
|
|
294
|
+
consola.error(errorMsg);
|
|
295
|
+
return lastError = errorMsg;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
compilerProcess.stdout.on('data', function(data) {
|
|
299
|
+
var stdoutMsg;
|
|
300
|
+
stdoutMsg = data.toString().trim();
|
|
301
|
+
if (stdoutMsg) {
|
|
302
|
+
consola.log(stdoutMsg);
|
|
303
|
+
}
|
|
304
|
+
lastError = null;
|
|
305
|
+
if (debounceTimeout) {
|
|
306
|
+
clearTimeout(debounceTimeout);
|
|
307
|
+
}
|
|
308
|
+
return debounceTimeout = setTimeout(function() {
|
|
309
|
+
if (lastError) {
|
|
310
|
+
consola.warn("Compilation failed, plugins skipped.");
|
|
311
|
+
} else {
|
|
312
|
+
consola.success('Compilation successful (watch mode).');
|
|
313
|
+
runPlugins(config, optionsForPlugins, '(watch mode)', '');
|
|
314
|
+
}
|
|
315
|
+
return lastError = null;
|
|
316
|
+
}, 100);
|
|
317
|
+
});
|
|
318
|
+
compilerProcess.on('close', function(code) {
|
|
319
|
+
return consola.info(`Watch process exited with code ${code}.`);
|
|
320
|
+
});
|
|
321
|
+
return compilerProcess.on('error', function(err) {
|
|
322
|
+
consola.error('Failed to start watch process:', err);
|
|
323
|
+
return process.exit(1);
|
|
324
|
+
});
|
|
188
325
|
} else {
|
|
189
326
|
consola.start(`Compiling from \`${config.entry}\` to \`${config.output}\`...`);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
compilerProcess = exec(command, function(error, stdout, stderr) {
|
|
193
|
-
if (!options.watch) {
|
|
327
|
+
consola.info(`Executing: ${execCommand}`);
|
|
328
|
+
return compilerProcess = exec(execCommand, function(error, stdout, stderr) {
|
|
194
329
|
if (error) {
|
|
195
330
|
consola.error('Compilation failed:', error);
|
|
196
331
|
if (stderr) {
|
|
@@ -199,19 +334,14 @@
|
|
|
199
334
|
process.exit(1);
|
|
200
335
|
return;
|
|
201
336
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
211
|
-
if (options.watch) {
|
|
212
|
-
compilerProcess.stdout.pipe(process.stdout);
|
|
213
|
-
return compilerProcess.stderr.on('data', function(data) {
|
|
214
|
-
return consola.error(data.toString().trim());
|
|
337
|
+
consola.success('Compilation completed successfully!');
|
|
338
|
+
if (stdout) {
|
|
339
|
+
process.stdout.write(stdout);
|
|
340
|
+
}
|
|
341
|
+
if (stderr && !error) {
|
|
342
|
+
process.stderr.write(stderr);
|
|
343
|
+
}
|
|
344
|
+
return runPlugins(config, optionsForPlugins, stdout, stderr);
|
|
215
345
|
});
|
|
216
346
|
}
|
|
217
347
|
} catch (error1) {
|