UNPKG

792 BJavaScriptView Raw
1/**
2 * Take capture
3 * @function takeCapture
4 * @returns {Promise}
5 */
6'use strict'
7
8const execcli = require('execcli')
9const co = require('co')
10const mkdirp = require('mkdirp')
11const path = require('path')
12
13/** @lends takeCapture */
14function takeCapture (url, filename, options = {}) {
15 let { selector, width, height } = options
16 let size = [ width || 480, height || 240 ].join('x')
17 let script = require.resolve('../phantom_scripts/capture_elm.phantom.js')
18 return co(function * () {
19 yield new Promise((resolve, reject) =>
20 mkdirp(path.dirname(filename), (err) => err ? reject(err) : resolve())
21 )
22 yield execcli.npmBin('phantomjs', [ script, url, filename, selector, size ], {
23 notfound: 'Try `npm install -g phantomjs`'
24 })
25 })
26}
27
28module.exports = takeCapture