From 499cda0a7c7a9750337a04f4723a3e5e9516eaa6 Mon Sep 17 00:00:00 2001 From: archmoj Date: Fri, 22 Jan 2021 11:15:30 -0500 Subject: [PATCH 1/2] 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 --- package.json | 7 +++--- tasks/header_dist.js | 31 +++++++++++++++++++++++ tasks/{header.js => header_src.js} | 40 ++---------------------------- 3 files changed, 37 insertions(+), 41 deletions(-) create mode 100644 tasks/header_dist.js rename tasks/{header.js => header_src.js} (65%) diff --git a/package.json b/package.json index 63bbe4b860d..21e82e765d1 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,11 @@ "scripts": { "preprocess": "node tasks/preprocess.js", "bundle": "node tasks/bundle.js", - "header": "node tasks/header.js", + "header-dist": "node tasks/header_dist.js", + "header-src": "node tasks/header_src.js", "stats": "node tasks/stats.js", "find-strings": "node tasks/find_locale_strings.js", - "build": "npm run preprocess && npm run find-strings && npm run bundle && npm run header && npm run stats", + "build": "npm run preprocess && npm run find-strings && npm run bundle && npm run header-dist && npm run stats", "cibuild": "npm run preprocess && node tasks/cibundle.js", "watch": "node tasks/watch.js", "lint": "eslint --version && eslint .", @@ -46,7 +47,7 @@ "start": "npm run start-test_dashboard", "baseline": "node tasks/baseline.js", "preversion": "check-node-version --node 12 --npm 6.14 && npm-link-check && npm ls --prod", - "version": "npm run build && npm run no-bad-char && git add -A dist src build", + "version": "npm run build && npm run no-bad-char && git add -A dist build src/version.js", "postversion": "node -e \"console.log('Version bumped and committed. If ok, run: git push && git push --tags')\"", "postpublish": "node tasks/sync_packages.js", "postshrinkwrap": "chttps ." diff --git a/tasks/header_dist.js b/tasks/header_dist.js new file mode 100644 index 00000000000..c0dce6d1950 --- /dev/null +++ b/tasks/header_dist.js @@ -0,0 +1,31 @@ +var prependFile = require('prepend-file'); +var constants = require('./util/constants'); +var common = require('./util/common'); + +(function addHeadersInDistFiles() { + function _prepend(path, header) { + prependFile(path, header + '\n', common.throwOnError); + } + + // add header to main dist bundles + var pathsDist = [ + constants.pathToPlotlyDistMin, + constants.pathToPlotlyDist, + constants.pathToPlotlyDistWithMeta, + constants.pathToPlotlyGeoAssetsDist + ]; + pathsDist.forEach(function(path) { + _prepend(path, constants.licenseDist); + }); + + // add header and bundle name to partial bundle + constants.partialBundlePaths.forEach(function(pathObj) { + var headerDist = constants.licenseDist + .replace('plotly.js', 'plotly.js (' + pathObj.name + ')'); + _prepend(pathObj.dist, headerDist); + + var headerDistMin = constants.licenseDist + .replace('plotly.js', 'plotly.js (' + pathObj.name + ' - minified)'); + _prepend(pathObj.distMin, headerDistMin); + }); +})(); diff --git a/tasks/header.js b/tasks/header_src.js similarity index 65% rename from tasks/header.js rename to tasks/header_src.js index 622edf71299..629608ad86a 100644 --- a/tasks/header.js +++ b/tasks/header_src.js @@ -1,48 +1,12 @@ var path = require('path'); var fs = require('fs'); - -var prependFile = require('prepend-file'); var falafel = require('falafel'); var glob = require('glob'); var constants = require('./util/constants'); var common = require('./util/common'); -// main -addHeadersInDistFiles(); -updateHeadersInSrcFiles(); - -// add headers to dist files -function addHeadersInDistFiles() { - function _prepend(path, header) { - prependFile(path, header + '\n', common.throwOnError); - } - - // add header to main dist bundles - var pathsDist = [ - constants.pathToPlotlyDistMin, - constants.pathToPlotlyDist, - constants.pathToPlotlyDistWithMeta, - constants.pathToPlotlyGeoAssetsDist - ]; - pathsDist.forEach(function(path) { - _prepend(path, constants.licenseDist); - }); - - // add header and bundle name to partial bundle - constants.partialBundlePaths.forEach(function(pathObj) { - var headerDist = constants.licenseDist - .replace('plotly.js', 'plotly.js (' + pathObj.name + ')'); - _prepend(pathObj.dist, headerDist); - - var headerDistMin = constants.licenseDist - .replace('plotly.js', 'plotly.js (' + pathObj.name + ' - minified)'); - _prepend(pathObj.distMin, headerDistMin); - }); -} - -// add or update header to src/ lib/ files -function updateHeadersInSrcFiles() { +(function updateHeadersInSrcAndLibFiles() { var srcGlob = path.join(constants.pathToSrc, '**/*.js'); var libGlob = path.join(constants.pathToLib, '**/*.js'); @@ -96,4 +60,4 @@ function updateHeadersInSrcFiles() { return (header.value.replace(regex, '') === licenseStr.replace(regex, '')); } -} +})(); From 321ac15d886a7ca565b2c787990dc74c522e086a Mon Sep 17 00:00:00 2001 From: archmoj Date: Tue, 26 Jan 2021 09:19:23 -0500 Subject: [PATCH 2/2] refactor - avoid IIFEs --- tasks/header_dist.js | 6 ++++-- tasks/header_src.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tasks/header_dist.js b/tasks/header_dist.js index c0dce6d1950..75d94ef221d 100644 --- a/tasks/header_dist.js +++ b/tasks/header_dist.js @@ -2,7 +2,7 @@ var prependFile = require('prepend-file'); var constants = require('./util/constants'); var common = require('./util/common'); -(function addHeadersInDistFiles() { +function addHeadersInDistFiles() { function _prepend(path, header) { prependFile(path, header + '\n', common.throwOnError); } @@ -28,4 +28,6 @@ var common = require('./util/common'); .replace('plotly.js', 'plotly.js (' + pathObj.name + ' - minified)'); _prepend(pathObj.distMin, headerDistMin); }); -})(); +} + +addHeadersInDistFiles(); diff --git a/tasks/header_src.js b/tasks/header_src.js index 629608ad86a..8fa4cfe251b 100644 --- a/tasks/header_src.js +++ b/tasks/header_src.js @@ -6,7 +6,7 @@ var glob = require('glob'); var constants = require('./util/constants'); var common = require('./util/common'); -(function updateHeadersInSrcAndLibFiles() { +function updateHeadersInSrcAndLibFiles() { var srcGlob = path.join(constants.pathToSrc, '**/*.js'); var libGlob = path.join(constants.pathToLib, '**/*.js'); @@ -60,4 +60,6 @@ var common = require('./util/common'); return (header.value.replace(regex, '') === licenseStr.replace(regex, '')); } -})(); +} + +updateHeadersInSrcAndLibFiles();