Skip to content

Commit 2a20e93

Browse files
authored
Merge pull request #821 from plotly/better-tasks-cli
Improve tasks CLI
2 parents 7710153 + cfda7d3 commit 2a20e93

29 files changed

+470
-365
lines changed

CONTRIBUTING.md

+4-9
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,21 @@ We use the following [labels](https://github.com/plotly/plotly.js/labels) to tra
3838

3939
#### Step 1: Clone the plotly.js repo and install its dependencies
4040

41-
```
41+
```bash
4242
git clone https://github.com/plotly/plotly.js.git
4343
cd plotly.js
4444
npm install
4545
```
4646

47-
#### Step 2: Setup Mapbox access token
48-
49-
As of `v1.13.0`, plotly.js includes a [`mapbox-gl`](https://github.com/mapbox/mapbox-gl-js) integration. Creating `mapbox-gl` graphs requires an
50-
[`accessToken`](https://www.mapbox.com/help/define-access-token/). To make sure
51-
that the plotly.js test suites and devtools work properly, locate your Mapbox access
52-
token and run:
47+
#### Step 2: Setup test environment
5348

5449
```bash
55-
export MAPBOX_ACCESS_TOKEN="<your access token>" && npm run pretest
50+
npm run pretest
5651
```
5752

5853
#### Step 3: Start the test dashboard
5954

60-
```
55+
```bash
6156
npm start
6257
```
6358

circle.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,17 @@ machine:
99
services:
1010
- docker
1111

12-
1312
dependencies:
1413
pre:
1514
- docker pull plotly/testbed:latest
1615
post:
1716
- npm run cibuild
1817
- npm run pretest
19-
- docker run -d --name mytestbed -v $PWD:/var/www/streambed/image_server/plotly.js -p 9010:9010 plotly/testbed:latest
20-
- sudo ./tasks/run_in_testbed.sh mytestbed "cp -f test/image/index.html ../server_app/index.html"
21-
- wget --server-response --spider --tries=8 --retry-connrefused http://localhost:9010/ping
18+
2219
test:
2320
override:
24-
- sudo ./tasks/run_in_testbed.sh mytestbed "export CIRCLECI=1 && node test/image/compare_pixels_test.js"
25-
- sudo ./tasks/run_in_testbed.sh mytestbed "node test/image/export_test.js"
21+
- npm run test-image
22+
- npm run test-export
2623
- npm run citest-jasmine
2724
- npm run test-bundle
2825
- npm run test-syntax

devtools/test_dashboard/server.js

+5-30
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ var http = require('http');
44
var ecstatic = require('ecstatic');
55
var open = require('open');
66
var browserify = require('browserify');
7-
var watchify = require('watchify');
87

98
var constants = require('../../tasks/util/constants');
10-
var compress = require('../../tasks/util/compress_attributes');
9+
var makeWatchifiedBundle = require('../../tasks/util/watchified_bundle');
1110
var shortcutPaths = require('../../tasks/util/shortcut_paths');
1211

1312
var PORT = process.argv[2] || 3000;
@@ -20,31 +19,22 @@ var server = http.createServer(ecstatic({
2019
gzip: true
2120
}));
2221

23-
// Bundle development source code
24-
var b = browserify(constants.pathToPlotlyIndex, {
25-
debug: true,
26-
standalone: 'Plotly',
27-
transform: [compress],
28-
cache: {},
29-
packageCache: {},
30-
plugin: [watchify]
22+
// Make watchified bundle for plotly.js
23+
var bundlePlotly = makeWatchifiedBundle(function() {
24+
// open up browser window on first bundle callback
25+
open('http://localhost:' + PORT + '/devtools/test_dashboard');
3126
});
32-
b.on('update', bundlePlotly);
3327

3428
// Bundle devtools code
3529
var devtoolsPath = path.join(constants.pathToRoot, 'devtools/test_dashboard');
3630
var devtools = browserify(path.join(devtoolsPath, 'devtools.js'), {
3731
transform: [shortcutPaths]
3832
});
3933

40-
var firstBundle = true;
41-
42-
4334
// Start the server up!
4435
server.listen(PORT);
4536

4637
// Build and bundle all the things!
47-
console.log('Building the first bundle. This might take a little while...\n');
4838
getMockFiles()
4939
.then(readFiles)
5040
.then(createMocksList)
@@ -140,21 +130,6 @@ function writeFilePromise(path, contents) {
140130
});
141131
}
142132

143-
function bundlePlotly() {
144-
b.bundle(function(err) {
145-
if(err) {
146-
console.error('Error while bundling!', JSON.stringify(String(err)));
147-
} else {
148-
console.log('Bundle updated at ' + new Date().toLocaleTimeString());
149-
}
150-
151-
if(firstBundle) {
152-
open('http://localhost:' + PORT + '/devtools/test_dashboard');
153-
firstBundle = false;
154-
}
155-
}).pipe(fs.createWriteStream(constants.pathToPlotlyBuild));
156-
}
157-
158133
function bundleDevtools() {
159134
return new Promise(function(resolve, reject) {
160135
devtools.bundle(function(err) {

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@
2727
"stats": "node tasks/stats.js",
2828
"build": "npm run preprocess && npm run bundle && npm run header && npm run stats",
2929
"cibuild": "npm run preprocess && node tasks/cibundle.js",
30-
"watch": "node tasks/watch_plotly.js",
30+
"watch": "node tasks/watch.js",
3131
"lint": "eslint . || true",
3232
"lint-fix": "eslint . --fix",
3333
"pretest": "node tasks/pretest.js",
3434
"test-jasmine": "karma start test/jasmine/karma.conf.js",
3535
"citest-jasmine": "karma start test/jasmine/karma.ciconf.js",
36-
"test-image": "./tasks/test_image.sh",
37-
"test-export": "./tasks/test_export.sh",
38-
"test-syntax": "node test/syntax_test.js",
36+
"test-image": "node tasks/test_image.js",
37+
"test-export": "node tasks/test_export.js",
38+
"test-syntax": "node tasks/test_syntax.js",
3939
"test-bundle": "node tasks/test_bundle.js",
4040
"test": "npm run citest-jasmine && npm run test-image && npm run test-syntax && npm run test-bundle",
4141
"start-test_dashboard": "node devtools/test_dashboard/server.js",
4242
"start-image_viewer": "node devtools/image_viewer/server.js",
4343
"start": "npm run start-test_dashboard",
44-
"baseline": "./tasks/baseline.sh",
44+
"baseline": "node tasks/baseline.js",
4545
"preversion": "npm-link-check && npm dedupe",
4646
"version": "npm run build && git add -A dist src build",
4747
"postversion": "git push && git push --tags"

tasks/baseline.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var constants = require('./util/constants');
2+
var common = require('./util/common');
3+
var containerCommands = require('./util/container_commands');
4+
5+
var msg = [
6+
'Generating baseline image(s) using build/plotly.js from',
7+
common.getTimeLastModified(constants.pathToPlotlyBuild),
8+
'\n'
9+
].join(' ');
10+
11+
var cmd = containerCommands.getRunCmd(
12+
process.env.CIRCLECI,
13+
'node test/image/make_baseline.js ' + process.argv.slice(2).join(' ')
14+
);
15+
16+
console.log(msg);
17+
common.execCmd(cmd);

tasks/baseline.sh

-20
This file was deleted.

tasks/bundle.js

+4-7
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

+4-7
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

+3-6
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

tasks/preprocess.js

+34-22
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
11
var fs = require('fs-extra');
2-
32
var sass = require('node-sass');
43

4+
var constants = require('./util/constants');
5+
var common = require('./util/common');
56
var pullCSS = require('./util/pull_css');
67
var pullFontSVG = require('./util/pull_font_svg');
78
var updateVersion = require('./util/update_version');
8-
var constants = require('./util/constants');
99

10+
// main
11+
makeBuildCSS();
12+
makeBuildFontSVG();
13+
copyTopojsonFiles();
14+
updateVersion(constants.pathToPlotlyCore);
15+
updateVersion(constants.pathToPlotlyGeoAssetsSrc);
1016

11-
// convert scss to css
12-
sass.render({
13-
file: constants.pathToSCSS,
14-
outputStyle: 'compressed'
15-
}, function(err, result) {
16-
if(err) console.log('SASS error');
17+
// convert scss to css to js
18+
function makeBuildCSS() {
19+
sass.render({
20+
file: constants.pathToSCSS,
21+
outputStyle: 'compressed'
22+
}, function(err, result) {
23+
if(err) throw err;
1724

18-
// css to js
19-
pullCSS(String(result.css), constants.pathToCSSBuild);
20-
});
25+
// css to js
26+
pullCSS(String(result.css), constants.pathToCSSBuild);
27+
});
28+
}
2129

2230
// convert font svg into js
23-
fs.readFile(constants.pathToFontSVG, function(err, data) {
24-
pullFontSVG(data.toString(), constants.pathToFontSVGBuild);
25-
});
31+
function makeBuildFontSVG() {
32+
fs.readFile(constants.pathToFontSVG, function(err, data) {
33+
if(err) throw err;
2634

27-
// copy topojson files from sane-topojson to dist/
28-
fs.copy(constants.pathToTopojsonSrc, constants.pathToTopojsonDist,
29-
{ clobber: true },
30-
function(err) { if(err) throw err; }
31-
);
35+
pullFontSVG(data.toString(), constants.pathToFontSVGBuild);
36+
});
37+
}
3238

33-
// inject package version into source index files
34-
updateVersion(constants.pathToPlotlyCore);
35-
updateVersion(constants.pathToPlotlyGeoAssetsSrc);
39+
// copy topojson files from sane-topojson to dist/
40+
function copyTopojsonFiles() {
41+
fs.copy(
42+
constants.pathToTopojsonSrc,
43+
constants.pathToTopojsonDist,
44+
{ clobber: true },
45+
common.throwOnError
46+
);
47+
}

0 commit comments

Comments
 (0)