@eclipse-glsp/cli
Advanced tools
Comparing version 1.1.0-next.4c65907.114 to 1.1.0-next.7026c40.129
#!/usr/bin/env node | ||
/******************************************************************************** | ||
* Copyright (c) 2022 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { Command } from 'commander'; | ||
export declare const ReleaseCommand: Command; | ||
export declare const COMMAND_VERSION = "1.1.0-next"; | ||
//# sourceMappingURL=app.d.ts.map |
#!/usr/bin/env node | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ReleaseCommand = void 0; | ||
exports.COMMAND_VERSION = void 0; | ||
/******************************************************************************** | ||
@@ -20,28 +20,14 @@ * Copyright (c) 2022 EclipseSource and others. | ||
********************************************************************************/ | ||
const commander_1 = require("commander"); | ||
const sh = require("shelljs"); | ||
const common_1 = require("./release/common"); | ||
const release_1 = require("./release/release"); | ||
const check_header_1 = require("./commands/check-header"); | ||
const coverage_report_1 = require("./commands/coverage-report"); | ||
const release_1 = require("./commands/release/release"); | ||
const command_util_1 = require("./util/command-util"); | ||
const validation_util_1 = require("./util/validation-util"); | ||
exports.ReleaseCommand = (0, command_util_1.baseConfiguration)(new commander_1.Command()) | ||
.name('release') | ||
.description('Prepare & publish a new release for a glsp component') | ||
.addArgument(new commander_1.Argument('<component>', 'The glsp component to be released').choices(common_1.Component.CLI_CHOICES).argParser(common_1.Component.parse)) | ||
.addArgument(new commander_1.Argument('<releaseType>', 'The release type').choices(common_1.ReleaseType.CLI_CHOICES)) | ||
.argument('[customVersion]', 'Custom version number. Will be ignored if the release type is not "custom"', validation_util_1.validateVersion) | ||
.option('-f, --force', 'Enable force mode', false) | ||
.option('-d, --checkoutDir <checkoutDir>', 'The git checkout directory', validation_util_1.validateDirectory, sh.pwd().stdout) | ||
.option('-b, --branch <branch>', 'The git branch to checkout', 'master') | ||
.option('-v, --verbose', 'Enable verbose (debug) log output', false) | ||
.option('--no-publish', 'Only prepare release but do not publish to github', true) | ||
.option('--draft', 'Publish github releases as drafts', false) | ||
.option('--npm-dryRun', 'Execute a npm dry-run for inspection. Publishes to the local npm registry and does not publish to github', false) | ||
.action(release_1.release); | ||
const app = (0, command_util_1.baseConfiguration)(new commander_1.Command()) | ||
.showSuggestionAfterError(true) | ||
.showHelpAfterError(true) | ||
exports.COMMAND_VERSION = '1.1.0-next'; | ||
const app = (0, command_util_1.baseCommand)() // | ||
.version(exports.COMMAND_VERSION) | ||
.name('glsp') | ||
.addCommand(exports.ReleaseCommand); | ||
.addCommand(coverage_report_1.CoverageReportCommand) | ||
.addCommand(release_1.ReleaseCommand) | ||
.addCommand(check_header_1.CheckHeaderCommand); | ||
app.parse(process.argv); | ||
//# sourceMappingURL=app.js.map |
@@ -18,15 +18,10 @@ /******************************************************************************** | ||
import * as sh from 'shelljs'; | ||
export declare const COMMAND_VERSION = "1.1.0-next"; | ||
export declare function baseConfiguration(cmd: Command): Command; | ||
export interface BaseCmdOptions { | ||
verbose: boolean; | ||
} | ||
export declare const SH_CONFIG: sh.ExecOptions & { | ||
export declare function baseCommand(cmd?: Command): Command; | ||
export type ShellConfig = sh.ExecOptions & { | ||
async: false; | ||
}; | ||
export declare function getShellConfig(options?: Partial<Omit<sh.ExecOptions, 'async'>>): sh.ExecOptions & { | ||
async: false; | ||
}; | ||
export declare function initialConfiguration(verbose: boolean): void; | ||
export declare function fatalExec(command: string, fatalErrorMessage: string, options?: Partial<Omit<sh.ExecOptions, 'async'>>): sh.ShellString; | ||
export declare const SH_CONFIG: ShellConfig; | ||
export declare function getShellConfig(options?: Partial<Omit<ShellConfig, 'async'>>): ShellConfig; | ||
export declare function configureShell(config: Partial<sh.ShellConfig>): void; | ||
export declare function fatalExec(command: string, fatalErrorMessage: string, options?: Partial<Omit<ShellConfig, 'async'>>): sh.ShellString; | ||
//# sourceMappingURL=command-util.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fatalExec = exports.initialConfiguration = exports.getShellConfig = exports.SH_CONFIG = exports.baseConfiguration = exports.COMMAND_VERSION = void 0; | ||
exports.fatalExec = exports.configureShell = exports.getShellConfig = exports.SH_CONFIG = exports.baseCommand = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2022 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const commander_1 = require("commander"); | ||
const sh = require("shelljs"); | ||
const logger_1 = require("./logger"); | ||
exports.COMMAND_VERSION = '1.1.0-next'; | ||
function baseConfiguration(cmd) { | ||
return cmd | ||
.version(exports.COMMAND_VERSION) // | ||
// Commander.js utils | ||
function baseCommand(cmd = new commander_1.Command()) { | ||
return cmd // | ||
.showSuggestionAfterError(true) | ||
@@ -14,3 +28,3 @@ .showHelpAfterError(true) | ||
} | ||
exports.baseConfiguration = baseConfiguration; | ||
exports.baseCommand = baseCommand; | ||
exports.SH_CONFIG = { | ||
@@ -25,8 +39,9 @@ async: false, | ||
exports.getShellConfig = getShellConfig; | ||
function initialConfiguration(verbose) { | ||
function configureShell(config) { | ||
sh.config.reset(); | ||
exports.SH_CONFIG.silent = !verbose; | ||
(0, logger_1.configureLogger)(verbose); | ||
getShellConfig({}); | ||
exports.SH_CONFIG.silent = config.silent; | ||
exports.SH_CONFIG.fatal = config.fatal; | ||
} | ||
exports.initialConfiguration = initialConfiguration; | ||
exports.configureShell = configureShell; | ||
function fatalExec(command, fatalErrorMessage, options = {}) { | ||
@@ -33,0 +48,0 @@ const result = sh.exec(command, getShellConfig(options)); |
/******************************************************************************** | ||
* Copyright (c) 2022 EclipseSource and others. | ||
* Copyright (c) 2022-2022 EclipseSource and others. | ||
* | ||
@@ -16,6 +16,45 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
export declare function isGithubCLIAuthenticated(): boolean; | ||
export declare function isGitRepository(path: string): boolean; | ||
export declare function isGitRepository(path?: string): boolean; | ||
export declare function getGitRoot(path?: string): string; | ||
export declare function hasGitChanges(path?: string): boolean; | ||
export declare function getLatestRelease(path?: string): string; | ||
/** | ||
* Returns the files that have uncommitted changes (staged, not staged and untracked) of a git repository. | ||
* Filepaths are absolute. | ||
*/ | ||
export declare function getUncommittedChanges(path?: string): string[]; | ||
/** | ||
* Returns the files tha have been changed with the last commit (also includes currently staged but uncommitted changes) | ||
* Filepaths are absolute. | ||
*/ | ||
export declare function getChangesOfLastCommit(path?: string): string[]; | ||
/** | ||
* Returns the last modification date of a file (or the last commit) in a git repo. | ||
* @param filePath The file. If undefined the modification date of the last commit will be returned | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @param excludeMessage Only consider commits that don`t match the excludeMessage | ||
* @returns The date or undefined if the file is outside of the git repo. | ||
*/ | ||
export declare function getLastModificationDate(filePath?: string, repoRoot?: string, excludeMessage?: string): Date | undefined; | ||
/** | ||
* Returns the last modification date of a file in a git repo. | ||
* @param filePath The file | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @param excludeMessage Only consider commits that don`t match the excludeMessage | ||
* @returns The date or undefined if the file is outside of the git repo. | ||
*/ | ||
export declare function getFirstModificationDate(filePath: string, repoRoot?: string, excludeMessage?: string): Date | undefined; | ||
export declare function getFilesOfCommit(commitHash: string, repoRoot?: string): string[]; | ||
/** | ||
* Returns the commit hash of the initial commit of the given repository | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @returns The commit hash or undefined if something went wrong. | ||
*/ | ||
export declare function getInitialCommit(repoRoot?: string): string | undefined; | ||
/** | ||
* Returns the commit hash of the first commit for a given file (across renames). | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @returns The commit hash or undefined if something went wrong. | ||
*/ | ||
export declare function getFirstCommit(filePath: string, repoRoot?: string): string | undefined; | ||
export declare function getLatestGithubRelease(path?: string): string; | ||
export declare function getLatestTag(path?: string): string; | ||
@@ -22,0 +61,0 @@ export declare function hasBranch(branch: string, path?: string): boolean; |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2022 EclipseSource and others. | ||
* Copyright (c) 2022-2022 EclipseSource and others. | ||
* | ||
@@ -18,46 +18,141 @@ * This program and the accompanying materials are made available under the | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getRemoteUrl = exports.hasBranch = exports.getLatestTag = exports.getLatestRelease = exports.hasGitChanges = exports.isGitRepository = exports.isGithubCLIAuthenticated = void 0; | ||
exports.getRemoteUrl = exports.hasBranch = exports.getLatestTag = exports.getLatestGithubRelease = exports.getFirstCommit = exports.getInitialCommit = exports.getFilesOfCommit = exports.getFirstModificationDate = exports.getLastModificationDate = exports.getChangesOfLastCommit = exports.getUncommittedChanges = exports.hasGitChanges = exports.getGitRoot = exports.isGitRepository = void 0; | ||
const path_1 = require("path"); | ||
const sh = require("shelljs"); | ||
const command_util_1 = require("./command-util"); | ||
const logger_1 = require("./logger"); | ||
const validation_util_1 = require("./validation-util"); | ||
function isGithubCLIAuthenticated() { | ||
logger_1.LOGGER.debug('Verify that Github CLI is installed'); | ||
(0, command_util_1.fatalExec)('which gh', 'Github CLI is not installed!'); | ||
const status = sh.exec('gh auth status', (0, command_util_1.getShellConfig)()); | ||
if (status.code !== 0) { | ||
if (status.stderr.includes('You are not logged into any GitHub hosts')) { | ||
return false; | ||
} | ||
throw new Error(status.stderr); | ||
} | ||
if (!status.stderr.trim().includes('Logged in to github.com')) { | ||
logger_1.LOGGER.debug("No user is logged in for host 'github.com'"); | ||
return false; | ||
} | ||
logger_1.LOGGER.debug('Github CLI is authenticated and ready to use'); | ||
return true; | ||
} | ||
exports.isGithubCLIAuthenticated = isGithubCLIAuthenticated; | ||
function isGitRepository(path) { | ||
logger_1.LOGGER.debug(`Check if the given directory is a git repo: ${path}`); | ||
sh.cd(path); | ||
return sh.exec('git rev-parse --is-inside-work-tree', (0, command_util_1.getShellConfig)()).stdout.trim().toLocaleLowerCase() === 'true'; | ||
cdIfPresent(path); | ||
const isGitRepo = sh | ||
.exec('git rev-parse --is-inside-work-tree', (0, command_util_1.getShellConfig)({ silent: true })) | ||
.stdout.trim() | ||
.toLocaleLowerCase() === 'true'; | ||
return isGitRepo; | ||
} | ||
exports.isGitRepository = isGitRepository; | ||
function hasGitChanges(path) { | ||
logger_1.LOGGER.debug(`Check if the directory has git changes: ${asDebugArg(path)}`); | ||
function getGitRoot(path) { | ||
cdIfPresent(path); | ||
return sh.exec('git status --porcelain').stdout.trim().length !== 0; | ||
const fileString = sh.exec('git rev-parse --show-toplevel', (0, command_util_1.getShellConfig)()).stdout.trim(); | ||
return (0, path_1.resolve)(fileString); | ||
} | ||
exports.getGitRoot = getGitRoot; | ||
function hasGitChanges(path) { | ||
return getUncommittedChanges(path).length > 0; | ||
} | ||
exports.hasGitChanges = hasGitChanges; | ||
function getLatestRelease(path) { | ||
logger_1.LOGGER.debug(`Retrieve latest release from repo: ${asDebugArg(path)}`); | ||
/** | ||
* Returns the files that have uncommitted changes (staged, not staged and untracked) of a git repository. | ||
* Filepaths are absolute. | ||
*/ | ||
function getUncommittedChanges(path) { | ||
cdIfPresent(path); | ||
return sh | ||
.exec('git status --porcelain', (0, command_util_1.getShellConfig)()) | ||
.stdout.trim() | ||
.split('\n') | ||
.filter(value => value.trim().length !== 0) | ||
.map(fileInfo => { var _a; | ||
// Extract relative file path from the info string and convert to absolute path | ||
return (0, path_1.resolve)(path !== null && path !== void 0 ? path : process.cwd(), (_a = fileInfo.trim().split(' ').pop()) !== null && _a !== void 0 ? _a : ''); }); | ||
} | ||
exports.getUncommittedChanges = getUncommittedChanges; | ||
/** | ||
* Returns the files tha have been changed with the last commit (also includes currently staged but uncommitted changes) | ||
* Filepaths are absolute. | ||
*/ | ||
function getChangesOfLastCommit(path) { | ||
cdIfPresent(path); | ||
return sh | ||
.exec('git diff --name-only HEAD^', (0, command_util_1.getShellConfig)()) | ||
.stdout.trim() | ||
.split('\n') | ||
.map(file => (0, path_1.resolve)(path !== null && path !== void 0 ? path : process.cwd(), file)); | ||
} | ||
exports.getChangesOfLastCommit = getChangesOfLastCommit; | ||
/** | ||
* Returns the last modification date of a file (or the last commit) in a git repo. | ||
* @param filePath The file. If undefined the modification date of the last commit will be returned | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @param excludeMessage Only consider commits that don`t match the excludeMessage | ||
* @returns The date or undefined if the file is outside of the git repo. | ||
*/ | ||
function getLastModificationDate(filePath, repoRoot, excludeMessage) { | ||
cdIfPresent(repoRoot); | ||
const additionalArgs = excludeMessage ? `--grep="${excludeMessage}" --invert-grep` : ''; | ||
const result = sh.exec(`git log -1 ${additionalArgs} --pretty="format:%ci" ${filePath !== null && filePath !== void 0 ? filePath : ''}`, (0, command_util_1.getShellConfig)()); | ||
if (result.code !== 0) { | ||
return undefined; | ||
} | ||
return new Date(result.stdout.trim()); | ||
} | ||
exports.getLastModificationDate = getLastModificationDate; | ||
/** | ||
* Returns the last modification date of a file in a git repo. | ||
* @param filePath The file | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @param excludeMessage Only consider commits that don`t match the excludeMessage | ||
* @returns The date or undefined if the file is outside of the git repo. | ||
*/ | ||
function getFirstModificationDate(filePath, repoRoot, excludeMessage) { | ||
cdIfPresent(repoRoot); | ||
const additionalArgs = excludeMessage ? `--grep="${excludeMessage}" --invert-grep` : ''; | ||
const result = sh.exec(`git log ${additionalArgs} --pretty="format:%ci" --follow ${filePath}`, (0, command_util_1.getShellConfig)()); | ||
if (result.code !== 0) { | ||
return undefined; | ||
} | ||
const datesString = result.stdout.trim(); | ||
if (datesString.length === 0) { | ||
return new Date(); | ||
} | ||
const date = datesString.split('\n').pop(); | ||
return date ? new Date(date) : undefined; | ||
} | ||
exports.getFirstModificationDate = getFirstModificationDate; | ||
function getFilesOfCommit(commitHash, repoRoot) { | ||
cdIfPresent(repoRoot); | ||
const result = sh.exec(`git show --pretty="" --name-only ${commitHash}`, (0, command_util_1.getShellConfig)()); | ||
if (result.code !== 0) { | ||
return []; | ||
} | ||
return result.stdout.trim().split('\n'); | ||
} | ||
exports.getFilesOfCommit = getFilesOfCommit; | ||
/** | ||
* Returns the commit hash of the initial commit of the given repository | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @returns The commit hash or undefined if something went wrong. | ||
*/ | ||
function getInitialCommit(repoRoot) { | ||
cdIfPresent(repoRoot); | ||
const result = sh.exec('git log --pretty=oneline --reverse', (0, command_util_1.getShellConfig)()); | ||
if (result.code !== 0) { | ||
return undefined; | ||
} | ||
const commits = result.stdout.trim(); | ||
if (commits.length === 0) { | ||
return undefined; | ||
} | ||
return commits.substring(0, commits.indexOf(' ')); | ||
} | ||
exports.getInitialCommit = getInitialCommit; | ||
/** | ||
* Returns the commit hash of the first commit for a given file (across renames). | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @returns The commit hash or undefined if something went wrong. | ||
*/ | ||
function getFirstCommit(filePath, repoRoot) { | ||
cdIfPresent(repoRoot); | ||
const result = sh.exec(`git log --follow --pretty=format:"%H" ${filePath}`, (0, command_util_1.getShellConfig)()); | ||
if (result.code !== 0) { | ||
return undefined; | ||
} | ||
return result.stdout.trim().split('\n').pop(); | ||
} | ||
exports.getFirstCommit = getFirstCommit; | ||
function getLatestGithubRelease(path) { | ||
cdIfPresent(path); | ||
const release = sh.exec('gh release list --exclude-drafts -L 1', (0, command_util_1.getShellConfig)()).stdout.trim().split('\t'); | ||
return release[release.length - 2]; | ||
} | ||
exports.getLatestRelease = getLatestRelease; | ||
exports.getLatestGithubRelease = getLatestGithubRelease; | ||
function getLatestTag(path) { | ||
logger_1.LOGGER.debug(`Retrieve latest tag from local repo : ${asDebugArg(path)}`); | ||
cdIfPresent(path); | ||
@@ -68,3 +163,2 @@ return sh.exec('git describe --abbrev=0 --tags', (0, command_util_1.getShellConfig)()).stdout.trim(); | ||
function hasBranch(branch, path) { | ||
logger_1.LOGGER.debug(`Check if branch exists: ${asDebugArg(path)}`); | ||
cdIfPresent(path); | ||
@@ -75,3 +169,2 @@ return sh.exec(`git branch --list ${branch}`, (0, command_util_1.getShellConfig)()).stdout.trim().length !== 0; | ||
function getRemoteUrl(path) { | ||
logger_1.LOGGER.debug(`Retrieve remote git url for: ${asDebugArg(path)}`); | ||
cdIfPresent(path); | ||
@@ -83,9 +176,5 @@ return sh.exec('git config --get remote.origin.url', (0, command_util_1.getShellConfig)()).stdout.trim(); | ||
if (path) { | ||
(0, validation_util_1.validateGitDirectory)(path); | ||
sh.cd(path); | ||
} | ||
} | ||
function asDebugArg(path) { | ||
return path !== null && path !== void 0 ? path : sh.pwd().stdout; | ||
} | ||
//# sourceMappingURL=git-util.js.map |
@@ -0,9 +1,23 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2022 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
export interface Logger extends Pick<Console, LogLevel> { | ||
newLine(): void; | ||
} | ||
export type LogLevel = 'info' | 'debug' | 'error' | 'warn'; | ||
export declare const LOGGER: Logger; | ||
export declare function configureLogger(isVerbose: boolean): void; | ||
export interface Logger { | ||
info(message: string, ...args: any[]): void; | ||
error(message: string, ...args: any[]): void; | ||
warn(message: string, ...args: any[]): void; | ||
debug(message: string, ...args: any[]): void; | ||
} | ||
export declare function configureLogger(level: LogLevel): void; | ||
export declare function configureLogger(verbose: boolean): void; | ||
//# sourceMappingURL=logger.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.configureLogger = exports.LOGGER = void 0; | ||
/******************************************************************************** | ||
@@ -19,17 +17,35 @@ * Copyright (c) 2022 EclipseSource and others. | ||
********************************************************************************/ | ||
let verbose = false; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.configureLogger = exports.LOGGER = void 0; | ||
const levels = { | ||
error: { threshold: 0, color: '\x1b[31m' }, | ||
warn: { threshold: 1, color: '\x1b[33m' }, | ||
info: { threshold: 2, color: '\x1b[0m' }, | ||
debug: { threshold: 3, color: '\x1b[32m' } // green | ||
}; | ||
let levelThreshold = levels.info.threshold; | ||
exports.LOGGER = { | ||
info: (message, ...args) => console.info(`[INFO] ${message}`, ...args), | ||
error: (message, ...args) => console.error(`[ERROR] ${message}`, ...args), | ||
warn: (message, ...args) => console.warn(`[WARNING] ${message}`, ...args), | ||
debug: (message, ...args) => { | ||
if (verbose) { | ||
console.log(`[DEBUG] ${message}`, ...args); | ||
} | ||
info: (...args) => log('info', ...args), | ||
error: (...args) => log('error', ...args), | ||
warn: (...args) => log('warn', ...args), | ||
debug: (...args) => log('debug', ...args), | ||
newLine: () => console.log('') | ||
}; | ||
function log(level, ...args) { | ||
const levelData = levels[level]; | ||
if (levelThreshold < levelData.threshold) { | ||
return; | ||
} | ||
}; | ||
function configureLogger(isVerbose) { | ||
verbose = isVerbose; | ||
console[level](levelData.color, ...args, '\x1b[0m'); | ||
} | ||
function configureLogger(levelOrVerbose) { | ||
if (typeof levelOrVerbose === 'boolean') { | ||
const level = levelOrVerbose ? 'debug' : 'info'; | ||
levelThreshold = levels[level].threshold; | ||
} | ||
else { | ||
levelThreshold = levels[levelOrVerbose].threshold; | ||
} | ||
} | ||
exports.configureLogger = configureLogger; | ||
//# sourceMappingURL=logger.js.map |
export declare const COMMAND_VERSION = "1.1.0-next"; | ||
export declare function validateDirectory(rootDir: string): string; | ||
export declare function validateFile(filePath: string, hasToExist?: boolean): string; | ||
export declare function validateVersion(version: string): string; | ||
export declare function validateGitDirectory(repository: string): string; | ||
//# sourceMappingURL=validation-util.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateGitDirectory = exports.validateVersion = exports.validateDirectory = exports.COMMAND_VERSION = void 0; | ||
exports.validateGitDirectory = exports.validateVersion = exports.validateFile = exports.validateDirectory = exports.COMMAND_VERSION = void 0; | ||
/******************************************************************************** | ||
@@ -37,6 +37,17 @@ * Copyright (c) 2022 EclipseSource and others. | ||
exports.validateDirectory = validateDirectory; | ||
function validateFile(filePath, hasToExist = false) { | ||
const path = (0, path_1.resolve)(filePath); | ||
if (hasToExist && !fs.existsSync(path)) { | ||
throw new commander_1.InvalidArgumentError('Not a valid file path!'); | ||
} | ||
if (!fs.statSync(path).isFile()) { | ||
throw new commander_1.InvalidArgumentError('Not a file!'); | ||
} | ||
return path; | ||
} | ||
exports.validateFile = validateFile; | ||
function validateVersion(version) { | ||
logger_1.LOGGER.debug(`Validate version format of: ${version}`); | ||
if (!semver.valid(version)) { | ||
throw new Error(`Not a valid version: ${version}`); | ||
throw new commander_1.InvalidArgumentError(`Not a valid version: ${version}`); | ||
} | ||
@@ -49,7 +60,7 @@ return version; | ||
if (!(0, git_util_1.isGitRepository)(repoPath)) { | ||
throw new Error('Not a valid git repository'); | ||
throw new commander_1.InvalidArgumentError('Not a valid git repository'); | ||
} | ||
return repoPath; | ||
return (0, git_util_1.getGitRoot)(repository); | ||
} | ||
exports.validateGitDirectory = validateGitDirectory; | ||
//# sourceMappingURL=validation-util.js.map |
{ | ||
"name": "@eclipse-glsp/cli", | ||
"version": "1.1.0-next.4c65907.114+4c65907", | ||
"version": "1.1.0-next.7026c40.129+7026c40", | ||
"description": "CLI Tooling & scripts for GLSP components", | ||
"license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)", | ||
"keywords": [ | ||
@@ -10,6 +9,4 @@ "eclipse", | ||
], | ||
"author": { | ||
"name": "Eclipse GLSP" | ||
}, | ||
"homepage": "https://www.eclipse.org/glsp/", | ||
"bugs": "https://github.com/eclipse-glsp/glsp/issues", | ||
"repository": { | ||
@@ -19,3 +16,6 @@ "type": "git", | ||
}, | ||
"bugs": "https://github.com/eclipse-glsp/glsp/issues", | ||
"license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)", | ||
"author": { | ||
"name": "Eclipse GLSP" | ||
}, | ||
"contributors": [ | ||
@@ -28,15 +28,22 @@ { | ||
], | ||
"bin": { | ||
"glsp": "bin/glsp" | ||
}, | ||
"files": [ | ||
"src", | ||
"bin", | ||
"lib" | ||
], | ||
"scripts": { | ||
"prepare": "yarn clean && yarn build && yarn lint", | ||
"clean": "rimraf lib tsconfig.tsbuildinfo ", | ||
"build": "tsc", | ||
"build": "tsc -b", | ||
"clean": "rimraf lib tsconfig.tsbuildinfo", | ||
"lint": "eslint --ext .ts,.tsx ./src", | ||
"lint:fix": "eslint --fix --ext .ts,.tsx ./src", | ||
"test": "node --enable-source-maps lib/app.js" | ||
"lint:ci": "yarn lint -o eslint.xml -f checkstyle", | ||
"prepare": "yarn clean && yarn build ", | ||
"start": "node --enable-source-maps lib/app.js", | ||
"watch": "tsc -w" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"commander": "^9.4.0", | ||
"glob": "^8.0.3", | ||
"node-fetch": "2.6.7", | ||
@@ -48,4 +55,4 @@ "readline-sync": "^1.4.10", | ||
"devDependencies": { | ||
"@eclipse-glsp/config": "1.1.0-next.4c65907.114+4c65907", | ||
"@types/node": "14.x", | ||
"@eclipse-glsp/config": "1.1.0-next.7026c40.129+7026c40", | ||
"@types/glob": "^8.0.0", | ||
"@types/node-fetch": "2.6.2", | ||
@@ -55,16 +62,8 @@ "@types/readline-sync": "1.4.4", | ||
"@types/shelljs": "0.8.11", | ||
"reflect-metadata": "0.1.13", | ||
"rimraf": "3.0.2", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.5.0" | ||
"ts-node": "^10.9.1" | ||
}, | ||
"bin": { | ||
"glsp": "bin/glsp" | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"src", | ||
"bin", | ||
"lib" | ||
], | ||
"gitHead": "4c6590739921232e7f8b1d99a85a940debb13e0b" | ||
"gitHead": "7026c40d0dafe0b03a94bf0813612de8179cef54" | ||
} |
@@ -14,8 +14,53 @@ # Eclipse GLSP - CLI | ||
## Commands | ||
## checkHeaders | ||
Eclipse GLSP committers can use the `release` following command to prepare & publish a new Github release | ||
for a specific GLSP component. | ||
The `checkHeaders` command can be used to validate the copyright year (range) of license headers. | ||
It checks for each file (matching the include pattern) whether the defined copyright range is in line with the first and last modification date in the git repository. | ||
Found violations are printed to the console and can be fixed automatically. | ||
The validation check can be restricted to pending changes and/or the last commit e.g. to validate a commit before creating a PR. | ||
```bash | ||
```console | ||
$ glsp checkHeaders -h | ||
Usage: glsp checkHeaders [options] <rootDir> | ||
Validates the copyright year range of license header files | ||
Arguments: | ||
rootDir The starting directory for the check | ||
Options: | ||
-t, --type <type> The scope of the check. In addition to a full recursive check, is also possible to only consider pending changes or the last commit (choices: "full", "changes", "lastCommit", default: | ||
"full") | ||
-f, --fileExtensions <extensions...> File extensions that should be checked (default: ["ts","tsx"]) | ||
-e, --exclude <exclude...> File patterns that should be excluded from the check. New exclude patterns are added to the default patterns (default: [**/@(node_modules|lib|dist|bundle)/**]) | ||
--no-exclude-defaults Disables the default excludes patterns. Only explicitly passed exclude patterns (-e, --exclude) are considered | ||
-j, --json Also persist validation results as json file (default: false) | ||
-s, --severity <severity> The severity of validation results that should be printed. (choices: "error", "warn", "ok", default: "error" (only)) | ||
-a, --autoFix Auto apply & commit fixes without prompting the user (default: false) | ||
-h, --help display help for command | ||
``` | ||
## coverageReport | ||
The `coverageReport` command can be used to create a full nyc test coverage report for a lerna/yarn mono repository. | ||
Individual coverage reports for each package are created and then combined to a full report. | ||
```console | ||
$ glsp coverageReport -h | ||
Usage: glsp coverageReport [options] | ||
Generate a test coverage report for a glsp component | ||
Options: | ||
-p, --projectRoot <projectRoot> The root directory of the GLSP component (default: "<cwd>") | ||
-c, --coverageScript <script> Script command of the package root for creating coverage reports (default: "test:coverage") | ||
-h, --help display help for command | ||
``` | ||
## release | ||
Eclipse GLSP committers can use the `release` command to prepare & publish a new Github release for a specific GLSP component. | ||
```console | ||
$ glsp release -h | ||
@@ -32,5 +77,4 @@ Usage: glsp release [options] <component> <releaseType> [customVersion] | ||
Options: | ||
-V, --version output the version number | ||
-f, --force Enable force mode (default: false) | ||
-d, --checkoutDir <checkoutDir> The git checkout directory (default: "/home/tobias/Git/OpenSource/glsp/glsp/dev-packages/cli") | ||
-d, --checkoutDir <checkoutDir> The git checkout directory (default: "<cwd>") | ||
-b, --branch <branch> The git branch to checkout (default: "master") | ||
@@ -37,0 +81,0 @@ -v, --verbose Enable verbose (debug) log output (default: false) |
@@ -17,34 +17,15 @@ #!/usr/bin/env node | ||
********************************************************************************/ | ||
import { Argument, Command } from 'commander'; | ||
import * as sh from 'shelljs'; | ||
import { Component, ReleaseType } from './release/common'; | ||
import { release } from './release/release'; | ||
import { baseConfiguration } from './util/command-util'; | ||
import { validateDirectory, validateVersion } from './util/validation-util'; | ||
import { CheckHeaderCommand } from './commands/check-header'; | ||
import { CoverageReportCommand } from './commands/coverage-report'; | ||
import { ReleaseCommand } from './commands/release/release'; | ||
import { baseCommand } from './util/command-util'; | ||
export const COMMAND_VERSION = '1.1.0-next'; | ||
export const ReleaseCommand = baseConfiguration(new Command()) | ||
.name('release') | ||
.description('Prepare & publish a new release for a glsp component') | ||
.addArgument(new Argument('<component>', 'The glsp component to be released').choices(Component.CLI_CHOICES).argParser(Component.parse)) | ||
.addArgument(new Argument('<releaseType>', 'The release type').choices(ReleaseType.CLI_CHOICES)) | ||
.argument('[customVersion]', 'Custom version number. Will be ignored if the release type is not "custom"', validateVersion) | ||
.option('-f, --force', 'Enable force mode', false) | ||
.option('-d, --checkoutDir <checkoutDir>', 'The git checkout directory', validateDirectory, sh.pwd().stdout) | ||
.option('-b, --branch <branch>', 'The git branch to checkout', 'master') | ||
.option('-v, --verbose', 'Enable verbose (debug) log output', false) | ||
.option('--no-publish', 'Only prepare release but do not publish to github', true) | ||
.option('--draft', 'Publish github releases as drafts', false) | ||
.option( | ||
'--npm-dryRun', | ||
'Execute a npm dry-run for inspection. Publishes to the local npm registry and does not publish to github', | ||
false | ||
) | ||
.action(release); | ||
const app = baseConfiguration(new Command()) | ||
.showSuggestionAfterError(true) | ||
.showHelpAfterError(true) | ||
const app = baseCommand() // | ||
.version(COMMAND_VERSION) | ||
.name('glsp') | ||
.addCommand(ReleaseCommand); | ||
.addCommand(CoverageReportCommand) | ||
.addCommand(ReleaseCommand) | ||
.addCommand(CheckHeaderCommand); | ||
app.parse(process.argv); |
@@ -18,8 +18,6 @@ /******************************************************************************** | ||
import * as sh from 'shelljs'; | ||
import { configureLogger } from './logger'; | ||
export const COMMAND_VERSION = '1.1.0-next'; | ||
export function baseConfiguration(cmd: Command): Command { | ||
return cmd | ||
.version(COMMAND_VERSION) // | ||
// Commander.js utils | ||
export function baseCommand(cmd = new Command()): Command { | ||
return cmd // | ||
.showSuggestionAfterError(true) | ||
@@ -30,7 +28,4 @@ .showHelpAfterError(true) | ||
export interface BaseCmdOptions { | ||
verbose: boolean; | ||
} | ||
export const SH_CONFIG: sh.ExecOptions & { async: false } = { | ||
export type ShellConfig = sh.ExecOptions & { async: false }; | ||
export const SH_CONFIG: ShellConfig = { | ||
async: false, | ||
@@ -41,3 +36,3 @@ fatal: true, | ||
export function getShellConfig(options: Partial<Omit<sh.ExecOptions, 'async'>> = {}): sh.ExecOptions & { async: false } { | ||
export function getShellConfig(options: Partial<Omit<ShellConfig, 'async'>> = {}): ShellConfig { | ||
return { | ||
@@ -49,14 +44,10 @@ ...SH_CONFIG, | ||
export function initialConfiguration(verbose: boolean): void { | ||
export function configureShell(config: Partial<sh.ShellConfig>): void { | ||
sh.config.reset(); | ||
SH_CONFIG.silent = !verbose; | ||
configureLogger(verbose); | ||
getShellConfig({}); | ||
SH_CONFIG.silent = config.silent; | ||
SH_CONFIG.fatal = config.fatal; | ||
} | ||
export function fatalExec( | ||
command: string, | ||
fatalErrorMessage: string, | ||
options: Partial<Omit<sh.ExecOptions, 'async'>> = {} | ||
): sh.ShellString { | ||
export function fatalExec(command: string, fatalErrorMessage: string, options: Partial<Omit<ShellConfig, 'async'>> = {}): sh.ShellString { | ||
const result = sh.exec(command, getShellConfig(options)); | ||
@@ -63,0 +54,0 @@ if (result.code !== 0) { |
/******************************************************************************** | ||
* Copyright (c) 2022 EclipseSource and others. | ||
* Copyright (c) 2022-2022 EclipseSource and others. | ||
* | ||
@@ -17,40 +17,138 @@ * This program and the accompanying materials are made available under the | ||
import { resolve } from 'path'; | ||
import * as sh from 'shelljs'; | ||
import { fatalExec, getShellConfig } from './command-util'; | ||
import { LOGGER } from './logger'; | ||
import { validateGitDirectory } from './validation-util'; | ||
import { getShellConfig } from './command-util'; | ||
export function isGithubCLIAuthenticated(): boolean { | ||
LOGGER.debug('Verify that Github CLI is installed'); | ||
fatalExec('which gh', 'Github CLI is not installed!'); | ||
export function isGitRepository(path?: string): boolean { | ||
cdIfPresent(path); | ||
const isGitRepo = | ||
sh | ||
.exec('git rev-parse --is-inside-work-tree', getShellConfig({ silent: true })) | ||
.stdout.trim() | ||
.toLocaleLowerCase() === 'true'; | ||
return isGitRepo; | ||
} | ||
const status = sh.exec('gh auth status', getShellConfig()); | ||
if (status.code !== 0) { | ||
if (status.stderr.includes('You are not logged into any GitHub hosts')) { | ||
return false; | ||
} | ||
throw new Error(status.stderr); | ||
export function getGitRoot(path?: string): string { | ||
cdIfPresent(path); | ||
const fileString = sh.exec('git rev-parse --show-toplevel', getShellConfig()).stdout.trim(); | ||
return resolve(fileString); | ||
} | ||
export function hasGitChanges(path?: string): boolean { | ||
return getUncommittedChanges(path).length > 0; | ||
} | ||
/** | ||
* Returns the files that have uncommitted changes (staged, not staged and untracked) of a git repository. | ||
* Filepaths are absolute. | ||
*/ | ||
export function getUncommittedChanges(path?: string): string[] { | ||
cdIfPresent(path); | ||
return sh | ||
.exec('git status --porcelain', getShellConfig()) | ||
.stdout.trim() | ||
.split('\n') | ||
.filter(value => value.trim().length !== 0) | ||
.map(fileInfo => | ||
// Extract relative file path from the info string and convert to absolute path | ||
resolve(path ?? process.cwd(), fileInfo.trim().split(' ').pop() ?? '') | ||
); | ||
} | ||
/** | ||
* Returns the files tha have been changed with the last commit (also includes currently staged but uncommitted changes) | ||
* Filepaths are absolute. | ||
*/ | ||
export function getChangesOfLastCommit(path?: string): string[] { | ||
cdIfPresent(path); | ||
return sh | ||
.exec('git diff --name-only HEAD^', getShellConfig()) | ||
.stdout.trim() | ||
.split('\n') | ||
.map(file => resolve(path ?? process.cwd(), file)); | ||
} | ||
/** | ||
* Returns the last modification date of a file (or the last commit) in a git repo. | ||
* @param filePath The file. If undefined the modification date of the last commit will be returned | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @param excludeMessage Only consider commits that don`t match the excludeMessage | ||
* @returns The date or undefined if the file is outside of the git repo. | ||
*/ | ||
export function getLastModificationDate(filePath?: string, repoRoot?: string, excludeMessage?: string): Date | undefined { | ||
cdIfPresent(repoRoot); | ||
const additionalArgs = excludeMessage ? `--grep="${excludeMessage}" --invert-grep` : ''; | ||
const result = sh.exec(`git log -1 ${additionalArgs} --pretty="format:%ci" ${filePath ?? ''}`, getShellConfig()); | ||
if (result.code !== 0) { | ||
return undefined; | ||
} | ||
if (!status.stderr.trim().includes('Logged in to github.com')) { | ||
LOGGER.debug("No user is logged in for host 'github.com'"); | ||
return false; | ||
return new Date(result.stdout.trim()); | ||
} | ||
/** | ||
* Returns the last modification date of a file in a git repo. | ||
* @param filePath The file | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @param excludeMessage Only consider commits that don`t match the excludeMessage | ||
* @returns The date or undefined if the file is outside of the git repo. | ||
*/ | ||
export function getFirstModificationDate(filePath: string, repoRoot?: string, excludeMessage?: string): Date | undefined { | ||
cdIfPresent(repoRoot); | ||
const additionalArgs = excludeMessage ? `--grep="${excludeMessage}" --invert-grep` : ''; | ||
const result = sh.exec(`git log ${additionalArgs} --pretty="format:%ci" --follow ${filePath}`, getShellConfig()); | ||
if (result.code !== 0) { | ||
return undefined; | ||
} | ||
LOGGER.debug('Github CLI is authenticated and ready to use'); | ||
return true; | ||
const datesString = result.stdout.trim(); | ||
if (datesString.length === 0) { | ||
return new Date(); | ||
} | ||
const date = datesString.split('\n').pop(); | ||
return date ? new Date(date) : undefined; | ||
} | ||
export function isGitRepository(path: string): boolean { | ||
LOGGER.debug(`Check if the given directory is a git repo: ${path}`); | ||
sh.cd(path); | ||
return sh.exec('git rev-parse --is-inside-work-tree', getShellConfig()).stdout.trim().toLocaleLowerCase() === 'true'; | ||
export function getFilesOfCommit(commitHash: string, repoRoot?: string): string[] { | ||
cdIfPresent(repoRoot); | ||
const result = sh.exec(`git show --pretty="" --name-only ${commitHash}`, getShellConfig()); | ||
if (result.code !== 0) { | ||
return []; | ||
} | ||
return result.stdout.trim().split('\n'); | ||
} | ||
export function hasGitChanges(path?: string): boolean { | ||
LOGGER.debug(`Check if the directory has git changes: ${asDebugArg(path)}`); | ||
cdIfPresent(path); | ||
return sh.exec('git status --porcelain').stdout.trim().length !== 0; | ||
/** | ||
* Returns the commit hash of the initial commit of the given repository | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @returns The commit hash or undefined if something went wrong. | ||
*/ | ||
export function getInitialCommit(repoRoot?: string): string | undefined { | ||
cdIfPresent(repoRoot); | ||
const result = sh.exec('git log --pretty=oneline --reverse', getShellConfig()); | ||
if (result.code !== 0) { | ||
return undefined; | ||
} | ||
const commits = result.stdout.trim(); | ||
if (commits.length === 0) { | ||
return undefined; | ||
} | ||
return commits.substring(0, commits.indexOf(' ')); | ||
} | ||
export function getLatestRelease(path?: string): string { | ||
LOGGER.debug(`Retrieve latest release from repo: ${asDebugArg(path)}`); | ||
/** | ||
* Returns the commit hash of the first commit for a given file (across renames). | ||
* @param repoRoot The path to the repo root. If undefined the current working directory is used. | ||
* @returns The commit hash or undefined if something went wrong. | ||
*/ | ||
export function getFirstCommit(filePath: string, repoRoot?: string): string | undefined { | ||
cdIfPresent(repoRoot); | ||
const result = sh.exec(`git log --follow --pretty=format:"%H" ${filePath}`, getShellConfig()); | ||
if (result.code !== 0) { | ||
return undefined; | ||
} | ||
return result.stdout.trim().split('\n').pop(); | ||
} | ||
export function getLatestGithubRelease(path?: string): string { | ||
cdIfPresent(path); | ||
@@ -62,3 +160,2 @@ const release = sh.exec('gh release list --exclude-drafts -L 1', getShellConfig()).stdout.trim().split('\t'); | ||
export function getLatestTag(path?: string): string { | ||
LOGGER.debug(`Retrieve latest tag from local repo : ${asDebugArg(path)}`); | ||
cdIfPresent(path); | ||
@@ -69,3 +166,2 @@ return sh.exec('git describe --abbrev=0 --tags', getShellConfig()).stdout.trim(); | ||
export function hasBranch(branch: string, path?: string): boolean { | ||
LOGGER.debug(`Check if branch exists: ${asDebugArg(path)}`); | ||
cdIfPresent(path); | ||
@@ -76,3 +172,2 @@ return sh.exec(`git branch --list ${branch}`, getShellConfig()).stdout.trim().length !== 0; | ||
export function getRemoteUrl(path?: string): string { | ||
LOGGER.debug(`Retrieve remote git url for: ${asDebugArg(path)}`); | ||
cdIfPresent(path); | ||
@@ -84,9 +179,4 @@ return sh.exec('git config --get remote.origin.url', getShellConfig()).stdout.trim(); | ||
if (path) { | ||
validateGitDirectory(path); | ||
sh.cd(path); | ||
} | ||
} | ||
function asDebugArg(path?: string): string { | ||
return path ?? sh.pwd().stdout; | ||
} |
@@ -16,24 +16,43 @@ /******************************************************************************** | ||
********************************************************************************/ | ||
let verbose = false; | ||
export interface Logger extends Pick<Console, LogLevel> { | ||
newLine(): void; | ||
} | ||
export type LogLevel = 'info' | 'debug' | 'error' | 'warn'; | ||
const levels: Record<LogLevel, { threshold: number; color: string }> = { | ||
error: { threshold: 0, color: '\x1b[31m' }, // red | ||
warn: { threshold: 1, color: '\x1b[33m' }, // yellow | ||
info: { threshold: 2, color: '\x1b[0m' }, // default terminal color | ||
debug: { threshold: 3, color: '\x1b[32m' } // green | ||
}; | ||
let levelThreshold: number = levels.info.threshold; | ||
export const LOGGER: Logger = { | ||
info: (message, ...args) => console.info(`[INFO] ${message}`, ...args), | ||
error: (message, ...args) => console.error(`[ERROR] ${message}`, ...args), | ||
warn: (message, ...args) => console.warn(`[WARNING] ${message}`, ...args), | ||
debug: (message, ...args) => { | ||
if (verbose) { | ||
console.log(`[DEBUG] ${message}`, ...args); | ||
} | ||
info: (...args) => log('info', ...args), | ||
error: (...args) => log('error', ...args), | ||
warn: (...args) => log('warn', ...args), | ||
debug: (...args) => log('debug', ...args), | ||
newLine: () => console.log('') | ||
} as const; | ||
function log(level: LogLevel, ...args: any[]): void { | ||
const levelData = levels[level]; | ||
if (levelThreshold < levelData.threshold) { | ||
return; | ||
} | ||
}; | ||
export function configureLogger(isVerbose: boolean): void { | ||
verbose = isVerbose; | ||
console[level](levelData.color, ...args, '\x1b[0m'); | ||
} | ||
export interface Logger { | ||
info(message: string, ...args: any[]): void; | ||
error(message: string, ...args: any[]): void; | ||
warn(message: string, ...args: any[]): void; | ||
debug(message: string, ...args: any[]): void; | ||
export function configureLogger(level: LogLevel): void; | ||
export function configureLogger(verbose: boolean): void; | ||
export function configureLogger(levelOrVerbose: LogLevel | boolean): void { | ||
if (typeof levelOrVerbose === 'boolean') { | ||
const level: LogLevel = levelOrVerbose ? 'debug' : 'info'; | ||
levelThreshold = levels[level].threshold; | ||
} else { | ||
levelThreshold = levels[levelOrVerbose].threshold; | ||
} | ||
} |
@@ -20,3 +20,3 @@ /******************************************************************************** | ||
import * as semver from 'semver'; | ||
import { isGitRepository } from './git-util'; | ||
import { getGitRoot, isGitRepository } from './git-util'; | ||
import { LOGGER } from './logger'; | ||
@@ -37,6 +37,18 @@ export const COMMAND_VERSION = '1.1.0-next'; | ||
export function validateFile(filePath: string, hasToExist = false): string { | ||
const path = resolve(filePath); | ||
if (hasToExist && !fs.existsSync(path)) { | ||
throw new InvalidArgumentError('Not a valid file path!'); | ||
} | ||
if (!fs.statSync(path).isFile()) { | ||
throw new InvalidArgumentError('Not a file!'); | ||
} | ||
return path; | ||
} | ||
export function validateVersion(version: string): string { | ||
LOGGER.debug(`Validate version format of: ${version}`); | ||
if (!semver.valid(version)) { | ||
throw new Error(`Not a valid version: ${version}`); | ||
throw new InvalidArgumentError(`Not a valid version: ${version}`); | ||
} | ||
@@ -49,5 +61,6 @@ return version; | ||
if (!isGitRepository(repoPath)) { | ||
throw new Error('Not a valid git repository'); | ||
throw new InvalidArgumentError('Not a valid git repository'); | ||
} | ||
return repoPath; | ||
return getGitRoot(repository); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 6 instances in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
264451
7
79
3497
90
6
12
60
4
2
+ Addedglob@^8.0.3
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedglob@8.1.0(transitive)
+ Addedminimatch@5.1.6(transitive)