2016-09-16 17:58:41 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
var fs = require('fs')
|
|
|
|
var execSync = require('child_process').execSync
|
|
|
|
|
2016-12-01 00:37:42 +00:00
|
|
|
var optRe = /^--/
|
|
|
|
var args = process.argv.slice(2).reduce((acc, arg) => {
|
|
|
|
if (optRe.test(arg)) {
|
|
|
|
acc.opts.push(arg)
|
|
|
|
} else {
|
|
|
|
acc.urls.push(arg)
|
|
|
|
}
|
2016-09-16 17:58:41 +00:00
|
|
|
|
2016-12-01 00:37:42 +00:00
|
|
|
return acc
|
|
|
|
}, { opts: [], urls: [] })
|
|
|
|
|
|
|
|
var urls = args.urls
|
2016-09-16 17:58:41 +00:00
|
|
|
|
2016-12-01 00:37:42 +00:00
|
|
|
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')
|
2016-09-16 17:58:41 +00:00
|
|
|
|
2016-11-30 22:08:56 +00:00
|
|
|
console.log(`Fetching link(s)`)
|
2016-09-16 19:03:40 +00:00
|
|
|
|
2016-11-30 22:08:56 +00:00
|
|
|
urls.map(url => {
|
|
|
|
Mercury.parse(url, null, { fallback: false }).then(function(result) {
|
|
|
|
var htmlFile = './preview.html'
|
|
|
|
var jsonFile = './preview.json'
|
2016-09-16 19:03:40 +00:00
|
|
|
|
2016-11-30 22:08:56 +00:00
|
|
|
var html = `<h1>${result.title}</h1>${result.content}`
|
2016-09-16 17:58:41 +00:00
|
|
|
|
2016-11-30 22:08:56 +00:00
|
|
|
fs.writeFileSync(htmlFile, html)
|
|
|
|
fs.writeFileSync(jsonFile, JSON.stringify(result))
|
|
|
|
execSync(`open ${jsonFile}`)
|
|
|
|
execSync(`open ${htmlFile}`)
|
|
|
|
})
|
|
|
|
})
|