@@ -7,6 +7,7 @@ const fs = require('fs');
7
7
const Jimp = require ( 'jimp' ) ;
8
8
const Nightmare = require ( 'nightmare' ) ;
9
9
const path = require ( 'path' ) ;
10
+ const prettyHrtime = require ( 'pretty-hrtime' ) ;
10
11
const tmp = require ( 'tmp' ) ;
11
12
12
13
const defaults = require ( './components-build-defaults' ) ;
@@ -38,6 +39,7 @@ const formatFromSizeToSize = (from, to) => `(${filesize(from)} => ${filesize(to)
38
39
39
40
module . exports = _options => new Promise ( ( resolve , reject ) => {
40
41
const options = _ . assign ( { } , defaults , _options ) ;
42
+ const startTime = process . hrtime ( ) ;
41
43
console . log ( chalk . magenta ( 'Working on components screenshots...' ) ) ;
42
44
if ( options . componentsForNavPath === undefined || ! fs . existsSync ( options . componentsForNavPath ) ) {
43
45
reject ( 'Can not find components nav JSON file' ) ;
@@ -74,7 +76,7 @@ module.exports = _options => new Promise((resolve, reject) => {
74
76
// Grab the size of the component enclosing rectangle
75
77
// https://github.com/segmentio/nightmare/issues/498#issuecomment-189156529
76
78
const componentRect = yield nightmare
77
- . viewport ( options . screenshotViewportWidth , options . screenshotViewportMaxHeight )
79
+ . viewport ( options . screenshotViewportWidth , options . screenshotViewportHeight )
78
80
// .wait(1000)
79
81
. goto ( `http://localhost:${ options . serverPort } ${ component . href } ` )
80
82
. wait ( selector )
@@ -101,12 +103,12 @@ module.exports = _options => new Promise((resolve, reject) => {
101
103
continue ; // eslint-disable-line
102
104
}
103
105
const tmpObj = tmp . fileSync ( { dir : path . dirname ( component . screenshot . path ) } ) ;
104
- componentRect . height = Math . min ( componentRect . height , options . screenshotViewportMaxHeight ) ;
106
+ componentRect . height = Math . min ( componentRect . height , options . screenshotViewportHeight ) ;
105
107
yield nightmare
106
108
// we can not use .screenshot() with componentRect, so constrain the viewport instead
107
109
. viewport (
108
110
componentRect . width || options . screenshotViewportWidth ,
109
- componentRect . height || options . screenshotViewportMaxHeight
111
+ componentRect . height || options . screenshotViewportHeight
110
112
) . scrollTo ( componentRect . y , componentRect . x )
111
113
// .wait(1000)
112
114
// do *not* use componentRect in .screenshot() below or risk distortions
@@ -119,13 +121,13 @@ module.exports = _options => new Promise((resolve, reject) => {
119
121
yield new Promise ( ( write_resolve , write_reject ) => {
120
122
if ( component . frontMatter . screenshot === undefined ||
121
123
component . frontMatter . screenshot . autocrop !== false ) {
122
- screenshot . autocrop ( 0.0 , false ) ;
124
+ screenshot . autocrop ( false ) ;
123
125
}
124
126
// Allow shrinking, up to a point
125
- const scaleHeight = screenshot . bitmap . height <= options . screenshotFinalMinHeight
126
- ? 0.0 : options . screenshotFinalMinHeight / screenshot . bitmap . height ;
127
- const scaleWidth = screenshot . bitmap . width <= options . screenshotFinalMinWidth
128
- ? 0.0 : options . screenshotFinalMinWidth / screenshot . bitmap . width ;
127
+ const scaleHeight = screenshot . bitmap . height <= options . screenshotTargetMinHeight
128
+ ? 0.0 : options . screenshotTargetMinHeight / screenshot . bitmap . height ;
129
+ const scaleWidth = screenshot . bitmap . width <= options . screenshotTargetMinWidth
130
+ ? 0.0 : options . screenshotTargetMinWidth / screenshot . bitmap . width ;
129
131
const scale = Math . max ( scaleHeight , scaleWidth ) ;
130
132
screenshot
131
133
. scale ( scale > 0 ? scale : 1.0 )
@@ -152,9 +154,11 @@ module.exports = _options => new Promise((resolve, reject) => {
152
154
yield nightmare . end ( ) ;
153
155
server . close ( ) ;
154
156
console . log ( '- Closed static HTML server' ) ;
157
+ const elapsed = process . hrtime ( startTime ) ;
155
158
console . log (
156
159
chalk . magenta ( 'Done with components screenshots!' ) ,
157
- chalk . dim ( formatFromSizeToSize ( tmpTotalFileSize , screenshotTotalFileSize ) )
160
+ chalk . dim ( formatFromSizeToSize ( tmpTotalFileSize , screenshotTotalFileSize ) ) ,
161
+ chalk . dim ( prettyHrtime ( elapsed ) )
158
162
) ;
159
163
} ) ;
160
164
0 commit comments