-
Notifications
You must be signed in to change notification settings - Fork 447
/
preview
executable file
·39 lines (30 loc) · 924 Bytes
/
preview
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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, { 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}`)
})
})