Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

convert cmd to coco

  • Loading branch information...
commit a228bf0313ea975a815562f7f8b4749d5053f9ec 1 parent 787ecc6
Andrew Kelley authored
Showing with 58 additions and 63 deletions.
  1. +2 −2 package.json
  2. +56 −0 src/cmd.co
  3. +0 −61 src/cmd.coffee
4 package.json
View
@@ -23,8 +23,8 @@
},
"scripts": {
"test": "node lib/test.js",
- "build": "coffee -bco lib/ src/",
- "watch": "coffee -wbco lib/ src/",
+ "build": "coco -bco lib/ src/",
+ "watch": "coco -wbco lib/ src/",
"clean": "rm -rf lib/"
},
"engines": {
56 src/cmd.co
View
@@ -0,0 +1,56 @@
+const {compile} = require('./jspackage')
+const fs = require('fs')
+const path = require('path')
+const optparse = require('optparse')
+
+const switches =
+ * '-h' '--help' "shows this help section"
+ * '-b' '--bare' "compile without a top-level function wrapper"
+ * '-w' '--watch' "watch source files and recompile when any change"
+ * '-l' '--lib PATH' "add an additional search directory for source files"
+
+const parser = new optparse.OptionParser(switches)
+
+printUsage = !->
+ parser.banner = "Usage: jspackage input_file output_file [options]"
+ console.log(parser.toString())
+
+parser.on \help, !->
+ printUsage!
+ process.exit(1)
+
+mainfile = null
+parser.on 0, !-> mainfile := it
+
+output = null
+parser.on 1, !-> output := it
+
+options = {}
+parser.on \bare, !-> options.bare = true
+parser.on \watch, !-> options.watch = true
+
+parser.on \lib, !(name, value) ->
+ options.@@libs.push value
+
+parser.parse(process.argv.splice(2))
+
+if not mainfile or not output
+ printUsage!
+ process.exit(1)
+
+# allow the user to specify the first song without an extension
+if (ext = path.extname(mainfile)).length > 0
+ mainfile .= substring(0, mainfile.length - ext.length)
+
+options <<< {mainfile}
+compile options, !(err, code) ->
+ if options.watch
+ const timestamp = (new Date()).toLocaleTimeString()
+ if err
+ console.error("#timestamp - error: #err")
+ else
+ console.info("#timestamp - generated #output")
+ fs.writeFile(output, code)
+ else
+ if err then throw err
+ fs.writeFile(output, code)
61 src/cmd.coffee
View
@@ -1,61 +0,0 @@
-{compile} = require('./jspackage')
-fs = require('fs')
-path = require('path')
-optparse = require('optparse')
-
-switches = [
- ['-h', '--help', "shows this help section"]
- ['-b', '--bare', "compile without a top-level function wrapper"]
- ['-w', '--watch', "watch source files and recompile when any change"]
- ['-l', '--lib PATH', "add an additional search directory for source files"]
-]
-
-parser = new optparse.OptionParser(switches)
-
-printUsage = ->
- parser.banner = "Usage: jspackage input_file output_file [options]"
- console.log(parser.toString())
-
-parser.on 'help', ->
- printUsage()
- process.exit(1)
-
-options = {}
-parser.on 0, (arg) ->
- options.mainfile = arg
-
-output = null
-parser.on 1, (arg) ->
- output = arg
-
-parser.on "bare", ->
- options.bare = true
-
-parser.on "watch", ->
- options.watch = true
-
-parser.on "lib", (name, value) ->
- (options.libs ?= []).push value
-
-parser.parse(process.argv.splice(2))
-
-if not options.mainfile or not output
- printUsage()
- process.exit(1)
-
-# allow the user to specify the first song without an extension
-if (ext = path.extname(options.mainfile)).length > 0
- without_ext = options.mainfile.substring(0, options.mainfile.length - ext.length)
- options.mainfile = without_ext
-
-compile options, (err, code) ->
- if options.watch
- timestamp = (new Date()).toLocaleTimeString()
- if err
- console.error("#{timestamp} - error: #{err}")
- else
- console.info("#{timestamp} - generated #{output}")
- fs.writeFile(output, code)
- else
- if (err) then throw err
- fs.writeFile(output, code)
Please sign in to comment.
Something went wrong with that request. Please try again.