@ckeditor/ckeditor5-dev-release-tools 34.1.3 ā 35.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.
- package/lib/index.js +5 -1
- package/lib/tasks/preparepackages.js +248 -0
- package/package.json +3 -2
package/lib/index.js
CHANGED
|
@@ -6,15 +6,18 @@
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
const releaseSubRepositories = require( './tasks/releasesubrepositories' );
|
|
9
|
+
const preparePackages = require( './tasks/preparepackages' );
|
|
9
10
|
const bumpVersions = require( './tasks/bumpversions' );
|
|
10
11
|
const generateChangelogForSinglePackage = require( './tasks/generatechangelogforsinglepackage' );
|
|
11
12
|
const generateChangelogForMonoRepository = require( './tasks/generatechangelogformonorepository' );
|
|
12
13
|
const updateCKEditor5Dependencies = require( './tasks/updateckeditor5dependencies' );
|
|
14
|
+
const updateDependenciesVersions = require( './utils/updatedependenciesversions' );
|
|
13
15
|
const { getLastFromChangelog, getCurrent, getLastTagFromGit } = require( './utils/versions' );
|
|
14
16
|
const { getChangesForVersion, getChangelog, saveChangelog } = require( './utils/changelog' );
|
|
15
17
|
|
|
16
18
|
module.exports = {
|
|
17
19
|
releaseSubRepositories,
|
|
20
|
+
preparePackages,
|
|
18
21
|
bumpVersions,
|
|
19
22
|
generateChangelogForSinglePackage,
|
|
20
23
|
generateChangelogForMonoRepository,
|
|
@@ -24,5 +27,6 @@ module.exports = {
|
|
|
24
27
|
getLastTagFromGit,
|
|
25
28
|
getChangesForVersion,
|
|
26
29
|
getChangelog,
|
|
27
|
-
saveChangelog
|
|
30
|
+
saveChangelog,
|
|
31
|
+
updateDependenciesVersions
|
|
28
32
|
};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-env node */
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const path = require( 'path' );
|
|
11
|
+
const fs = require( 'fs-extra' );
|
|
12
|
+
const chalk = require( 'chalk' );
|
|
13
|
+
const glob = require( 'glob' );
|
|
14
|
+
const { tools } = require( '@ckeditor/ckeditor5-dev-utils' );
|
|
15
|
+
const { getLastFromChangelog } = require( '../utils/versions' );
|
|
16
|
+
const executeOnPackages = require( '../utils/executeonpackages' );
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Fields that will not be removed from `package.json` while preparing a package.
|
|
20
|
+
*/
|
|
21
|
+
const PACKAGE_JSON_FIELDS = [
|
|
22
|
+
'author',
|
|
23
|
+
'dependencies',
|
|
24
|
+
'description',
|
|
25
|
+
'engine',
|
|
26
|
+
'homepage',
|
|
27
|
+
'license',
|
|
28
|
+
'keywords',
|
|
29
|
+
'name',
|
|
30
|
+
'version',
|
|
31
|
+
'files',
|
|
32
|
+
'main',
|
|
33
|
+
'types',
|
|
34
|
+
'scripts'
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Prepares packages to be released:
|
|
39
|
+
*
|
|
40
|
+
* * removes TypeScript sources (but keeps typings),
|
|
41
|
+
* * secures the code of packages,
|
|
42
|
+
* * replaces the main package entry point (use JS file instead of TS),
|
|
43
|
+
* * prepares builds for all packages if a command is specified as npm script.
|
|
44
|
+
*
|
|
45
|
+
* The dry-run mode is not supported as the script creates a directory that should not be tracked by Git.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} options
|
|
48
|
+
* @param {String} options.cwd Current working directory (packages) from which all paths will be resolved.
|
|
49
|
+
* @param {String} options.packages Where to look for sources of packages (dependencies).
|
|
50
|
+
* @param {String} options.releaseDirectory Where to copy the packages (dependencies).
|
|
51
|
+
* @param {String} options.changelogDirectory An absolute path to the directory where the `CHANGELOG.md` file is saved.
|
|
52
|
+
* @param {String} options.buildScript A name of npm script that builds the package. It is executed per package.
|
|
53
|
+
* @param {String} options.secureScript A name of npm script that secures the code in the entire repository.
|
|
54
|
+
* @returns {Promise}
|
|
55
|
+
*/
|
|
56
|
+
module.exports = async function preparePackages( options ) {
|
|
57
|
+
const cwd = process.cwd();
|
|
58
|
+
const packagesDirectory = path.join( options.cwd, options.packages );
|
|
59
|
+
const releaseDirectory = path.join( options.cwd, options.releaseDirectory );
|
|
60
|
+
const ckeditor5Version = getLastFromChangelog( options.changelogDirectory );
|
|
61
|
+
|
|
62
|
+
// Clean the release directory before doing anything.
|
|
63
|
+
logProcess( 'Removing the release directory...' );
|
|
64
|
+
await fs.remove( releaseDirectory );
|
|
65
|
+
|
|
66
|
+
// Copy packages to the temporary, release directory.
|
|
67
|
+
logProcess( 'Copying packages to release...' );
|
|
68
|
+
await fs.copy( packagesDirectory, releaseDirectory );
|
|
69
|
+
|
|
70
|
+
// Find all short package names in the release directory.
|
|
71
|
+
// Then, map the names to absolute paths and their `package.json`.
|
|
72
|
+
const directoryNames = ( await fs.readdir( releaseDirectory, { withFileTypes: true } ) )
|
|
73
|
+
.filter( dirent => dirent.isDirectory() )
|
|
74
|
+
.map( dirent => dirent.name )
|
|
75
|
+
.map( name => {
|
|
76
|
+
const packagePath = path.join( releaseDirectory, name );
|
|
77
|
+
const packageJson = require( path.join( packagePath, 'package.json' ) );
|
|
78
|
+
|
|
79
|
+
return [ packagePath, packageJson ];
|
|
80
|
+
} );
|
|
81
|
+
|
|
82
|
+
const packages = new Map( directoryNames );
|
|
83
|
+
|
|
84
|
+
// Filter out packages without changes. They won't be released.
|
|
85
|
+
logProcess( 'Verifying packages...' );
|
|
86
|
+
await filterOutPackagesWithoutChanges( packages, ckeditor5Version );
|
|
87
|
+
|
|
88
|
+
if ( !packages.size ) {
|
|
89
|
+
logProcess( 'Nothing to release. Aborting.' );
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
logProcess( 'Preparing packages...' );
|
|
94
|
+
await preparePackagesToBeReleased( packages );
|
|
95
|
+
|
|
96
|
+
// Secure the entire release directory.
|
|
97
|
+
logProcess( 'Securing the code...' );
|
|
98
|
+
exec( options.secureScript );
|
|
99
|
+
|
|
100
|
+
logProcess( 'Preparing builds...' );
|
|
101
|
+
await prepareBuilds( packages, options.buildScript );
|
|
102
|
+
|
|
103
|
+
process.chdir( cwd );
|
|
104
|
+
|
|
105
|
+
logProcess( 'Done.' );
|
|
106
|
+
logInfo( chalk.grey( `Review the "${ options.releaseDirectory }/" directory before publishing the packages on npm.\n` ) );
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Check if packages should be released. It compares the packages' version against the latest version in CKEditor 5 changelog.
|
|
111
|
+
*
|
|
112
|
+
* If they are different, it means that a package should not be released and it is removed from the release directory.
|
|
113
|
+
*
|
|
114
|
+
* @param {Map.<String, PackageJson>} packages
|
|
115
|
+
* @param {String} ckeditor5Version
|
|
116
|
+
* @returns {Promise}
|
|
117
|
+
*/
|
|
118
|
+
function filterOutPackagesWithoutChanges( packages, ckeditor5Version ) {
|
|
119
|
+
return executeOnPackages( packages.keys(), async packagePath => {
|
|
120
|
+
const { name: packageName, version: packageVersion } = packages.get( packagePath );
|
|
121
|
+
|
|
122
|
+
logInfo( `* Checking "${ chalk.underline( packageName ) }"...`, { indent: 1, startWithNewLine: true } );
|
|
123
|
+
|
|
124
|
+
if ( packageVersion !== ckeditor5Version ) {
|
|
125
|
+
logInfo( chalk.grey( 'Nothing to release. Skipping.' ), { indent: 1 } );
|
|
126
|
+
|
|
127
|
+
await fs.remove( packagePath );
|
|
128
|
+
packages.delete( packagePath );
|
|
129
|
+
}
|
|
130
|
+
} );
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Prepare packages to be released. It means, for each package we do the following actions:
|
|
135
|
+
*
|
|
136
|
+
* * Remove TypeScript sources, but keep typing files (`.d.ts`).
|
|
137
|
+
* * Redefine the main script of a package. Replace the TypeScript extension with JavaScript.
|
|
138
|
+
* * Remove all tests of the package as they should not be released.
|
|
139
|
+
* * Remove the `build/` directory. The build script will re-create it from the JavaScript code.
|
|
140
|
+
*
|
|
141
|
+
* @param {Map.<String, PackageJson>} packages
|
|
142
|
+
* @returns {Promise}
|
|
143
|
+
*/
|
|
144
|
+
function preparePackagesToBeReleased( packages ) {
|
|
145
|
+
return executeOnPackages( packages.keys(), async packagePath => {
|
|
146
|
+
const { name: packageName } = packages.get( packagePath );
|
|
147
|
+
|
|
148
|
+
logInfo( `* Processing "${ chalk.underline( packageName ) }"...`, { indent: 1, startWithNewLine: true } );
|
|
149
|
+
logInfo( chalk.grey( 'Cleaning-up the package directory...' ), { indent: 2 } );
|
|
150
|
+
|
|
151
|
+
// The build will be refreshed. To avoid weird caches or building from TypeScript, let's clean the directory.
|
|
152
|
+
await fs.remove( path.join( packagePath, 'build' ) );
|
|
153
|
+
|
|
154
|
+
// Tests will not be published anyway. To increase readability, let's clean it too.
|
|
155
|
+
await fs.remove( path.join( packagePath, 'tests' ) );
|
|
156
|
+
|
|
157
|
+
// Update the entry point in the `package.json` file to point to a JavaScript file.
|
|
158
|
+
logInfo( chalk.grey( 'Replacing the package entry point (TS => JS)...' ), { indent: 2 } );
|
|
159
|
+
|
|
160
|
+
tools.updateJSONFile( path.join( packagePath, 'package.json' ), packageJson => {
|
|
161
|
+
const { main } = packageJson;
|
|
162
|
+
|
|
163
|
+
// Remove properties from package.json that are not related to the production package.
|
|
164
|
+
for ( const property of Object.keys( packageJson ) ) {
|
|
165
|
+
if ( !PACKAGE_JSON_FIELDS.includes( property ) ) {
|
|
166
|
+
delete packageJson[ property ];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if ( !main ) {
|
|
171
|
+
return packageJson;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
packageJson.main = main.replace( /.ts$/, '.js' );
|
|
175
|
+
packageJson.types = main.replace( /.ts$/, '.d.ts' );
|
|
176
|
+
|
|
177
|
+
return packageJson;
|
|
178
|
+
} );
|
|
179
|
+
|
|
180
|
+
// Find all TypeScript sources...
|
|
181
|
+
const typescriptFiles = await new Promise( ( resolve, reject ) => {
|
|
182
|
+
glob( '**/*.ts', { cwd: packagePath }, ( err, files ) => {
|
|
183
|
+
return err ? reject( err ) : resolve( files );
|
|
184
|
+
} );
|
|
185
|
+
} );
|
|
186
|
+
|
|
187
|
+
logInfo( chalk.grey( 'Removing TypeScript sources...' ), { indent: 2 } );
|
|
188
|
+
|
|
189
|
+
// ...and remove all non-typing files.
|
|
190
|
+
for ( const tsFile of typescriptFiles ) {
|
|
191
|
+
if ( !tsFile.endsWith( '.d.ts' ) ) {
|
|
192
|
+
await fs.remove( path.join( packagePath, tsFile ) );
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} );
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Executed a build task for all packages.
|
|
200
|
+
*
|
|
201
|
+
* @param {Map.<String, PackageJson>} packages
|
|
202
|
+
* @param {String} buildScript
|
|
203
|
+
* @returns {Promise}
|
|
204
|
+
*/
|
|
205
|
+
function prepareBuilds( packages, buildScript ) {
|
|
206
|
+
return executeOnPackages( packages.keys(), async packagePath => {
|
|
207
|
+
const { name: packageName, scripts = {} } = packages.get( packagePath );
|
|
208
|
+
|
|
209
|
+
if ( buildScript in scripts ) {
|
|
210
|
+
logInfo( `* Processing "${ chalk.underline( packageName ) }"...`, { indent: 1, startWithNewLine: true } );
|
|
211
|
+
|
|
212
|
+
process.chdir( packagePath );
|
|
213
|
+
|
|
214
|
+
exec( `yarn run ${ buildScript }` );
|
|
215
|
+
}
|
|
216
|
+
} );
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @param {String} message
|
|
221
|
+
*/
|
|
222
|
+
function logProcess( message ) {
|
|
223
|
+
console.log( '\nš ' + chalk.cyan( message ) );
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @param {String} message
|
|
228
|
+
* @param {Object} options
|
|
229
|
+
* @param {Number} [options.indent=0]
|
|
230
|
+
* @param {Boolean} [options.startWithNewLine=false]
|
|
231
|
+
*/
|
|
232
|
+
function logInfo( message, { indent = 0, startWithNewLine = false } = {} ) {
|
|
233
|
+
console.log( ( startWithNewLine ? '\n' : '' ) + ' '.repeat( indent * 3 ) + message );
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @param {String} command
|
|
238
|
+
* @returns {String}
|
|
239
|
+
*/
|
|
240
|
+
function exec( command ) {
|
|
241
|
+
return tools.shExec( command );
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @typedef {Object} PackageJson
|
|
246
|
+
* @property {String} version
|
|
247
|
+
* @property {String} name
|
|
248
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-dev-release-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "35.0.0",
|
|
4
4
|
"description": "Tools used for releasing CKEditor 5 and related packages.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@ckeditor/ckeditor5-dev-utils": "^
|
|
8
|
+
"@ckeditor/ckeditor5-dev-utils": "^35.0.0",
|
|
9
9
|
"@octokit/rest": "^17.9.2",
|
|
10
10
|
"chalk": "^4.0.0",
|
|
11
11
|
"cli-table": "^0.3.1",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"conventional-changelog-writer": "^4.0.16",
|
|
15
15
|
"conventional-commits-filter": "^2.0.6",
|
|
16
16
|
"conventional-commits-parser": "^3.1.0",
|
|
17
|
+
"fs-extra": "^9.1.0",
|
|
17
18
|
"diff": "^5.0.0",
|
|
18
19
|
"git-raw-commits": "^2.0.7",
|
|
19
20
|
"glob": "^7.1.6",
|