Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
feat(nodejs) Use the new test-parser API from Gutenberg.
Browse files Browse the repository at this point in the history
See the latest commits from
WordPress/gutenberg#6030.
  • Loading branch information
Hywan committed May 7, 2018
1 parent 2d741e7 commit 107188c
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions bindings/nodejs/lib/gutenberg-test-parser.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
#!/usr/bin/env node

const fs = require('fs');
const parser = require('../native');
const arguments = process.argv.slice(2);

function parseFromFile(file_input, file_output) {
const input = fs.readFileSync(file_input, 'utf-8');
const output = parser.root(input);
const stdin = process.stdin;
const stdout = process.stdout;
let input = '';

fs.writeFileSync(file_output, JSON.stringify(output));
}
stdin.setEncoding('utf-8');
stdin.on(
'readable',
() => {
let chunk;

parseFromFile(arguments[0], arguments[1]);
while (chunk = stdin.read()) {
input += chunk;
}
}
);
stdin.on(
'end',
() => {
stdout.write(
JSON.stringify(
parser.root(input)
)
);
}
);

0 comments on commit 107188c

Please sign in to comment.