Skip to content

Commit

Permalink
cli read and processing directories
Browse files Browse the repository at this point in the history
  • Loading branch information
paulvollmer committed Oct 26, 2017
1 parent c95cda5 commit 3518d1c
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,39 @@ function schemaError (str, err) {
"\ndetails: " + JSON.stringify(err.details);
}


function processFile(file) {
var src = path.normalize(file);
let source = parse(fs.readFileSync(src, "utf8"));
if (options.inplace) {
fs.writeSync(fs.openSync(src,'w+'), source, 0, "utf8");
} else {
if (! options.quiet) { console.log(source)};
}
}

function processSources(src) {
let srcStat = fs.statSync(src)
if (srcStat.isFile()) {
processFile(src)
}

if (srcStat.isDirectory()) {
sources = fs.readdirSync(src)
for (var i = 0; i < sources.length; i++) {
processSources(path.join(src, sources[i]))
}
}
}

function main (args) {
var source = '';
if (options.file) {

for (var i = 0; i < options.file.length; i++) {
var json = path.normalize(options.file[i]);
source = parse(fs.readFileSync(json, "utf8"));
if (options.inplace) {
fs.writeSync(fs.openSync(json,'w+'), source, 0, "utf8");
} else {
if (! options.quiet) { console.log(source)};
}
processSources(options.file[i])
}

} else {
var stdin = process.openStdin();
stdin.setEncoding('utf8');
Expand Down

0 comments on commit 3518d1c

Please sign in to comment.