milkee 2.0.0 → 2.1.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 +113 -20
- 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, executePlugins, fs, getCompiledFiles, hideBin, path, pkg, runPlugins, setup, spawn, yargs;
|
|
3
|
+
var CONFIG_FILE, CONFIG_PATH, CWD, argv, checkCoffee, compile, consola, crypto, exec, executePlugins, fs, getCompiledFiles, hideBin, path, pkg, runPlugins, setup, spawn, yargs;
|
|
4
4
|
|
|
5
5
|
yargs = require('yargs');
|
|
6
6
|
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
({exec, spawn} = require('child_process'));
|
|
16
16
|
|
|
17
|
+
crypto = require('crypto');
|
|
18
|
+
|
|
17
19
|
pkg = require('../package.json');
|
|
18
20
|
|
|
19
21
|
CWD = process.cwd();
|
|
@@ -156,7 +158,7 @@
|
|
|
156
158
|
};
|
|
157
159
|
|
|
158
160
|
compile = async function() {
|
|
159
|
-
var compilerProcess, config, debounceTimeout, enabledOptions, enabledOptionsList, error, execCommand, execCommandParts, execOtherOptionStrings, i, item,
|
|
161
|
+
var backupFiles, backupName, backupPath, clearBackups, compilerProcess, config, debounceTimeout, dirName, enabledOptions, enabledOptionsList, error, execCommand, execCommandParts, execOtherOptionStrings, fileName, hash, i, item, items, lastError, len, milkee, milkeeOptions, options, originalPath, restoreBackups, spawnArgs, stat, summary, targetDir, toContinue;
|
|
160
162
|
checkCoffee();
|
|
161
163
|
if (!fs.existsSync(CONFIG_PATH)) {
|
|
162
164
|
consola.error(`\`${CONFIG_FILE}\` not found in this directory: ${CWD}`);
|
|
@@ -169,7 +171,7 @@
|
|
|
169
171
|
consola.error('`entry` and `output` properties are required in your configuration.');
|
|
170
172
|
process.exit(1);
|
|
171
173
|
}
|
|
172
|
-
options = config.options || {};
|
|
174
|
+
options = {...(config.options || {})};
|
|
173
175
|
milkee = config.milkee || {};
|
|
174
176
|
milkeeOptions = config.milkee.options || {};
|
|
175
177
|
execCommandParts = ['coffee'];
|
|
@@ -259,29 +261,111 @@
|
|
|
259
261
|
return;
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
|
-
optionsForPlugins = {...options};
|
|
263
264
|
delete options.join;
|
|
265
|
+
backupFiles = [];
|
|
266
|
+
restoreBackups = function() {
|
|
267
|
+
var backup, e, i, len;
|
|
268
|
+
if (backupFiles.length > 0) {
|
|
269
|
+
consola.info("Restoring previous files...");
|
|
270
|
+
for (i = 0, len = backupFiles.length; i < len; i++) {
|
|
271
|
+
backup = backupFiles[i];
|
|
272
|
+
try {
|
|
273
|
+
if (fs.existsSync(backup.original)) {
|
|
274
|
+
fs.rmSync(backup.original, {
|
|
275
|
+
force: true
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
if (fs.existsSync(backup.backup)) {
|
|
279
|
+
fs.renameSync(backup.backup, backup.original);
|
|
280
|
+
}
|
|
281
|
+
} catch (error1) {
|
|
282
|
+
e = error1;
|
|
283
|
+
consola.warn(`Failed to restore ${backup.original}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return consola.success("Restored!");
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
clearBackups = function() {
|
|
290
|
+
var backup, e, i, len, results;
|
|
291
|
+
if (backupFiles.length > 0) {
|
|
292
|
+
consola.trace("Cleaning up backups...");
|
|
293
|
+
results = [];
|
|
294
|
+
for (i = 0, len = backupFiles.length; i < len; i++) {
|
|
295
|
+
backup = backupFiles[i];
|
|
296
|
+
try {
|
|
297
|
+
if (fs.existsSync(backup.backup)) {
|
|
298
|
+
results.push(fs.rmSync(backup.backup, {
|
|
299
|
+
force: true
|
|
300
|
+
}));
|
|
301
|
+
} else {
|
|
302
|
+
results.push(void 0);
|
|
303
|
+
}
|
|
304
|
+
} catch (error1) {
|
|
305
|
+
e = error1;
|
|
306
|
+
results.push(null);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return results;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
264
312
|
if (milkeeOptions.refresh) {
|
|
265
313
|
targetDir = path.join(CWD, config.output);
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
314
|
+
if (fs.existsSync(targetDir)) {
|
|
315
|
+
stat = fs.statSync(targetDir);
|
|
316
|
+
hash = crypto.randomBytes(4).toString('hex');
|
|
317
|
+
try {
|
|
318
|
+
if (stat.isDirectory()) {
|
|
319
|
+
consola.info("Executing: Refresh");
|
|
320
|
+
items = fs.readdirSync(targetDir);
|
|
321
|
+
for (i = 0, len = items.length; i < len; i++) {
|
|
322
|
+
item = items[i];
|
|
323
|
+
originalPath = path.join(targetDir, item);
|
|
324
|
+
backupName = `${hash}.${item}.bak`;
|
|
325
|
+
backupPath = path.join(targetDir, backupName);
|
|
326
|
+
fs.renameSync(originalPath, backupPath);
|
|
327
|
+
backupFiles.push({
|
|
328
|
+
original: originalPath,
|
|
329
|
+
backup: backupPath
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
// itemPath = path.join targetDir, item
|
|
333
|
+
// fs.rmSync itemPath, recursive: true, force: true
|
|
334
|
+
consola.success(`Existing: files backed up with hash \`${hash}\``);
|
|
335
|
+
} else {
|
|
336
|
+
// consola.success "Refreshed!"
|
|
337
|
+
consola.info("Executing: Refresh (Single File)");
|
|
338
|
+
originalPath = targetDir;
|
|
339
|
+
fileName = path.basename(originalPath);
|
|
340
|
+
dirName = path.dirname(originalPath);
|
|
341
|
+
backupName = `${hash}.${fileName}.bak`;
|
|
342
|
+
backupPath = path.join(dirName, backupName);
|
|
343
|
+
fs.renameSync(originalPath, backupPath);
|
|
344
|
+
backupFiles.push({
|
|
345
|
+
original: originalPath,
|
|
346
|
+
backup: backupPath
|
|
347
|
+
});
|
|
348
|
+
consola.success(`Existing file backed up as \`${backupName}\``);
|
|
349
|
+
}
|
|
350
|
+
} catch (error1) {
|
|
351
|
+
// fs.rmSync targetDir, force: true
|
|
352
|
+
// consola.success "Refreshed!"
|
|
353
|
+
error = error1;
|
|
354
|
+
consola.error("Failed to create backups during refresh:", error);
|
|
355
|
+
restoreBackups();
|
|
356
|
+
process.exit(1);
|
|
278
357
|
}
|
|
279
|
-
|
|
358
|
+
} else {
|
|
359
|
+
consola.info("Refresh skipped.");
|
|
280
360
|
}
|
|
281
361
|
}
|
|
282
362
|
if (options.watch) {
|
|
283
363
|
consola.start(`Watching for changes in \`${config.entry}\`...`);
|
|
284
364
|
consola.info(`Executing: coffee ${spawnArgs.join(' ')}`);
|
|
365
|
+
if (milkeeOptions.refresh) {
|
|
366
|
+
consola.warn("Refresh backup is disabled in watch mode (backups are cleared immediately).");
|
|
367
|
+
clearBackups();
|
|
368
|
+
}
|
|
285
369
|
compilerProcess = spawn('coffee', spawnArgs, {
|
|
286
370
|
shell: true
|
|
287
371
|
});
|
|
@@ -301,6 +385,7 @@
|
|
|
301
385
|
if (stdoutMsg) {
|
|
302
386
|
consola.log(stdoutMsg);
|
|
303
387
|
}
|
|
388
|
+
debounceTimeout = null;
|
|
304
389
|
lastError = null;
|
|
305
390
|
if (debounceTimeout) {
|
|
306
391
|
clearTimeout(debounceTimeout);
|
|
@@ -310,7 +395,7 @@
|
|
|
310
395
|
consola.warn("Compilation failed, plugins skipped.");
|
|
311
396
|
} else {
|
|
312
397
|
consola.success('Compilation successful (watch mode).');
|
|
313
|
-
runPlugins(config,
|
|
398
|
+
runPlugins(config, {...(config.options || {})}, '(watch mode)', '');
|
|
314
399
|
}
|
|
315
400
|
return lastError = null;
|
|
316
401
|
}, 100);
|
|
@@ -331,17 +416,25 @@
|
|
|
331
416
|
if (stderr) {
|
|
332
417
|
consola.error(stderr.toString().trim());
|
|
333
418
|
}
|
|
419
|
+
if (milkeeOptions.refresh) {
|
|
420
|
+
restoreBackups();
|
|
421
|
+
}
|
|
334
422
|
process.exit(1);
|
|
335
423
|
return;
|
|
424
|
+
setTimeout(function() {
|
|
425
|
+
if (milkeeOptions.refresh) {
|
|
426
|
+
clearBackups();
|
|
427
|
+
}
|
|
428
|
+
return consola.success('Compilation completed successfully!');
|
|
429
|
+
}, 500);
|
|
336
430
|
}
|
|
337
|
-
consola.success('Compilation completed successfully!');
|
|
338
431
|
if (stdout) {
|
|
339
432
|
process.stdout.write(stdout);
|
|
340
433
|
}
|
|
341
434
|
if (stderr && !error) {
|
|
342
435
|
process.stderr.write(stderr);
|
|
343
436
|
}
|
|
344
|
-
return runPlugins(config,
|
|
437
|
+
return runPlugins(config, {...(config.options || {})}, stdout, stderr);
|
|
345
438
|
});
|
|
346
439
|
}
|
|
347
440
|
} catch (error1) {
|