milkee 2.2.1 → 2.3.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/README.md +4 -1
- package/dist/checks.js +58 -0
- package/dist/commands/compile.js +276 -0
- package/dist/commands/setup.js +49 -0
- package/dist/constants.js +14 -0
- package/dist/main.js +20 -530
- package/dist/options/confirm.js +19 -0
- package/dist/options/copy.js +79 -0
- package/dist/options/refresh.js +114 -0
- package/dist/plugins.js +59 -0
- package/dist/utils.js +48 -0
- package/package.json +2 -2
- package/temp/coffee.config.cjs +2 -0
package/README.md
CHANGED
|
@@ -75,8 +75,10 @@ module.exports = {
|
|
|
75
75
|
options: {
|
|
76
76
|
// Before compiling, reset the directory.
|
|
77
77
|
// refresh: false,
|
|
78
|
-
// Before compiling,
|
|
78
|
+
// Before compiling, prompt "Do you want to Continue?".
|
|
79
79
|
// confirm: false,
|
|
80
|
+
// After compiling, copy non-coffee files from entry to output directory. (Only works when options.join is false)
|
|
81
|
+
// copy: false,
|
|
80
82
|
},
|
|
81
83
|
plugins: []
|
|
82
84
|
},
|
|
@@ -108,6 +110,7 @@ These options control Milkee's behavior.
|
|
|
108
110
|
| :-------- | :-------- | :------ | :----------------------------------------------------- |
|
|
109
111
|
| `refresh` | `boolean` | `false` | Before compiling, reset the output directory. |
|
|
110
112
|
| `confirm` | `boolean` | `false` | Before compiling, prompt "Do you want to Continue?". |
|
|
113
|
+
| `copy` | `boolean` | `false` | After compiling, copy non-coffee files from entry to output directory. (Only works when `options.join` is `false`) |
|
|
111
114
|
|
|
112
115
|
##### `milkee.plugins` (Milkee Specific Plugins)
|
|
113
116
|
|
package/dist/checks.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CWD, checkCoffee, checkLatest, consola, exec, fs, isPackageLatest, path, pkg;
|
|
3
|
+
|
|
4
|
+
fs = require('fs');
|
|
5
|
+
|
|
6
|
+
path = require('path');
|
|
7
|
+
|
|
8
|
+
({exec} = require('child_process'));
|
|
9
|
+
|
|
10
|
+
consola = require('consola');
|
|
11
|
+
|
|
12
|
+
({isPackageLatest} = require('is-package-latest'));
|
|
13
|
+
|
|
14
|
+
({pkg, CWD} = require('./constants'));
|
|
15
|
+
|
|
16
|
+
// async
|
|
17
|
+
checkLatest = async function() {
|
|
18
|
+
var res;
|
|
19
|
+
try {
|
|
20
|
+
res = (await isPackageLatest(pkg));
|
|
21
|
+
if (res.success && !res.isLatest) {
|
|
22
|
+
consola.box({
|
|
23
|
+
title: "A new version is now available!",
|
|
24
|
+
message: `${res.currentVersion} --> \`${res.latestVersion}\`\n\n# global installation\n\`npm i -g milkee@latest\`\n# or local installation\n\`npm i -D milkee@latest\``
|
|
25
|
+
});
|
|
26
|
+
return true;
|
|
27
|
+
} else {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
} catch (error1) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
checkCoffee = function() {
|
|
36
|
+
var PKG_PATH, error, pkgData, pkgFile, ref, ref1;
|
|
37
|
+
PKG_PATH = path.join(CWD, 'package.json');
|
|
38
|
+
if (fs.existsSync(PKG_PATH)) {
|
|
39
|
+
try {
|
|
40
|
+
pkgFile = fs.readFileSync(PKG_PATH, 'utf-8');
|
|
41
|
+
pkgData = JSON.parse(pkgFile);
|
|
42
|
+
if (((ref = pkgData.dependencies) != null ? ref.coffeescript : void 0) || ((ref1 = pkgData.devDependencies) != null ? ref1.coffeescript : void 0)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
} catch (error1) {
|
|
46
|
+
error = error1;
|
|
47
|
+
consola.warn(`Could not parse \`package.json\`: ${error.message}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return exec('coffee --version', function(error) {
|
|
51
|
+
if (error) {
|
|
52
|
+
consola.warn('CoffeeScript is not found in local dependencies (`dependencies`, `devDependencies`) or globally.');
|
|
53
|
+
return consola.info('Please install it via `npm install --save-dev coffeescript` to continue.');
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = {checkLatest, checkCoffee};
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CONFIG_FILE, CONFIG_PATH, CWD, checkCoffee, checkLatest, clearBackups, compile, confirmContinue, consola, crypto, exec, executeCopy, executeRefresh, fs, path, restoreBackups, runPlugins, spawn;
|
|
3
|
+
|
|
4
|
+
fs = require('fs');
|
|
5
|
+
|
|
6
|
+
path = require('path');
|
|
7
|
+
|
|
8
|
+
crypto = require('crypto');
|
|
9
|
+
|
|
10
|
+
({spawn, exec} = require('child_process'));
|
|
11
|
+
|
|
12
|
+
consola = require('consola');
|
|
13
|
+
|
|
14
|
+
({CWD, CONFIG_PATH, CONFIG_FILE} = require('../constants'));
|
|
15
|
+
|
|
16
|
+
({checkLatest, checkCoffee} = require('../checks'));
|
|
17
|
+
|
|
18
|
+
({runPlugins} = require('../plugins'));
|
|
19
|
+
|
|
20
|
+
confirmContinue = require('../options/confirm');
|
|
21
|
+
|
|
22
|
+
({executeRefresh, restoreBackups, clearBackups} = require('../options/refresh'));
|
|
23
|
+
|
|
24
|
+
executeCopy = require('../options/copy');
|
|
25
|
+
|
|
26
|
+
// async
|
|
27
|
+
compile = async function() {
|
|
28
|
+
var action, backupFiles, cl, compilerProcess, config, debounceTimeout, enabledOptions, enabledOptionsList, error, execCommand, execCommandParts, execOtherOptionStrings, installCmd, lastError, milkee, milkeeOptions, options, spawnArgs, summary, toContinue;
|
|
29
|
+
cl = (await checkLatest());
|
|
30
|
+
if (cl) {
|
|
31
|
+
action = (await consola.prompt("Do you want to update now?", {
|
|
32
|
+
type: 'select',
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
label: 'No (Skip)',
|
|
36
|
+
value: 'skip',
|
|
37
|
+
hint: 'Start compiling directly'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: 'Yes (Global)',
|
|
41
|
+
value: 'global',
|
|
42
|
+
hint: 'npm i -g milkee@latest'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: 'Yes (Local)',
|
|
46
|
+
value: 'local',
|
|
47
|
+
hint: 'npm i -D milkee@latest'
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}));
|
|
51
|
+
if (action && action !== 'skip') {
|
|
52
|
+
installCmd = action === 'global' ? 'npm i -g milkee@latest' : 'npm i -D milkee@latest';
|
|
53
|
+
consola.start("Updating milkee...");
|
|
54
|
+
await new Promise(function(resolve) {
|
|
55
|
+
var cp;
|
|
56
|
+
cp = spawn(installCmd, {
|
|
57
|
+
shell: true,
|
|
58
|
+
stdio: 'inherit'
|
|
59
|
+
});
|
|
60
|
+
return cp.on('close', resolve);
|
|
61
|
+
});
|
|
62
|
+
consola.success("Update finished! Please run the command again.");
|
|
63
|
+
process.exit(0);
|
|
64
|
+
} else if (action === 'skip') {
|
|
65
|
+
consola.info("Skipped!");
|
|
66
|
+
} else if (!action) {
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
checkCoffee();
|
|
71
|
+
if (!fs.existsSync(CONFIG_PATH)) {
|
|
72
|
+
consola.error(`\`${CONFIG_FILE}\` not found in this directory: ${CWD}`);
|
|
73
|
+
consola.info('Please run `milkee --setup` to create a configuration file.');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
config = require(CONFIG_PATH);
|
|
78
|
+
if (!(config.entry && config.output)) {
|
|
79
|
+
consola.error('`entry` and `output` properties are required in your configuration.');
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
options = {...(config.options || {})};
|
|
83
|
+
milkee = config.milkee || {};
|
|
84
|
+
milkeeOptions = config.milkee.options || {};
|
|
85
|
+
execCommandParts = ['coffee'];
|
|
86
|
+
if (options.join) {
|
|
87
|
+
execCommandParts.push('--join');
|
|
88
|
+
execCommandParts.push(`\"${config.output}\"`);
|
|
89
|
+
} else {
|
|
90
|
+
execCommandParts.push('--output');
|
|
91
|
+
execCommandParts.push(`\"${config.output}\"`);
|
|
92
|
+
}
|
|
93
|
+
execOtherOptionStrings = [];
|
|
94
|
+
if (options.bare) {
|
|
95
|
+
execOtherOptionStrings.push('--bare');
|
|
96
|
+
}
|
|
97
|
+
if (options.map) {
|
|
98
|
+
execOtherOptionStrings.push('--map');
|
|
99
|
+
}
|
|
100
|
+
if (options.inlineMap) {
|
|
101
|
+
execOtherOptionStrings.push('--inline-map');
|
|
102
|
+
}
|
|
103
|
+
if (options.noHeader) {
|
|
104
|
+
execOtherOptionStrings.push('--no-header');
|
|
105
|
+
}
|
|
106
|
+
if (options.transpile) {
|
|
107
|
+
execOtherOptionStrings.push('--transpile');
|
|
108
|
+
}
|
|
109
|
+
if (options.literate) {
|
|
110
|
+
execOtherOptionStrings.push('--literate');
|
|
111
|
+
}
|
|
112
|
+
if (execOtherOptionStrings.length > 0) {
|
|
113
|
+
execCommandParts.push(execOtherOptionStrings.join(' '));
|
|
114
|
+
}
|
|
115
|
+
execCommandParts.push('--compile');
|
|
116
|
+
execCommandParts.push(`\"${config.entry}\"`);
|
|
117
|
+
execCommand = execCommandParts.filter(Boolean).join(' ');
|
|
118
|
+
spawnArgs = [];
|
|
119
|
+
if (options.join) {
|
|
120
|
+
spawnArgs.push('--join');
|
|
121
|
+
spawnArgs.push(config.output);
|
|
122
|
+
} else {
|
|
123
|
+
spawnArgs.push('--output');
|
|
124
|
+
spawnArgs.push(config.output);
|
|
125
|
+
}
|
|
126
|
+
if (options.bare) {
|
|
127
|
+
spawnArgs.push('--bare');
|
|
128
|
+
}
|
|
129
|
+
if (options.map) {
|
|
130
|
+
spawnArgs.push('--map');
|
|
131
|
+
}
|
|
132
|
+
if (options.inlineMap) {
|
|
133
|
+
spawnArgs.push('--inline-map');
|
|
134
|
+
}
|
|
135
|
+
if (options.noHeader) {
|
|
136
|
+
spawnArgs.push('--no-header');
|
|
137
|
+
}
|
|
138
|
+
if (options.transpile) {
|
|
139
|
+
spawnArgs.push('--transpile');
|
|
140
|
+
}
|
|
141
|
+
if (options.literate) {
|
|
142
|
+
spawnArgs.push('--literate');
|
|
143
|
+
}
|
|
144
|
+
if (options.watch) {
|
|
145
|
+
spawnArgs.push('--watch');
|
|
146
|
+
}
|
|
147
|
+
spawnArgs.push('--compile');
|
|
148
|
+
spawnArgs.push(config.entry);
|
|
149
|
+
summary = [];
|
|
150
|
+
summary.push(`Entry: \`${config.entry}\``);
|
|
151
|
+
summary.push(`Output: \`${config.output}\``);
|
|
152
|
+
enabledOptions = Object.keys(options).filter(function(key) {
|
|
153
|
+
return options[key];
|
|
154
|
+
});
|
|
155
|
+
if (enabledOptions.length > 0) {
|
|
156
|
+
enabledOptionsList = enabledOptions.join(',');
|
|
157
|
+
summary.push(`Options: ${enabledOptionsList}`);
|
|
158
|
+
}
|
|
159
|
+
consola.box({
|
|
160
|
+
title: "Milkee Compilation Summary",
|
|
161
|
+
message: summary.join('\n')
|
|
162
|
+
});
|
|
163
|
+
if (milkeeOptions.confirm) {
|
|
164
|
+
toContinue = (await confirmContinue());
|
|
165
|
+
if (!toContinue) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
delete options.join;
|
|
170
|
+
backupFiles = [];
|
|
171
|
+
if (milkeeOptions.refresh) {
|
|
172
|
+
try {
|
|
173
|
+
await executeRefresh(config, backupFiles);
|
|
174
|
+
} catch (error1) {
|
|
175
|
+
error = error1;
|
|
176
|
+
restoreBackups(backupFiles);
|
|
177
|
+
process.exit(1);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (options.watch) {
|
|
181
|
+
consola.start(`Watching for changes in \`${config.entry}\`...`);
|
|
182
|
+
consola.info(`Executing: coffee ${spawnArgs.join(' ')}`);
|
|
183
|
+
if (milkeeOptions.refresh) {
|
|
184
|
+
consola.warn("Refresh backup is disabled in watch mode (backups are cleared immediately).");
|
|
185
|
+
clearBackups(backupFiles);
|
|
186
|
+
}
|
|
187
|
+
compilerProcess = spawn('coffee', spawnArgs, {
|
|
188
|
+
shell: true
|
|
189
|
+
});
|
|
190
|
+
debounceTimeout = null;
|
|
191
|
+
lastError = null;
|
|
192
|
+
compilerProcess.stderr.on('data', function(data) {
|
|
193
|
+
var errorMsg;
|
|
194
|
+
errorMsg = data.toString().trim();
|
|
195
|
+
if (errorMsg) {
|
|
196
|
+
consola.error(errorMsg);
|
|
197
|
+
return lastError = errorMsg;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
compilerProcess.stdout.on('data', function(data) {
|
|
201
|
+
var stdoutMsg;
|
|
202
|
+
stdoutMsg = data.toString().trim();
|
|
203
|
+
if (stdoutMsg) {
|
|
204
|
+
consola.log(stdoutMsg);
|
|
205
|
+
}
|
|
206
|
+
debounceTimeout = null;
|
|
207
|
+
lastError = null;
|
|
208
|
+
if (debounceTimeout) {
|
|
209
|
+
clearTimeout(debounceTimeout);
|
|
210
|
+
}
|
|
211
|
+
return debounceTimeout = setTimeout(function() {
|
|
212
|
+
if (lastError) {
|
|
213
|
+
consola.warn("Compilation failed, plugins skipped.");
|
|
214
|
+
} else {
|
|
215
|
+
consola.success('Compilation successful (watch mode).');
|
|
216
|
+
runPlugins(config, {...(config.options || {})}, '(watch mode)', '');
|
|
217
|
+
}
|
|
218
|
+
return lastError = null;
|
|
219
|
+
}, 100);
|
|
220
|
+
});
|
|
221
|
+
compilerProcess.on('close', function(code) {
|
|
222
|
+
return consola.info(`Watch process exited with code ${code}.`);
|
|
223
|
+
});
|
|
224
|
+
return compilerProcess.on('error', function(err) {
|
|
225
|
+
consola.error('Failed to start watch process:', err);
|
|
226
|
+
return process.exit(1);
|
|
227
|
+
});
|
|
228
|
+
} else {
|
|
229
|
+
consola.start(`Compiling from \`${config.entry}\` to \`${config.output}\`...`);
|
|
230
|
+
consola.info(`Executing: ${execCommand}`);
|
|
231
|
+
return compilerProcess = exec(execCommand, function(error, stdout, stderr) {
|
|
232
|
+
if (error) {
|
|
233
|
+
consola.error('Compilation failed:', error);
|
|
234
|
+
if (stderr) {
|
|
235
|
+
consola.error(stderr.toString().trim());
|
|
236
|
+
}
|
|
237
|
+
if (milkeeOptions.refresh) {
|
|
238
|
+
restoreBackups(backupFiles);
|
|
239
|
+
}
|
|
240
|
+
process.exit(1);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
setTimeout(async function() {
|
|
244
|
+
if (milkeeOptions.refresh) {
|
|
245
|
+
clearBackups(backupFiles);
|
|
246
|
+
consola.success('Backup clearing completed!');
|
|
247
|
+
}
|
|
248
|
+
if (milkeeOptions.copy) {
|
|
249
|
+
try {
|
|
250
|
+
await executeCopy(config);
|
|
251
|
+
} catch (error1) {
|
|
252
|
+
error = error1;
|
|
253
|
+
consola.error('Failed to copy non-coffee files');
|
|
254
|
+
process.exit(1);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return consola.success('Compilation completed successfully!');
|
|
259
|
+
}, 500);
|
|
260
|
+
if (stdout) {
|
|
261
|
+
process.stdout.write(stdout);
|
|
262
|
+
}
|
|
263
|
+
if (stderr && !error) {
|
|
264
|
+
process.stderr.write(stderr);
|
|
265
|
+
}
|
|
266
|
+
return runPlugins(config, {...(config.options || {})}, stdout, stderr);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
} catch (error1) {
|
|
270
|
+
error = error1;
|
|
271
|
+
consola.error('Failed to load or execute configuration:', error);
|
|
272
|
+
return process.exit(1);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
module.exports = compile;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CONFIG_FILE, CONFIG_PATH, checkCoffee, consola, fs, path, setup;
|
|
3
|
+
|
|
4
|
+
fs = require('fs');
|
|
5
|
+
|
|
6
|
+
path = require('path');
|
|
7
|
+
|
|
8
|
+
consola = require('consola');
|
|
9
|
+
|
|
10
|
+
({CONFIG_FILE, CONFIG_PATH} = require('../constants'));
|
|
11
|
+
|
|
12
|
+
({checkCoffee} = require('../checks'));
|
|
13
|
+
|
|
14
|
+
// async
|
|
15
|
+
setup = async function() {
|
|
16
|
+
var CONFIG_TEMPLATE, TEMPLATE_PATH, check, error, pstat, stat;
|
|
17
|
+
checkCoffee();
|
|
18
|
+
pstat = "created";
|
|
19
|
+
stat = "create";
|
|
20
|
+
if (fs.existsSync(CONFIG_PATH)) {
|
|
21
|
+
consola.warn(`\`${CONFIG_FILE}\` already exists in this directory.`);
|
|
22
|
+
check = (await consola.prompt(`Do you want to reset \`${CONFIG_FILE}\`?`, {
|
|
23
|
+
type: "confirm"
|
|
24
|
+
}));
|
|
25
|
+
if (!check) {
|
|
26
|
+
consola.info("Cancelled.");
|
|
27
|
+
return;
|
|
28
|
+
} else {
|
|
29
|
+
fs.rmSync(CONFIG_PATH, {
|
|
30
|
+
recursive: true,
|
|
31
|
+
force: true
|
|
32
|
+
});
|
|
33
|
+
pstat = "reset";
|
|
34
|
+
stat = "reset";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
TEMPLATE_PATH = path.join(__dirname, '..', '..', 'temp', CONFIG_FILE);
|
|
39
|
+
CONFIG_TEMPLATE = fs.readFileSync(TEMPLATE_PATH, 'utf-8');
|
|
40
|
+
fs.writeFileSync(CONFIG_PATH, CONFIG_TEMPLATE);
|
|
41
|
+
return consola.success(`Successfully ${pstat} \`${CONFIG_FILE}\`!`);
|
|
42
|
+
} catch (error1) {
|
|
43
|
+
error = error1;
|
|
44
|
+
consola.error(`Failed to ${stat} \`${CONFIG_FILE}\`:`, error);
|
|
45
|
+
return consola.info(`Template file may be missing from the package installation at \`${TEMPLATE_PATH}\``);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
module.exports = setup;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CONFIG_FILE, CONFIG_PATH, CWD, path, pkg;
|
|
3
|
+
|
|
4
|
+
path = require('path');
|
|
5
|
+
|
|
6
|
+
pkg = require('../package.json');
|
|
7
|
+
|
|
8
|
+
CWD = process.cwd();
|
|
9
|
+
|
|
10
|
+
CONFIG_FILE = 'coffee.config.cjs';
|
|
11
|
+
|
|
12
|
+
CONFIG_PATH = path.join(CWD, CONFIG_FILE);
|
|
13
|
+
|
|
14
|
+
module.exports = {pkg, CWD, CONFIG_FILE, CONFIG_PATH};
|
package/dist/main.js
CHANGED
|
@@ -1,538 +1,28 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
|
-
|
|
3
|
-
var CONFIG_FILE, CONFIG_PATH, CWD, argv, checkCoffee, checkLatest, compile, consola, crypto, exec, executePlugins, fs, getCompiledFiles, hideBin, isPackageLatest, path, pkg, runPlugins, setup, sleep, spawn, yargs;
|
|
2
|
+
var argv, compile, hideBin, pkg, setup, yargs;
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
yargs = require('yargs');
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
({hideBin} = require('yargs/helpers'));
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
({pkg} = require('./constants'));
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
setup = require('./commands/setup');
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
compile = require('./commands/compile');
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').option('setup', {
|
|
15
|
+
alias: 's',
|
|
16
|
+
describe: "Generate a default config file",
|
|
17
|
+
type: 'boolean'
|
|
18
|
+
}).option('compile', {
|
|
19
|
+
alias: 'c',
|
|
20
|
+
describe: "Compile CoffeeScript (default)",
|
|
21
|
+
type: 'boolean'
|
|
22
|
+
}).version('version', pkg.version).alias('v', 'version').help('help').alias('h', 'help').argv;
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
CWD = process.cwd();
|
|
24
|
-
|
|
25
|
-
CONFIG_FILE = 'coffee.config.cjs';
|
|
26
|
-
|
|
27
|
-
CONFIG_PATH = path.join(CWD, CONFIG_FILE);
|
|
28
|
-
|
|
29
|
-
sleep = function(time) {
|
|
30
|
-
return new Promise(function(resolve) {
|
|
31
|
-
return setTimeout(resolve, time);
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// async
|
|
36
|
-
checkLatest = async function() {
|
|
37
|
-
var res;
|
|
38
|
-
try {
|
|
39
|
-
res = (await isPackageLatest(pkg));
|
|
40
|
-
if (res.success && !res.isLatest) {
|
|
41
|
-
consola.box({
|
|
42
|
-
title: "A new version is now available!",
|
|
43
|
-
message: `${res.currentVersion} --> \`${res.latestVersion}\`\n\n# global installation\n\`npm i -g milkee@latest\`\n# or local installation\n\`npm i -D milkee@latest\``
|
|
44
|
-
});
|
|
45
|
-
return true;
|
|
46
|
-
} else {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
} catch (error1) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
checkCoffee = function() {
|
|
55
|
-
var PKG_PATH, error, pkgData, pkgFile, ref, ref1;
|
|
56
|
-
PKG_PATH = path.join(CWD, 'package.json');
|
|
57
|
-
if (fs.existsSync(PKG_PATH)) {
|
|
58
|
-
try {
|
|
59
|
-
pkgFile = fs.readFileSync(PKG_PATH, 'utf-8');
|
|
60
|
-
pkgData = JSON.parse(pkgFile);
|
|
61
|
-
if (((ref = pkgData.dependencies) != null ? ref.coffeescript : void 0) || ((ref1 = pkgData.devDependencies) != null ? ref1.coffeescript : void 0)) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
} catch (error1) {
|
|
65
|
-
error = error1;
|
|
66
|
-
consola.warn(`Could not parse \`package.json\`: ${error.message}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return exec('coffee --version', function(error) {
|
|
70
|
-
if (error) {
|
|
71
|
-
consola.warn('CoffeeScript is not found in local dependencies (`dependencies`, `devDependencies`) or globally.');
|
|
72
|
-
return consola.info('Please install it via `npm install --save-dev coffeescript` to continue.');
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// async
|
|
78
|
-
setup = async function() {
|
|
79
|
-
var CONFIG_TEMPLATE, TEMPLATE_PATH, check, error, pstat, stat;
|
|
80
|
-
checkCoffee();
|
|
81
|
-
pstat = "created";
|
|
82
|
-
stat = "create";
|
|
83
|
-
if (fs.existsSync(CONFIG_PATH)) {
|
|
84
|
-
consola.warn(`\`${CONFIG_FILE}\` already exists in this directory.`);
|
|
85
|
-
check = (await consola.prompt(`Do you want to reset \`${CONFIG_FILE}\`?`, {
|
|
86
|
-
type: "confirm"
|
|
87
|
-
}));
|
|
88
|
-
if (!check) {
|
|
89
|
-
consola.info("Cancelled.");
|
|
90
|
-
return;
|
|
91
|
-
} else {
|
|
92
|
-
fs.rmSync(CONFIG_PATH, {
|
|
93
|
-
recursive: true,
|
|
94
|
-
force: true
|
|
95
|
-
});
|
|
96
|
-
pstat = "reset";
|
|
97
|
-
stat = "reset";
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
TEMPLATE_PATH = path.join(__dirname, '..', 'temp', CONFIG_FILE);
|
|
102
|
-
CONFIG_TEMPLATE = fs.readFileSync(TEMPLATE_PATH, 'utf-8');
|
|
103
|
-
fs.writeFileSync(CONFIG_PATH, CONFIG_TEMPLATE);
|
|
104
|
-
return consola.success(`Successfully ${pstat} \`${CONFIG_FILE}\`!`);
|
|
105
|
-
} catch (error1) {
|
|
106
|
-
error = error1;
|
|
107
|
-
consola.error(`Failed to ${stat} \`${CONFIG_FILE}\`:`, error);
|
|
108
|
-
return consola.info(`Template file may be missing from the package installation at \`${TEMPLATE_PATH}\``);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
getCompiledFiles = function(targetPath) {
|
|
113
|
-
var error, filesList, i, item, itemPath, items, len, stat;
|
|
114
|
-
filesList = [];
|
|
115
|
-
if (!fs.existsSync(targetPath)) {
|
|
116
|
-
consola.warn(`Path does not exist, skipping scan ${targetPath}`);
|
|
117
|
-
return [];
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
stat = fs.statSync(targetPath);
|
|
121
|
-
if (stat.isDirectory()) {
|
|
122
|
-
consola.start(`Scanning directory: ${targetPath}`);
|
|
123
|
-
items = fs.readdirSync(targetPath);
|
|
124
|
-
for (i = 0, len = items.length; i < len; i++) {
|
|
125
|
-
item = items[i];
|
|
126
|
-
itemPath = path.join(targetPath, item);
|
|
127
|
-
filesList = filesList.concat(getCompiledFiles(itemPath));
|
|
128
|
-
}
|
|
129
|
-
} else if (stat.isFile()) {
|
|
130
|
-
if (targetPath.endsWith('.js' || targetPath.endsWith('.js.map'))) {
|
|
131
|
-
if (fs.existsSync(targetPath)) {
|
|
132
|
-
consola.info(`Found file: \`${targetPath}\``);
|
|
133
|
-
}
|
|
134
|
-
filesList.push(targetPath);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch (error1) {
|
|
138
|
-
error = error1;
|
|
139
|
-
consola.warn(`Could not scan output path ${targetPath}: ${error.message}`);
|
|
140
|
-
}
|
|
141
|
-
return filesList;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
executePlugins = function(config, compilationResult) {
|
|
145
|
-
var plugins, ref;
|
|
146
|
-
plugins = ((ref = config.milkee) != null ? ref.plugins : void 0) || [];
|
|
147
|
-
if (!(plugins.length > 0)) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
consola.start(`Running ${plugins.length} plugin(s)...`);
|
|
151
|
-
return (async function() { // async
|
|
152
|
-
var error, i, len, pluginFn;
|
|
153
|
-
try {
|
|
154
|
-
for (i = 0, len = plugins.length; i < len; i++) {
|
|
155
|
-
pluginFn = plugins[i];
|
|
156
|
-
if (typeof pluginFn === 'function') {
|
|
157
|
-
await Promise.resolve(pluginFn(compilationResult));
|
|
158
|
-
} else {
|
|
159
|
-
consola.warn(`Invalid plugin definition skipped (expected a function, got ${typeof pluginFn}).`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return consola.success("Plugins executed successfully.");
|
|
163
|
-
} catch (error1) {
|
|
164
|
-
error = error1;
|
|
165
|
-
return consola.error("An error occurred during plugin execution:", error);
|
|
166
|
-
}
|
|
167
|
-
})();
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
runPlugins = function(config, options, stdout = '', stderr = '') {
|
|
171
|
-
var compilationResult, compiledFiles, mapPath, outputPath;
|
|
172
|
-
outputPath = path.join(CWD, config.output);
|
|
173
|
-
compiledFiles = getCompiledFiles(outputPath);
|
|
174
|
-
if (options.join && options.map && !options.inlineMap) {
|
|
175
|
-
mapPath = `${outputPath}.map`;
|
|
176
|
-
if (fs.existsSync(mapPath && !compiledFiles.includes(mapPath))) {
|
|
177
|
-
compiledFiles = compiledFiles.concat(getCompiledFiles(mapPath));
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
compilationResult = {
|
|
181
|
-
config: config,
|
|
182
|
-
compiledFiles: compiledFiles,
|
|
183
|
-
stdout: stdout,
|
|
184
|
-
stderr: stderr
|
|
185
|
-
};
|
|
186
|
-
return executePlugins(config, compilationResult);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// async
|
|
190
|
-
compile = async function() {
|
|
191
|
-
var action, backupFiles, backupName, backupPath, cl, clearBackups, compilerProcess, config, debounceTimeout, dirName, enabledOptions, enabledOptionsList, error, execCommand, execCommandParts, execOtherOptionStrings, fileName, hash, i, installCmd, item, items, lastError, len, milkee, milkeeOptions, options, originalPath, restoreBackups, spawnArgs, stat, summary, targetDir, toContinue;
|
|
192
|
-
cl = (await checkLatest());
|
|
193
|
-
if (cl) {
|
|
194
|
-
action = (await consola.prompt("Do you want to update now?", {
|
|
195
|
-
type: 'select',
|
|
196
|
-
options: [
|
|
197
|
-
{
|
|
198
|
-
label: 'No (Skip)',
|
|
199
|
-
value: 'skip',
|
|
200
|
-
hint: 'Start compiling directly'
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
label: 'Yes (Global)',
|
|
204
|
-
value: 'global',
|
|
205
|
-
hint: 'npm i -g milkee@latest'
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
label: 'Yes (Local)',
|
|
209
|
-
value: 'local',
|
|
210
|
-
hint: 'npm i -D milkee@latest'
|
|
211
|
-
}
|
|
212
|
-
]
|
|
213
|
-
}));
|
|
214
|
-
if (action && action !== 'skip') {
|
|
215
|
-
installCmd = action === 'global' ? 'npm i -g milkee@latest' : 'npm i -D milkee@latest';
|
|
216
|
-
consola.start("Updating milkee...");
|
|
217
|
-
await new Promise(function(resolve) {
|
|
218
|
-
var cp;
|
|
219
|
-
cp = spawn(installCmd, {
|
|
220
|
-
shell: true,
|
|
221
|
-
stdio: 'inherit'
|
|
222
|
-
});
|
|
223
|
-
return cp.on('close', resolve);
|
|
224
|
-
});
|
|
225
|
-
consola.success("Update finished! Please run the command again.");
|
|
226
|
-
process.exit(0);
|
|
227
|
-
} else if (action === 'skip') {
|
|
228
|
-
consola.info("Skipped!");
|
|
229
|
-
} else if (!action) {
|
|
230
|
-
process.exit(1);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
checkCoffee();
|
|
234
|
-
if (!fs.existsSync(CONFIG_PATH)) {
|
|
235
|
-
consola.error(`\`${CONFIG_FILE}\` not found in this directory: ${CWD}`);
|
|
236
|
-
consola.info('Please run `milkee --setup` to create a configuration file.');
|
|
237
|
-
process.exit(1);
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
config = require(CONFIG_PATH);
|
|
241
|
-
if (!(config.entry && config.output)) {
|
|
242
|
-
consola.error('`entry` and `output` properties are required in your configuration.');
|
|
243
|
-
process.exit(1);
|
|
244
|
-
}
|
|
245
|
-
options = {...(config.options || {})};
|
|
246
|
-
milkee = config.milkee || {};
|
|
247
|
-
milkeeOptions = config.milkee.options || {};
|
|
248
|
-
execCommandParts = ['coffee'];
|
|
249
|
-
if (options.join) {
|
|
250
|
-
execCommandParts.push('--join');
|
|
251
|
-
execCommandParts.push(`\"${config.output}\"`);
|
|
252
|
-
} else {
|
|
253
|
-
execCommandParts.push('--output');
|
|
254
|
-
execCommandParts.push(`\"${config.output}\"`);
|
|
255
|
-
}
|
|
256
|
-
execOtherOptionStrings = [];
|
|
257
|
-
if (options.bare) {
|
|
258
|
-
execOtherOptionStrings.push('--bare');
|
|
259
|
-
}
|
|
260
|
-
if (options.map) {
|
|
261
|
-
execOtherOptionStrings.push('--map');
|
|
262
|
-
}
|
|
263
|
-
if (options.inlineMap) {
|
|
264
|
-
execOtherOptionStrings.push('--inline-map');
|
|
265
|
-
}
|
|
266
|
-
if (options.noHeader) {
|
|
267
|
-
execOtherOptionStrings.push('--no-header');
|
|
268
|
-
}
|
|
269
|
-
if (options.transpile) {
|
|
270
|
-
execOtherOptionStrings.push('--transpile');
|
|
271
|
-
}
|
|
272
|
-
if (options.literate) {
|
|
273
|
-
execOtherOptionStrings.push('--literate');
|
|
274
|
-
}
|
|
275
|
-
if (execOtherOptionStrings.length > 0) {
|
|
276
|
-
execCommandParts.push(execOtherOptionStrings.join(' '));
|
|
277
|
-
}
|
|
278
|
-
execCommandParts.push('--compile');
|
|
279
|
-
execCommandParts.push(`\"${config.entry}\"`);
|
|
280
|
-
execCommand = execCommandParts.filter(Boolean).join(' ');
|
|
281
|
-
spawnArgs = [];
|
|
282
|
-
if (options.join) {
|
|
283
|
-
spawnArgs.push('--join');
|
|
284
|
-
spawnArgs.push(config.output);
|
|
285
|
-
} else {
|
|
286
|
-
spawnArgs.push('--output');
|
|
287
|
-
spawnArgs.push(config.output);
|
|
288
|
-
}
|
|
289
|
-
if (options.bare) {
|
|
290
|
-
spawnArgs.push('--bare');
|
|
291
|
-
}
|
|
292
|
-
if (options.map) {
|
|
293
|
-
spawnArgs.push('--map');
|
|
294
|
-
}
|
|
295
|
-
if (options.inlineMap) {
|
|
296
|
-
spawnArgs.push('--inline-map');
|
|
297
|
-
}
|
|
298
|
-
if (options.noHeader) {
|
|
299
|
-
spawnArgs.push('--no-header');
|
|
300
|
-
}
|
|
301
|
-
if (options.transpile) {
|
|
302
|
-
spawnArgs.push('--transpile');
|
|
303
|
-
}
|
|
304
|
-
if (options.literate) {
|
|
305
|
-
spawnArgs.push('--literate');
|
|
306
|
-
}
|
|
307
|
-
if (options.watch) {
|
|
308
|
-
spawnArgs.push('--watch');
|
|
309
|
-
}
|
|
310
|
-
spawnArgs.push('--compile');
|
|
311
|
-
spawnArgs.push(config.entry);
|
|
312
|
-
summary = [];
|
|
313
|
-
summary.push(`Entry: \`${config.entry}\``);
|
|
314
|
-
summary.push(`Output: \`${config.output}\``);
|
|
315
|
-
enabledOptions = Object.keys(options).filter(function(key) {
|
|
316
|
-
return options[key];
|
|
317
|
-
});
|
|
318
|
-
if (enabledOptions.length > 0) {
|
|
319
|
-
enabledOptionsList = enabledOptions.join(',');
|
|
320
|
-
summary.push(`Options: ${enabledOptionsList}`);
|
|
321
|
-
}
|
|
322
|
-
consola.box({
|
|
323
|
-
title: "Milkee Compilation Summary",
|
|
324
|
-
message: summary.join('\n')
|
|
325
|
-
});
|
|
326
|
-
if (milkeeOptions.confirm) {
|
|
327
|
-
toContinue = (await consola.prompt("Do you want to continue?", {
|
|
328
|
-
type: "confirm"
|
|
329
|
-
}));
|
|
330
|
-
if (!toContinue) {
|
|
331
|
-
consola.info("Canceled.");
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
delete options.join;
|
|
336
|
-
backupFiles = [];
|
|
337
|
-
restoreBackups = function() {
|
|
338
|
-
var backup, e, i, len;
|
|
339
|
-
consola.info("Restoring previous files...");
|
|
340
|
-
if (backupFiles.length > 0) {
|
|
341
|
-
for (i = 0, len = backupFiles.length; i < len; i++) {
|
|
342
|
-
backup = backupFiles[i];
|
|
343
|
-
try {
|
|
344
|
-
if (fs.existsSync(backup.original)) {
|
|
345
|
-
fs.rmSync(backup.original, {
|
|
346
|
-
force: true
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
if (fs.existsSync(backup.backup)) {
|
|
350
|
-
fs.renameSync(backup.backup, backup.original);
|
|
351
|
-
}
|
|
352
|
-
} catch (error1) {
|
|
353
|
-
e = error1;
|
|
354
|
-
consola.warn(`Failed to restore ${backup.original}`);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
return consola.success("Restored!");
|
|
358
|
-
} else {
|
|
359
|
-
return consola.info("No files found to restore.");
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
clearBackups = function() {
|
|
363
|
-
var backup, e, i, len, results;
|
|
364
|
-
if (backupFiles.length > 0) {
|
|
365
|
-
consola.start("Cleaning up backups...");
|
|
366
|
-
results = [];
|
|
367
|
-
for (i = 0, len = backupFiles.length; i < len; i++) {
|
|
368
|
-
backup = backupFiles[i];
|
|
369
|
-
try {
|
|
370
|
-
if (fs.existsSync(backup.backup)) {
|
|
371
|
-
results.push(fs.rmSync(backup.backup, {
|
|
372
|
-
force: true
|
|
373
|
-
}));
|
|
374
|
-
} else {
|
|
375
|
-
results.push(void 0);
|
|
376
|
-
}
|
|
377
|
-
} catch (error1) {
|
|
378
|
-
e = error1;
|
|
379
|
-
results.push(null);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return results;
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
if (milkeeOptions.refresh) {
|
|
386
|
-
targetDir = path.join(CWD, config.output);
|
|
387
|
-
if (fs.existsSync(targetDir)) {
|
|
388
|
-
stat = fs.statSync(targetDir);
|
|
389
|
-
hash = crypto.randomBytes(4).toString('hex');
|
|
390
|
-
try {
|
|
391
|
-
if (stat.isDirectory()) {
|
|
392
|
-
consola.info("Executing: Refresh");
|
|
393
|
-
items = fs.readdirSync(targetDir);
|
|
394
|
-
consola.start("Bucking up files...");
|
|
395
|
-
for (i = 0, len = items.length; i < len; i++) {
|
|
396
|
-
item = items[i];
|
|
397
|
-
originalPath = path.join(targetDir, item);
|
|
398
|
-
backupName = `${hash}.${item}.bak`;
|
|
399
|
-
backupPath = path.join(targetDir, backupName);
|
|
400
|
-
fs.renameSync(originalPath, backupPath);
|
|
401
|
-
backupFiles.push({
|
|
402
|
-
original: originalPath,
|
|
403
|
-
backup: backupPath
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
// itemPath = path.join targetDir, item
|
|
407
|
-
// fs.rmSync itemPath, recursive: true, force: true
|
|
408
|
-
consola.success(`Files backed up with hash \`${hash}\``);
|
|
409
|
-
} else {
|
|
410
|
-
// consola.success "Refreshed!"
|
|
411
|
-
consola.info("Executing: Refresh (Single File)");
|
|
412
|
-
originalPath = targetDir;
|
|
413
|
-
fileName = path.basename(originalPath);
|
|
414
|
-
dirName = path.dirname(originalPath);
|
|
415
|
-
backupName = `${hash}.${fileName}.bak`;
|
|
416
|
-
backupPath = path.join(dirName, backupName);
|
|
417
|
-
fs.renameSync(originalPath, backupPath);
|
|
418
|
-
backupFiles.push({
|
|
419
|
-
original: originalPath,
|
|
420
|
-
backup: backupPath
|
|
421
|
-
});
|
|
422
|
-
consola.success(`Existing file backed up as \`${backupName}\``);
|
|
423
|
-
}
|
|
424
|
-
} catch (error1) {
|
|
425
|
-
// fs.rmSync targetDir, force: true
|
|
426
|
-
// consola.success "Refreshed!"
|
|
427
|
-
error = error1;
|
|
428
|
-
consola.error("Failed to create backups during refresh:", error);
|
|
429
|
-
restoreBackups();
|
|
430
|
-
process.exit(1);
|
|
431
|
-
}
|
|
432
|
-
} else {
|
|
433
|
-
consola.info("Refresh skipped.");
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
if (options.watch) {
|
|
437
|
-
consola.start(`Watching for changes in \`${config.entry}\`...`);
|
|
438
|
-
consola.info(`Executing: coffee ${spawnArgs.join(' ')}`);
|
|
439
|
-
if (milkeeOptions.refresh) {
|
|
440
|
-
consola.warn("Refresh backup is disabled in watch mode (backups are cleared immediately).");
|
|
441
|
-
clearBackups();
|
|
442
|
-
}
|
|
443
|
-
compilerProcess = spawn('coffee', spawnArgs, {
|
|
444
|
-
shell: true
|
|
445
|
-
});
|
|
446
|
-
debounceTimeout = null;
|
|
447
|
-
lastError = null;
|
|
448
|
-
compilerProcess.stderr.on('data', function(data) {
|
|
449
|
-
var errorMsg;
|
|
450
|
-
errorMsg = data.toString().trim();
|
|
451
|
-
if (errorMsg) {
|
|
452
|
-
consola.error(errorMsg);
|
|
453
|
-
return lastError = errorMsg;
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
compilerProcess.stdout.on('data', function(data) {
|
|
457
|
-
var stdoutMsg;
|
|
458
|
-
stdoutMsg = data.toString().trim();
|
|
459
|
-
if (stdoutMsg) {
|
|
460
|
-
consola.log(stdoutMsg);
|
|
461
|
-
}
|
|
462
|
-
debounceTimeout = null;
|
|
463
|
-
lastError = null;
|
|
464
|
-
if (debounceTimeout) {
|
|
465
|
-
clearTimeout(debounceTimeout);
|
|
466
|
-
}
|
|
467
|
-
return debounceTimeout = setTimeout(function() {
|
|
468
|
-
if (lastError) {
|
|
469
|
-
consola.warn("Compilation failed, plugins skipped.");
|
|
470
|
-
} else {
|
|
471
|
-
consola.success('Compilation successful (watch mode).');
|
|
472
|
-
runPlugins(config, {...(config.options || {})}, '(watch mode)', '');
|
|
473
|
-
}
|
|
474
|
-
return lastError = null;
|
|
475
|
-
}, 100);
|
|
476
|
-
});
|
|
477
|
-
compilerProcess.on('close', function(code) {
|
|
478
|
-
return consola.info(`Watch process exited with code ${code}.`);
|
|
479
|
-
});
|
|
480
|
-
return compilerProcess.on('error', function(err) {
|
|
481
|
-
consola.error('Failed to start watch process:', err);
|
|
482
|
-
return process.exit(1);
|
|
483
|
-
});
|
|
484
|
-
} else {
|
|
485
|
-
consola.start(`Compiling from \`${config.entry}\` to \`${config.output}\`...`);
|
|
486
|
-
consola.info(`Executing: ${execCommand}`);
|
|
487
|
-
return compilerProcess = exec(execCommand, function(error, stdout, stderr) {
|
|
488
|
-
if (error) {
|
|
489
|
-
consola.error('Compilation failed:', error);
|
|
490
|
-
if (stderr) {
|
|
491
|
-
consola.error(stderr.toString().trim());
|
|
492
|
-
}
|
|
493
|
-
if (milkeeOptions.refresh) {
|
|
494
|
-
restoreBackups();
|
|
495
|
-
}
|
|
496
|
-
process.exit(1);
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
setTimeout(function() {
|
|
500
|
-
if (milkeeOptions.refresh) {
|
|
501
|
-
clearBackups();
|
|
502
|
-
consola.success('Backup clearing completed!');
|
|
503
|
-
}
|
|
504
|
-
return consola.success('Compilation completed successfully!');
|
|
505
|
-
}, 500);
|
|
506
|
-
if (stdout) {
|
|
507
|
-
process.stdout.write(stdout);
|
|
508
|
-
}
|
|
509
|
-
if (stderr && !error) {
|
|
510
|
-
process.stderr.write(stderr);
|
|
511
|
-
}
|
|
512
|
-
return runPlugins(config, {...(config.options || {})}, stdout, stderr);
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
} catch (error1) {
|
|
516
|
-
error = error1;
|
|
517
|
-
consola.error('Failed to load or execute configuration:', error);
|
|
518
|
-
return process.exit(1);
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').option('setup', {
|
|
523
|
-
alias: 's',
|
|
524
|
-
describe: `Generate a default ${CONFIG_FILE}`,
|
|
525
|
-
type: 'boolean'
|
|
526
|
-
}).option('compile', {
|
|
527
|
-
alias: 'c',
|
|
528
|
-
describe: `Compile CoffeeScript based on ${CONFIG_FILE} (default)`,
|
|
529
|
-
type: 'boolean'
|
|
530
|
-
}).version('version', pkg.version).alias('v', 'version').help('help').alias('h', 'help').argv;
|
|
531
|
-
|
|
532
|
-
if (argv.setup) {
|
|
533
|
-
setup();
|
|
534
|
-
} else {
|
|
535
|
-
compile();
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
}).call(this);
|
|
24
|
+
if (argv.setup) {
|
|
25
|
+
setup();
|
|
26
|
+
} else {
|
|
27
|
+
compile();
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var confirmContinue, consola;
|
|
3
|
+
|
|
4
|
+
consola = require('consola');
|
|
5
|
+
|
|
6
|
+
// Confirm processing
|
|
7
|
+
confirmContinue = async function() {
|
|
8
|
+
var toContinue;
|
|
9
|
+
toContinue = (await consola.prompt("Do you want to continue?", {
|
|
10
|
+
type: "confirm"
|
|
11
|
+
}));
|
|
12
|
+
if (!toContinue) {
|
|
13
|
+
consola.info("Canceled.");
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = confirmContinue;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CWD, consola, executeCopy, fs, path;
|
|
3
|
+
|
|
4
|
+
fs = require('fs');
|
|
5
|
+
|
|
6
|
+
path = require('path');
|
|
7
|
+
|
|
8
|
+
consola = require('consola');
|
|
9
|
+
|
|
10
|
+
({CWD} = require('../constants'));
|
|
11
|
+
|
|
12
|
+
executeCopy = function(config) {
|
|
13
|
+
var copyNonCoffeeFiles, entryPath, error, outputPath, ref, stat;
|
|
14
|
+
entryPath = path.join(CWD, config.entry);
|
|
15
|
+
outputPath = path.join(CWD, config.output);
|
|
16
|
+
if (!fs.existsSync(entryPath)) {
|
|
17
|
+
consola.warn(`Entry path does not exist: ${config.entry}`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if ((ref = config.options) != null ? ref.join : void 0) {
|
|
21
|
+
consola.info("Copy skipped (join option is enabled)");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!fs.existsSync(outputPath)) {
|
|
25
|
+
consola.warn(`Output path does not exist: ${config.output}`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
stat = fs.statSync(entryPath);
|
|
29
|
+
if (!stat.isDirectory()) {
|
|
30
|
+
consola.info("Copy skipped (entry is not a directory)");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
consola.start("Copying non-coffee files...");
|
|
34
|
+
try {
|
|
35
|
+
copyNonCoffeeFiles = function(srcDir, destDir) {
|
|
36
|
+
var destItemPath, i, item, items, len, parentDir, results, srcItemPath;
|
|
37
|
+
items = fs.readdirSync(srcDir);
|
|
38
|
+
results = [];
|
|
39
|
+
for (i = 0, len = items.length; i < len; i++) {
|
|
40
|
+
item = items[i];
|
|
41
|
+
srcItemPath = path.join(srcDir, item);
|
|
42
|
+
destItemPath = path.join(destDir, item);
|
|
43
|
+
stat = fs.statSync(srcItemPath);
|
|
44
|
+
if (stat.isDirectory()) {
|
|
45
|
+
if (!fs.existsSync(destItemPath)) {
|
|
46
|
+
fs.mkdirSync(destItemPath, {
|
|
47
|
+
recursive: true
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
results.push(copyNonCoffeeFiles(srcItemPath, destItemPath));
|
|
51
|
+
} else {
|
|
52
|
+
// Skip .coffee files
|
|
53
|
+
if (!item.endsWith('.coffee')) {
|
|
54
|
+
// Create parent directory if needed
|
|
55
|
+
parentDir = path.dirname(destItemPath);
|
|
56
|
+
if (!fs.existsSync(parentDir)) {
|
|
57
|
+
fs.mkdirSync(parentDir, {
|
|
58
|
+
recursive: true
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Copy file
|
|
62
|
+
results.push(fs.copyFileSync(srcItemPath, destItemPath));
|
|
63
|
+
} else {
|
|
64
|
+
results.push(void 0);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return results;
|
|
69
|
+
};
|
|
70
|
+
copyNonCoffeeFiles(entryPath, outputPath);
|
|
71
|
+
return consola.success("Non-coffee files copied successfully!");
|
|
72
|
+
} catch (error1) {
|
|
73
|
+
error = error1;
|
|
74
|
+
consola.error("Failed to copy non-coffee files:", error);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
module.exports = executeCopy;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CWD, clearBackups, consola, crypto, executeRefresh, fs, path, restoreBackups;
|
|
3
|
+
|
|
4
|
+
fs = require('fs');
|
|
5
|
+
|
|
6
|
+
path = require('path');
|
|
7
|
+
|
|
8
|
+
crypto = require('crypto');
|
|
9
|
+
|
|
10
|
+
consola = require('consola');
|
|
11
|
+
|
|
12
|
+
({CWD} = require('../constants'));
|
|
13
|
+
|
|
14
|
+
// Execute refresh processing
|
|
15
|
+
executeRefresh = function(config, backupFiles) {
|
|
16
|
+
var backupName, backupPath, dirName, error, fileName, hash, i, item, items, len, originalPath, stat, targetDir;
|
|
17
|
+
targetDir = path.join(CWD, config.output);
|
|
18
|
+
if (fs.existsSync(targetDir)) {
|
|
19
|
+
stat = fs.statSync(targetDir);
|
|
20
|
+
hash = crypto.randomBytes(4).toString('hex');
|
|
21
|
+
try {
|
|
22
|
+
if (stat.isDirectory()) {
|
|
23
|
+
consola.info("Executing: Refresh");
|
|
24
|
+
items = fs.readdirSync(targetDir);
|
|
25
|
+
consola.start("Backing up files...");
|
|
26
|
+
for (i = 0, len = items.length; i < len; i++) {
|
|
27
|
+
item = items[i];
|
|
28
|
+
originalPath = path.join(targetDir, item);
|
|
29
|
+
backupName = `${hash}.${item}.bak`;
|
|
30
|
+
backupPath = path.join(targetDir, backupName);
|
|
31
|
+
fs.renameSync(originalPath, backupPath);
|
|
32
|
+
backupFiles.push({
|
|
33
|
+
original: originalPath,
|
|
34
|
+
backup: backupPath
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return consola.success(`Files backed up with hash \`${hash}\``);
|
|
38
|
+
} else {
|
|
39
|
+
consola.info("Executing: Refresh (Single File)");
|
|
40
|
+
originalPath = targetDir;
|
|
41
|
+
fileName = path.basename(originalPath);
|
|
42
|
+
dirName = path.dirname(originalPath);
|
|
43
|
+
backupName = `${hash}.${fileName}.bak`;
|
|
44
|
+
backupPath = path.join(dirName, backupName);
|
|
45
|
+
fs.renameSync(originalPath, backupPath);
|
|
46
|
+
backupFiles.push({
|
|
47
|
+
original: originalPath,
|
|
48
|
+
backup: backupPath
|
|
49
|
+
});
|
|
50
|
+
return consola.success(`Existing file backed up as \`${backupName}\``);
|
|
51
|
+
}
|
|
52
|
+
} catch (error1) {
|
|
53
|
+
error = error1;
|
|
54
|
+
consola.error("Failed to create backups during refresh:", error);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
return consola.info("Refresh skipped.");
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Restore backup files
|
|
63
|
+
restoreBackups = function(backupFiles) {
|
|
64
|
+
var backup, e, i, len;
|
|
65
|
+
consola.info("Restoring previous files...");
|
|
66
|
+
if (backupFiles.length > 0) {
|
|
67
|
+
for (i = 0, len = backupFiles.length; i < len; i++) {
|
|
68
|
+
backup = backupFiles[i];
|
|
69
|
+
try {
|
|
70
|
+
if (fs.existsSync(backup.original)) {
|
|
71
|
+
fs.rmSync(backup.original, {
|
|
72
|
+
force: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (fs.existsSync(backup.backup)) {
|
|
76
|
+
fs.renameSync(backup.backup, backup.original);
|
|
77
|
+
}
|
|
78
|
+
} catch (error1) {
|
|
79
|
+
e = error1;
|
|
80
|
+
consola.warn(`Failed to restore ${backup.original}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return consola.success("Restored!");
|
|
84
|
+
} else {
|
|
85
|
+
return consola.info("No files found to restore.");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Clear backup files
|
|
90
|
+
clearBackups = function(backupFiles) {
|
|
91
|
+
var backup, e, i, len, results;
|
|
92
|
+
if (backupFiles.length > 0) {
|
|
93
|
+
consola.start("Cleaning up backups...");
|
|
94
|
+
results = [];
|
|
95
|
+
for (i = 0, len = backupFiles.length; i < len; i++) {
|
|
96
|
+
backup = backupFiles[i];
|
|
97
|
+
try {
|
|
98
|
+
if (fs.existsSync(backup.backup)) {
|
|
99
|
+
results.push(fs.rmSync(backup.backup, {
|
|
100
|
+
force: true
|
|
101
|
+
}));
|
|
102
|
+
} else {
|
|
103
|
+
results.push(void 0);
|
|
104
|
+
}
|
|
105
|
+
} catch (error1) {
|
|
106
|
+
e = error1;
|
|
107
|
+
results.push(null);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return results;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
module.exports = {executeRefresh, restoreBackups, clearBackups};
|
package/dist/plugins.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var CWD, consola, executePlugins, fs, getCompiledFiles, path, runPlugins;
|
|
3
|
+
|
|
4
|
+
path = require('path');
|
|
5
|
+
|
|
6
|
+
fs = require('fs');
|
|
7
|
+
|
|
8
|
+
consola = require('consola');
|
|
9
|
+
|
|
10
|
+
({CWD} = require('./constants'));
|
|
11
|
+
|
|
12
|
+
({getCompiledFiles} = require('./utils'));
|
|
13
|
+
|
|
14
|
+
executePlugins = function(config, compilationResult) {
|
|
15
|
+
var plugins, ref;
|
|
16
|
+
plugins = ((ref = config.milkee) != null ? ref.plugins : void 0) || [];
|
|
17
|
+
if (!(plugins.length > 0)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
consola.start(`Running ${plugins.length} plugin(s)...`);
|
|
21
|
+
return (async function() { // async
|
|
22
|
+
var error, i, len, pluginFn;
|
|
23
|
+
try {
|
|
24
|
+
for (i = 0, len = plugins.length; i < len; i++) {
|
|
25
|
+
pluginFn = plugins[i];
|
|
26
|
+
if (typeof pluginFn === 'function') {
|
|
27
|
+
await Promise.resolve(pluginFn(compilationResult));
|
|
28
|
+
} else {
|
|
29
|
+
consola.warn(`Invalid plugin definition skipped (expected a function, got ${typeof pluginFn}).`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return consola.success("Plugins executed successfully.");
|
|
33
|
+
} catch (error1) {
|
|
34
|
+
error = error1;
|
|
35
|
+
return consola.error("An error occurred during plugin execution:", error);
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
runPlugins = function(config, options, stdout = '', stderr = '') {
|
|
41
|
+
var compilationResult, compiledFiles, mapPath, outputPath;
|
|
42
|
+
outputPath = path.join(CWD, config.output);
|
|
43
|
+
compiledFiles = getCompiledFiles(outputPath);
|
|
44
|
+
if (options.join && options.map && !options.inlineMap) {
|
|
45
|
+
mapPath = `${outputPath}.map`;
|
|
46
|
+
if (fs.existsSync(mapPath && !compiledFiles.includes(mapPath))) {
|
|
47
|
+
compiledFiles = compiledFiles.concat(getCompiledFiles(mapPath));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
compilationResult = {
|
|
51
|
+
config: config,
|
|
52
|
+
compiledFiles: compiledFiles,
|
|
53
|
+
stdout: stdout,
|
|
54
|
+
stderr: stderr
|
|
55
|
+
};
|
|
56
|
+
return executePlugins(config, compilationResult);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
module.exports = {runPlugins};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
var consola, fs, getCompiledFiles, path, sleep;
|
|
3
|
+
|
|
4
|
+
fs = require('fs');
|
|
5
|
+
|
|
6
|
+
path = require('path');
|
|
7
|
+
|
|
8
|
+
consola = require('consola');
|
|
9
|
+
|
|
10
|
+
sleep = function(time) {
|
|
11
|
+
return new Promise(function(resolve) {
|
|
12
|
+
return setTimeout(resolve, time);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
getCompiledFiles = function(targetPath) {
|
|
17
|
+
var error, filesList, i, item, itemPath, items, len, stat;
|
|
18
|
+
filesList = [];
|
|
19
|
+
if (!fs.existsSync(targetPath)) {
|
|
20
|
+
consola.warn(`Path does not exist, skipping scan ${targetPath}`);
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
stat = fs.statSync(targetPath);
|
|
25
|
+
if (stat.isDirectory()) {
|
|
26
|
+
consola.start(`Scanning directory: ${targetPath}`);
|
|
27
|
+
items = fs.readdirSync(targetPath);
|
|
28
|
+
for (i = 0, len = items.length; i < len; i++) {
|
|
29
|
+
item = items[i];
|
|
30
|
+
itemPath = path.join(targetPath, item);
|
|
31
|
+
filesList = filesList.concat(getCompiledFiles(itemPath));
|
|
32
|
+
}
|
|
33
|
+
} else if (stat.isFile()) {
|
|
34
|
+
if (targetPath.endsWith('.js' || targetPath.endsWith('.js.map'))) {
|
|
35
|
+
if (fs.existsSync(targetPath)) {
|
|
36
|
+
consola.info(`Found file: \`${targetPath}\``);
|
|
37
|
+
}
|
|
38
|
+
filesList.push(targetPath);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} catch (error1) {
|
|
42
|
+
error = error1;
|
|
43
|
+
consola.warn(`Could not scan output path ${targetPath}: ${error.message}`);
|
|
44
|
+
}
|
|
45
|
+
return filesList;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports = {sleep, getCompiledFiles};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "milkee",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A simple CoffeeScript build tool with coffee.config.cjs",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "echo \"No test specified\" && exit 0",
|
|
11
|
-
"build": "coffee --output dist/ --compile src/"
|
|
11
|
+
"build": "coffee --output dist/ --compile --bare src/"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
package/temp/coffee.config.cjs
CHANGED
|
@@ -29,6 +29,8 @@ module.exports = {
|
|
|
29
29
|
// refresh: false,
|
|
30
30
|
// Before compiling, confirm "Do you want to Continue?"
|
|
31
31
|
// confirm: false,
|
|
32
|
+
// After compiling, copy non-coffee files from entry to output directory. (Only works when options.join is false)
|
|
33
|
+
// copy: false,
|
|
32
34
|
},
|
|
33
35
|
plugins: []
|
|
34
36
|
},
|