@eclipse-glsp/cli 2.6.0-next.183 → 2.6.0-next.4
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/README.md +143 -38
- package/dist/cli.js +22240 -0
- package/dist/cli.js.map +6 -0
- package/package.json +22 -29
- package/bin/glsp +0 -2
- package/lib/app.d.ts +0 -3
- package/lib/app.d.ts.map +0 -1
- package/lib/app.js +0 -36
- package/lib/app.js.map +0 -1
- package/lib/commands/check-header.d.ts +0 -21
- package/lib/commands/check-header.d.ts.map +0 -1
- package/lib/commands/check-header.js +0 -250
- package/lib/commands/check-header.js.map +0 -1
- package/lib/commands/coverage-report.d.ts +0 -29
- package/lib/commands/coverage-report.d.ts.map +0 -1
- package/lib/commands/coverage-report.js +0 -136
- package/lib/commands/coverage-report.js.map +0 -1
- package/lib/commands/generate-index.d.ts +0 -46
- package/lib/commands/generate-index.d.ts.map +0 -1
- package/lib/commands/generate-index.js +0 -182
- package/lib/commands/generate-index.js.map +0 -1
- package/lib/commands/release/common.d.ts +0 -68
- package/lib/commands/release/common.d.ts.map +0 -1
- package/lib/commands/release/common.js +0 -303
- package/lib/commands/release/common.js.map +0 -1
- package/lib/commands/release/release-client.d.ts +0 -3
- package/lib/commands/release/release-client.d.ts.map +0 -1
- package/lib/commands/release/release-client.js +0 -57
- package/lib/commands/release/release-client.js.map +0 -1
- package/lib/commands/release/release-eclipse-integration.d.ts +0 -18
- package/lib/commands/release/release-eclipse-integration.d.ts.map +0 -1
- package/lib/commands/release/release-eclipse-integration.js +0 -92
- package/lib/commands/release/release-eclipse-integration.js.map +0 -1
- package/lib/commands/release/release-java-server.d.ts +0 -3
- package/lib/commands/release/release-java-server.d.ts.map +0 -1
- package/lib/commands/release/release-java-server.js +0 -70
- package/lib/commands/release/release-java-server.js.map +0 -1
- package/lib/commands/release/release-server-node.d.ts +0 -18
- package/lib/commands/release/release-server-node.d.ts.map +0 -1
- package/lib/commands/release/release-server-node.js +0 -53
- package/lib/commands/release/release-server-node.js.map +0 -1
- package/lib/commands/release/release-theia-integration.d.ts +0 -18
- package/lib/commands/release/release-theia-integration.d.ts.map +0 -1
- package/lib/commands/release/release-theia-integration.js +0 -53
- package/lib/commands/release/release-theia-integration.js.map +0 -1
- package/lib/commands/release/release-vscode-integration.d.ts +0 -18
- package/lib/commands/release/release-vscode-integration.d.ts.map +0 -1
- package/lib/commands/release/release-vscode-integration.js +0 -53
- package/lib/commands/release/release-vscode-integration.js.map +0 -1
- package/lib/commands/release/release.d.ts +0 -14
- package/lib/commands/release/release.d.ts.map +0 -1
- package/lib/commands/release/release.js +0 -201
- package/lib/commands/release/release.js.map +0 -1
- package/lib/commands/update-next.d.ts +0 -20
- package/lib/commands/update-next.d.ts.map +0 -1
- package/lib/commands/update-next.js +0 -156
- package/lib/commands/update-next.js.map +0 -1
- package/lib/util/command-util.d.ts +0 -26
- package/lib/util/command-util.d.ts.map +0 -1
- package/lib/util/command-util.js +0 -59
- package/lib/util/command-util.js.map +0 -1
- package/lib/util/git-util.d.ts +0 -42
- package/lib/util/git-util.d.ts.map +0 -1
- package/lib/util/git-util.js +0 -124
- package/lib/util/git-util.js.map +0 -1
- package/lib/util/logger.d.ts +0 -23
- package/lib/util/logger.d.ts.map +0 -1
- package/lib/util/logger.js +0 -50
- package/lib/util/logger.js.map +0 -1
- package/lib/util/validation-util.d.ts +0 -5
- package/lib/util/validation-util.d.ts.map +0 -1
- package/lib/util/validation-util.js +0 -95
- package/lib/util/validation-util.js.map +0 -1
- package/src/app.ts +0 -35
- package/src/commands/check-header.ts +0 -280
- package/src/commands/coverage-report.ts +0 -113
- package/src/commands/generate-index.ts +0 -169
- package/src/commands/release/common.ts +0 -306
- package/src/commands/release/release-client.ts +0 -55
- package/src/commands/release/release-eclipse-integration.ts +0 -113
- package/src/commands/release/release-java-server.ts +0 -73
- package/src/commands/release/release-server-node.ts +0 -61
- package/src/commands/release/release-theia-integration.ts +0 -65
- package/src/commands/release/release-vscode-integration.ts +0 -67
- package/src/commands/release/release.ts +0 -215
- package/src/commands/update-next.ts +0 -129
- package/src/util/command-util.ts +0 -54
- package/src/util/git-util.ts +0 -123
- package/src/util/logger.ts +0 -57
- package/src/util/validation-util.ts +0 -62
package/lib/util/git-util.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/********************************************************************************
|
|
3
|
-
* Copyright (c) 2022-2024 EclipseSource and others.
|
|
4
|
-
*
|
|
5
|
-
* This program and the accompanying materials are made available under the
|
|
6
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
*
|
|
9
|
-
* This Source Code may also be made available under the following Secondary
|
|
10
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
* with the GNU Classpath Exception which is available at
|
|
13
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
*
|
|
15
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
-
********************************************************************************/
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.isGitRepository = isGitRepository;
|
|
22
|
-
exports.getGitRoot = getGitRoot;
|
|
23
|
-
exports.hasGitChanges = hasGitChanges;
|
|
24
|
-
exports.getUncommittedChanges = getUncommittedChanges;
|
|
25
|
-
exports.getChangesOfLastCommit = getChangesOfLastCommit;
|
|
26
|
-
exports.getLastModificationDate = getLastModificationDate;
|
|
27
|
-
exports.getFilesOfCommit = getFilesOfCommit;
|
|
28
|
-
exports.getLatestGithubRelease = getLatestGithubRelease;
|
|
29
|
-
exports.getLatestTag = getLatestTag;
|
|
30
|
-
exports.hasBranch = hasBranch;
|
|
31
|
-
exports.getRemoteUrl = getRemoteUrl;
|
|
32
|
-
const path_1 = require("path");
|
|
33
|
-
const shelljs_1 = __importDefault(require("shelljs"));
|
|
34
|
-
const command_util_1 = require("./command-util");
|
|
35
|
-
function isGitRepository(path) {
|
|
36
|
-
cdIfPresent(path);
|
|
37
|
-
const isGitRepo = shelljs_1.default
|
|
38
|
-
.exec('git rev-parse --is-inside-work-tree', (0, command_util_1.getShellConfig)({ silent: true }))
|
|
39
|
-
.stdout.trim()
|
|
40
|
-
.toLocaleLowerCase() === 'true';
|
|
41
|
-
return isGitRepo;
|
|
42
|
-
}
|
|
43
|
-
function getGitRoot(path) {
|
|
44
|
-
cdIfPresent(path);
|
|
45
|
-
const fileString = shelljs_1.default.exec('git rev-parse --show-toplevel', (0, command_util_1.getShellConfig)()).stdout.trim();
|
|
46
|
-
return (0, path_1.resolve)(fileString);
|
|
47
|
-
}
|
|
48
|
-
function hasGitChanges(path) {
|
|
49
|
-
return getUncommittedChanges(path).length > 0;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns the files that have uncommitted changes (staged, not staged and untracked) of a git repository.
|
|
53
|
-
* Filepaths are absolute.
|
|
54
|
-
*/
|
|
55
|
-
function getUncommittedChanges(path) {
|
|
56
|
-
cdIfPresent(path);
|
|
57
|
-
return shelljs_1.default
|
|
58
|
-
.exec('git status --porcelain', (0, command_util_1.getShellConfig)())
|
|
59
|
-
.stdout.trim()
|
|
60
|
-
.split('\n')
|
|
61
|
-
.filter(value => value.trim().length !== 0)
|
|
62
|
-
.map(fileInfo => { var _a;
|
|
63
|
-
// Extract relative file path from the info string and convert to absolute path
|
|
64
|
-
return (0, path_1.resolve)(path !== null && path !== void 0 ? path : process.cwd(), (_a = fileInfo.trim().split(' ').pop()) !== null && _a !== void 0 ? _a : ''); });
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Returns the files tha have been changed with the last commit (also includes currently staged but uncommitted changes)
|
|
68
|
-
* Filepaths are absolute.
|
|
69
|
-
*/
|
|
70
|
-
function getChangesOfLastCommit(path) {
|
|
71
|
-
cdIfPresent(path);
|
|
72
|
-
return shelljs_1.default
|
|
73
|
-
.exec('git diff --name-only HEAD^', (0, command_util_1.getShellConfig)())
|
|
74
|
-
.stdout.trim()
|
|
75
|
-
.split('\n')
|
|
76
|
-
.map(file => (0, path_1.resolve)(path !== null && path !== void 0 ? path : process.cwd(), file));
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Returns the last modification date of a file (or the last commit) in a git repo.
|
|
80
|
-
* @param filePath The file. If undefined the modification date of the last commit will be returned
|
|
81
|
-
* @param repoRoot The path to the repo root. If undefined the current working directory is used.
|
|
82
|
-
* @param excludeMessage Only consider commits that don`t match the excludeMessage
|
|
83
|
-
* @returns The date or undefined if the file is outside of the git repo.
|
|
84
|
-
*/
|
|
85
|
-
function getLastModificationDate(filePath, repoRoot, excludeMessage) {
|
|
86
|
-
cdIfPresent(repoRoot);
|
|
87
|
-
const additionalArgs = excludeMessage ? `--grep="${excludeMessage}" --invert-grep` : '';
|
|
88
|
-
const result = shelljs_1.default.exec(`git log -1 ${additionalArgs} --pretty="format:%ci" ${filePath !== null && filePath !== void 0 ? filePath : ''}`, (0, command_util_1.getShellConfig)());
|
|
89
|
-
if (result.code !== 0) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
return new Date(result.stdout.trim());
|
|
93
|
-
}
|
|
94
|
-
function getFilesOfCommit(commitHash, repoRoot) {
|
|
95
|
-
cdIfPresent(repoRoot);
|
|
96
|
-
const result = shelljs_1.default.exec(`git show --pretty="" --name-only ${commitHash}`, (0, command_util_1.getShellConfig)());
|
|
97
|
-
if (result.code !== 0) {
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
return result.stdout.trim().split('\n');
|
|
101
|
-
}
|
|
102
|
-
function getLatestGithubRelease(path) {
|
|
103
|
-
cdIfPresent(path);
|
|
104
|
-
const release = shelljs_1.default.exec('gh release list --exclude-drafts -L 1', (0, command_util_1.getShellConfig)()).stdout.trim().split('\t');
|
|
105
|
-
return release[release.length - 2];
|
|
106
|
-
}
|
|
107
|
-
function getLatestTag(path) {
|
|
108
|
-
cdIfPresent(path);
|
|
109
|
-
return shelljs_1.default.exec('git describe --abbrev=0 --tags', (0, command_util_1.getShellConfig)()).stdout.trim();
|
|
110
|
-
}
|
|
111
|
-
function hasBranch(branch, path) {
|
|
112
|
-
cdIfPresent(path);
|
|
113
|
-
return shelljs_1.default.exec(`git branch --list ${branch}`, (0, command_util_1.getShellConfig)()).stdout.trim().length !== 0;
|
|
114
|
-
}
|
|
115
|
-
function getRemoteUrl(path) {
|
|
116
|
-
cdIfPresent(path);
|
|
117
|
-
return shelljs_1.default.exec('git config --get remote.origin.url', (0, command_util_1.getShellConfig)()).stdout.trim();
|
|
118
|
-
}
|
|
119
|
-
function cdIfPresent(path) {
|
|
120
|
-
if (path) {
|
|
121
|
-
shelljs_1.default.cd(path);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=git-util.js.map
|
package/lib/util/git-util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"git-util.js","sourceRoot":"","sources":["../../src/util/git-util.ts"],"names":[],"mappings":"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"}
|
package/lib/util/logger.d.ts
DELETED
|
@@ -1,23 +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
|
-
export interface Logger extends Pick<Console, LogLevel> {
|
|
17
|
-
newLine(): void;
|
|
18
|
-
}
|
|
19
|
-
export type LogLevel = 'info' | 'debug' | 'error' | 'warn';
|
|
20
|
-
export declare const LOGGER: Logger;
|
|
21
|
-
export declare function configureLogger(level: LogLevel): void;
|
|
22
|
-
export declare function configureLogger(verbose: boolean): void;
|
|
23
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/lib/util/logger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,MAAM,WAAW,MAAO,SAAQ,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;IACnD,OAAO,IAAI,IAAI,CAAC;CACnB;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAW3D,eAAO,MAAM,MAAM,EAAE,MAMX,CAAC;AAUX,wBAAgB,eAAe,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;AACvD,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC"}
|
package/lib/util/logger.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/********************************************************************************
|
|
3
|
-
* Copyright (c) 2022-2023 EclipseSource and others.
|
|
4
|
-
*
|
|
5
|
-
* This program and the accompanying materials are made available under the
|
|
6
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
*
|
|
9
|
-
* This Source Code may also be made available under the following Secondary
|
|
10
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
* with the GNU Classpath Exception which is available at
|
|
13
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
*
|
|
15
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
-
********************************************************************************/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.LOGGER = void 0;
|
|
19
|
-
exports.configureLogger = configureLogger;
|
|
20
|
-
const levels = {
|
|
21
|
-
error: { threshold: 0, color: '\x1b[31m' }, // red
|
|
22
|
-
warn: { threshold: 1, color: '\x1b[33m' }, // yellow
|
|
23
|
-
info: { threshold: 2, color: '\x1b[0m' }, // default terminal color
|
|
24
|
-
debug: { threshold: 3, color: '\x1b[32m' } // green
|
|
25
|
-
};
|
|
26
|
-
let levelThreshold = levels.info.threshold;
|
|
27
|
-
exports.LOGGER = {
|
|
28
|
-
info: (...args) => log('info', ...args),
|
|
29
|
-
error: (...args) => log('error', ...args),
|
|
30
|
-
warn: (...args) => log('warn', ...args),
|
|
31
|
-
debug: (...args) => log('debug', ...args),
|
|
32
|
-
newLine: () => console.log('')
|
|
33
|
-
};
|
|
34
|
-
function log(level, ...args) {
|
|
35
|
-
const levelData = levels[level];
|
|
36
|
-
if (levelThreshold < levelData.threshold) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
console[level](levelData.color, ...args, '\x1b[0m');
|
|
40
|
-
}
|
|
41
|
-
function configureLogger(levelOrVerbose) {
|
|
42
|
-
if (typeof levelOrVerbose === 'boolean') {
|
|
43
|
-
const level = levelOrVerbose ? 'debug' : 'info';
|
|
44
|
-
levelThreshold = levels[level].threshold;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
levelThreshold = levels[levelOrVerbose].threshold;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=logger.js.map
|
package/lib/util/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/util/logger.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAmClF,0CAOC;AAlCD,MAAM,MAAM,GAA2D;IACnE,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,MAAM;IAClD,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,SAAS;IACpD,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,yBAAyB;IACnE,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,QAAQ;CACtD,CAAC;AAEF,IAAI,cAAc,GAAW,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;AAEtC,QAAA,MAAM,GAAW;IAC1B,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IACvC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;IACzC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IACvC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;IACzC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;CACxB,CAAC;AAEX,SAAS,GAAG,CAAC,KAAe,EAAE,GAAG,IAAW;IACxC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,IAAI,cAAc,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QACvC,OAAO;IACX,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC;AAID,SAAgB,eAAe,CAAC,cAAkC;IAC9D,IAAI,OAAO,cAAc,KAAK,SAAS,EAAE,CAAC;QACtC,MAAM,KAAK,GAAa,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;QAC1D,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC;IAC7C,CAAC;SAAM,CAAC;QACJ,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;AACL,CAAC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare function validateDirectory(rootDir: string): string;
|
|
2
|
-
export declare function validateFile(filePath: string, hasToExist?: boolean): string;
|
|
3
|
-
export declare function validateVersion(version: string): string;
|
|
4
|
-
export declare function validateGitDirectory(repository: string): string;
|
|
5
|
-
//# sourceMappingURL=validation-util.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation-util.d.ts","sourceRoot":"","sources":["../../src/util/validation-util.ts"],"names":[],"mappings":"AAsBA,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAUzD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,MAAM,CAUzE;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAO/D"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.validateDirectory = validateDirectory;
|
|
37
|
-
exports.validateFile = validateFile;
|
|
38
|
-
exports.validateVersion = validateVersion;
|
|
39
|
-
exports.validateGitDirectory = validateGitDirectory;
|
|
40
|
-
/********************************************************************************
|
|
41
|
-
* Copyright (c) 2022-2024 EclipseSource and others.
|
|
42
|
-
*
|
|
43
|
-
* This program and the accompanying materials are made available under the
|
|
44
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
45
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
46
|
-
*
|
|
47
|
-
* This Source Code may also be made available under the following Secondary
|
|
48
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
49
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
50
|
-
* with the GNU Classpath Exception which is available at
|
|
51
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
52
|
-
*
|
|
53
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
54
|
-
********************************************************************************/
|
|
55
|
-
const commander_1 = require("commander");
|
|
56
|
-
const fs = __importStar(require("fs"));
|
|
57
|
-
const path_1 = require("path");
|
|
58
|
-
const semver = __importStar(require("semver"));
|
|
59
|
-
const git_util_1 = require("./git-util");
|
|
60
|
-
const logger_1 = require("./logger");
|
|
61
|
-
function validateDirectory(rootDir) {
|
|
62
|
-
const path = (0, path_1.resolve)(rootDir);
|
|
63
|
-
if (!fs.existsSync(path)) {
|
|
64
|
-
throw new commander_1.InvalidArgumentError('Not a valid file path!');
|
|
65
|
-
}
|
|
66
|
-
if (!fs.statSync(path).isDirectory()) {
|
|
67
|
-
throw new commander_1.InvalidArgumentError('Not a directory!');
|
|
68
|
-
}
|
|
69
|
-
return path;
|
|
70
|
-
}
|
|
71
|
-
function validateFile(filePath, hasToExist = false) {
|
|
72
|
-
const path = (0, path_1.resolve)(filePath);
|
|
73
|
-
if (hasToExist && !fs.existsSync(path)) {
|
|
74
|
-
throw new commander_1.InvalidArgumentError('Not a valid file path!');
|
|
75
|
-
}
|
|
76
|
-
if (!fs.statSync(path).isFile()) {
|
|
77
|
-
throw new commander_1.InvalidArgumentError('Not a file!');
|
|
78
|
-
}
|
|
79
|
-
return path;
|
|
80
|
-
}
|
|
81
|
-
function validateVersion(version) {
|
|
82
|
-
logger_1.LOGGER.debug(`Validate version format of: ${version}`);
|
|
83
|
-
if (!semver.valid(version)) {
|
|
84
|
-
throw new commander_1.InvalidArgumentError(`Not a valid version: ${version}`);
|
|
85
|
-
}
|
|
86
|
-
return version;
|
|
87
|
-
}
|
|
88
|
-
function validateGitDirectory(repository) {
|
|
89
|
-
const repoPath = validateDirectory(repository);
|
|
90
|
-
if (!(0, git_util_1.isGitRepository)(repoPath)) {
|
|
91
|
-
throw new commander_1.InvalidArgumentError('Not a valid git repository');
|
|
92
|
-
}
|
|
93
|
-
return (0, git_util_1.getGitRoot)(repository);
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=validation-util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation-util.js","sourceRoot":"","sources":["../../src/util/validation-util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,8CAUC;AAED,oCAUC;AAED,0CAMC;AAED,oDAOC;AA7DD;;;;;;;;;;;;;;kFAckF;AAClF,yCAAiD;AACjD,uCAAyB;AACzB,+BAA+B;AAC/B,+CAAiC;AACjC,yCAAyD;AACzD,qCAAkC;AAElC,SAAgB,iBAAiB,CAAC,OAAe;IAC7C,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,gCAAoB,CAAC,wBAAwB,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QACnC,MAAM,IAAI,gCAAoB,CAAC,kBAAkB,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAgB,YAAY,CAAC,QAAgB,EAAE,UAAU,GAAG,KAAK;IAC7D,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;IAE/B,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,gCAAoB,CAAC,wBAAwB,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,gCAAoB,CAAC,aAAa,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAgB,eAAe,CAAC,OAAe;IAC3C,eAAM,CAAC,KAAK,CAAC,+BAA+B,OAAO,EAAE,CAAC,CAAC;IACvD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,gCAAoB,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,SAAgB,oBAAoB,CAAC,UAAkB;IACnD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,CAAC,IAAA,0BAAe,EAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,gCAAoB,CAAC,4BAA4B,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,IAAA,qBAAU,EAAC,UAAU,CAAC,CAAC;AAClC,CAAC"}
|
package/src/app.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/********************************************************************************
|
|
3
|
-
* Copyright (c) 2022 EclipseSource and others.
|
|
4
|
-
*
|
|
5
|
-
* This program and the accompanying materials are made available under the
|
|
6
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
*
|
|
9
|
-
* This Source Code may also be made available under the following Secondary
|
|
10
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
* with the GNU Classpath Exception which is available at
|
|
13
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
*
|
|
15
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
-
********************************************************************************/
|
|
17
|
-
import { CheckHeaderCommand } from './commands/check-header';
|
|
18
|
-
import { CoverageReportCommand } from './commands/coverage-report';
|
|
19
|
-
import { GenerateIndex } from './commands/generate-index';
|
|
20
|
-
import { ReleaseCommand } from './commands/release/release';
|
|
21
|
-
import { UpdateNextCommand } from './commands/update-next';
|
|
22
|
-
import { baseCommand } from './util/command-util';
|
|
23
|
-
|
|
24
|
-
export const COMMAND_VERSION = '1.1.0-next';
|
|
25
|
-
|
|
26
|
-
const app = baseCommand() //
|
|
27
|
-
.version(COMMAND_VERSION)
|
|
28
|
-
.name('glsp')
|
|
29
|
-
.addCommand(CoverageReportCommand)
|
|
30
|
-
.addCommand(ReleaseCommand)
|
|
31
|
-
.addCommand(CheckHeaderCommand)
|
|
32
|
-
.addCommand(UpdateNextCommand)
|
|
33
|
-
.addCommand(GenerateIndex);
|
|
34
|
-
|
|
35
|
-
app.parse(process.argv);
|
|
@@ -1,280 +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
|
-
/* eslint-disable max-len */
|
|
17
|
-
import { Option } from 'commander';
|
|
18
|
-
import * as fs from 'fs';
|
|
19
|
-
import { glob } from 'glob';
|
|
20
|
-
import * as minimatch from 'minimatch';
|
|
21
|
-
import * as readline from 'readline-sync';
|
|
22
|
-
import sh from 'shelljs';
|
|
23
|
-
import { baseCommand, configureShell, getShellConfig } from '../util/command-util';
|
|
24
|
-
import { getChangesOfLastCommit, getLastModificationDate, getUncommittedChanges } from '../util/git-util';
|
|
25
|
-
|
|
26
|
-
import * as path from 'path';
|
|
27
|
-
import { LOGGER } from '../util/logger';
|
|
28
|
-
import { validateGitDirectory } from '../util/validation-util';
|
|
29
|
-
|
|
30
|
-
export interface HeaderCheckOptions {
|
|
31
|
-
type: CheckType;
|
|
32
|
-
exclude: string[];
|
|
33
|
-
fileExtensions: string[];
|
|
34
|
-
json: boolean;
|
|
35
|
-
excludeDefaults: boolean;
|
|
36
|
-
autoFix: boolean;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const checkTypes = ['full', 'changes', 'lastCommit'] as const;
|
|
40
|
-
type CheckType = (typeof checkTypes)[number];
|
|
41
|
-
|
|
42
|
-
const DEFAULT_EXCLUDES = ['**/@(node_modules|lib|dist|bundle)/**'];
|
|
43
|
-
const YEAR_RANGE_REGEX = /\d{4}/g;
|
|
44
|
-
const HEADER_PATTERN = 'Copyright \\([cC]\\) \\d{4}';
|
|
45
|
-
const AUTO_FIX_MESSAGE = 'Fix copyright header violations';
|
|
46
|
-
|
|
47
|
-
export const CheckHeaderCommand = baseCommand() //
|
|
48
|
-
.name('checkHeaders')
|
|
49
|
-
.description('Validates the copyright year range (end year) of license header files')
|
|
50
|
-
.argument('<rootDir>', 'The starting directory for the check', validateGitDirectory)
|
|
51
|
-
.addOption(
|
|
52
|
-
new Option(
|
|
53
|
-
'-t, --type <type>',
|
|
54
|
-
'The scope of the check. In addition to a full recursive check, is also possible to only' +
|
|
55
|
-
' consider pending changes or the last commit'
|
|
56
|
-
)
|
|
57
|
-
.choices(checkTypes)
|
|
58
|
-
.default('full')
|
|
59
|
-
)
|
|
60
|
-
.option('-f, --fileExtensions <extensions...>', 'File extensions that should be checked', ['ts', 'tsx'])
|
|
61
|
-
.addOption(
|
|
62
|
-
new Option(
|
|
63
|
-
'-e, --exclude <exclude...>',
|
|
64
|
-
'File patterns that should be excluded from the check. New exclude patterns are added to the default patterns'
|
|
65
|
-
).default([], `[${DEFAULT_EXCLUDES}]`)
|
|
66
|
-
)
|
|
67
|
-
.option(
|
|
68
|
-
'--no-exclude-defaults',
|
|
69
|
-
'Disables the default excludes patterns. Only explicitly passed exclude patterns (-e, --exclude) are considered'
|
|
70
|
-
)
|
|
71
|
-
.option('-j, --json', 'Also persist validation results as json file', false)
|
|
72
|
-
.option('-a, --autoFix', 'Auto apply & commit fixes without prompting the user', false)
|
|
73
|
-
.action(checkHeaders);
|
|
74
|
-
|
|
75
|
-
export function checkHeaders(rootDir: string, options: HeaderCheckOptions): void {
|
|
76
|
-
configureShell({ silent: true, fatal: true });
|
|
77
|
-
|
|
78
|
-
if (options.excludeDefaults) {
|
|
79
|
-
options.exclude.push(...DEFAULT_EXCLUDES);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
sh.cd(rootDir);
|
|
83
|
-
const files = getFiles(rootDir, options);
|
|
84
|
-
LOGGER.info(`Check copy right headers of ${files.length} files`);
|
|
85
|
-
if (files.length === 0) {
|
|
86
|
-
LOGGER.info('Check completed');
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const results = validate(rootDir, files, options);
|
|
90
|
-
handleValidationResults(rootDir, results, options);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function getFiles(rootDir: string, options: HeaderCheckOptions): string[] {
|
|
94
|
-
const includePattern = `**/*.@(${options.fileExtensions.join('|')})`;
|
|
95
|
-
const excludePattern = options.exclude;
|
|
96
|
-
|
|
97
|
-
if (options.type === 'full') {
|
|
98
|
-
return glob.sync(includePattern, {
|
|
99
|
-
cwd: rootDir,
|
|
100
|
-
ignore: excludePattern
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let changedFiles = options.type === 'changes' ? getUncommittedChanges(rootDir) : getChangesOfLastCommit(rootDir);
|
|
105
|
-
changedFiles = changedFiles.filter(minimatch.filter(includePattern));
|
|
106
|
-
|
|
107
|
-
excludePattern.forEach(pattern => {
|
|
108
|
-
changedFiles = changedFiles.filter(minimatch.filter(`!${pattern}`));
|
|
109
|
-
});
|
|
110
|
-
return changedFiles.filter(file => fs.existsSync(file));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function validate(rootDir: string, files: string[], options: HeaderCheckOptions): ValidationResult[] {
|
|
114
|
-
// Derives all files with valid headers and all files with no or invalid headers
|
|
115
|
-
const filesWithHeader = sh.grep('-l', HEADER_PATTERN, files).stdout.trim().split('\n');
|
|
116
|
-
const noHeaders = files.filter(file => !filesWithHeader.includes(file));
|
|
117
|
-
|
|
118
|
-
const results: ValidationResult[] = [];
|
|
119
|
-
const allFilesLength = files.length;
|
|
120
|
-
|
|
121
|
-
// Create validation results for all files with no or invalid headers
|
|
122
|
-
const noHeadersLength = noHeaders.length;
|
|
123
|
-
if (noHeadersLength > 0) {
|
|
124
|
-
LOGGER.info(`Found ${noHeadersLength} files with no (or an invalid) copyright header`);
|
|
125
|
-
}
|
|
126
|
-
noHeaders.forEach((file, i) => {
|
|
127
|
-
printFileProgress(i + 1, allFilesLength, `Validating ${file}`);
|
|
128
|
-
results.push({ file: path.resolve(rootDir, file), violation: 'noOrMissingHeader' });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
// Performance optimization: avoid retrieving the dates for each individual file by precalculating the endYear if possible.
|
|
132
|
-
let defaultEndYear: number | undefined;
|
|
133
|
-
if (options.type === 'changes') {
|
|
134
|
-
defaultEndYear = new Date().getFullYear();
|
|
135
|
-
} else if (options.type === 'lastCommit') {
|
|
136
|
-
defaultEndYear = getLastModificationDate(undefined, rootDir)?.getFullYear();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Create validation results for all files with valid headers
|
|
140
|
-
filesWithHeader.forEach((file, i) => {
|
|
141
|
-
printFileProgress(i + 1 + noHeadersLength, allFilesLength, `Validating ${file}`);
|
|
142
|
-
const copyrightLine = sh.head({ '-n': 2 }, file).stdout.trim().split('\n')[1];
|
|
143
|
-
const copyRightYears = copyrightLine.match(YEAR_RANGE_REGEX)!;
|
|
144
|
-
if (!copyRightYears) {
|
|
145
|
-
const result: ValidationResult = { file, violation: 'noYear', line: copyrightLine };
|
|
146
|
-
results.push(result);
|
|
147
|
-
} else {
|
|
148
|
-
const currentStartYear = Number.parseInt(copyRightYears[0], 10);
|
|
149
|
-
const currentEndYear = copyRightYears[1] ? Number.parseInt(copyRightYears[1], 10) : undefined;
|
|
150
|
-
const result: DateValidationResult = {
|
|
151
|
-
currentStartYear,
|
|
152
|
-
currentEndYear,
|
|
153
|
-
expectedEndYear: defaultEndYear ?? getLastModificationDate(file, rootDir, AUTO_FIX_MESSAGE)!.getFullYear(),
|
|
154
|
-
file,
|
|
155
|
-
violation: 'none'
|
|
156
|
-
};
|
|
157
|
-
validateEndYear(result);
|
|
158
|
-
results.push(result);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
results.sort((a, b) => a.file.localeCompare(b.file));
|
|
163
|
-
|
|
164
|
-
process.stdout.clearLine(0);
|
|
165
|
-
return results;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function validateEndYear(result: DateValidationResult): void {
|
|
169
|
-
const { currentStartYear, expectedEndYear, currentEndYear } = result;
|
|
170
|
-
result.violation = 'invalidEndYear';
|
|
171
|
-
|
|
172
|
-
const valid = currentEndYear ? currentEndYear === expectedEndYear : currentStartYear === expectedEndYear;
|
|
173
|
-
|
|
174
|
-
if (valid) {
|
|
175
|
-
result.violation = 'none';
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function printFileProgress(currentFileCount: number, maxFileCount: number, message: string, clear = true): void {
|
|
181
|
-
if (clear) {
|
|
182
|
-
process.stdout.clearLine(0);
|
|
183
|
-
process.stdout.cursorTo(0);
|
|
184
|
-
}
|
|
185
|
-
process.stdout.write(`[${currentFileCount} of ${maxFileCount}] ${message}`);
|
|
186
|
-
if (!clear) {
|
|
187
|
-
process.stdout.write('\n');
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export function handleValidationResults(rootDir: string, results: ValidationResult[], options: HeaderCheckOptions): void {
|
|
192
|
-
LOGGER.newLine();
|
|
193
|
-
LOGGER.info(`Header validation for ${results.length} files completed`);
|
|
194
|
-
const violations = results.filter(result => result.violation !== 'none');
|
|
195
|
-
// Adjust results to print based on configured severity level
|
|
196
|
-
const toPrint = violations;
|
|
197
|
-
|
|
198
|
-
LOGGER.info(`Found ${toPrint.length} copyright header violations:`);
|
|
199
|
-
LOGGER.newLine();
|
|
200
|
-
|
|
201
|
-
toPrint.forEach((result, i) => LOGGER.info(`${i + 1}. `, result.file, ':', toPrintMessage(result)));
|
|
202
|
-
|
|
203
|
-
LOGGER.newLine();
|
|
204
|
-
|
|
205
|
-
if (options.json) {
|
|
206
|
-
fs.writeFileSync(path.join(rootDir, 'headerCheck.json'), JSON.stringify(results, undefined, 2));
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
violations.length > 0 &&
|
|
211
|
-
(options.autoFix || readline.keyInYN('Do you want to automatically fix copyright year range violations?'))
|
|
212
|
-
) {
|
|
213
|
-
const toFix = violations.filter(violation => isDateValidationResult(violation)) as DateValidationResult[];
|
|
214
|
-
fixViolations(rootDir, toFix, options);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
LOGGER.info('Check completed');
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function toPrintMessage(result: ValidationResult): string {
|
|
221
|
-
const error = '\x1b[31m';
|
|
222
|
-
const info = '\x1b[32m';
|
|
223
|
-
|
|
224
|
-
if (isDateValidationResult(result) && result.violation === 'invalidEndYear') {
|
|
225
|
-
const expected = result.expectedEndYear.toString();
|
|
226
|
-
const actual = result.currentEndYear
|
|
227
|
-
? `${result.currentEndYear} (${result.currentStartYear}-${result.currentEndYear})`
|
|
228
|
-
: result.currentStartYear.toString();
|
|
229
|
-
const message = 'Invalid copyright end year';
|
|
230
|
-
return `${error} ${message}! Expected end year '${expected}' but is '${actual}'`;
|
|
231
|
-
} else if (result.violation === 'noOrMissingHeader') {
|
|
232
|
-
return `${error} No or invalid copyright header!`;
|
|
233
|
-
} else if (result.violation === 'noYear') {
|
|
234
|
-
return `${error} No year found!${result.line ? ' (line: ' + result.line + ')' : ''}`;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return `${info} OK`;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function fixViolations(rootDir: string, violations: DateValidationResult[], options: HeaderCheckOptions): void {
|
|
241
|
-
LOGGER.newLine();
|
|
242
|
-
violations.forEach((violation, i) => {
|
|
243
|
-
printFileProgress(i + 1, violations.length, `Fix ${violation.file}`, false);
|
|
244
|
-
|
|
245
|
-
const currentRange = `${violation.currentStartYear}${violation.currentEndYear ? '-' + violation.currentEndYear : ''}`;
|
|
246
|
-
const fixedRange =
|
|
247
|
-
violation.currentEndYear || violation.currentStartYear < violation.expectedEndYear
|
|
248
|
-
? `${violation.currentStartYear}-${violation.expectedEndYear}`
|
|
249
|
-
: `${violation.expectedEndYear}`;
|
|
250
|
-
|
|
251
|
-
sh.sed('-i', RegExp('Copyright \\([cC]\\) ' + currentRange), `Copyright (c) ${fixedRange}`, violation.file);
|
|
252
|
-
});
|
|
253
|
-
LOGGER.newLine();
|
|
254
|
-
if (options.autoFix || readline.keyInYN('Do you want to create a commit for the fixed files?')) {
|
|
255
|
-
LOGGER.newLine();
|
|
256
|
-
const files = violations.map(violation => violation.file).join(' ');
|
|
257
|
-
sh.exec(`git add ${files}`, getShellConfig());
|
|
258
|
-
sh.exec(`git commit -m "${AUTO_FIX_MESSAGE}"`);
|
|
259
|
-
LOGGER.newLine();
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Helper types
|
|
264
|
-
interface ValidationResult {
|
|
265
|
-
file: string;
|
|
266
|
-
violation: Violation;
|
|
267
|
-
line?: string;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
interface DateValidationResult extends ValidationResult {
|
|
271
|
-
currentStartYear: number;
|
|
272
|
-
currentEndYear?: number;
|
|
273
|
-
expectedEndYear: number;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function isDateValidationResult(object: ValidationResult): object is DateValidationResult {
|
|
277
|
-
return 'currentStartYear' in object && 'expectedEndYear' in object;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
type Violation = 'none' | 'noOrMissingHeader' | 'invalidEndYear' | 'noYear';
|