Skip to content

Commit 04096de

Browse files
committed
tasks: use common utils
1 parent f564a85 commit 04096de

File tree

4 files changed

+14
-37
lines changed

4 files changed

+14
-37
lines changed

tasks/bundle.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ var path = require('path');
44
var browserify = require('browserify');
55
var UglifyJS = require('uglify-js');
66

7-
var compressAttributes = require('./util/compress_attributes');
87
var constants = require('./util/constants');
8+
var common = require('./util/common');
9+
var compressAttributes = require('./util/compress_attributes');
10+
var doesFileExist = common.doesFileExist;
911

1012
/*
1113
* This script takes one argument
@@ -23,18 +25,13 @@ var DEV = (arg === 'dev') || (arg === '--dev');
2325

2426

2527
// Check if style and font build files are there
26-
try {
27-
fs.statSync(constants.pathToCSSBuild).isFile();
28-
fs.statSync(constants.pathToFontSVGBuild).isFile();
29-
}
30-
catch(e) {
28+
if(!doesFileExist(constants.pathToCSSBuild) || !doesFileExist(constants.pathToFontSVG)) {
3129
throw new Error([
3230
'build/ is missing one or more files',
3331
'Please run `npm run preprocess` first'
3432
].join('\n'));
3533
}
3634

37-
3835
// Browserify plotly.js
3936
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDist, {
4037
standalone: 'Plotly',

tasks/cibundle.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ var fs = require('fs');
22

33
var browserify = require('browserify');
44

5-
var compressAttributes = require('./util/compress_attributes');
65
var constants = require('./util/constants');
6+
var common = require('./util/common');
7+
var compressAttributes = require('./util/compress_attributes');
78

89
/*
910
* Trimmed down version of ./bundle.js for CI testing
@@ -20,17 +21,13 @@ browserify(constants.pathToPlotlyIndex, {
2021
standalone: 'Plotly',
2122
transform: [compressAttributes]
2223
})
23-
.bundle(function(err) {
24-
if(err) throw err;
25-
})
24+
.bundle(common.throwOnError)
2625
.pipe(fs.createWriteStream(constants.pathToPlotlyBuild));
2726

2827

2928
// Browserify the geo assets
3029
browserify(constants.pathToPlotlyGeoAssetsSrc, {
3130
standalone: 'PlotlyGeoAssets'
3231
})
33-
.bundle(function(err) {
34-
if(err) throw err;
35-
})
32+
.bundle(common.throwOnError)
3633
.pipe(fs.createWriteStream(constants.pathToPlotlyGeoAssetsDist));

tasks/header.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var falafel = require('falafel');
66
var glob = require('glob');
77

88
var constants = require('./util/constants');
9+
var common = require('./util/common');
910

1011
// main
1112
addHeadersInDistFiles();
@@ -14,9 +15,7 @@ updateHeadersInSrcFiles();
1415
// add headers to dist files
1516
function addHeadersInDistFiles() {
1617
function _prepend(path, header) {
17-
prependFile(path, header + '\n', function(err) {
18-
if(err) throw err;
19-
});
18+
prependFile(path, header + '\n', common.throwOnError);
2019
}
2120

2221
// add header to main dist bundles
@@ -77,9 +76,7 @@ function updateHeadersInSrcFiles() {
7776

7877
var newCode = licenseSrc + '\n' + codeLines.join('\n');
7978

80-
fs.writeFile(file, newCode, function(err) {
81-
if(err) throw err;
82-
});
79+
common.writeFile(file, newCode);
8380
}
8481
else {
8582
// otherwise, throw an error

test/image/compare_pixels_test.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var fs = require('fs');
22

3+
var common = require('../../tasks/util/common');
34
var getMockList = require('./assets/get_mock_list');
45
var getRequestOpts = require('./assets/get_image_request_options');
56
var getImagePaths = require('./assets/get_image_paths');
@@ -149,7 +150,7 @@ function comparePixels(mockName, cb) {
149150
function checkImage() {
150151

151152
// baseline image must be generated first
152-
if(!doesFileExist(imagePaths.baseline)) {
153+
if(!common.doesFileExist(imagePaths.baseline)) {
153154
var err = new Error('baseline image not found');
154155
return onEqualityCheck(err, false);
155156
}
@@ -186,7 +187,7 @@ function comparePixels(mockName, cb) {
186187

187188
function onEqualityCheck(err, isEqual) {
188189
if(err) {
189-
touch(imagePaths.diff);
190+
common.touch(imagePaths.diff);
190191
return console.error(err, mockName);
191192
}
192193
if(isEqual) {
@@ -200,18 +201,3 @@ function comparePixels(mockName, cb) {
200201
.pipe(saveImageStream)
201202
.on('close', checkImage);
202203
}
203-
204-
function doesFileExist(filePath) {
205-
try {
206-
if(fs.statSync(filePath).isFile()) return true;
207-
}
208-
catch(e) {
209-
return false;
210-
}
211-
212-
return false;
213-
}
214-
215-
function touch(filePath) {
216-
fs.closeSync(fs.openSync(filePath, 'w'));
217-
}

0 commit comments

Comments
 (0)