@ckeditor/ckeditor5-dev-release-tools 32.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE.md +16 -0
  2. package/README.md +89 -0
  3. package/lib/index.js +28 -0
  4. package/lib/tasks/bumpversions.js +354 -0
  5. package/lib/tasks/generatechangelogformonorepository.js +723 -0
  6. package/lib/tasks/generatechangelogforsinglepackage.js +202 -0
  7. package/lib/tasks/releasesubrepositories.js +929 -0
  8. package/lib/tasks/updateckeditor5dependencies.js +392 -0
  9. package/lib/templates/commit.hbs +29 -0
  10. package/lib/templates/footer.hbs +10 -0
  11. package/lib/templates/header.hbs +23 -0
  12. package/lib/templates/release-package.json +12 -0
  13. package/lib/templates/template.hbs +37 -0
  14. package/lib/utils/changelog.js +67 -0
  15. package/lib/utils/cli.js +324 -0
  16. package/lib/utils/creategithubrelease.js +35 -0
  17. package/lib/utils/displaycommits.js +105 -0
  18. package/lib/utils/displayskippedpackages.js +32 -0
  19. package/lib/utils/executeonpackages.js +26 -0
  20. package/lib/utils/generatechangelog.js +121 -0
  21. package/lib/utils/getchangedfilesforcommit.js +33 -0
  22. package/lib/utils/getcommits.js +104 -0
  23. package/lib/utils/getnewversiontype.js +53 -0
  24. package/lib/utils/getpackagejson.js +24 -0
  25. package/lib/utils/getpackagespaths.js +90 -0
  26. package/lib/utils/getpackagestorelease.js +152 -0
  27. package/lib/utils/getwriteroptions.js +33 -0
  28. package/lib/utils/parseroptions.js +26 -0
  29. package/lib/utils/transformcommitfactory.js +492 -0
  30. package/lib/utils/transformcommitutils.js +163 -0
  31. package/lib/utils/updatedependenciesversions.js +32 -0
  32. package/lib/utils/validatepackagetorelease.js +54 -0
  33. package/lib/utils/versions.js +59 -0
  34. package/package.json +52 -0
@@ -0,0 +1,202 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ const fs = require( 'fs' );
9
+ const { tools, logger } = require( '@ckeditor/ckeditor5-dev-utils' );
10
+ const chalk = require( 'chalk' );
11
+ const semver = require( 'semver' );
12
+ const cli = require( '../utils/cli' );
13
+ const changelogUtils = require( '../utils/changelog' );
14
+ const displayCommits = require( '../utils/displaycommits' );
15
+ const generateChangelog = require( '../utils/generatechangelog' );
16
+ const getPackageJson = require( '../utils/getpackagejson' );
17
+ const getNewVersionType = require( '../utils/getnewversiontype' );
18
+ const getCommits = require( '../utils/getcommits' );
19
+ const getWriterOptions = require( '../utils/getwriteroptions' );
20
+ const { getRepositoryUrl } = require( '../utils/transformcommitutils' );
21
+ const transformCommitFactory = require( '../utils/transformcommitfactory' );
22
+
23
+ const SKIP_GENERATE_CHANGELOG = 'Typed "skip" as a new version. Aborting.';
24
+
25
+ /**
26
+ * Generates the changelog based on commit messages in a package that is located under current work directory (cwd).
27
+ *
28
+ * If the package does not have any commit, the user has to confirm whether the changelog should be generated.
29
+ *
30
+ * @param {Object} [options={}] Additional options.
31
+ *
32
+ * @param {Boolean} [options.skipLinks=false] If set on true, links to release or commits will be omitted.
33
+ *
34
+ * @param {String} [options.from] A commit or tag name that will be the first param of the range of commits to collect.
35
+ *
36
+ * @param {Boolean} [options.highlightsPlaceholder=false] Whether to add a note about release highlights.
37
+ *
38
+ * @param {Boolean} [options.collaborationFeatures=false] Whether to add a note about collaboration features.
39
+ *
40
+ * @param {String} [options.releaseBranch='master'] A name of the branch that should be used for releasing packages.
41
+ *
42
+ * @returns {Promise}
43
+ */
44
+ module.exports = async function generateChangelogForSinglePackage( options = {} ) {
45
+ const log = logger();
46
+ const pkgJson = getPackageJson();
47
+
48
+ logProcess( chalk.bold( `Generating changelog for "${ chalk.underline( pkgJson.name ) }"...` ) );
49
+
50
+ const transformCommit = transformCommitFactory();
51
+
52
+ logProcess( 'Collecting all commits since the last release...' );
53
+
54
+ const commitOptions = {
55
+ from: options.from ? options.from : 'v' + pkgJson.version,
56
+ releaseBranch: options.releaseBranch
57
+ };
58
+
59
+ // Initial release.
60
+ if ( semver.eq( pkgJson.version, '0.0.1' ) ) {
61
+ commitOptions.from = null;
62
+ }
63
+
64
+ // Collection of all entries (real commits + additional "fake" commits extracted from descriptions).
65
+ let allCommits;
66
+
67
+ // A new version inserted into the changelog.
68
+ let newVersion;
69
+
70
+ return getCommits( transformCommit, commitOptions )
71
+ .then( commits => {
72
+ allCommits = commits;
73
+
74
+ logInfo( `Found ${ commits.length } entries to parse.`, { indentLevel: 1 } );
75
+ } )
76
+ .then( () => {
77
+ logProcess( 'Preparing new version for the package...' );
78
+
79
+ const releaseType = getNewVersionType( allCommits );
80
+
81
+ displayCommits( allCommits, { indentLevel: 1 } );
82
+
83
+ return cli.provideVersion( pkgJson.version, releaseType, { indentLevel: 1 } );
84
+ } )
85
+ .then( version => {
86
+ if ( version === 'skip' ) {
87
+ throw new Error( SKIP_GENERATE_CHANGELOG );
88
+ }
89
+
90
+ const isInternalRelease = version === 'internal';
91
+
92
+ if ( version === 'internal' ) {
93
+ version = semver.inc( pkgJson.version, 'patch' );
94
+ }
95
+
96
+ newVersion = version;
97
+
98
+ logProcess( 'Generating the changelog...' );
99
+
100
+ const previousTag = commitOptions.from ? 'v' + pkgJson.version : null;
101
+
102
+ const writerContext = {
103
+ version,
104
+ commit: 'commit',
105
+ repoUrl: getRepositoryUrl(),
106
+ currentTag: 'v' + version,
107
+ previousTag,
108
+ isPatch: semver.diff( version, pkgJson.version ) === 'patch',
109
+ isInternalRelease,
110
+ highlightsPlaceholder: Boolean( options.highlightsPlaceholder ),
111
+ collaborationFeatures: Boolean( options.collaborationFeatures ),
112
+ skipCommitsLink: Boolean( options.skipLinks ),
113
+ skipCompareLink: Boolean( options.skipLinks )
114
+ };
115
+
116
+ const writerOptions = getWriterOptions( {
117
+ // We do not allow modifying the commit hash value by the generator itself.
118
+ hash: hash => hash
119
+ } );
120
+
121
+ const publicCommits = [ ...allCommits ]
122
+ .filter( commit => commit.isPublicCommit )
123
+ .map( commit => {
124
+ commit.scope = null;
125
+ commit.notes = commit.notes.map( note => {
126
+ note.scope = null;
127
+
128
+ return note;
129
+ } );
130
+
131
+ return commit;
132
+ } );
133
+
134
+ return generateChangelog( publicCommits, writerContext, writerOptions )
135
+ .then( changes => {
136
+ logInfo( 'Changes based on commits have been generated.', { indentLevel: 1 } );
137
+
138
+ return Promise.resolve( changes );
139
+ } );
140
+ } )
141
+ .then( changesFromCommits => {
142
+ logProcess( 'Saving changelog...' );
143
+
144
+ if ( !fs.existsSync( changelogUtils.changelogFile ) ) {
145
+ logInfo( 'Changelog file does not exist. Creating...', { isWarning: true, indentLevel: 1 } );
146
+
147
+ changelogUtils.saveChangelog( changelogUtils.changelogHeader );
148
+ }
149
+
150
+ let currentChangelog = changelogUtils.getChangelog();
151
+
152
+ // Remove header from current changelog.
153
+ currentChangelog = currentChangelog.replace( changelogUtils.changelogHeader, '' );
154
+
155
+ // Concat header, new and current changelog.
156
+ let newChangelog = changelogUtils.changelogHeader + changesFromCommits + currentChangelog.trim();
157
+ newChangelog = newChangelog.trim() + '\n';
158
+
159
+ // Save the changelog.
160
+ changelogUtils.saveChangelog( newChangelog );
161
+
162
+ tools.shExec( `git add ${ changelogUtils.changelogFile }`, { verbosity: 'error' } );
163
+ tools.shExec( 'git commit -m "Docs: Changelog. [skip ci]"', { verbosity: 'error' } );
164
+
165
+ logInfo( 'Saved.', { indentLevel: 1 } );
166
+ } )
167
+ .then( () => {
168
+ logInfo( `Changelog for "${ chalk.underline( pkgJson.name ) }" (v${ newVersion }) has been generated.`, { indentLevel: 1 } );
169
+ } )
170
+ .catch( err => {
171
+ if ( err.message === SKIP_GENERATE_CHANGELOG ) {
172
+ logInfo( `Skipping generating the changelog for "${ chalk.underline( pkgJson.name ) }".`, {
173
+ indentLevel: 1,
174
+ isWarning: true,
175
+ startWithNewLine: true
176
+ } );
177
+
178
+ return;
179
+ }
180
+
181
+ throw err;
182
+ } );
183
+
184
+ function logProcess( message ) {
185
+ log.info( '\n📍 ' + chalk.cyan( message ) );
186
+ }
187
+
188
+ /**
189
+ * @param {String} message
190
+ * @param {Object} [options={}]
191
+ * @param {Number} [options.indentLevel=0]
192
+ * @param {Boolean} [options.startWithNewLine=false] Whether to append a new line before the message.
193
+ * @param {Boolean} [options.isWarning=false] Whether to use `warning` method instead of `log`.
194
+ */
195
+ function logInfo( message, options = {} ) {
196
+ const indentLevel = options.indentLevel || 0;
197
+ const startWithNewLine = options.startWithNewLine || false;
198
+ const method = options.isWarning ? 'warning' : 'info';
199
+
200
+ log[ method ]( `${ startWithNewLine ? '\n' : '' }${ ' '.repeat( indentLevel * cli.INDENT_SIZE ) }` + message );
201
+ }
202
+ };