Skip to content

Commit 499cda0

Browse files
committed
split header task into two tasks one for source files the other for dist
- at build time only run header-dist - at publish time only commit version.js from the src - with a new year simply run header-src and it will not touch the dist
1 parent e53a3f6 commit 499cda0

File tree

3 files changed

+37
-41
lines changed

3 files changed

+37
-41
lines changed

Diff for: package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
"scripts": {
2424
"preprocess": "node tasks/preprocess.js",
2525
"bundle": "node tasks/bundle.js",
26-
"header": "node tasks/header.js",
26+
"header-dist": "node tasks/header_dist.js",
27+
"header-src": "node tasks/header_src.js",
2728
"stats": "node tasks/stats.js",
2829
"find-strings": "node tasks/find_locale_strings.js",
29-
"build": "npm run preprocess && npm run find-strings && npm run bundle && npm run header && npm run stats",
30+
"build": "npm run preprocess && npm run find-strings && npm run bundle && npm run header-dist && npm run stats",
3031
"cibuild": "npm run preprocess && node tasks/cibundle.js",
3132
"watch": "node tasks/watch.js",
3233
"lint": "eslint --version && eslint .",
@@ -46,7 +47,7 @@
4647
"start": "npm run start-test_dashboard",
4748
"baseline": "node tasks/baseline.js",
4849
"preversion": "check-node-version --node 12 --npm 6.14 && npm-link-check && npm ls --prod",
49-
"version": "npm run build && npm run no-bad-char && git add -A dist src build",
50+
"version": "npm run build && npm run no-bad-char && git add -A dist build src/version.js",
5051
"postversion": "node -e \"console.log('Version bumped and committed. If ok, run: git push && git push --tags')\"",
5152
"postpublish": "node tasks/sync_packages.js",
5253
"postshrinkwrap": "chttps ."

Diff for: tasks/header_dist.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var prependFile = require('prepend-file');
2+
var constants = require('./util/constants');
3+
var common = require('./util/common');
4+
5+
(function addHeadersInDistFiles() {
6+
function _prepend(path, header) {
7+
prependFile(path, header + '\n', common.throwOnError);
8+
}
9+
10+
// add header to main dist bundles
11+
var pathsDist = [
12+
constants.pathToPlotlyDistMin,
13+
constants.pathToPlotlyDist,
14+
constants.pathToPlotlyDistWithMeta,
15+
constants.pathToPlotlyGeoAssetsDist
16+
];
17+
pathsDist.forEach(function(path) {
18+
_prepend(path, constants.licenseDist);
19+
});
20+
21+
// add header and bundle name to partial bundle
22+
constants.partialBundlePaths.forEach(function(pathObj) {
23+
var headerDist = constants.licenseDist
24+
.replace('plotly.js', 'plotly.js (' + pathObj.name + ')');
25+
_prepend(pathObj.dist, headerDist);
26+
27+
var headerDistMin = constants.licenseDist
28+
.replace('plotly.js', 'plotly.js (' + pathObj.name + ' - minified)');
29+
_prepend(pathObj.distMin, headerDistMin);
30+
});
31+
})();

Diff for: tasks/header.js renamed to tasks/header_src.js

+2-38
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,12 @@
11
var path = require('path');
22
var fs = require('fs');
3-
4-
var prependFile = require('prepend-file');
53
var falafel = require('falafel');
64
var glob = require('glob');
75

86
var constants = require('./util/constants');
97
var common = require('./util/common');
108

11-
// main
12-
addHeadersInDistFiles();
13-
updateHeadersInSrcFiles();
14-
15-
// add headers to dist files
16-
function addHeadersInDistFiles() {
17-
function _prepend(path, header) {
18-
prependFile(path, header + '\n', common.throwOnError);
19-
}
20-
21-
// add header to main dist bundles
22-
var pathsDist = [
23-
constants.pathToPlotlyDistMin,
24-
constants.pathToPlotlyDist,
25-
constants.pathToPlotlyDistWithMeta,
26-
constants.pathToPlotlyGeoAssetsDist
27-
];
28-
pathsDist.forEach(function(path) {
29-
_prepend(path, constants.licenseDist);
30-
});
31-
32-
// add header and bundle name to partial bundle
33-
constants.partialBundlePaths.forEach(function(pathObj) {
34-
var headerDist = constants.licenseDist
35-
.replace('plotly.js', 'plotly.js (' + pathObj.name + ')');
36-
_prepend(pathObj.dist, headerDist);
37-
38-
var headerDistMin = constants.licenseDist
39-
.replace('plotly.js', 'plotly.js (' + pathObj.name + ' - minified)');
40-
_prepend(pathObj.distMin, headerDistMin);
41-
});
42-
}
43-
44-
// add or update header to src/ lib/ files
45-
function updateHeadersInSrcFiles() {
9+
(function updateHeadersInSrcAndLibFiles() {
4610
var srcGlob = path.join(constants.pathToSrc, '**/*.js');
4711
var libGlob = path.join(constants.pathToLib, '**/*.js');
4812

@@ -96,4 +60,4 @@ function updateHeadersInSrcFiles() {
9660

9761
return (header.value.replace(regex, '') === licenseStr.replace(regex, ''));
9862
}
99-
}
63+
})();

0 commit comments

Comments
 (0)