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