Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added support for saving the generated source maps in separate files. #2

Open
wants to merge 3 commits into from

1 participant

@csillag

This solves #1

csillag added some commits
@csillag csillag Added support for saving the generated source maps in separate files. 1c3e765
@csillag csillag Fix a path inconsistency on sourcemaps
The 'file' field in the generated source maps should not contain
the directory part, since the generated sourcemap is placed in
the same directory, too.
932eb2d
@csillag csillag Normalize input paths 8e91a11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2013
  1. @csillag
  2. @csillag

    Fix a path inconsistency on sourcemaps

    csillag authored
    The 'file' field in the generated source maps should not contain
    the directory part, since the generated sourcemap is placed in
    the same directory, too.
  3. @csillag

    Normalize input paths

    csillag authored
This page is out of date. Refresh to see the latest.
View
6 README.md
@@ -33,7 +33,8 @@ Install globally via npm:
-h, --help output usage information
-V, --version output the version number
-b, --bare compile without a top-level function wrapper
- -M, --map create source maps
+ -M, --map create source maps, appended to the JS file
+ -x, --extmap create source maps, shipped in a separate file
-m, --minify minify output files
-o, --output <path> output path
-s, --silent suppress console output
@@ -69,7 +70,8 @@ Compiles all .coffee files found in `inputPaths`, which can be a single string o
* `minify` - Minify output files. Defaults to false.
* `output` - The path to the output file. If the path has a file extension, all files will be joined at that location. Otherwise, the path is assumed to be a directory.
* `silent` - Suppress all console output. Defaults to true.
-* `sourceMap` - Generate source maps for output files. Not currentl compatible with minification. Defaults to false.
+* `sourceMap` - Generate source maps for output files, and append them to the JS. Not currentl compatible with minification. Defaults to false.
+* `extSourceMap` - Generate source maps for output files, and save them in saparate files. Not currentl compatible with minification. Defaults to false.
* `watch` - (boolean) Watch all files and directories for changes and recompile automatically. Defaults to false.
##### Example:
View
16 src/coffeebar.coffee
@@ -40,8 +40,11 @@ class Coffeebar
@options.watch ?= false
@options.silent ?= true
@options.minify ?= false
+ @options.extSourceMap ?= false
+ @options.extSourceMap = false if @options.minify
@options.sourceMap ?= false
@options.sourceMap = false if @options.minify
+ @options.sourceMap = @options.sourceMap or @options.extSourceMap
@options.join = true if @options.output and path.extname(@options.output)
@options.bare ?= false
@@ -59,6 +62,7 @@ class Coffeebar
unless Array.isArray(@inputPaths) then @inputPaths = [@inputPaths]
for inputPath, i in @inputPaths
+ @inputPaths[i] = inputPath = path.normalize inputPath
unless path.extname(inputPath)
@inputPaths[i] = "#{inputPath}/**/*.{#{exts}}"
@@ -115,15 +119,21 @@ class Coffeebar
# src file that we sent to the compiler.
mapSources: ->
unless @options.join
- source.writeMapComment() for source in @sources
+ unless @options.extSourceMap
+ source.writeMapComment() for source in @sources
+ else
+ source.writeMapCommentExt() for source in @sources
return
return unless @outputs[0].sourceMap
smOld = new sourcemap.SourceMapConsumer @outputs[0].sourceMap
- smNew = new sourcemap.SourceMapGenerator {file: smOld.file, sourceRoot: "#{path.basename(@options.output, '.js')}_mapsrc"}
+ smNew = new sourcemap.SourceMapGenerator {file: (path.basename smOld.file), sourceRoot: "#{path.basename(@options.output, '.js')}_mapsrc"}
smOld.eachMapping (map) => smNew.addMapping(@offsetMapping map)
- @outputs[0].writeMapComment smNew.toString()
+ unless @options.extSourceMap
+ @outputs[0].writeMapComment smNew.toString()
+ else
+ @outputs[0].writeMapCommentExt smNew.toString()
# After compilation, report each error that was logged. In the event
# that this is a joined output file, use the line number offset to
View
4 src/command.coffee
@@ -15,7 +15,8 @@ module.exports.run = ->
.usage('[options] [path ...]')
.option('-b, --bare', 'compile without a top-level function wrapper')
.option('-m, --minify', 'minify output files')
- .option('-M, --map', 'create source maps')
+ .option('-M, --map', 'create source maps, appended to the JS file')
+ .option('-x, --extmap', 'create source maps, shipped in a separate file')
.option('-o, --output <path>', 'output path')
.option('-s, --silent', 'suppress console output')
.option('-w, --watch', 'watch files for changes')
@@ -28,6 +29,7 @@ module.exports.run = ->
silent : program.silent || false
minify : program.minify
sourceMap : program.map
+ extSourceMap : program.extmap
bare : program.bare
console.log '' unless options.silent
View
10 src/source.coffee
@@ -96,6 +96,16 @@ class Source
commentMap = "//@ sourceMappingURL=data:application/json;base64,#{commentMap}"
@compiled = "#{@compiled}\n#{commentMap}"
+ # Save the source map to an external file.
+ writeMapCommentExt: (map) ->
+ mkdirp.sync path.dirname @outputPath
+ mapOutput = @outputPath.replace '.js', '.map'
+ map or= JSON.stringify @sourceMap
+ fs.writeFileSync mapOutput, map, 'utf8'
+ mapName = path.basename mapOutput
+ commentMap = "//@ sourceMappingURL=#{mapName}"
+ @compiled = "#{@compiled}\n#{commentMap}"
+
# Utilities
# ---------
Something went wrong with that request. Please try again.