@eclipse-glsp/cli 1.1.0-next.4c65907.114

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 (69) hide show
  1. package/LICENSE +642 -0
  2. package/README.md +45 -0
  3. package/bin/glsp +2 -0
  4. package/lib/app.d.ts +19 -0
  5. package/lib/app.d.ts.map +1 -0
  6. package/lib/app.js +46 -0
  7. package/lib/app.js.map +1 -0
  8. package/lib/release/common.d.ts +69 -0
  9. package/lib/release/common.d.ts.map +1 -0
  10. package/lib/release/common.js +273 -0
  11. package/lib/release/common.js.map +1 -0
  12. package/lib/release/release-client.d.ts +3 -0
  13. package/lib/release/release-client.d.ts.map +1 -0
  14. package/lib/release/release-client.js +53 -0
  15. package/lib/release/release-client.js.map +1 -0
  16. package/lib/release/release-eclipse-integration.d.ts +18 -0
  17. package/lib/release/release-eclipse-integration.d.ts.map +1 -0
  18. package/lib/release/release-eclipse-integration.js +90 -0
  19. package/lib/release/release-eclipse-integration.js.map +1 -0
  20. package/lib/release/release-java-server.d.ts +3 -0
  21. package/lib/release/release-java-server.d.ts.map +1 -0
  22. package/lib/release/release-java-server.js +67 -0
  23. package/lib/release/release-java-server.js.map +1 -0
  24. package/lib/release/release-server-node.d.ts +18 -0
  25. package/lib/release/release-server-node.d.ts.map +1 -0
  26. package/lib/release/release-server-node.js +51 -0
  27. package/lib/release/release-server-node.js.map +1 -0
  28. package/lib/release/release-theia-integration.d.ts +18 -0
  29. package/lib/release/release-theia-integration.d.ts.map +1 -0
  30. package/lib/release/release-theia-integration.js +62 -0
  31. package/lib/release/release-theia-integration.js.map +1 -0
  32. package/lib/release/release-vscode-integration.d.ts +18 -0
  33. package/lib/release/release-vscode-integration.d.ts.map +1 -0
  34. package/lib/release/release-vscode-integration.js +51 -0
  35. package/lib/release/release-vscode-integration.js.map +1 -0
  36. package/lib/release/release.d.ts +13 -0
  37. package/lib/release/release.d.ts.map +1 -0
  38. package/lib/release/release.js +133 -0
  39. package/lib/release/release.js.map +1 -0
  40. package/lib/util/command-util.d.ts +31 -0
  41. package/lib/util/command-util.d.ts.map +1 -0
  42. package/lib/util/command-util.js +38 -0
  43. package/lib/util/command-util.js.map +1 -0
  44. package/lib/util/git-util.d.ts +23 -0
  45. package/lib/util/git-util.d.ts.map +1 -0
  46. package/lib/util/git-util.js +87 -0
  47. package/lib/util/git-util.js.map +1 -0
  48. package/lib/util/logger.d.ts +9 -0
  49. package/lib/util/logger.d.ts.map +1 -0
  50. package/lib/util/logger.js +34 -0
  51. package/lib/util/logger.js.map +1 -0
  52. package/lib/util/validation-util.d.ts +5 -0
  53. package/lib/util/validation-util.d.ts.map +1 -0
  54. package/lib/util/validation-util.js +53 -0
  55. package/lib/util/validation-util.js.map +1 -0
  56. package/package.json +65 -0
  57. package/src/app.ts +49 -0
  58. package/src/release/common.ts +312 -0
  59. package/src/release/release-client.ts +64 -0
  60. package/src/release/release-eclipse-integration.ts +113 -0
  61. package/src/release/release-java-server.ts +72 -0
  62. package/src/release/release-server-node.ts +61 -0
  63. package/src/release/release-theia-integration.ts +77 -0
  64. package/src/release/release-vscode-integration.ts +65 -0
  65. package/src/release/release.ts +174 -0
  66. package/src/util/command-util.ts +63 -0
  67. package/src/util/git-util.ts +87 -0
  68. package/src/util/logger.ts +38 -0
  69. package/src/util/validation-util.ts +50 -0
@@ -0,0 +1,77 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 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 sh from 'shelljs';
18
+ import { LOGGER } from '../util/logger';
19
+ import {
20
+ asMvnVersion,
21
+ checkoutAndCd,
22
+ commitAndTag,
23
+ isExistingMavenVersion,
24
+ lernaSetVersion,
25
+ publish,
26
+ ReleaseOptions,
27
+ updateLernaForDryRun,
28
+ updateServerConfig,
29
+ updateVersion,
30
+ yarnInstall
31
+ } from './common';
32
+
33
+ let REPO_ROOT: string;
34
+
35
+ export async function releaseTheiaIntegration(options: ReleaseOptions): Promise<void> {
36
+ LOGGER.info('Prepare glsp-theia-integration release');
37
+ LOGGER.debug('Release options: ', options);
38
+ REPO_ROOT = checkoutAndCd(options);
39
+ updateExternalGLSPDependencies(options.version);
40
+ await updateDownloadServerScript(options.version);
41
+ generateChangeLog();
42
+ lernaSetVersion(REPO_ROOT, options.version);
43
+ build();
44
+ if (options.npmDryRun) {
45
+ updateLernaForDryRun();
46
+ }
47
+ commitAndTag(options.version, REPO_ROOT);
48
+ publish(REPO_ROOT, options);
49
+ }
50
+
51
+ function updateExternalGLSPDependencies(version: string): void {
52
+ LOGGER.info('Update external GLSP dependencies (Client and workflow example)');
53
+ sh.cd(REPO_ROOT);
54
+ updateVersion({ name: '@eclipse-glsp/client', version }, { name: '@eclipse-glsp-examples/workflow-glsp', version });
55
+ }
56
+
57
+ async function updateDownloadServerScript(version: string): Promise<void> {
58
+ LOGGER.info('Update example server download config');
59
+ const mvnVersion = asMvnVersion(version);
60
+ if (!isExistingMavenVersion('org.eclipse.glsp', 'org.eclipse.glsp.server', mvnVersion)) {
61
+ LOGGER.warn(`No Java GLSP server with version ${mvnVersion} found on maven central!. Please release a new Java GLSP Server version
62
+ before publishing this release!`);
63
+ }
64
+
65
+ sh.cd(`${REPO_ROOT}/examples/workflow-theia/src/node`);
66
+ updateServerConfig('server-config.json', mvnVersion, false);
67
+ }
68
+
69
+ function build(): void {
70
+ LOGGER.info('Install & Build with yarn');
71
+ yarnInstall(REPO_ROOT);
72
+ LOGGER.debug('Build successful');
73
+ }
74
+
75
+ function generateChangeLog(): void {
76
+ // do nothing for now
77
+ }
@@ -0,0 +1,65 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 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 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';
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
+ );
55
+ }
56
+
57
+ function build(): void {
58
+ LOGGER.info('Install & Build with yarn');
59
+ yarnInstall(REPO_ROOT);
60
+ LOGGER.debug('Build successful');
61
+ }
62
+
63
+ function generateChangeLog(): void {
64
+ // do nothing for now
65
+ }
@@ -0,0 +1,174 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 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 { exit } from 'process';
18
+ import { createInterface } from 'readline';
19
+ import * as readline from 'readline-sync';
20
+ import * as semver from 'semver';
21
+ import * as sh from 'shelljs';
22
+ import { BaseCmdOptions, fatalExec, getShellConfig, initialConfiguration } from '../util/command-util';
23
+ import { isGithubCLIAuthenticated } from '../util/git-util';
24
+ import { LOGGER } from '../util/logger';
25
+ import { validateVersion } from '../util/validation-util';
26
+ import {
27
+ asMvnVersion,
28
+ checkIfMavenVersionExists,
29
+ checkIfNpmVersionExists,
30
+ Component,
31
+ ReleaseOptions,
32
+ ReleaseType,
33
+ VERDACCIO_REGISTRY
34
+ } from './common';
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
+ interface ReleaseCmdOptions extends BaseCmdOptions {
42
+ checkoutDir: string;
43
+ branch: string;
44
+ force: boolean;
45
+ publish: boolean;
46
+ npmDryRun: boolean;
47
+ draft: boolean;
48
+ }
49
+
50
+ let verdaccioChildProcess: ChildProcess | undefined = undefined;
51
+
52
+ export async function release(
53
+ component: Component,
54
+ releaseType: ReleaseType,
55
+ customVersion: string | undefined,
56
+ cliOptions: ReleaseCmdOptions
57
+ ): Promise<void> {
58
+ try {
59
+ LOGGER.debug('Cli options:', cliOptions);
60
+ initialConfiguration(cliOptions.verbose);
61
+ checkGHCli();
62
+ const version = deriveVersion(releaseType, customVersion);
63
+ const options: ReleaseOptions = { ...cliOptions, component, releaseType, version };
64
+ if (cliOptions.npmDryRun && options.component.releaseRepo === 'npm') {
65
+ await launchVerdaccio().catch(error => LOGGER.error('Error occurred during verdaccio launch', error));
66
+ }
67
+ switch (component.type) {
68
+ case 'server-java':
69
+ checkIfMavenVersionExists('org.eclipse.glsp', 'org.eclipse.glsp.server', asMvnVersion(version));
70
+ return releaseJavaServer(options);
71
+ case 'server-node':
72
+ await checkIfNpmVersionExists('@eclipse-glsp/server-node', version);
73
+ return releaseServerNode(options);
74
+ case 'client':
75
+ await checkIfNpmVersionExists('@eclipse-glsp/client', version);
76
+ return releaseClient(options);
77
+ case 'theia-integration':
78
+ await checkIfNpmVersionExists('@eclipse-glsp/theia-integration', version);
79
+ return releaseTheiaIntegration(options);
80
+ case 'vscode-integration':
81
+ await checkIfNpmVersionExists('@eclipse-glsp/vscode-integration', version);
82
+ return releaseVscodeIntegration(options);
83
+ case 'eclipse-integration':
84
+ await checkIfNpmVersionExists('@eclipse-glsp/ide', version);
85
+ return releaseEclipseIntegration(options);
86
+ }
87
+ } catch (err) {
88
+ console.error('An error occurred during command execution:', err);
89
+ exit(1);
90
+ } finally {
91
+ if (verdaccioChildProcess) {
92
+ verdaccioChildProcess.kill();
93
+ }
94
+ }
95
+ }
96
+
97
+ function checkGHCli(): void {
98
+ LOGGER.debug('Verify that Github CLI is configured correctly');
99
+ if (!isGithubCLIAuthenticated()) {
100
+ throw new Error("Github CLI is not configured properly. No user is logged in for host 'github.com'");
101
+ }
102
+ }
103
+
104
+ function launchVerdaccio(): Promise<void> {
105
+ LOGGER.debug('Verify that verdaccio is installed and start if necessary');
106
+ fatalExec('which verdaccio', 'Verdaccio is not installed!');
107
+ // Check if verdaccio is alreaddy running
108
+ const result = sh.exec(`curl -i ${VERDACCIO_REGISTRY}`, getShellConfig());
109
+ if (result.code !== 0) {
110
+ LOGGER.info('Starting local verdaccio registry');
111
+ verdaccioChildProcess = sh.exec('verdaccio', { async: true, silent: true });
112
+ return new Promise(resolve => {
113
+ createInterface(verdaccioChildProcess!.stdout!).on('line', line => {
114
+ if (line.includes(`http address - ${VERDACCIO_REGISTRY}`)) {
115
+ resolve();
116
+ }
117
+ });
118
+ });
119
+ }
120
+ return Promise.resolve();
121
+ }
122
+
123
+ function deriveVersion(release: ReleaseType, customVersion?: string): string {
124
+ LOGGER.debug(`Derive version from release type: ${release}`);
125
+ switch (release) {
126
+ case 'custom':
127
+ return getCustomVersion(customVersion);
128
+ case 'rc':
129
+ return getRCVersion();
130
+ case 'patch':
131
+ case 'major':
132
+ case 'minor':
133
+ return semverInc(release);
134
+ }
135
+ }
136
+
137
+ const REFERENCE_NPM_PACKAGE = '@eclipse-glsp/ide';
138
+
139
+ function getRCVersion(): string {
140
+ LOGGER.debug('Retrieve and new RC version');
141
+ const newBaseVersion = semverInc('minor');
142
+ const currentRcVersion = sh.exec(`npm view ${REFERENCE_NPM_PACKAGE} dist-tags.rc`, getShellConfig()).stdout.trim();
143
+ const currentRcBaseVersion = currentRcVersion.split('-')[0];
144
+ if (currentRcBaseVersion !== newBaseVersion) {
145
+ return `${newBaseVersion}-RC01`;
146
+ }
147
+ let rcNumber = Number.parseInt(currentRcVersion.replace(`${currentRcBaseVersion}-RC`, ''), 10);
148
+ rcNumber++;
149
+
150
+ return `${newBaseVersion}-RC` + `${rcNumber}`.padStart(2, '0');
151
+ }
152
+
153
+ function getCustomVersion(customVersion?: string): string {
154
+ LOGGER.debug('Retrieve and validate custom version');
155
+ LOGGER.debug(customVersion ? `Custom version has been passed as argument: ${customVersion}` : 'Prompt custom version from user');
156
+ const version = customVersion ?? readline.question('> Please enter the new version');
157
+ return validateVersion(version);
158
+ }
159
+
160
+ function getCurrentVersion(): string {
161
+ LOGGER.debug('Retrieve base version by querying the latest tag of the reference npm package');
162
+ const version = sh.exec(`npm view ${REFERENCE_NPM_PACKAGE} dist-tags.latest`, getShellConfig()).stdout.trim();
163
+ return validateVersion(version);
164
+ }
165
+
166
+ function semverInc(releaseType: semver.ReleaseType, identifier?: string): string {
167
+ const currentVersion = getCurrentVersion();
168
+ LOGGER.debug(`Execute: semver.inc("${currentVersion}", ${releaseType}, ${identifier})`);
169
+ const newVersion = semver.inc(currentVersion, releaseType, identifier);
170
+ if (!newVersion) {
171
+ throw new Error(`Could not increment version: ${currentVersion} `);
172
+ }
173
+ return newVersion;
174
+ }
@@ -0,0 +1,63 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 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 * as sh from 'shelljs';
18
+ import { configureLogger } from './logger';
19
+ export const COMMAND_VERSION = '1.1.0-next';
20
+
21
+ export function baseConfiguration(cmd: Command): Command {
22
+ return cmd
23
+ .version(COMMAND_VERSION) //
24
+ .showSuggestionAfterError(true)
25
+ .showHelpAfterError(true)
26
+ .allowUnknownOption(false);
27
+ }
28
+
29
+ export interface BaseCmdOptions {
30
+ verbose: boolean;
31
+ }
32
+
33
+ export const SH_CONFIG: sh.ExecOptions & { async: false } = {
34
+ async: false,
35
+ fatal: true,
36
+ silent: false
37
+ };
38
+
39
+ export function getShellConfig(options: Partial<Omit<sh.ExecOptions, 'async'>> = {}): sh.ExecOptions & { async: false } {
40
+ return {
41
+ ...SH_CONFIG,
42
+ ...options
43
+ };
44
+ }
45
+
46
+ export function initialConfiguration(verbose: boolean): void {
47
+ sh.config.reset();
48
+
49
+ SH_CONFIG.silent = !verbose;
50
+ configureLogger(verbose);
51
+ }
52
+
53
+ export function fatalExec(
54
+ command: string,
55
+ fatalErrorMessage: string,
56
+ options: Partial<Omit<sh.ExecOptions, 'async'>> = {}
57
+ ): sh.ShellString {
58
+ const result = sh.exec(command, getShellConfig(options));
59
+ if (result.code !== 0) {
60
+ throw new Error(fatalErrorMessage);
61
+ }
62
+ return result;
63
+ }
@@ -0,0 +1,87 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 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 sh from 'shelljs';
18
+ import { fatalExec, getShellConfig } from './command-util';
19
+ import { LOGGER } from './logger';
20
+ import { validateGitDirectory } from './validation-util';
21
+
22
+ export function isGithubCLIAuthenticated(): boolean {
23
+ LOGGER.debug('Verify that Github CLI is installed');
24
+ fatalExec('which gh', 'Github CLI is not installed!');
25
+
26
+ const status = sh.exec('gh auth status', getShellConfig());
27
+ if (status.code !== 0) {
28
+ if (status.stderr.includes('You are not logged into any GitHub hosts')) {
29
+ return false;
30
+ }
31
+ throw new Error(status.stderr);
32
+ }
33
+ if (!status.stderr.trim().includes('Logged in to github.com')) {
34
+ LOGGER.debug("No user is logged in for host 'github.com'");
35
+ return false;
36
+ }
37
+ LOGGER.debug('Github CLI is authenticated and ready to use');
38
+ return true;
39
+ }
40
+
41
+ export function isGitRepository(path: string): boolean {
42
+ LOGGER.debug(`Check if the given directory is a git repo: ${path}`);
43
+ sh.cd(path);
44
+ return sh.exec('git rev-parse --is-inside-work-tree', getShellConfig()).stdout.trim().toLocaleLowerCase() === 'true';
45
+ }
46
+
47
+ export function hasGitChanges(path?: string): boolean {
48
+ LOGGER.debug(`Check if the directory has git changes: ${asDebugArg(path)}`);
49
+ cdIfPresent(path);
50
+ return sh.exec('git status --porcelain').stdout.trim().length !== 0;
51
+ }
52
+
53
+ export function getLatestRelease(path?: string): string {
54
+ LOGGER.debug(`Retrieve latest release from repo: ${asDebugArg(path)}`);
55
+ cdIfPresent(path);
56
+ const release = sh.exec('gh release list --exclude-drafts -L 1', getShellConfig()).stdout.trim().split('\t');
57
+ return release[release.length - 2];
58
+ }
59
+
60
+ export function getLatestTag(path?: string): string {
61
+ LOGGER.debug(`Retrieve latest tag from local repo : ${asDebugArg(path)}`);
62
+ cdIfPresent(path);
63
+ return sh.exec('git describe --abbrev=0 --tags', getShellConfig()).stdout.trim();
64
+ }
65
+
66
+ export function hasBranch(branch: string, path?: string): boolean {
67
+ LOGGER.debug(`Check if branch exists: ${asDebugArg(path)}`);
68
+ cdIfPresent(path);
69
+ return sh.exec(`git branch --list ${branch}`, getShellConfig()).stdout.trim().length !== 0;
70
+ }
71
+
72
+ export function getRemoteUrl(path?: string): string {
73
+ LOGGER.debug(`Retrieve remote git url for: ${asDebugArg(path)}`);
74
+ cdIfPresent(path);
75
+ return sh.exec('git config --get remote.origin.url', getShellConfig()).stdout.trim();
76
+ }
77
+
78
+ function cdIfPresent(path?: string): void {
79
+ if (path) {
80
+ validateGitDirectory(path);
81
+ sh.cd(path);
82
+ }
83
+ }
84
+
85
+ function asDebugArg(path?: string): string {
86
+ return path ?? sh.pwd().stdout;
87
+ }
@@ -0,0 +1,38 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 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
+ let verbose = false;
17
+
18
+ export const LOGGER: Logger = {
19
+ info: (message, ...args) => console.info(`[INFO] ${message}`, ...args),
20
+ error: (message, ...args) => console.error(`[ERROR] ${message}`, ...args),
21
+ warn: (message, ...args) => console.warn(`[WARNING] ${message}`, ...args),
22
+ debug: (message, ...args) => {
23
+ if (verbose) {
24
+ console.log(`[DEBUG] ${message}`, ...args);
25
+ }
26
+ }
27
+ };
28
+
29
+ export function configureLogger(isVerbose: boolean): void {
30
+ verbose = isVerbose;
31
+ }
32
+
33
+ export interface Logger {
34
+ info(message: string, ...args: any[]): void;
35
+ error(message: string, ...args: any[]): void;
36
+ warn(message: string, ...args: any[]): void;
37
+ debug(message: string, ...args: any[]): void;
38
+ }
@@ -0,0 +1,50 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 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 { InvalidArgumentError } from 'commander';
17
+ import * as fs from 'fs';
18
+ import { resolve } from 'path';
19
+ import * as semver from 'semver';
20
+ import { isGitRepository } from './git-util';
21
+ import { LOGGER } from './logger';
22
+ export const COMMAND_VERSION = '1.1.0-next';
23
+
24
+ export function validateDirectory(rootDir: string): string {
25
+ const path = resolve(rootDir);
26
+ if (!fs.existsSync(path)) {
27
+ throw new InvalidArgumentError('Not a valid file path!');
28
+ }
29
+
30
+ if (!fs.statSync(path).isDirectory()) {
31
+ throw new InvalidArgumentError('Not a directory!');
32
+ }
33
+ return path;
34
+ }
35
+
36
+ export function validateVersion(version: string): string {
37
+ LOGGER.debug(`Validate version format of: ${version}`);
38
+ if (!semver.valid(version)) {
39
+ throw new Error(`Not a valid version: ${version}`);
40
+ }
41
+ return version;
42
+ }
43
+
44
+ export function validateGitDirectory(repository: string): string {
45
+ const repoPath = validateDirectory(repository);
46
+ if (!isGitRepository(repoPath)) {
47
+ throw new Error('Not a valid git repository');
48
+ }
49
+ return repoPath;
50
+ }