milkee 2.2.0 → 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 CHANGED
@@ -75,8 +75,10 @@ module.exports = {
75
75
  options: {
76
76
  // Before compiling, reset the directory.
77
77
  // refresh: false,
78
- // Before compiling, confirm "Do you want to Continue?"
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,501 +1,28 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- (function() {
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
- yargs = require('yargs');
4
+ yargs = require('yargs');
6
5
 
7
- ({hideBin} = require('yargs/helpers'));
6
+ ({hideBin} = require('yargs/helpers'));
8
7
 
9
- consola = require('consola');
8
+ ({pkg} = require('./constants'));
10
9
 
11
- ({isPackageLatest} = require('is-package-latest'));
10
+ setup = require('./commands/setup');
12
11
 
13
- fs = require('fs');
12
+ compile = require('./commands/compile');
14
13
 
15
- path = require('path');
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
- ({exec, spawn} = require('child_process'));
18
-
19
- crypto = require('crypto');
20
-
21
- pkg = require('../package.json');
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\n# or local installation\n\`npm i -D milkee@latest\`\n`
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 backupFiles, backupName, backupPath, cl, 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;
192
- cl = (await checkLatest());
193
- if (cl) {
194
- await sleep(1000);
195
- }
196
- checkCoffee();
197
- if (!fs.existsSync(CONFIG_PATH)) {
198
- consola.error(`\`${CONFIG_FILE}\` not found in this directory: ${CWD}`);
199
- consola.info('Please run `milkee --setup` to create a configuration file.');
200
- process.exit(1);
201
- }
202
- try {
203
- config = require(CONFIG_PATH);
204
- if (!(config.entry && config.output)) {
205
- consola.error('`entry` and `output` properties are required in your configuration.');
206
- process.exit(1);
207
- }
208
- options = {...(config.options || {})};
209
- milkee = config.milkee || {};
210
- milkeeOptions = config.milkee.options || {};
211
- execCommandParts = ['coffee'];
212
- if (options.join) {
213
- execCommandParts.push('--join');
214
- execCommandParts.push(`\"${config.output}\"`);
215
- } else {
216
- execCommandParts.push('--output');
217
- execCommandParts.push(`\"${config.output}\"`);
218
- }
219
- execOtherOptionStrings = [];
220
- if (options.bare) {
221
- execOtherOptionStrings.push('--bare');
222
- }
223
- if (options.map) {
224
- execOtherOptionStrings.push('--map');
225
- }
226
- if (options.inlineMap) {
227
- execOtherOptionStrings.push('--inline-map');
228
- }
229
- if (options.noHeader) {
230
- execOtherOptionStrings.push('--no-header');
231
- }
232
- if (options.transpile) {
233
- execOtherOptionStrings.push('--transpile');
234
- }
235
- if (options.literate) {
236
- execOtherOptionStrings.push('--literate');
237
- }
238
- if (execOtherOptionStrings.length > 0) {
239
- execCommandParts.push(execOtherOptionStrings.join(' '));
240
- }
241
- execCommandParts.push('--compile');
242
- execCommandParts.push(`\"${config.entry}\"`);
243
- execCommand = execCommandParts.filter(Boolean).join(' ');
244
- spawnArgs = [];
245
- if (options.join) {
246
- spawnArgs.push('--join');
247
- spawnArgs.push(config.output);
248
- } else {
249
- spawnArgs.push('--output');
250
- spawnArgs.push(config.output);
251
- }
252
- if (options.bare) {
253
- spawnArgs.push('--bare');
254
- }
255
- if (options.map) {
256
- spawnArgs.push('--map');
257
- }
258
- if (options.inlineMap) {
259
- spawnArgs.push('--inline-map');
260
- }
261
- if (options.noHeader) {
262
- spawnArgs.push('--no-header');
263
- }
264
- if (options.transpile) {
265
- spawnArgs.push('--transpile');
266
- }
267
- if (options.literate) {
268
- spawnArgs.push('--literate');
269
- }
270
- if (options.watch) {
271
- spawnArgs.push('--watch');
272
- }
273
- spawnArgs.push('--compile');
274
- spawnArgs.push(config.entry);
275
- summary = [];
276
- summary.push(`Entry: \`${config.entry}\``);
277
- summary.push(`Output: \`${config.output}\``);
278
- enabledOptions = Object.keys(options).filter(function(key) {
279
- return options[key];
280
- });
281
- if (enabledOptions.length > 0) {
282
- enabledOptionsList = enabledOptions.join(',');
283
- summary.push(`Options: ${enabledOptionsList}`);
284
- }
285
- consola.box({
286
- title: "Milkee Compilation Summary",
287
- message: summary.join('\n')
288
- });
289
- if (milkeeOptions.confirm) {
290
- toContinue = (await consola.prompt("Do you want to continue?", {
291
- type: "confirm"
292
- }));
293
- if (!toContinue) {
294
- consola.info("Canceled.");
295
- return;
296
- }
297
- }
298
- delete options.join;
299
- backupFiles = [];
300
- restoreBackups = function() {
301
- var backup, e, i, len;
302
- consola.info("Restoring previous files...");
303
- if (backupFiles.length > 0) {
304
- for (i = 0, len = backupFiles.length; i < len; i++) {
305
- backup = backupFiles[i];
306
- try {
307
- if (fs.existsSync(backup.original)) {
308
- fs.rmSync(backup.original, {
309
- force: true
310
- });
311
- }
312
- if (fs.existsSync(backup.backup)) {
313
- fs.renameSync(backup.backup, backup.original);
314
- }
315
- } catch (error1) {
316
- e = error1;
317
- consola.warn(`Failed to restore ${backup.original}`);
318
- }
319
- }
320
- return consola.success("Restored!");
321
- } else {
322
- return consola.info("No files found to restore.");
323
- }
324
- };
325
- clearBackups = function() {
326
- var backup, e, i, len, results;
327
- if (backupFiles.length > 0) {
328
- consola.start("Cleaning up backups...");
329
- results = [];
330
- for (i = 0, len = backupFiles.length; i < len; i++) {
331
- backup = backupFiles[i];
332
- try {
333
- if (fs.existsSync(backup.backup)) {
334
- results.push(fs.rmSync(backup.backup, {
335
- force: true
336
- }));
337
- } else {
338
- results.push(void 0);
339
- }
340
- } catch (error1) {
341
- e = error1;
342
- results.push(null);
343
- }
344
- }
345
- return results;
346
- }
347
- };
348
- if (milkeeOptions.refresh) {
349
- targetDir = path.join(CWD, config.output);
350
- if (fs.existsSync(targetDir)) {
351
- stat = fs.statSync(targetDir);
352
- hash = crypto.randomBytes(4).toString('hex');
353
- try {
354
- if (stat.isDirectory()) {
355
- consola.info("Executing: Refresh");
356
- items = fs.readdirSync(targetDir);
357
- consola.start("Bucking up files...");
358
- for (i = 0, len = items.length; i < len; i++) {
359
- item = items[i];
360
- originalPath = path.join(targetDir, item);
361
- backupName = `${hash}.${item}.bak`;
362
- backupPath = path.join(targetDir, backupName);
363
- fs.renameSync(originalPath, backupPath);
364
- backupFiles.push({
365
- original: originalPath,
366
- backup: backupPath
367
- });
368
- }
369
- // itemPath = path.join targetDir, item
370
- // fs.rmSync itemPath, recursive: true, force: true
371
- consola.success(`Files backed up with hash \`${hash}\``);
372
- } else {
373
- // consola.success "Refreshed!"
374
- consola.info("Executing: Refresh (Single File)");
375
- originalPath = targetDir;
376
- fileName = path.basename(originalPath);
377
- dirName = path.dirname(originalPath);
378
- backupName = `${hash}.${fileName}.bak`;
379
- backupPath = path.join(dirName, backupName);
380
- fs.renameSync(originalPath, backupPath);
381
- backupFiles.push({
382
- original: originalPath,
383
- backup: backupPath
384
- });
385
- consola.success(`Existing file backed up as \`${backupName}\``);
386
- }
387
- } catch (error1) {
388
- // fs.rmSync targetDir, force: true
389
- // consola.success "Refreshed!"
390
- error = error1;
391
- consola.error("Failed to create backups during refresh:", error);
392
- restoreBackups();
393
- process.exit(1);
394
- }
395
- } else {
396
- consola.info("Refresh skipped.");
397
- }
398
- }
399
- if (options.watch) {
400
- consola.start(`Watching for changes in \`${config.entry}\`...`);
401
- consola.info(`Executing: coffee ${spawnArgs.join(' ')}`);
402
- if (milkeeOptions.refresh) {
403
- consola.warn("Refresh backup is disabled in watch mode (backups are cleared immediately).");
404
- clearBackups();
405
- }
406
- compilerProcess = spawn('coffee', spawnArgs, {
407
- shell: true
408
- });
409
- debounceTimeout = null;
410
- lastError = null;
411
- compilerProcess.stderr.on('data', function(data) {
412
- var errorMsg;
413
- errorMsg = data.toString().trim();
414
- if (errorMsg) {
415
- consola.error(errorMsg);
416
- return lastError = errorMsg;
417
- }
418
- });
419
- compilerProcess.stdout.on('data', function(data) {
420
- var stdoutMsg;
421
- stdoutMsg = data.toString().trim();
422
- if (stdoutMsg) {
423
- consola.log(stdoutMsg);
424
- }
425
- debounceTimeout = null;
426
- lastError = null;
427
- if (debounceTimeout) {
428
- clearTimeout(debounceTimeout);
429
- }
430
- return debounceTimeout = setTimeout(function() {
431
- if (lastError) {
432
- consola.warn("Compilation failed, plugins skipped.");
433
- } else {
434
- consola.success('Compilation successful (watch mode).');
435
- runPlugins(config, {...(config.options || {})}, '(watch mode)', '');
436
- }
437
- return lastError = null;
438
- }, 100);
439
- });
440
- compilerProcess.on('close', function(code) {
441
- return consola.info(`Watch process exited with code ${code}.`);
442
- });
443
- return compilerProcess.on('error', function(err) {
444
- consola.error('Failed to start watch process:', err);
445
- return process.exit(1);
446
- });
447
- } else {
448
- consola.start(`Compiling from \`${config.entry}\` to \`${config.output}\`...`);
449
- consola.info(`Executing: ${execCommand}`);
450
- return compilerProcess = exec(execCommand, function(error, stdout, stderr) {
451
- if (error) {
452
- consola.error('Compilation failed:', error);
453
- if (stderr) {
454
- consola.error(stderr.toString().trim());
455
- }
456
- if (milkeeOptions.refresh) {
457
- restoreBackups();
458
- }
459
- process.exit(1);
460
- return;
461
- }
462
- setTimeout(function() {
463
- if (milkeeOptions.refresh) {
464
- clearBackups();
465
- consola.success('Backup clearing completed!');
466
- }
467
- return consola.success('Compilation completed successfully!');
468
- }, 500);
469
- if (stdout) {
470
- process.stdout.write(stdout);
471
- }
472
- if (stderr && !error) {
473
- process.stderr.write(stderr);
474
- }
475
- return runPlugins(config, {...(config.options || {})}, stdout, stderr);
476
- });
477
- }
478
- } catch (error1) {
479
- error = error1;
480
- consola.error('Failed to load or execute configuration:', error);
481
- return process.exit(1);
482
- }
483
- };
484
-
485
- argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').option('setup', {
486
- alias: 's',
487
- describe: `Generate a default ${CONFIG_FILE}`,
488
- type: 'boolean'
489
- }).option('compile', {
490
- alias: 'c',
491
- describe: `Compile CoffeeScript based on ${CONFIG_FILE} (default)`,
492
- type: 'boolean'
493
- }).version('version', pkg.version).alias('v', 'version').help('help').alias('h', 'help').argv;
494
-
495
- if (argv.setup) {
496
- setup();
497
- } else {
498
- compile();
499
- }
500
-
501
- }).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};
@@ -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.2.0",
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",
@@ -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
  },