mirror of
https://github.com/postlight/mercury-parser
synced 2024-11-17 03:25:31 +00:00
bd0694fbba
Now the preview script has an optional build step. Adding --no-rebuild as an argument to the script will skip the rebuild step and just show a preview of the parse as is with the current build.
40 lines
930 B
JavaScript
Executable File
40 lines
930 B
JavaScript
Executable File
#!/usr/bin/env node
|
|
var fs = require('fs')
|
|
var execSync = require('child_process').execSync
|
|
|
|
var optRe = /^--/
|
|
var args = process.argv.slice(2).reduce((acc, arg) => {
|
|
if (optRe.test(arg)) {
|
|
acc.opts.push(arg)
|
|
} else {
|
|
acc.urls.push(arg)
|
|
}
|
|
|
|
return acc
|
|
}, { opts: [], urls: [] })
|
|
|
|
var urls = args.urls
|
|
|
|
if (!args.opts.find(arg => arg === '--no-rebuild')) {
|
|
console.log('Rebuilding Mercury')
|
|
execSync('MERCURY_TEST_BUILD=true npm run build')
|
|
}
|
|
|
|
var Mercury = require('./dist/mercury_test')
|
|
|
|
console.log(`Fetching link(s)`)
|
|
|
|
urls.map(url => {
|
|
Mercury.parse(url, null, { fallback: false }).then(function(result) {
|
|
var htmlFile = './preview.html'
|
|
var jsonFile = './preview.json'
|
|
|
|
var html = `<h1>${result.title}</h1>${result.content}`
|
|
|
|
fs.writeFileSync(htmlFile, html)
|
|
fs.writeFileSync(jsonFile, JSON.stringify(result))
|
|
execSync(`open ${jsonFile}`)
|
|
execSync(`open ${htmlFile}`)
|
|
})
|
|
})
|