milkee 0.0.2 → 0.0.3
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/bin/milkee.js +3 -0
- package/dist/main.js +125 -0
- package/package.json +4 -4
- package/dist/bin.js +0 -122
package/bin/milkee.js
ADDED
package/dist/main.js
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
2
|
+
(function() {
|
3
|
+
var CONFIG_FILE, CONFIG_PATH, CWD, TEMPLATE_PATH, argv, compile, consola, exec, fs, hideBin, path, pkg, setup, yargs;
|
4
|
+
|
5
|
+
yargs = require('yargs');
|
6
|
+
|
7
|
+
({hideBin} = require('yargs/helpers'));
|
8
|
+
|
9
|
+
consola = require('consola');
|
10
|
+
|
11
|
+
fs = require('fs');
|
12
|
+
|
13
|
+
path = require('path');
|
14
|
+
|
15
|
+
({exec} = require('child_process'));
|
16
|
+
|
17
|
+
pkg = require('../package.json');
|
18
|
+
|
19
|
+
CWD = process.cwd();
|
20
|
+
|
21
|
+
CONFIG_FILE = 'coffee.config.js';
|
22
|
+
|
23
|
+
CONFIG_PATH = path.join(CWD, CONFIG_FILE);
|
24
|
+
|
25
|
+
TEMPLATE_PATH = path.join(__dirname, '..', 'temp', 'coffee.config.js');
|
26
|
+
|
27
|
+
setup = function() {
|
28
|
+
var error;
|
29
|
+
if (fs.existsSync(CONFIG_PATH)) {
|
30
|
+
consola.warn(`\`${CONFIG_FILE}\` already exists in this directory.`);
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
try {
|
34
|
+
fs.writeFileSync(CONFIG_PATH, CONFIG_TEMPLATE);
|
35
|
+
return consola.success(`Successfully created \`${CONFIG_FILE}\`.`);
|
36
|
+
} catch (error1) {
|
37
|
+
error = error1;
|
38
|
+
return consola.error(`Failed to create \`${CONFIG_FILE}\`:`, error);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
compile = async(async function() {
|
43
|
+
var command, commandParts, config, configPathUrl, error, key, options, otherOptionStrings, value;
|
44
|
+
if (!fs.existsSync(CONFIG_PATH)) {
|
45
|
+
consola.error(`\`${CONFIG_FILE}\` not found.`);
|
46
|
+
consola.info('Please run `milkee --setup` to create a configuration file.');
|
47
|
+
process.exit(1);
|
48
|
+
}
|
49
|
+
try {
|
50
|
+
configPathUrl = path.toFileUrl(CONFIG_PATH).href;
|
51
|
+
({
|
52
|
+
default: config
|
53
|
+
} = (await import(configPathUrl)));
|
54
|
+
if (!(config.entry && config.output)) {
|
55
|
+
consola.error('`entry` and `output` properties are required in your configuration.');
|
56
|
+
process.exit(1);
|
57
|
+
}
|
58
|
+
options = config.options || {};
|
59
|
+
commandParts = ['coffee'];
|
60
|
+
if (options.join) {
|
61
|
+
commandParts.push('--join');
|
62
|
+
commandParts.push(`\"${config.output}\"`);
|
63
|
+
} else {
|
64
|
+
commandParts.push('--output');
|
65
|
+
commandParts.push(`\"${config.output}\"`);
|
66
|
+
}
|
67
|
+
delete options.join;
|
68
|
+
otherOptionStrings = [];
|
69
|
+
for (key in options) {
|
70
|
+
value = options[key];
|
71
|
+
if (value === true) {
|
72
|
+
otherOptionStrings.push(`--${key}`);
|
73
|
+
} else if (value !== false) {
|
74
|
+
otherOptionStrings.push(`--${key} \"${value}\"`);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
if (otherOptionStrings.length > 0) {
|
78
|
+
commandParts.push(otherOptionStrings.join(' '));
|
79
|
+
}
|
80
|
+
commandParts.push('--compile');
|
81
|
+
commandParts.push(`\"${config.entry}\"`);
|
82
|
+
command = commandParts.filter(Boolean).join(' ');
|
83
|
+
consola.start(`Compiling from \`${config.entry}\` to \`${config.output}\`...`);
|
84
|
+
consola.info(`Executing: ${command}`);
|
85
|
+
return exec(command, function(error, stdout, stderr) {
|
86
|
+
if (error) {
|
87
|
+
consola.error('Compilation failed:', error);
|
88
|
+
if (stderr) {
|
89
|
+
process.stderr.write(stderr);
|
90
|
+
}
|
91
|
+
process.exit(1);
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
consola.success('Compilation completed successfully!');
|
95
|
+
if (stdout) {
|
96
|
+
process.stdout.write(stdout);
|
97
|
+
}
|
98
|
+
if (stderr) {
|
99
|
+
return process.stderr.write(stderr);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
} catch (error1) {
|
103
|
+
error = error1;
|
104
|
+
consola.error('Failed to load or execute configuration:', error);
|
105
|
+
return process.exit(1);
|
106
|
+
}
|
107
|
+
});
|
108
|
+
|
109
|
+
argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').option('setup', {
|
110
|
+
alias: 's',
|
111
|
+
describe: 'Generate a default coffee.config.js',
|
112
|
+
type: 'boolean'
|
113
|
+
}).option('compile', {
|
114
|
+
alias: 'c',
|
115
|
+
describe: 'Compile CoffeeScript based on coffee.config.js (default)',
|
116
|
+
type: 'boolean'
|
117
|
+
}).version('version', pkg.version).alias('v', 'version').help('help').alias('h', 'help').argv;
|
118
|
+
|
119
|
+
if (argv.setup) {
|
120
|
+
setup();
|
121
|
+
} else {
|
122
|
+
compile();
|
123
|
+
}
|
124
|
+
|
125
|
+
}).call(this);
|
package/package.json
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "milkee",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
4
|
"description": "A simple CoffeeScript build tool with coffee.config.js",
|
5
|
-
"main": "dist/
|
5
|
+
"main": "dist/main.js",
|
6
6
|
"bin": {
|
7
|
-
"milkee": "
|
7
|
+
"milkee": "bin/milkee.js"
|
8
8
|
},
|
9
9
|
"scripts": {
|
10
10
|
"test": "echo \"No test specified\" && exit 0",
|
11
|
-
"build": "coffee --
|
11
|
+
"build": "coffee --output dist/ --compile src/"
|
12
12
|
},
|
13
13
|
"repository": {
|
14
14
|
"type": "git",
|
package/dist/bin.js
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node;
|
2
|
-
var CONFIG_FILE, CONFIG_PATH, CWD, TEMPLATE_PATH, argv, compile, consola, exec, fs, hideBin, path, pkg, setup, yargs;
|
3
|
-
|
4
|
-
yargs = require('yargs');
|
5
|
-
|
6
|
-
({hideBin} = require('yargs/helpers'));
|
7
|
-
|
8
|
-
consola = require('consola');
|
9
|
-
|
10
|
-
fs = require('fs');
|
11
|
-
|
12
|
-
path = require('path');
|
13
|
-
|
14
|
-
({exec} = require('child_process'));
|
15
|
-
|
16
|
-
pkg = require('../package.json');
|
17
|
-
|
18
|
-
CWD = process.cwd();
|
19
|
-
|
20
|
-
CONFIG_FILE = 'coffee.config.js';
|
21
|
-
|
22
|
-
CONFIG_PATH = path.join(CWD, CONFIG_FILE);
|
23
|
-
|
24
|
-
TEMPLATE_PATH = path.join(__dirname, '..', 'temp', 'coffee.config.js');
|
25
|
-
|
26
|
-
setup = function() {
|
27
|
-
var error;
|
28
|
-
if (fs.existsSync(CONFIG_PATH)) {
|
29
|
-
consola.warn(`\`${CONFIG_FILE}\` already exists in this directory.`);
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
try {
|
33
|
-
fs.writeFileSync(CONFIG_PATH, CONFIG_TEMPLATE);
|
34
|
-
return consola.success(`Successfully created \`${CONFIG_FILE}\`.`);
|
35
|
-
} catch (error1) {
|
36
|
-
error = error1;
|
37
|
-
return consola.error(`Failed to create \`${CONFIG_FILE}\`:`, error);
|
38
|
-
}
|
39
|
-
};
|
40
|
-
|
41
|
-
compile = async(async function() {
|
42
|
-
var command, commandParts, config, configPathUrl, error, key, options, otherOptionStrings, value;
|
43
|
-
if (!fs.existsSync(CONFIG_PATH)) {
|
44
|
-
consola.error(`\`${CONFIG_FILE}\` not found.`);
|
45
|
-
consola.info('Please run `milkee --setup` to create a configuration file.');
|
46
|
-
process.exit(1);
|
47
|
-
}
|
48
|
-
try {
|
49
|
-
configPathUrl = path.toFileUrl(CONFIG_PATH).href;
|
50
|
-
({
|
51
|
-
default: config
|
52
|
-
} = (await import(configPathUrl)));
|
53
|
-
if (!(config.entry && config.output)) {
|
54
|
-
consola.error('`entry` and `output` properties are required in your configuration.');
|
55
|
-
process.exit(1);
|
56
|
-
}
|
57
|
-
options = config.options || {};
|
58
|
-
commandParts = ['coffee'];
|
59
|
-
if (options.join) {
|
60
|
-
commandParts.push('--join');
|
61
|
-
commandParts.push(`\"${config.output}\"`);
|
62
|
-
} else {
|
63
|
-
commandParts.push('--output');
|
64
|
-
commandParts.push(`\"${config.output}\"`);
|
65
|
-
}
|
66
|
-
delete options.join;
|
67
|
-
otherOptionStrings = [];
|
68
|
-
for (key in options) {
|
69
|
-
value = options[key];
|
70
|
-
if (value === true) {
|
71
|
-
otherOptionStrings.push(`--${key}`);
|
72
|
-
} else if (value !== false) {
|
73
|
-
otherOptionStrings.push(`--${key} \"${value}\"`);
|
74
|
-
}
|
75
|
-
}
|
76
|
-
if (otherOptionStrings.length > 0) {
|
77
|
-
commandParts.push(otherOptionStrings.join(' '));
|
78
|
-
}
|
79
|
-
commandParts.push('--compile');
|
80
|
-
commandParts.push(`\"${config.entry}\"`);
|
81
|
-
command = commandParts.filter(Boolean).join(' ');
|
82
|
-
consola.start(`Compiling from \`${config.entry}\` to \`${config.output}\`...`);
|
83
|
-
consola.info(`Executing: ${command}`);
|
84
|
-
return exec(command, function(error, stdout, stderr) {
|
85
|
-
if (error) {
|
86
|
-
consola.error('Compilation failed:', error);
|
87
|
-
if (stderr) {
|
88
|
-
process.stderr.write(stderr);
|
89
|
-
}
|
90
|
-
process.exit(1);
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
consola.success('Compilation completed successfully!');
|
94
|
-
if (stdout) {
|
95
|
-
process.stdout.write(stdout);
|
96
|
-
}
|
97
|
-
if (stderr) {
|
98
|
-
return process.stderr.write(stderr);
|
99
|
-
}
|
100
|
-
});
|
101
|
-
} catch (error1) {
|
102
|
-
error = error1;
|
103
|
-
consola.error('Failed to load or execute configuration:', error);
|
104
|
-
return process.exit(1);
|
105
|
-
}
|
106
|
-
});
|
107
|
-
|
108
|
-
argv = yargs(hideBin(process.argv)).scriptName('milkee').usage('$0 [command]').option('setup', {
|
109
|
-
alias: 's',
|
110
|
-
describe: 'Generate a default coffee.config.js',
|
111
|
-
type: 'boolean'
|
112
|
-
}).option('compile', {
|
113
|
-
alias: 'c',
|
114
|
-
describe: 'Compile CoffeeScript based on coffee.config.js (default)',
|
115
|
-
type: 'boolean'
|
116
|
-
}).version('version', pkg.version).alias('v', 'version').help('help').alias('h', 'help').argv;
|
117
|
-
|
118
|
-
if (argv.setup) {
|
119
|
-
setup();
|
120
|
-
} else {
|
121
|
-
compile();
|
122
|
-
}
|