Skip to content

Commit fcdc935

Browse files
committed
Adding CLi command
1 parent df1b6ce commit fcdc935

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ validate(minifiedCode, [sourceMap], [sourceContent]);
1717
* `sourceContent` is a map to the raw source files
1818
* Optional - If left empty, the inline `sourceContent` in `sourceMap` will be used
1919

20+
### CLI Usage
21+
22+
sourcemap-validate $minifiedFilePath $sourceMapFilePath
23+
2024
## Examples
2125

2226
```js

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#!/usr/bin/env node
12
var validate
23
, validateMapping
34
, toAscii
45
, assert = require('assert')
6+
, fs = require('fs')
57
, SMConsumer = require('source-map').SourceMapConsumer
68
, each = require('lodash.foreach')
79
, template = require('lodash.template')
@@ -74,7 +76,7 @@ validate = function (min, map, srcs) {
7476
consumer = new SMConsumer(map);
7577
}
7678
catch (e) {
77-
throw new Error('The map is not valid JSON');
79+
throw new Error('The map is not valid JSON: ' + e);
7880
}
7981

8082
each(consumer.sources, function (src) {
@@ -159,4 +161,10 @@ validate = function (min, map, srcs) {
159161
assert.ok(mappingCount > 0, 'There were no mappings in the file');
160162
};
161163

164+
// "main" entrypoint:
165+
if (typeof require !== 'undefined' && require.main === module) {
166+
validate(fs.readFileSync(process.argv[2], 'utf-8'), fs.readFileSync(process.argv[3], 'utf-8'));
167+
process.stdout.write("Validation OK");
168+
}
169+
162170
module.exports = validate;

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
"scripts": {
3333
"test": "jake test --trace"
3434
},
35+
"bin": {
36+
"sourcemap-validate": "./index.js"
37+
},
3538
"devDependencies": {
3639
"jake": "0.7.x",
3740
"uglify-js": "2.4.x"

0 commit comments

Comments
 (0)