From fcdc935382deaf6d2af0e6d01e3b8e671a25c23b Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Fri, 6 Sep 2019 12:20:55 +0200 Subject: [PATCH] Adding CLi command --- README.md | 4 ++++ index.js | 10 +++++++++- package.json | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) 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 f96be99..a01f418 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 b2128ba..4119bad 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,9 @@ "scripts": { "test": "jake test --trace" }, + "bin": { + "sourcemap-validate": "./index.js" + }, "devDependencies": { "jake": "0.7.x", "uglify-js": "2.4.x"