This repository has been archived by the owner on Jun 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nodejs) Use the new
test-parser
API from Gutenberg.
See the latest commits from WordPress/gutenberg#6030.
- Loading branch information
Showing
1 changed file
with
23 additions
and
8 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
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) | ||
) | ||
); | ||
} | ||
); |