Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add individual tools/jsonlint.js to lint package.json files
- Loading branch information
1 parent
bda189b
commit 0d38ef8
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'); | ||
var glob = require('glob'); | ||
var async = require('async'); | ||
var colors = require('colors'); | ||
var jsonlint = require("jsonlint"); | ||
var errorCount = 0; | ||
|
||
var jsonfiles = glob.sync("ajax/libs/*/package.json"); | ||
|
||
console.log("Found " + jsonfiles.length + " json file(s)"); | ||
|
||
async.map(jsonfiles, function lintjson(item, cb) { | ||
fs.readFile(item, 'utf8', (err, data) => { | ||
if (err) throw err; | ||
try { | ||
jsonlint.parse(data); | ||
} catch(e) { | ||
errorCount++; | ||
console.log("\n" + item.yellow + " parsing failed:\n".red); | ||
console.log(e.toString().magenta); | ||
} | ||
cb(); | ||
}); | ||
}, function (err, results) { | ||
if (err) { | ||
console.dir(err); | ||
} | ||
if (errorCount > 0) { | ||
console.log("\nYou can validate json here: https://jsonlint.com/ once you revised the file(s) with formatting problem.\n".cyan); | ||
} else if (jsonfiles > 0) { | ||
console.log("\nAll json parsed without problem!\n".green); | ||
} | ||
}); | ||
|