1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict'
|
7 |
|
8 | const execcli = require('execcli')
|
9 | const co = require('co')
|
10 | const mkdirp = require('mkdirp')
|
11 | const path = require('path')
|
12 |
|
13 |
|
14 | function 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 |
|
28 | module.exports = takeCapture
|