milkee 0.0.1 → 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/{bin.js → main.js} +0 -1
- package/package.json +3 -3
- package/src/bin.coffee +0 -109
package/bin/milkee.js
ADDED
package/dist/{bin.js → main.js}
RENAMED
package/package.json
CHANGED
@@ -1,10 +1,10 @@
|
|
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",
|
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()
|