milkee 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -41,7 +41,7 @@
41
41
  };
42
42
 
43
43
  compile = function() {
44
- var command, commandParts, config, error, key, options, otherOptionStrings, value;
44
+ var command, commandParts, compilerProcess, config, error, i, item, itemPath, items, len, milkee, milkeeOptions, options, otherOptionStrings, targetDir;
45
45
  if (!fs.existsSync(CONFIG_PATH)) {
46
46
  consola.error(`\`${CONFIG_FILE}\` not found in this directory: ${CWD}`);
47
47
  consola.info('Please run `milkee --setup` to create a configuration file.');
@@ -54,6 +54,8 @@
54
54
  process.exit(1);
55
55
  }
56
56
  options = config.options || {};
57
+ milkee = config.milkee || {};
58
+ milkeeOptions = config.milkee.options || {};
57
59
  commandParts = ['coffee'];
58
60
  if (options.join) {
59
61
  commandParts.push('--join');
@@ -62,41 +64,80 @@
62
64
  commandParts.push('--output');
63
65
  commandParts.push(`\"${config.output}\"`);
64
66
  }
65
- delete options.join;
66
67
  otherOptionStrings = [];
67
- for (key in options) {
68
- value = options[key];
69
- if (value === true) {
70
- otherOptionStrings.push(`--${key}`);
71
- } else if (value !== false) {
72
- otherOptionStrings.push(`--${key} \"${value}\"`);
68
+ if (milkeeOptions.refresh) {
69
+ targetDir = path.join(CWD, config.output);
70
+ if (!fs.existsSync(targetDir)) {
71
+ consola.info("Refresh skipped.");
72
+ } else {
73
+ items = fs.readdirSync(targetDir);
74
+ for (i = 0, len = items.length; i < len; i++) {
75
+ item = items[i];
76
+ itemPath = path.join(targetDir, item);
77
+ fs.rmSync(itemPath, {
78
+ recursive: true,
79
+ force: true
80
+ });
81
+ }
82
+ consola.success("Refreshed!");
73
83
  }
74
84
  }
85
+ if (options.bare) {
86
+ otherOptionStrings.push("--bare");
87
+ }
88
+ if (options.map) {
89
+ otherOptionStrings.push('--map');
90
+ }
91
+ if (options.inlineMap) {
92
+ otherOptionStrings.push('--inline-map');
93
+ }
94
+ if (options.noHeader) {
95
+ otherOptionStrings.push('--no-header');
96
+ }
97
+ if (options.transpile) {
98
+ otherOptionStrings.push('--transpile');
99
+ }
100
+ if (options.literate) {
101
+ otherOptionStrings.push('--literate');
102
+ }
103
+ if (options.watch) {
104
+ otherOptionStrings.push('--watch');
105
+ }
75
106
  if (otherOptionStrings.length > 0) {
76
107
  commandParts.push(otherOptionStrings.join(' '));
77
108
  }
78
109
  commandParts.push('--compile');
79
110
  commandParts.push(`\"${config.entry}\"`);
80
111
  command = commandParts.filter(Boolean).join(' ');
81
- consola.start(`Compiling from \`${config.entry}\` to \`${config.output}\`...`);
112
+ if (options.watch) {
113
+ consola.start(`Watching for changes in \`${config.entry}\`...`);
114
+ } else {
115
+ consola.start(`Compiling from \`${config.entry}\` to \`${config.output}\`...`);
116
+ }
82
117
  consola.info(`Executing: ${command}`);
83
- return exec(command, function(error, stdout, stderr) {
84
- if (error) {
85
- consola.error('Compilation failed:', error);
86
- if (stderr) {
87
- process.stderr.write(stderr);
118
+ compilerProcess = exec(command, function(error, stdout, stderr) {
119
+ if (!options.watch) {
120
+ if (error) {
121
+ consola.error('Compilation failed:', error);
122
+ if (stderr) {
123
+ process.stderr.write(stderr);
124
+ }
125
+ process.exit(1);
126
+ return;
88
127
  }
89
- process.exit(1);
90
- return;
91
128
  }
92
129
  consola.success('Compilation completed successfully!');
93
130
  if (stdout) {
94
131
  process.stdout.write(stdout);
95
132
  }
96
- if (stderr) {
133
+ if (stderr && !error) {
97
134
  return process.stderr.write(stderr);
98
135
  }
99
136
  });
137
+ if (options.watch) {
138
+ compilerProcess.stdout.pipe(process.stdout);
139
+ return compilerProcess.stderr.pipe(process.stderr);
140
+ }
100
141
  } catch (error1) {
101
142
  error = error1;
102
143
  consola.error('Failed to load or execute configuration:', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "milkee",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "A simple CoffeeScript build tool with coffee.config.js",
5
5
  "main": "dist/main.js",
6
6
  "bin": {
@@ -2,22 +2,30 @@ module.exports = {
2
2
  // The entry point for compilation.
3
3
  // This can be a single file or a directory.
4
4
  entry: 'src',
5
-
6
5
  // The output for the compiled JavaScript files.
7
6
  // If 'join' is true, this should be a single file path (e.g., 'dist/app.js').
8
7
  // If 'join' is false, this should be a directory (e.g., 'dist').
9
8
  output: 'dist',
10
-
11
9
  // (Optional) Additional options for the CoffeeScript compiler.
12
10
  // See `coffee --help` for all available options.
11
+ // Web: https://coffeescript.org/annotated-source/command.html
13
12
  options: {
14
- // Join all scripts into a single file.
13
+ // The following options are supported:
14
+ // bare: false,
15
15
  // join: false,
16
-
17
- // Add a header to the top of the compiled JavaScript.
18
- // header: false,
19
-
20
- // Compile without the top-level function wrapper.
21
- // bare: true
22
- }
16
+ // map: false,
17
+ // inlineMap: false,
18
+ // noHeader: false,
19
+ // transpile: false,
20
+ // literate: false,
21
+ // watch: false,
22
+ },
23
+ // (Optional) Additional options/plugins for the Milkee builder.
24
+ milkee: {
25
+ options: {
26
+ // Before compiling, reset the directory.
27
+ // refresh: false,
28
+ },
29
+ plugins: []
30
+ },
23
31
  };