@eclipse-glsp/cli 2.2.1 → 2.3.0-next.17

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 (138) hide show
  1. package/README.md +143 -38
  2. package/dist/cli.js +21959 -0
  3. package/dist/cli.js.map +6 -0
  4. package/package.json +22 -29
  5. package/bin/glsp +0 -2
  6. package/lib/app.d.ts +0 -3
  7. package/lib/app.d.ts.map +0 -1
  8. package/lib/app.js +0 -36
  9. package/lib/app.js.map +0 -1
  10. package/lib/commands/check-header.d.ts +0 -21
  11. package/lib/commands/check-header.d.ts.map +0 -1
  12. package/lib/commands/check-header.js +0 -240
  13. package/lib/commands/check-header.js.map +0 -1
  14. package/lib/commands/checkout.d.ts +0 -27
  15. package/lib/commands/checkout.d.ts.map +0 -1
  16. package/lib/commands/checkout.js +0 -41
  17. package/lib/commands/checkout.js.map +0 -1
  18. package/lib/commands/coverage-report.d.ts +0 -29
  19. package/lib/commands/coverage-report.d.ts.map +0 -1
  20. package/lib/commands/coverage-report.js +0 -126
  21. package/lib/commands/coverage-report.js.map +0 -1
  22. package/lib/commands/generate-index.d.ts +0 -46
  23. package/lib/commands/generate-index.d.ts.map +0 -1
  24. package/lib/commands/generate-index.js +0 -172
  25. package/lib/commands/generate-index.js.map +0 -1
  26. package/lib/commands/release/common.d.ts +0 -68
  27. package/lib/commands/release/common.d.ts.map +0 -1
  28. package/lib/commands/release/common.js +0 -293
  29. package/lib/commands/release/common.js.map +0 -1
  30. package/lib/commands/release/release-client.d.ts +0 -3
  31. package/lib/commands/release/release-client.d.ts.map +0 -1
  32. package/lib/commands/release/release-client.js +0 -57
  33. package/lib/commands/release/release-client.js.map +0 -1
  34. package/lib/commands/release/release-eclipse-integration.d.ts +0 -18
  35. package/lib/commands/release/release-eclipse-integration.d.ts.map +0 -1
  36. package/lib/commands/release/release-eclipse-integration.js +0 -92
  37. package/lib/commands/release/release-eclipse-integration.js.map +0 -1
  38. package/lib/commands/release/release-java-server.d.ts +0 -3
  39. package/lib/commands/release/release-java-server.d.ts.map +0 -1
  40. package/lib/commands/release/release-java-server.js +0 -70
  41. package/lib/commands/release/release-java-server.js.map +0 -1
  42. package/lib/commands/release/release-server-node.d.ts +0 -18
  43. package/lib/commands/release/release-server-node.d.ts.map +0 -1
  44. package/lib/commands/release/release-server-node.js +0 -53
  45. package/lib/commands/release/release-server-node.js.map +0 -1
  46. package/lib/commands/release/release-theia-integration.d.ts +0 -18
  47. package/lib/commands/release/release-theia-integration.d.ts.map +0 -1
  48. package/lib/commands/release/release-theia-integration.js +0 -53
  49. package/lib/commands/release/release-theia-integration.js.map +0 -1
  50. package/lib/commands/release/release-vscode-integration.d.ts +0 -18
  51. package/lib/commands/release/release-vscode-integration.d.ts.map +0 -1
  52. package/lib/commands/release/release-vscode-integration.js +0 -53
  53. package/lib/commands/release/release-vscode-integration.js.map +0 -1
  54. package/lib/commands/release/release.d.ts +0 -14
  55. package/lib/commands/release/release.d.ts.map +0 -1
  56. package/lib/commands/release/release.js +0 -191
  57. package/lib/commands/release/release.js.map +0 -1
  58. package/lib/commands/repo/clone.d.ts +0 -28
  59. package/lib/commands/repo/clone.d.ts.map +0 -1
  60. package/lib/commands/repo/clone.js +0 -113
  61. package/lib/commands/repo/clone.js.map +0 -1
  62. package/lib/commands/repo/clone.spec.d.ts +0 -17
  63. package/lib/commands/repo/clone.spec.d.ts.map +0 -1
  64. package/lib/commands/repo/clone.spec.js +0 -126
  65. package/lib/commands/repo/clone.spec.js.map +0 -1
  66. package/lib/commands/repo/common.d.ts +0 -23
  67. package/lib/commands/repo/common.d.ts.map +0 -1
  68. package/lib/commands/repo/common.js +0 -18
  69. package/lib/commands/repo/common.js.map +0 -1
  70. package/lib/commands/repo/config.d.ts +0 -18
  71. package/lib/commands/repo/config.d.ts.map +0 -1
  72. package/lib/commands/repo/config.js +0 -28
  73. package/lib/commands/repo/config.js.map +0 -1
  74. package/lib/commands/repo/repo.d.ts +0 -17
  75. package/lib/commands/repo/repo.d.ts.map +0 -1
  76. package/lib/commands/repo/repo.js +0 -25
  77. package/lib/commands/repo/repo.js.map +0 -1
  78. package/lib/commands/update-next.d.ts +0 -20
  79. package/lib/commands/update-next.d.ts.map +0 -1
  80. package/lib/commands/update-next.js +0 -146
  81. package/lib/commands/update-next.js.map +0 -1
  82. package/lib/common/glsp-component.d.ts +0 -27
  83. package/lib/common/glsp-component.d.ts.map +0 -1
  84. package/lib/common/glsp-component.js +0 -13
  85. package/lib/common/glsp-component.js.map +0 -1
  86. package/lib/common/glsp-repo.d.ts +0 -44
  87. package/lib/common/glsp-repo.d.ts.map +0 -1
  88. package/lib/common/glsp-repo.js +0 -135
  89. package/lib/common/glsp-repo.js.map +0 -1
  90. package/lib/common/glsp-repo.spec.d.ts +0 -17
  91. package/lib/common/glsp-repo.spec.d.ts.map +0 -1
  92. package/lib/common/glsp-repo.spec.js +0 -130
  93. package/lib/common/glsp-repo.spec.js.map +0 -1
  94. package/lib/foo.spec.d.ts +0 -17
  95. package/lib/foo.spec.d.ts.map +0 -1
  96. package/lib/foo.spec.js +0 -23
  97. package/lib/foo.spec.js.map +0 -1
  98. package/lib/index.d.ts +0 -18
  99. package/lib/index.d.ts.map +0 -1
  100. package/lib/index.js +0 -18
  101. package/lib/index.js.map +0 -1
  102. package/lib/util/command-util.d.ts +0 -26
  103. package/lib/util/command-util.d.ts.map +0 -1
  104. package/lib/util/command-util.js +0 -59
  105. package/lib/util/command-util.js.map +0 -1
  106. package/lib/util/git-util.d.ts +0 -42
  107. package/lib/util/git-util.d.ts.map +0 -1
  108. package/lib/util/git-util.js +0 -124
  109. package/lib/util/git-util.js.map +0 -1
  110. package/lib/util/logger.d.ts +0 -23
  111. package/lib/util/logger.d.ts.map +0 -1
  112. package/lib/util/logger.js +0 -50
  113. package/lib/util/logger.js.map +0 -1
  114. package/lib/util/test-util.spec.d.ts +0 -2
  115. package/lib/util/test-util.spec.d.ts.map +0 -1
  116. package/lib/util/test-util.spec.js +0 -44
  117. package/lib/util/test-util.spec.js.map +0 -1
  118. package/lib/util/validation-util.d.ts +0 -5
  119. package/lib/util/validation-util.d.ts.map +0 -1
  120. package/lib/util/validation-util.js +0 -85
  121. package/lib/util/validation-util.js.map +0 -1
  122. package/src/app.ts +0 -35
  123. package/src/commands/check-header.ts +0 -280
  124. package/src/commands/coverage-report.ts +0 -113
  125. package/src/commands/generate-index.ts +0 -169
  126. package/src/commands/release/common.ts +0 -306
  127. package/src/commands/release/release-client.ts +0 -55
  128. package/src/commands/release/release-eclipse-integration.ts +0 -113
  129. package/src/commands/release/release-java-server.ts +0 -73
  130. package/src/commands/release/release-server-node.ts +0 -61
  131. package/src/commands/release/release-theia-integration.ts +0 -65
  132. package/src/commands/release/release-vscode-integration.ts +0 -67
  133. package/src/commands/release/release.ts +0 -215
  134. package/src/commands/update-next.ts +0 -129
  135. package/src/util/command-util.ts +0 -54
  136. package/src/util/git-util.ts +0 -123
  137. package/src/util/logger.ts +0 -57
  138. package/src/util/validation-util.ts +0 -62
@@ -1,67 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2022-2024 EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- import sh from 'shelljs';
18
- import { LOGGER } from '../../util/logger';
19
- import {
20
- checkoutAndCd,
21
- commitAndTag,
22
- lernaSetVersion,
23
- publish,
24
- ReleaseOptions,
25
- updateLernaForDryRun,
26
- updateVersion,
27
- yarnInstall
28
- } from './common.js';
29
-
30
- let REPO_ROOT: string;
31
-
32
- export async function releaseVscodeIntegration(options: ReleaseOptions): Promise<void> {
33
- LOGGER.info('Prepare glsp-vscode-integration release');
34
- LOGGER.debug('Release options: ', options);
35
- REPO_ROOT = checkoutAndCd(options);
36
- updateExternalGLSPDependencies(options.version);
37
- generateChangeLog();
38
- lernaSetVersion(REPO_ROOT, options.version);
39
- build();
40
- if (options.npmDryRun) {
41
- updateLernaForDryRun();
42
- }
43
- commitAndTag(options.version, REPO_ROOT);
44
- publish(REPO_ROOT, options);
45
- }
46
-
47
- function updateExternalGLSPDependencies(version: string): void {
48
- LOGGER.info('Update external GLSP dependencies (Protocol)');
49
- sh.cd(REPO_ROOT);
50
- updateVersion(
51
- { name: '@eclipse-glsp/protocol', version },
52
- { name: '@eclipse-glsp/client', version },
53
- { name: '@eclipse-glsp-examples/workflow-glsp', version },
54
- { name: '@eclipse-glsp-examples/workflow-server', version },
55
- { name: '@eclipse-glsp-examples/workflow-server-bundled', version }
56
- );
57
- }
58
-
59
- function build(): void {
60
- LOGGER.info('Install & Build with yarn');
61
- yarnInstall(REPO_ROOT);
62
- LOGGER.debug('Build successful');
63
- }
64
-
65
- function generateChangeLog(): void {
66
- // do nothing for now
67
- }
@@ -1,215 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2022-2024 EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { ChildProcess } from 'child_process';
17
- import { Argument } from 'commander';
18
- import { exit } from 'process';
19
- import { createInterface } from 'readline';
20
- import * as readline from 'readline-sync';
21
- import * as semver from 'semver';
22
- import sh from 'shelljs';
23
- import { baseCommand, configureShell, fatalExec, getShellConfig } from '../../util/command-util';
24
- import { LOGGER, configureLogger } from '../../util/logger';
25
- import { validateDirectory, validateVersion } from '../../util/validation-util';
26
- import {
27
- Component,
28
- ReleaseOptions,
29
- ReleaseType,
30
- VERDACCIO_REGISTRY,
31
- asMvnVersion,
32
- checkIfMavenVersionExists,
33
- checkIfNpmVersionIsNew
34
- } from './common.js';
35
- import { releaseClient } from './release-client';
36
- import { releaseEclipseIntegration } from './release-eclipse-integration';
37
- import { releaseJavaServer } from './release-java-server';
38
- import { releaseServerNode } from './release-server-node';
39
- import { releaseTheiaIntegration } from './release-theia-integration';
40
- import { releaseVscodeIntegration } from './release-vscode-integration';
41
-
42
- interface ReleaseCmdOptions {
43
- checkoutDir: string;
44
- branch: string;
45
- force: boolean;
46
- publish: boolean;
47
- npmDryRun: boolean;
48
- draft: boolean;
49
- verbose: boolean;
50
- }
51
-
52
- export const ReleaseCommand = baseCommand()
53
- .name('release')
54
- .description('Prepare & publish a new release for a glsp component')
55
- .addArgument(new Argument('<component>', 'The glsp component to be released').choices(Component.CLI_CHOICES).argParser(Component.parse))
56
- .addArgument(new Argument('<releaseType>', 'The release type').choices(ReleaseType.CLI_CHOICES))
57
- .argument('[customVersion]', 'Custom version number. Will be ignored if the release type is not "custom"', validateVersion)
58
- .option('-f, --force', 'Enable force mode', false)
59
- .option('-d, --checkoutDir <checkoutDir>', 'The git checkout directory', validateDirectory, process.cwd())
60
- .option('-b, --branch <branch>', 'The git branch to checkout', 'master')
61
- .option('-v, --verbose', 'Enable verbose (debug) log output', false)
62
- .option('--no-publish', 'Only prepare release but do not publish to github', true)
63
- .option('--draft', 'Publish github releases as drafts', false)
64
- .option(
65
- '--npm-dryRun',
66
- 'Execute a npm dry-run for inspection. Publishes to the local npm registry and does not publish to github',
67
- false
68
- )
69
- .action(release);
70
-
71
- let verdaccioChildProcess: ChildProcess | undefined = undefined;
72
-
73
- export async function release(
74
- component: Component,
75
- releaseType: ReleaseType,
76
- customVersion: string | undefined,
77
- cliOptions: ReleaseCmdOptions
78
- ): Promise<void> {
79
- try {
80
- configureLogger(cliOptions.verbose);
81
- LOGGER.debug('Cli options:', cliOptions);
82
- configureShell({ silent: !cliOptions.verbose });
83
- checkGHCli();
84
- const version = deriveVersion(releaseType, customVersion);
85
- const options: ReleaseOptions = { ...cliOptions, component, releaseType, version };
86
- if (cliOptions.npmDryRun && options.component.releaseRepo === 'npm') {
87
- await launchVerdaccio().catch(error => LOGGER.error('Error occurred during verdaccio launch', error));
88
- }
89
- switch (component.type) {
90
- case 'server-java':
91
- checkIfMavenVersionExists('org.eclipse.glsp', 'org.eclipse.glsp.server', asMvnVersion(version));
92
- return releaseJavaServer(options);
93
- case 'server-node':
94
- await checkIfNpmVersionIsNew('@eclipse-glsp/server-node', version);
95
- return releaseServerNode(options);
96
- case 'client':
97
- await checkIfNpmVersionIsNew('@eclipse-glsp/client', version);
98
- return releaseClient(options);
99
- case 'theia-integration':
100
- await checkIfNpmVersionIsNew('@eclipse-glsp/theia-integration', version);
101
- return releaseTheiaIntegration(options);
102
- case 'vscode-integration':
103
- await checkIfNpmVersionIsNew('@eclipse-glsp/vscode-integration', version);
104
- return releaseVscodeIntegration(options);
105
- case 'eclipse-integration':
106
- await checkIfNpmVersionIsNew('@eclipse-glsp/ide', version);
107
- return releaseEclipseIntegration(options);
108
- }
109
- } catch (err) {
110
- console.error('An error occurred during command execution:', err);
111
- exit(1);
112
- } finally {
113
- if (verdaccioChildProcess) {
114
- verdaccioChildProcess.kill();
115
- }
116
- }
117
- }
118
-
119
- function checkGHCli(): void {
120
- LOGGER.debug('Verify that Github CLI is configured correctly');
121
- if (!isGithubCLIAuthenticated()) {
122
- throw new Error("Github CLI is not configured properly. No user is logged in for host 'github.com'");
123
- }
124
- }
125
-
126
- function isGithubCLIAuthenticated(): boolean {
127
- LOGGER.debug('Verify that Github CLI is installed');
128
- fatalExec('which gh', 'Github CLI is not installed!');
129
-
130
- const status = sh.exec('gh auth status', getShellConfig());
131
- if (status.code !== 0) {
132
- if (status.stderr.includes('You are not logged into any GitHub hosts')) {
133
- return false;
134
- }
135
- throw new Error(status.stderr);
136
- }
137
- if (!status.stdout.trim().includes('Logged in to github.com')) {
138
- LOGGER.debug("No user is logged in for host 'github.com'");
139
- return false;
140
- }
141
- LOGGER.debug('Github CLI is authenticated and ready to use');
142
- return true;
143
- }
144
-
145
- function launchVerdaccio(): Promise<void> {
146
- LOGGER.debug('Verify that verdaccio is installed and start if necessary');
147
- fatalExec('which verdaccio', 'Verdaccio is not installed!');
148
- // Check if verdaccio is alreaddy running
149
- const result = sh.exec(`curl -i ${VERDACCIO_REGISTRY}`, getShellConfig());
150
- if (result.code !== 0) {
151
- LOGGER.info('Starting local verdaccio registry');
152
- verdaccioChildProcess = sh.exec('verdaccio', { async: true, silent: true });
153
- return new Promise(resolve => {
154
- createInterface(verdaccioChildProcess!.stdout!).on('line', line => {
155
- if (line.includes(`http address - ${VERDACCIO_REGISTRY}`)) {
156
- resolve();
157
- }
158
- });
159
- });
160
- }
161
- return Promise.resolve();
162
- }
163
-
164
- function deriveVersion(releaseType: ReleaseType, customVersion?: string): string {
165
- LOGGER.debug(`Derive version from release type: ${release}`);
166
- switch (releaseType) {
167
- case 'custom':
168
- return getCustomVersion(customVersion);
169
- case 'rc':
170
- return getRCVersion();
171
- case 'patch':
172
- case 'major':
173
- case 'minor':
174
- return semverInc(releaseType);
175
- }
176
- }
177
-
178
- const REFERENCE_NPM_PACKAGE = '@eclipse-glsp/ide';
179
-
180
- function getRCVersion(): string {
181
- LOGGER.debug('Retrieve and new RC version');
182
- const newBaseVersion = semverInc('minor');
183
- const currentRcVersion = sh.exec(`npm view ${REFERENCE_NPM_PACKAGE} dist-tags.rc`, getShellConfig()).stdout.trim();
184
- const currentRcBaseVersion = currentRcVersion.split('-')[0];
185
- if (currentRcBaseVersion !== newBaseVersion) {
186
- return `${newBaseVersion}-RC01`;
187
- }
188
- let rcNumber = Number.parseInt(currentRcVersion.replace(`${currentRcBaseVersion}-RC`, ''), 10);
189
- rcNumber++;
190
-
191
- return `${newBaseVersion}-RC` + `${rcNumber}`.padStart(2, '0');
192
- }
193
-
194
- function getCustomVersion(customVersion?: string): string {
195
- LOGGER.debug('Retrieve and validate custom version');
196
- LOGGER.debug(customVersion ? `Custom version has been passed as argument: ${customVersion}` : 'Prompt custom version from user');
197
- const version = customVersion ?? readline.question('> Please enter the new version');
198
- return validateVersion(version);
199
- }
200
-
201
- function getCurrentVersion(): string {
202
- LOGGER.debug('Retrieve base version by querying the latest tag of the reference npm package');
203
- const version = sh.exec(`npm view ${REFERENCE_NPM_PACKAGE} dist-tags.latest`, getShellConfig()).stdout.trim();
204
- return validateVersion(version);
205
- }
206
-
207
- function semverInc(releaseType: semver.ReleaseType, identifier?: string): string {
208
- const currentVersion = getCurrentVersion();
209
- LOGGER.debug(`Execute: semver.inc("${currentVersion}", ${releaseType}, ${identifier})`);
210
- const newVersion = semver.inc(currentVersion, releaseType, identifier);
211
- if (!newVersion) {
212
- throw new Error(`Could not increment version: ${currentVersion} `);
213
- }
214
- return newVersion;
215
- }
@@ -1,129 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2024 EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- import * as fs from 'fs';
18
- import { glob } from 'glob';
19
- import * as jq from 'node-jq';
20
- import * as path from 'path';
21
- import sh from 'shelljs';
22
- import { baseCommand, configureShell } from '../util/command-util';
23
- import { getUncommittedChanges } from '../util/git-util';
24
- import { LOGGER, configureLogger } from '../util/logger';
25
- import { validateGitDirectory } from '../util/validation-util';
26
-
27
- export const UpdateNextCommand = baseCommand()
28
- .name('updateNext')
29
- .alias('u')
30
- .description('Updates all `next` dependencies in GLSP project to the latest version')
31
- .argument('[rootDir]', 'The repository root', validateGitDirectory, process.cwd())
32
- .option('-v, --verbose', 'Enable verbose (debug) log output', false)
33
- .action(updateNext);
34
-
35
- export async function updateNext(rootDir: string, options: { verbose: boolean }): Promise<void> {
36
- configureLogger(options.verbose);
37
- configureShell({ silent: true, fatal: true });
38
-
39
- const rootPackage = path.join(rootDir, 'package.json');
40
- if (getUncommittedChanges(rootDir).includes(rootPackage)) {
41
- LOGGER.warn('Uncommitted changes in root `package.json`. Please commit or stash them before running this command.');
42
- return;
43
- }
44
-
45
- configureShell({ silent: false, fatal: true });
46
-
47
- LOGGER.info('Updating next dependencies ...');
48
- rootDir = path.resolve(rootDir);
49
- const packages = await getWorkspacePackages(rootDir);
50
- LOGGER.debug(`Scanning ${packages.length} packages to derive resolutions`, packages);
51
- const resolutions = await getResolutions(packages);
52
- if (Object.keys(resolutions).length === 0) {
53
- LOGGER.info('No next dependencies found');
54
- return;
55
- }
56
- LOGGER.info('Upgrade and rebuild packages ...');
57
- const packageJson = fs.readFileSync(path.join(rootDir, 'package.json'), 'utf-8');
58
- LOGGER.debug('Updating package.json with resolutions', resolutions);
59
- fs.writeFileSync(path.join(rootDir, 'package.json'), JSON.stringify({ ...JSON.parse(packageJson), resolutions }, undefined, 2));
60
- LOGGER.debug('Running yarn install');
61
- sh.exec('yarn install --ignore-scripts');
62
- LOGGER.debug('Reverting package.json');
63
- sh.exec('git checkout HEAD -- package.json');
64
- LOGGER.debug('Rebuild to update yarn.lock');
65
- sh.exec('yarn');
66
- LOGGER.info('Upgrade successfully completed');
67
- }
68
-
69
- async function getWorkspacePackages(rootDir: string): Promise<string[]> {
70
- const rootPackage = path.join(rootDir, 'package.json');
71
- const packages = [rootPackage];
72
- if (!fs.existsSync(rootPackage)) {
73
- LOGGER.error('No package.json found in root directory');
74
- process.exit(1);
75
- }
76
- const workspaces = await getWorkspaceConfig(rootPackage);
77
- if (workspaces) {
78
- workspaces
79
- .map(workspace => `${workspace}/**/package.json`)
80
- .forEach(pattern => {
81
- glob.sync(pattern, {
82
- cwd: rootDir,
83
- ignore: ['**/node_modules/**']
84
- }).forEach(packageJson => packages.push(path.join(rootDir, packageJson)));
85
- });
86
- }
87
-
88
- return [...new Set(packages)];
89
- }
90
-
91
- async function getResolutions(packages: string[]): Promise<Record<string, string>> {
92
- let dependencies: string[] = [];
93
- for (const pkg of packages) {
94
- const deps = await jq.run(
95
- '.dependencies //{} + .devDependencies + .peerDependencies | with_entries(select(.value == "next")) | keys',
96
- pkg,
97
- {
98
- output: 'json'
99
- }
100
- );
101
- if (Array.isArray(deps)) {
102
- dependencies.push(...deps);
103
- }
104
- }
105
- dependencies = [...new Set(dependencies)];
106
- LOGGER.debug(`Found ${dependencies.length} 'next' dependencies`, dependencies);
107
- LOGGER.info('Retrieve next versions ... ');
108
- const resolutions: Record<string, string> = {};
109
- [...new Set(dependencies)].forEach(dep => {
110
- LOGGER.info(`Retrieving next version for ${dep}`);
111
- const version = sh.exec(`npm view ${dep}@next version`, { silent: true }).stdout.trim();
112
- resolutions[`**/${dep}`] = version;
113
- });
114
- return resolutions;
115
- }
116
- async function getWorkspaceConfig(rootPackage: string): Promise<string[] | undefined> {
117
- const result = await jq.run('.workspaces', rootPackage, { output: 'json' });
118
- if (!result) {
119
- return undefined;
120
- }
121
- if (Array.isArray(result)) {
122
- return result;
123
- }
124
- if (typeof result === 'object' && 'packages' in result && Array.isArray(result.packages)) {
125
- return result.packages;
126
- }
127
-
128
- return undefined;
129
- }
@@ -1,54 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2022-2024 EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
- import { Command } from 'commander';
17
- import sh from 'shelljs';
18
-
19
- // Commander.js utils
20
- export function baseCommand(cmd = new Command()): Command {
21
- return cmd //
22
- .showSuggestionAfterError(true)
23
- .showHelpAfterError(true)
24
- .allowUnknownOption(false);
25
- }
26
-
27
- export type ShellConfig = sh.ExecOptions & { async: false };
28
- export const SH_CONFIG: ShellConfig = {
29
- async: false,
30
- fatal: true,
31
- silent: false
32
- };
33
-
34
- export function getShellConfig(options: Partial<Omit<ShellConfig, 'async'>> = {}): ShellConfig {
35
- return {
36
- ...SH_CONFIG,
37
- ...options
38
- };
39
- }
40
-
41
- export function configureShell(config: Partial<sh.ShellConfig>): void {
42
- sh.config.reset();
43
- getShellConfig({});
44
- SH_CONFIG.silent = config.silent;
45
- SH_CONFIG.fatal = config.fatal;
46
- }
47
-
48
- export function fatalExec(command: string, fatalErrorMessage: string, options: Partial<Omit<ShellConfig, 'async'>> = {}): sh.ShellString {
49
- const result = sh.exec(command, getShellConfig(options));
50
- if (result.code !== 0) {
51
- throw new Error(fatalErrorMessage);
52
- }
53
- return result;
54
- }
@@ -1,123 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2022-2024 EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- import { resolve } from 'path';
18
- import sh from 'shelljs';
19
- import { getShellConfig } from './command-util';
20
-
21
- export function isGitRepository(path?: string): boolean {
22
- cdIfPresent(path);
23
- const isGitRepo =
24
- sh
25
- .exec('git rev-parse --is-inside-work-tree', getShellConfig({ silent: true }))
26
- .stdout.trim()
27
- .toLocaleLowerCase() === 'true';
28
- return isGitRepo;
29
- }
30
-
31
- export function getGitRoot(path?: string): string {
32
- cdIfPresent(path);
33
- const fileString = sh.exec('git rev-parse --show-toplevel', getShellConfig()).stdout.trim();
34
- return resolve(fileString);
35
- }
36
-
37
- export function hasGitChanges(path?: string): boolean {
38
- return getUncommittedChanges(path).length > 0;
39
- }
40
-
41
- /**
42
- * Returns the files that have uncommitted changes (staged, not staged and untracked) of a git repository.
43
- * Filepaths are absolute.
44
- */
45
- export function getUncommittedChanges(path?: string): string[] {
46
- cdIfPresent(path);
47
- return sh
48
- .exec('git status --porcelain', getShellConfig())
49
- .stdout.trim()
50
- .split('\n')
51
- .filter(value => value.trim().length !== 0)
52
- .map(fileInfo =>
53
- // Extract relative file path from the info string and convert to absolute path
54
- resolve(path ?? process.cwd(), fileInfo.trim().split(' ').pop() ?? '')
55
- );
56
- }
57
-
58
- /**
59
- * Returns the files tha have been changed with the last commit (also includes currently staged but uncommitted changes)
60
- * Filepaths are absolute.
61
- */
62
- export function getChangesOfLastCommit(path?: string): string[] {
63
- cdIfPresent(path);
64
- return sh
65
- .exec('git diff --name-only HEAD^', getShellConfig())
66
- .stdout.trim()
67
- .split('\n')
68
- .map(file => resolve(path ?? process.cwd(), file));
69
- }
70
-
71
- /**
72
- * Returns the last modification date of a file (or the last commit) in a git repo.
73
- * @param filePath The file. If undefined the modification date of the last commit will be returned
74
- * @param repoRoot The path to the repo root. If undefined the current working directory is used.
75
- * @param excludeMessage Only consider commits that don`t match the excludeMessage
76
- * @returns The date or undefined if the file is outside of the git repo.
77
- */
78
- export function getLastModificationDate(filePath?: string, repoRoot?: string, excludeMessage?: string): Date | undefined {
79
- cdIfPresent(repoRoot);
80
- const additionalArgs = excludeMessage ? `--grep="${excludeMessage}" --invert-grep` : '';
81
- const result = sh.exec(`git log -1 ${additionalArgs} --pretty="format:%ci" ${filePath ?? ''}`, getShellConfig());
82
- if (result.code !== 0) {
83
- return undefined;
84
- }
85
- return new Date(result.stdout.trim());
86
- }
87
-
88
- export function getFilesOfCommit(commitHash: string, repoRoot?: string): string[] {
89
- cdIfPresent(repoRoot);
90
- const result = sh.exec(`git show --pretty="" --name-only ${commitHash}`, getShellConfig());
91
- if (result.code !== 0) {
92
- return [];
93
- }
94
-
95
- return result.stdout.trim().split('\n');
96
- }
97
-
98
- export function getLatestGithubRelease(path?: string): string {
99
- cdIfPresent(path);
100
- const release = sh.exec('gh release list --exclude-drafts -L 1', getShellConfig()).stdout.trim().split('\t');
101
- return release[release.length - 2];
102
- }
103
-
104
- export function getLatestTag(path?: string): string {
105
- cdIfPresent(path);
106
- return sh.exec('git describe --abbrev=0 --tags', getShellConfig()).stdout.trim();
107
- }
108
-
109
- export function hasBranch(branch: string, path?: string): boolean {
110
- cdIfPresent(path);
111
- return sh.exec(`git branch --list ${branch}`, getShellConfig()).stdout.trim().length !== 0;
112
- }
113
-
114
- export function getRemoteUrl(path?: string): string {
115
- cdIfPresent(path);
116
- return sh.exec('git config --get remote.origin.url', getShellConfig()).stdout.trim();
117
- }
118
-
119
- function cdIfPresent(path?: string): void {
120
- if (path) {
121
- sh.cd(path);
122
- }
123
- }
@@ -1,57 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2022-2023 EclipseSource and others.
3
- *
4
- * This program and the accompanying materials are made available under the
5
- * terms of the Eclipse Public License v. 2.0 which is available at
6
- * http://www.eclipse.org/legal/epl-2.0.
7
- *
8
- * This Source Code may also be made available under the following Secondary
9
- * Licenses when the conditions for such availability set forth in the Eclipse
10
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- * with the GNU Classpath Exception which is available at
12
- * https://www.gnu.org/software/classpath/license.html.
13
- *
14
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
- ********************************************************************************/
16
-
17
- export interface Logger extends Pick<Console, LogLevel> {
18
- newLine(): void;
19
- }
20
-
21
- export type LogLevel = 'info' | 'debug' | 'error' | 'warn';
22
-
23
- const levels: Record<LogLevel, { threshold: number; color: string }> = {
24
- error: { threshold: 0, color: '\x1b[31m' }, // red
25
- warn: { threshold: 1, color: '\x1b[33m' }, // yellow
26
- info: { threshold: 2, color: '\x1b[0m' }, // default terminal color
27
- debug: { threshold: 3, color: '\x1b[32m' } // green
28
- };
29
-
30
- let levelThreshold: number = levels.info.threshold;
31
-
32
- export const LOGGER: Logger = {
33
- info: (...args) => log('info', ...args),
34
- error: (...args) => log('error', ...args),
35
- warn: (...args) => log('warn', ...args),
36
- debug: (...args) => log('debug', ...args),
37
- newLine: () => console.log('')
38
- } as const;
39
-
40
- function log(level: LogLevel, ...args: any[]): void {
41
- const levelData = levels[level];
42
- if (levelThreshold < levelData.threshold) {
43
- return;
44
- }
45
- console[level](levelData.color, ...args, '\x1b[0m');
46
- }
47
-
48
- export function configureLogger(level: LogLevel): void;
49
- export function configureLogger(verbose: boolean): void;
50
- export function configureLogger(levelOrVerbose: LogLevel | boolean): void {
51
- if (typeof levelOrVerbose === 'boolean') {
52
- const level: LogLevel = levelOrVerbose ? 'debug' : 'info';
53
- levelThreshold = levels[level].threshold;
54
- } else {
55
- levelThreshold = levels[levelOrVerbose].threshold;
56
- }
57
- }