sorcery
Advanced tools
Comparing version 0.9.4 to 0.10.0
@@ -8,8 +8,8 @@ Sorcery version <%= version %> | ||
Options: | ||
-h, --help Show help message | ||
-v, --version Show version | ||
-i, --input <file> Input file | ||
-o, --output <file> Output file (if absent, will overwrite input) | ||
-d, --datauri Append map as a data URI, rather than separate file | ||
-x, --excludeContent Don't populate the sourcesContent array | ||
-h, --help Show help message | ||
-v, --version Show version | ||
-i, --input <file|folder> Input file | ||
-o, --output <file|folder> Output file (if absent, will overwrite input) | ||
-d, --datauri Append map as a data URI, rather than separate file | ||
-x, --excludeContent Don't populate the sourcesContent array | ||
@@ -20,4 +20,5 @@ | ||
sorcery --input some/generated/code.min.js | ||
sorcery --input tmp --output dist | ||
For more information visit https://github.com/Rich-Harris/sorcery | ||
For more information visit https://github.com/Rich-Harris/sorcery |
@@ -10,2 +10,4 @@ #!/usr/bin/env node | ||
var validExtensions = { js: true }; | ||
command = minimist( process.argv.slice( 2 ), { | ||
@@ -42,15 +44,19 @@ alias: { | ||
return sander.lsr( command.input ).then( function ( files ) { | ||
var promises = files.map( function ( file ) { | ||
var input = path.join( command.input, file ); | ||
var output = path.join( command.output || command.input, file ); | ||
files = files.filter( function ( file ) { | ||
return validExtensions[ path.extname( file ).slice( 1 ) ]; | ||
}); | ||
return sorcery.load( input ).then( function ( chain ) { | ||
return chain.write( output, { | ||
inline: command.datauri, | ||
includeContent: !command.excludeContent | ||
return files.reduce( function ( promise, file ) { | ||
return promise.then( function () { | ||
var input = path.join( command.input, file ); | ||
var output = path.join( command.output || command.input, file ); | ||
return sorcery.load( input ).then( function ( chain ) { | ||
return chain.write( output, { | ||
inline: command.datauri, | ||
includeContent: !command.excludeContent | ||
}); | ||
}); | ||
}); | ||
}); | ||
return sander.Promise.all( promises ); | ||
}, Promise.resolve() ); | ||
}); | ||
@@ -57,0 +63,0 @@ } |
# changelog | ||
## 0.10.0 | ||
* Allow CLI to recurse over a directory ([#13](https://github.com/Rich-Harris/sorcery/issues/13)) | ||
## 0.9.4 | ||
@@ -4,0 +8,0 @@ |
@@ -223,2 +223,10 @@ 'use strict'; | ||
function parseJSON ( json, url ) { | ||
try { | ||
return JSON.parse( json ); | ||
} catch ( err ) { | ||
throw new Error( ("Could not parse sourcemap (" + url + "): " + (err.message)) ); | ||
} | ||
} | ||
/** | ||
@@ -243,3 +251,3 @@ * Turns a sourceMappingURL into a sourcemap | ||
var json = atob( match[1] ); | ||
var map = JSON.parse( json ); | ||
var map = parseJSON( json, ("data URI in " + base) ); | ||
return sync ? map : sander.Promise.resolve( map ); | ||
@@ -251,5 +259,5 @@ } | ||
if ( sync ) { | ||
return JSON.parse( sander.readFileSync( url ).toString() ); | ||
return parseJSON( sander.readFileSync( url, { encoding: 'utf-8' }), url ); | ||
} else { | ||
return sander.readFile( url ).then( String ).then( JSON.parse ); | ||
return sander.readFile( url, { encoding: 'utf-8' }).then( function ( json ) { return parseJSON( json, url ); } ); | ||
} | ||
@@ -363,3 +371,3 @@ } | ||
if ( !sourcesContentByPath[ this.file ] ) { | ||
sourcesContentByPath[ this.file ] = sander.readFileSync( this.file ).toString(); | ||
sourcesContentByPath[ this.file ] = sander.readFileSync( this.file, { encoding: 'utf-8' }); | ||
} | ||
@@ -473,3 +481,3 @@ | ||
if ( !node.content ) { | ||
return sander.readFile( node.file ).then( String ); | ||
return sander.readFile( node.file, { encoding: 'utf-8' }); | ||
} | ||
@@ -518,3 +526,3 @@ | ||
"\\/\\*#?\\s*" + SOURCEMAPPING_URL$1 + "=([^'\"]+)\\s\\*\\/)" + // css | ||
"\\s*$", 'g' ); | ||
'\\s*$', 'g' ); | ||
@@ -521,0 +529,0 @@ function Chain ( node, sourcesContentByPath ) { |
@@ -221,2 +221,10 @@ import { resolve, dirname, relative, basename, extname } from 'path'; | ||
function parseJSON ( json, url ) { | ||
try { | ||
return JSON.parse( json ); | ||
} catch ( err ) { | ||
throw new Error( ("Could not parse sourcemap (" + url + "): " + (err.message)) ); | ||
} | ||
} | ||
/** | ||
@@ -241,3 +249,3 @@ * Turns a sourceMappingURL into a sourcemap | ||
var json = atob( match[1] ); | ||
var map = JSON.parse( json ); | ||
var map = parseJSON( json, ("data URI in " + base) ); | ||
return sync ? map : Promise$1.resolve( map ); | ||
@@ -249,5 +257,5 @@ } | ||
if ( sync ) { | ||
return JSON.parse( readFileSync( url ).toString() ); | ||
return parseJSON( readFileSync( url, { encoding: 'utf-8' }), url ); | ||
} else { | ||
return readFile( url ).then( String ).then( JSON.parse ); | ||
return readFile( url, { encoding: 'utf-8' }).then( function ( json ) { return parseJSON( json, url ); } ); | ||
} | ||
@@ -361,3 +369,3 @@ } | ||
if ( !sourcesContentByPath[ this.file ] ) { | ||
sourcesContentByPath[ this.file ] = readFileSync( this.file ).toString(); | ||
sourcesContentByPath[ this.file ] = readFileSync( this.file, { encoding: 'utf-8' }); | ||
} | ||
@@ -471,3 +479,3 @@ | ||
if ( !node.content ) { | ||
return readFile( node.file ).then( String ); | ||
return readFile( node.file, { encoding: 'utf-8' }); | ||
} | ||
@@ -516,3 +524,3 @@ | ||
"\\/\\*#?\\s*" + SOURCEMAPPING_URL$1 + "=([^'\"]+)\\s\\*\\/)" + // css | ||
"\\s*$", 'g' ); | ||
'\\s*$', 'g' ); | ||
@@ -519,0 +527,0 @@ function Chain ( node, sourcesContentByPath ) { |
{ | ||
"name": "sorcery", | ||
"description": "Resolve a chain of sourcemaps back to the original source", | ||
"version": "0.9.4", | ||
"version": "0.10.0", | ||
"author": "Rich Harris", | ||
@@ -17,2 +17,3 @@ "repository": "https://github.com/Rich-Harris/sorcery", | ||
"devDependencies": { | ||
"buble": "^0.5.6", | ||
"codecov.io": "^0.1.6", | ||
@@ -41,3 +42,3 @@ "coffee-script": "^1.10.0", | ||
"prepare-tests": "node test/samples/prepare-tests.js", | ||
"test": "mocha", | ||
"test": "mocha --compilers js:buble/register", | ||
"prepublish": "npm test", | ||
@@ -44,0 +45,0 @@ "lint": "eslint src", |
@@ -11,3 +11,3 @@ import { basename, dirname, extname, relative, resolve } from 'path'; | ||
`\\/\\*#?\\s*${SOURCEMAPPING_URL}=([^'"]+)\\s\\*\\/)` + // css | ||
`\\s*$`, 'g' ); | ||
'\\s*$', 'g' ); | ||
@@ -14,0 +14,0 @@ export default function Chain ( node, sourcesContentByPath ) { |
@@ -64,3 +64,3 @@ import { dirname, resolve } from 'path'; | ||
if ( !sourcesContentByPath[ this.file ] ) { | ||
sourcesContentByPath[ this.file ] = readFileSync( this.file ).toString(); | ||
sourcesContentByPath[ this.file ] = readFileSync( this.file, { encoding: 'utf-8' }); | ||
} | ||
@@ -172,3 +172,3 @@ | ||
if ( !node.content ) { | ||
return readFile( node.file ).then( String ); | ||
return readFile( node.file, { encoding: 'utf-8' }); | ||
} | ||
@@ -175,0 +175,0 @@ |
@@ -6,2 +6,10 @@ import { dirname, resolve } from 'path'; | ||
function parseJSON ( json, url ) { | ||
try { | ||
return JSON.parse( json ); | ||
} catch ( err ) { | ||
throw new Error( `Could not parse sourcemap (${url}): ${err.message}` ); | ||
} | ||
} | ||
/** | ||
@@ -26,3 +34,3 @@ * Turns a sourceMappingURL into a sourcemap | ||
const json = atob( match[1] ); | ||
const map = JSON.parse( json ); | ||
const map = parseJSON( json, `data URI in ${base}` ); | ||
return sync ? map : Promise.resolve( map ); | ||
@@ -34,6 +42,6 @@ } | ||
if ( sync ) { | ||
return JSON.parse( readFileSync( url ).toString() ); | ||
return parseJSON( readFileSync( url, { encoding: 'utf-8' }), url ); | ||
} else { | ||
return readFile( url ).then( String ).then( JSON.parse ); | ||
return readFile( url, { encoding: 'utf-8' }).then( json => parseJSON( json, url ) ); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
147424
1634
16