Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

lib: Detect and compile coffee files

Allow building and testing coffeescript files with
javascript files. Assume that coffeescript files
should be compiled if provided.
  • Loading branch information...
commit 05f269f274928b7f9d8dcd8ad468cea0cda6f09a 1 parent 2435b22
Greg Guthe authored

Showing 3 changed files with 31 additions and 31 deletions. Show diff stats Hide diff stats

  1. +0 2  README.md
  2. +0 1  lib/cli.coffee
  3. +31 28 lib/package.coffee
2  README.md
Source Rendered
@@ -93,8 +93,6 @@ that you can specify when configuring your project:
93 93
94 94 Optional configs. These all have sane default values, but can be tweaked if desired:
95 95
96   - * `coffee` - (False) Is this project written in CoffeeScript? Any truthy value will
97   - flip jspackle to run in CoffeeScript mode
98 96 * `test_build_folder` - ("build") Temporary folder to put compiled coffeescript source files to run tests.
99 97 * `depends_folder` - ("requires") Folder that contains dependencies in order for the
100 98 tests to run
1  lib/cli.coffee
@@ -23,7 +23,6 @@ module.exports = ->
23 23 .option('-q, --quiet', 'Only print critical errors to the screen')
24 24 .option('-n, --no-color', 'Disable colors in the output')
25 25 .option('-m, --minify', 'Minify the build (uses uglify-js)')
26   - .option('-c, --coffee', 'Look for and compile coffee-script files')
27 26 .option('-r, --root <root>', 'The of the project', process.cwd()+'/')
28 27 .option('-p, --path <path>', 'Path of the config file, relative to root', 'jspackle.json')
29 28 .option('-s, --test_server <test_server>', 'Test server', 'http://localhost:9876')
59 lib/package.coffee
@@ -5,8 +5,10 @@ pathLib = require 'path'
5 5 String::isHTTP = ->
6 6 @substring(0, 7) == 'http://' or @substring(0, 8) == 'https://'
7 7
8   -String::isScript = ->
9   - this.substring(this.length-2) is 'js' or this.substring(this.length-6) is 'coffee'
  8 +String::isCoffee = -> pathLib.extname(pathLib.basename(@)) == '.coffee'
  9 +String::isJs = -> pathLib.extname(pathLib.basename(@)) == '.js'
  10 +
  11 +String::isScript = -> @isCoffee or @isJs
10 12
11 13 ###
12 14 Load any methods or libraries that interact with the outside
@@ -314,27 +316,22 @@ Output:
314 316 logging.debug "Dumping configs to: #{path}"
315 317 yaml.dump configs, path, callback
316 318
317   - _coffeeCompile: (sources, buildFolder)->
318   - paths = []
319   - for src in sources
320   - if src.isHTTP()
321   - paths.push src
322   - else
323   - try
324   - compiled = coffee.compile fs.readFileSync(src).toString()
325   - catch e
326   - logging.critical "Cannot parse #{src} as valid CoffeeScript!"
327   - logging.critical e
328   - throw e
329   -
330   - fileName = pathLib.join buildFolder, src.replace('.coffee', '.js')
331   - filePath = pathLib.join buildFolder, pathLib.dirname src
332   -
333   - fs.mkdirSync filePath, 0777, true
334   - logging.info "Compiling #{src} to '#{fileName}'"
335   - fs.writeFileSync fileName, compiled
336   - paths.push fileName
337   - return paths
  319 + _coffeeCompile: (src, buildFolder)->
  320 + # Compiles a coffeescript file and writes it to buildFolder
  321 + try
  322 + compiled = coffee.compile fs.readFileSync(src).toString()
  323 + catch e
  324 + logging.critical "Cannot parse #{src} as valid CoffeeScript!"
  325 + logging.critical e
  326 + throw e
  327 +
  328 + fileName = pathLib.join buildFolder, src.replace('.coffee', '.js')
  329 + filePath = pathLib.join buildFolder, pathLib.dirname src
  330 +
  331 + fs.mkdirSync filePath, 0777, true
  332 + logging.info "Compiling #{src} to '#{fileName}'"
  333 + fs.writeFileSync fileName, compiled
  334 + return fileName
338 335
339 336 _findTests: ->
340 337 found = readDir @opts.root+@opts.spec_folder
@@ -355,7 +352,7 @@ Output:
355 352 filePath = filePath.replace re, @opts[variable]
356 353 return filePath
357 354
358   - _process: (option, folder, buildFolder='')->
  355 + _process: (option, folder, buildFolder=@opts.test_build_folder)->
359 356 root = folder+'/'
360 357 sources = []
361 358 if typeof option == 'string'
@@ -365,11 +362,17 @@ Output:
365 362
366 363 for source in srcPaths
367 364 if source.isHTTP()
368   - sources.push source
  365 + if source.isJs()
  366 + sources.push source
  367 + else
  368 + logging.warn "Cannot include coffee script HTTP resources!"
  369 + else if source.isJs()
  370 + sources.push root+source
  371 + else if source.isCoffee()
  372 + sources.push @_coffeeCompile root+source, buildFolder
369 373 else
370   - sources.push root+source
371   - return sources if not (buildFolder and @opts.coffee)
372   - @_coffeeCompile sources, buildFolder
  374 + logging.warn "Ignoring unkonown file type #{source}"
  375 + return sources
373 376
374 377 ###
375 378 Read only properties

0 comments on commit 05f269f

Please sign in to comment.
Something went wrong with that request. Please try again.