diff --git a/README.md b/README.md index 4642e82..c8beb13 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ validate(minifiedCode, [sourceMap], [sourceContent]); * `sourceContent` is a map to the raw source files * Optional - If left empty, the inline `sourceContent` in `sourceMap` will be used +### CLI Usage + + sourcemap-validate $minifiedFilePath $sourceMapFilePath + ## Examples ```js diff --git a/index.js b/index.js index 39ad676..41762e0 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,9 @@ +#!/usr/bin/env node var validate , validateMapping , toAscii , assert = require('assert') + , fs = require('fs') , SMConsumer = require('source-map').SourceMapConsumer , each = require('lodash.foreach') , template = require('lodash.template') @@ -74,7 +76,7 @@ validate = function (min, map, srcs) { consumer = new SMConsumer(map); } catch (e) { - throw new Error('The map is not valid JSON'); + throw new Error('The map is not valid JSON: ' + e); } each(consumer.sources, function (src) { @@ -159,4 +161,10 @@ validate = function (min, map, srcs) { assert.ok(mappingCount > 0, 'There were no mappings in the file'); }; +// "main" entrypoint: +if (typeof require !== 'undefined' && require.main === module) { + validate(fs.readFileSync(process.argv[2], 'utf-8'), fs.readFileSync(process.argv[3], 'utf-8')); + process.stdout.write("Validation OK"); +} + module.exports = validate; diff --git a/package.json b/package.json index b6223b0..55e5fc9 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,9 @@ "scripts": { "test": "jake test --trace" }, + "bin": { + "sourcemap-validate": "./index.js" + }, "devDependencies": { "jake": "0.7.x", "uglify-js": "2.4.x"