Skip to content

Commit

Permalink
Adding CLi command
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Sep 6, 2019
1 parent df1b6ce commit fcdc935
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"scripts": {
"test": "jake test --trace"
},
"bin": {
"sourcemap-validate": "./index.js"
},
"devDependencies": {
"jake": "0.7.x",
"uglify-js": "2.4.x"
Expand Down

0 comments on commit fcdc935

Please sign in to comment.