From a4a22441ae6082d2137a94c478660eadb49f7808 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 28 Jun 2021 11:58:11 -0400 Subject: [PATCH 1/8] start draftlog folder --- draftlogs/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/.gitignore diff --git a/draftlogs/.gitignore b/draftlogs/.gitignore new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/draftlogs/.gitignore @@ -0,0 +1 @@ + From 80d614e82ea2ae5cf6512513f5c5ba2680f21762 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 28 Jun 2021 13:14:37 -0400 Subject: [PATCH 2/8] add log for merged pull 5779 --- draftlogs/5779_fix.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 draftlogs/5779_fix.md diff --git a/draftlogs/5779_fix.md b/draftlogs/5779_fix.md new file mode 100644 index 00000000000..c45f560f477 --- /dev/null +++ b/draftlogs/5779_fix.md @@ -0,0 +1,2 @@ + - Improve README for ES6 module import [[#5779](https://github.com/plotly/plotly.js/pull/5779)], + with thanks to @andreafonso for the contribution! From 7154fa439616c6ffd6755239d361841bf5a7bf37 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 28 Jun 2021 13:38:22 -0400 Subject: [PATCH 3/8] centralize util for making an empty directory --- tasks/empty_dist.js | 31 ++++------------------------- tasks/util/make_empty_directory.js | 32 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 27 deletions(-) create mode 100644 tasks/util/make_empty_directory.js diff --git a/tasks/empty_dist.js b/tasks/empty_dist.js index 7302f41448c..8d8350f1f26 100644 --- a/tasks/empty_dist.js +++ b/tasks/empty_dist.js @@ -1,36 +1,13 @@ -var path = require('path'); -var fs = require('fs-extra'); -var common = require('./util/common'); var constants = require('./util/constants'); +var makeEmptyDirectory = require('./util/make_empty_directory'); +var emptyDir = makeEmptyDirectory.emptyDir; +var makeDir = makeEmptyDirectory.makeDir; var dist = constants.pathToDist; // dist var distTopojson = constants.pathToTopojsonDist; // dist/topojson + // main emptyDir(distTopojson); emptyDir(dist); makeDir(dist); makeDir(distTopojson); - -function emptyDir(dir) { - if(common.doesDirExist(dir)) { - console.log('empty ' + dir); - try { - var allFiles = fs.readdirSync(dir); - allFiles.forEach(function(file) { - // remove file - fs.unlinkSync(path.join(dir, file)); - }); - - fs.rmdirSync(dir); - } catch(err) { - console.error(err); - } - } -} - -function makeDir(dir) { - if(!common.doesDirExist(dir)) { - // create folder - fs.mkdirSync(dir); - } -} diff --git a/tasks/util/make_empty_directory.js b/tasks/util/make_empty_directory.js new file mode 100644 index 00000000000..e08ae3d9b89 --- /dev/null +++ b/tasks/util/make_empty_directory.js @@ -0,0 +1,32 @@ +var path = require('path'); +var fs = require('fs-extra'); +var common = require('./common'); + +module.exports = { + emptyDir: emptyDir, + makeDir: makeDir +}; + +function emptyDir(dir) { + if(common.doesDirExist(dir)) { + console.log('empty ' + dir); + try { + var allFiles = fs.readdirSync(dir); + allFiles.forEach(function(file) { + // remove file + fs.unlinkSync(path.join(dir, file)); + }); + + fs.rmdirSync(dir); + } catch(err) { + console.error(err); + } + } +} + +function makeDir(dir) { + if(!common.doesDirExist(dir)) { + // create folder + fs.mkdirSync(dir); + } +} From 4e68725a3d38b571f3e4ab4dcb14ad8aec60a176 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 28 Jun 2021 14:43:57 -0400 Subject: [PATCH 4/8] add script to draft new changelog based on draftlogs --- package.json | 7 ++- tasks/empty_draftlogs.js | 18 +++++++ tasks/use_draftlogs.js | 77 ++++++++++++++++++++++++++++++ tasks/util/constants.js | 3 ++ tasks/util/make_empty_directory.js | 12 ++++- 5 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 tasks/empty_draftlogs.js create mode 100644 tasks/use_draftlogs.js diff --git a/package.json b/package.json index 9b6416c4df7..f5ae9bd10cb 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,11 @@ "stats": "node tasks/stats.js", "find-strings": "node tasks/find_locale_strings.js", "preprocess": "node tasks/preprocess.js", - "build": "node tasks/empty_dist.js && npm run preprocess && npm run find-strings && npm run bundle && npm run extra-bundles && npm run stats", - "cibuild": "node tasks/empty_dist.js && npm run preprocess && node tasks/cibundle.js", + "use-draftlogs": "node tasks/use_draftlogs.js", + "empty-draftlogs": "node tasks/empty_draftlogs.js", + "empty-dist": "node tasks/empty_dist.js", + "build": "npm run empty-dist && npm run preprocess && npm run find-strings && npm run bundle && npm run extra-bundles && npm run stats", + "cibuild": "npm run empty-dist && npm run preprocess && node tasks/cibundle.js", "watch": "node tasks/watch.js", "lint": "eslint --version && eslint .", "lint-fix": "eslint . --fix || true", diff --git a/tasks/empty_draftlogs.js b/tasks/empty_draftlogs.js new file mode 100644 index 00000000000..1ddd5484c14 --- /dev/null +++ b/tasks/empty_draftlogs.js @@ -0,0 +1,18 @@ +var constants = require('./util/constants'); +var makeEmptyDirectory = require('./util/make_empty_directory'); +var emptyDir = makeEmptyDirectory.emptyDir; +var makeDir = makeEmptyDirectory.makeDir; + +var pathToDraftlogs = constants.pathToDraftlogs; + +var chZero = '0'.charCodeAt(0); +var chNine = '9'.charCodeAt(0); + +function startsWithNumber(v) { + var ch = v.charCodeAt(0); + return chZero <= ch && ch <= chNine; +} + +// main +emptyDir(pathToDraftlogs, { filter: startsWithNumber }); +makeDir(pathToDraftlogs); diff --git a/tasks/use_draftlogs.js b/tasks/use_draftlogs.js new file mode 100644 index 00000000000..00a530a740b --- /dev/null +++ b/tasks/use_draftlogs.js @@ -0,0 +1,77 @@ +var fs = require('fs'); +var path = require('path'); +var constants = require('./util/constants'); + +var pathToDraftlogs = constants.pathToDraftlogs; +var pathToChangelog = constants.pathToChangelog; + +var chZero = '0'.charCodeAt(0); +var chNine = '9'.charCodeAt(0); + +function startsWithNumber(v) { + var ch = v.charCodeAt(0); + return chZero <= ch && ch <= chNine; +} + +var allLogs = fs.readdirSync(pathToDraftlogs).filter(startsWithNumber); + +var len = allLogs.length; +if(!len) return; + +var writeAfterMe = 'where X.Y.Z is the semver of most recent plotly.js release.'; +var changelog = fs.readFileSync(pathToChangelog).toString().split(writeAfterMe); +var head = changelog[0]; +var foot = changelog[1]; + +var all = { + Added: [], + Removed: [], + Deprecated: [], + Changed: [], + Fixed: [] +}; + +var ENTER = '\n'; + +for(var i = 0; i < len; i++) { + var filename = allLogs[i]; + var message = fs.readFileSync(path.join(pathToDraftlogs, filename), { encoding: 'utf-8' }).toString(); + // trim empty lines + message = message.split(ENTER).filter(function(e) { return !!e; }).join(ENTER); + + if(filename.endsWith('_add.md')) { + all.Added.push(message); + } else if(filename.endsWith('_remove.md')) { + all.Removed.push(message); + } else if(filename.endsWith('_deprecate.md')) { + all.Deprecated.push(message); + } else if(filename.endsWith('_change.md')) { + all.Changed.push(message); + } else if(filename.endsWith('_fix.md')) { + all.Fixed.push(message); + } +} + +var draftNewChangelog = [ + head + writeAfterMe, + '', + '## [X.Y.Z] -- UNRELEASED' +]; + +var append = function(key) { + var newMessages = all[key]; + if(!newMessages.length) return; + draftNewChangelog.push(''); + draftNewChangelog.push('### ' + key); + draftNewChangelog.push(newMessages.join(ENTER)); +}; + +append('Added'); +append('Removed'); +append('Deprecated'); +append('Changed'); +append('Fixed'); + +draftNewChangelog.push(foot); + +fs.writeFileSync(pathToChangelog, draftNewChangelog.join(ENTER), { encoding: 'utf-8' }); diff --git a/tasks/util/constants.js b/tasks/util/constants.js index 98508b8c18f..dbc873daabb 100644 --- a/tasks/util/constants.js +++ b/tasks/util/constants.js @@ -7,6 +7,7 @@ var pathToSrc = path.join(pathToRoot, 'src/'); var pathToLib = path.join(pathToRoot, 'lib/'); var pathToImageTest = path.join(pathToRoot, 'test/image'); var pathToStrictD3Module = path.join(pathToRoot, 'test/strict-d3.js'); +var pathToDraftlogs = path.join(pathToRoot, 'draftlogs/'); var pathToDist = path.join(pathToRoot, 'dist/'); var pathToBuild = path.join(pathToRoot, 'build/'); @@ -168,6 +169,8 @@ module.exports = { pathToLib: pathToLib, pathToBuild: pathToBuild, pathToDist: pathToDist, + pathToDraftlogs: pathToDraftlogs, + pathToChangelog: path.join(pathToRoot, 'CHANGELOG.md'), partialBundleTraces: partialBundleTraces, diff --git a/tasks/util/make_empty_directory.js b/tasks/util/make_empty_directory.js index e08ae3d9b89..cf34b0bce71 100644 --- a/tasks/util/make_empty_directory.js +++ b/tasks/util/make_empty_directory.js @@ -7,17 +7,25 @@ module.exports = { makeDir: makeDir }; -function emptyDir(dir) { +function emptyDir(dir, opts) { if(common.doesDirExist(dir)) { console.log('empty ' + dir); try { var allFiles = fs.readdirSync(dir); + var hasFilter = false; + if(opts && opts.filter) { + hasFilter = true; + allFiles = allFiles.filter(opts.filter); + } + allFiles.forEach(function(file) { // remove file fs.unlinkSync(path.join(dir, file)); }); - fs.rmdirSync(dir); + if(!hasFilter) { + fs.rmdirSync(dir); + } } catch(err) { console.error(err); } From 3a91c0e380886d6292b12a71b22fd25d298b5f82 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 30 Jun 2021 16:53:11 -0400 Subject: [PATCH 5/8] create a readme for draft logs - throw an error when skipping bad filenames --- draftlogs/.gitignore | 1 - draftlogs/README.md | 22 ++++++++++++++++++++++ tasks/use_draftlogs.js | 9 +++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) delete mode 100644 draftlogs/.gitignore create mode 100644 draftlogs/README.md diff --git a/draftlogs/.gitignore b/draftlogs/.gitignore deleted file mode 100644 index 8b137891791..00000000000 --- a/draftlogs/.gitignore +++ /dev/null @@ -1 +0,0 @@ - diff --git a/draftlogs/README.md b/draftlogs/README.md new file mode 100644 index 00000000000..db87b010be8 --- /dev/null +++ b/draftlogs/README.md @@ -0,0 +1,22 @@ +## Directory of draft logs to help prepare the upcoming [CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md) + +It is required that the PR contributors start the filename with a number. +This number should preferably be the PR number. +The number of issue they are trying to close could also be used. +The markdown file should end with one of the followings: +1. `_fix.md` to propose a bug fix +2. `_add.md` to propose new features +3. `_remove.md` to propose a feature removal +4. `_change.md` to propose a minor/major change +5. `_deprecate.md` to propose a feature deprecate + +### Example filename and content for PR numbered 5546 for adding a new feature +- filename: `5546_add.md` +- content: +``` + - Add `icicle` trace type [[#5546](https://github.com/plotly/plotly.js/pull/5546)] +``` +which would render + - Add `icicle` trace type [[#5546](https://github.com/plotly/plotly.js/pull/5546)] + +> Please start your single-line or multiple lined message with a verb. You could basically use the PR description while providing a link to the PR similar to the above example is appreciated too. diff --git a/tasks/use_draftlogs.js b/tasks/use_draftlogs.js index 00a530a740b..d0ac292b002 100644 --- a/tasks/use_draftlogs.js +++ b/tasks/use_draftlogs.js @@ -33,6 +33,7 @@ var all = { var ENTER = '\n'; +var skippedFiles = []; for(var i = 0; i < len; i++) { var filename = allLogs[i]; var message = fs.readFileSync(path.join(pathToDraftlogs, filename), { encoding: 'utf-8' }).toString(); @@ -49,6 +50,8 @@ for(var i = 0; i < len; i++) { all.Changed.push(message); } else if(filename.endsWith('_fix.md')) { all.Fixed.push(message); + } else { + skippedFiles.push(filename); } } @@ -75,3 +78,9 @@ append('Fixed'); draftNewChangelog.push(foot); fs.writeFileSync(pathToChangelog, draftNewChangelog.join(ENTER), { encoding: 'utf-8' }); + +if(skippedFiles.length) { + throw JSON.stringify({ + 'skippedFiles': skippedFiles + }, null, 2); +} From eefab9b8178f40c60b138bb7544ef13886d1ec34 Mon Sep 17 00:00:00 2001 From: archmoj Date: Wed, 30 Jun 2021 17:29:35 -0400 Subject: [PATCH 6/8] update and improve pull request template --- .github/PULL_REQUEST_TEMPLATE.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8ce0abc990c..d189a503397 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,11 +9,14 @@ Thanks for your interest in plotly.js! ### Features, Bug fixes, and others: Before opening a pull request, developer should: +1. make sure they are not on the `master` branch of their fork as using `master` for a pull request would make it difficult to fetch `upstream` changes. +2. fetch latest changes from `upstream/master` into your fork i.e. `origin/master` then pull `origin/master` from you local `master`. +3. then `git rebase master` their local dev branch off the latest `master` which should be sync with `upstream/master` at this time. +4. make sure to **not** `git add` the `dist/` folder (the `dist/` is updated only on version bumps). +5. make sure to commit changes to the `package-lock.json` file (if any new dependency required). +6. provide a title and write an overview of what the PR attempts to do with a link to the issue they are trying to address. +7. select the _Allow edits from maintainers_ option (see this [article](https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/) for more details). -- `git rebase` their local branch off the latest `master`, -- make sure to **not** `git add` the `dist/` folder (the `dist/` is updated only on version bumps), -- make sure to commit changes to the `package-lock.json` file (if any new dependency required), -- write an overview of what the PR attempts to do, -- select the _Allow edits from maintainers_ option (see this [article](https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/) for more details). - -Note that it is forbidden to force push (i.e. `git push -f`) to remote branches associated with opened pull requests. Force pushes make it hard for maintainers to keep track of updates. Therefore, if required, please `git merge master` into your PR branch instead of `git rebase master`. +After opening a pull request, developer: + - should create a new small markdown log file using the PR number e.g. `1010_fix.md` or `1010_add.md` inside `draftlogs` folder as described in this [README](https://github.com/plotly/plotly.js/blob/master/draftlogs/README.md), commit it and push. + - should **not** force push (i.e. `git push -f`) to remote branches associated with opened pull requests. Force pushes make it hard for maintainers to keep track of updates. Therefore, if required, please fetch `upstream/master` and "merge" with master instead of "rebase". From ec4417fefab927cee4f6548d52e3041a1e857752 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> Date: Wed, 7 Jul 2021 09:56:55 -0400 Subject: [PATCH 7/8] Update draftlogs/README.md Co-authored-by: Alex Johnson --- draftlogs/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/draftlogs/README.md b/draftlogs/README.md index db87b010be8..73d6e0e2112 100644 --- a/draftlogs/README.md +++ b/draftlogs/README.md @@ -8,7 +8,9 @@ The markdown file should end with one of the followings: 2. `_add.md` to propose new features 3. `_remove.md` to propose a feature removal 4. `_change.md` to propose a minor/major change -5. `_deprecate.md` to propose a feature deprecate +5. `_deprecate.md` to propose a feature be deprecated + +If your PR falls into more than one category - for example adding a new feature and changing an existing feature - you should include each in a separate file. ### Example filename and content for PR numbered 5546 for adding a new feature - filename: `5546_add.md` From d17e77c6895af965ac7141899db963f8572f21a4 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> Date: Wed, 7 Jul 2021 09:57:20 -0400 Subject: [PATCH 8/8] Update draftlogs/README.md Co-authored-by: Alex Johnson --- draftlogs/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/draftlogs/README.md b/draftlogs/README.md index 73d6e0e2112..5ae928cb0cc 100644 --- a/draftlogs/README.md +++ b/draftlogs/README.md @@ -1,9 +1,7 @@ ## Directory of draft logs to help prepare the upcoming [CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md) -It is required that the PR contributors start the filename with a number. -This number should preferably be the PR number. -The number of issue they are trying to close could also be used. -The markdown file should end with one of the followings: +Every pull request should add at least one markdown file to this directory. +The filename must start with a number, preferably the PR number, followed by one of these: 1. `_fix.md` to propose a bug fix 2. `_add.md` to propose new features 3. `_remove.md` to propose a feature removal