Skip to content

Commit

Permalink
feat: add helper cli
Browse files Browse the repository at this point in the history
  • Loading branch information
uanid committed Jun 12, 2024
1 parent efdbcad commit fb28a0e
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 37 deletions.
27 changes: 27 additions & 0 deletions lib/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node
import {Command} from "commander";
import {addMergeCommand} from "./cli-merge.js";

Check failure on line 3 in lib/cli.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './cli-merge.js' or its corresponding type declarations.

Check failure on line 3 in lib/cli.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './cli-merge.js' or its corresponding type declarations.

Check failure on line 3 in lib/cli.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './cli-merge.js' or its corresponding type declarations.
import chalk from "chalk";

const command = new Command();
addMergeCommand(command);

command.hook('preAction', (thisCommand: Command, actionCommand: Command) => {
performance.mark('command-preaction');
console.log(chalk.whiteBright.bold(`semantic-release-gitlabmonorepo-helper ${actionCommand.name()} ${actionCommand.args.join(' ')}`) + ' ' + chalk.gray(thisCommand.version()));
});
command.hook('postAction', (_thisCommand: Command, _actionCommand: Command) => {
performance.mark('command-postaction');
const result = performance.measure('command', 'command-preaction', 'command-postaction');

let roundedDuration: string;
if (result.duration > 2000) {
roundedDuration = (Math.round(result.duration) / 1000).toFixed(2) + 's';
} else {
roundedDuration = result.duration.toFixed(2) + 'ms';
}
// 명령을 실행하는데 걸린 시간을 로그로 남긴다.
console.log(chalk.green('Execution time') + ' ' + chalk.gray(roundedDuration));
});

command.parse();
15 changes: 7 additions & 8 deletions lib/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import urlJoin from "url-join";
import axios, {type AxiosInstance, type InternalAxiosRequestConfig} from "axios";

export interface UserConfig {
gitlabUrl: string | undefined;
projectId: string | undefined;
assets: Assets[] | undefined;
commitTitle: string | undefined;
branchName: string | undefined;
gitlabUrl?: string | undefined;
projectId?: string | undefined;
assets?: Assets[] | undefined;
commitTitle?: string | undefined;
branchName?: string | undefined;
}

export interface Assets {
Expand Down Expand Up @@ -52,13 +52,12 @@ export function resolvePluginConfig(userConfig: UserConfig, context: VerifyCondi
return assertPluginConfig(pluginConfig);
}

function getOriginUrl(context: VerifyConditionsContext): string {
context.logger.log('Getting origin url via command call $ git remote get-url origin');
export function getOriginUrl(context: VerifyConditionsContext): string {
const buf = execSync('git remote get-url origin', {cwd: context.cwd, encoding: 'utf-8'});
return buf.toString().trim();
}

function getProjectId(origin: string): string {
export function getProjectId(origin: string): string {
const parsed = gitUrlParse(origin);

let path = parsed.pathname;
Expand Down
86 changes: 57 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@
},
"dependencies": {
"axios": "^1.7.2",
"chalk": "^5.3.0",
"commander": "^12.1.0",
"git-url-parse": "^14.0.0",
"lodash-es": "^4.17.21",
"typia": "^6.0.6",
"url-join": "^5.0.0"
},
"bin": {
"semantic-release-gitlabmonorepo-helper": "./dist/cli.js"
},
"files": [
"bin/*",
"dist/*",
"lib/*",
"package.json",
Expand Down

0 comments on commit fb28a0e

Please sign in to comment.