Skip to content

Commit 529a501

Browse files
authored
feat: add -v command to check info (#74)
* chore: check question store before pull and init if not * feat(common): add -v command to check all info about leetcode-practice
1 parent 464d7d3 commit 529a501

File tree

10 files changed

+43
-12
lines changed

10 files changed

+43
-12
lines changed

bin/lc.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ program
3131
.option('-d, --directory <directory>', 'Set the question directory.')
3232
.option('-l, --language [language]', 'Set/Get the code language of question.')
3333
.option('-a, --all', 'Get all questions.')
34+
.option('-v, --ver', 'Check the version info and some extra info about leetcode-practice.')
3435
.option('-u, --update', 'Check the version to determine whether to update to the latest one.')
3536
.parse(process.argv);
3637

bin/lf.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ program
1818
.option('-e, --easy', 'Use easy mode.')
1919
.option('-d, --directory <directory>', 'Set the question directory.')
2020
.option('-l, --language [language]', 'Set/Get the code language of question.')
21+
.option('-v, --ver', 'Check the version info and some extra info about leetcode-practice.')
2122
.option('-u, --update', 'Check the version to determine whether to update to the latest one.')
2223
.parse(process.argv);
2324

bin/lk.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ program
3434
.option('-e, --easy', 'Use easy mode.')
3535
.option('-d, --directory <directory>', 'Set the question directory.')
3636
.option('-l, --language [language]', 'Set/Get the code language of question.')
37+
.option('-v, --ver', 'Check the version info and some extra info about leetcode-practice.')
3738
.option('-u, --update', 'Check the version to determine whether to update to the latest one.')
3839
.parse(process.argv);
3940

common/constants/question.const.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export const GITHUB_HOST = 'EternalHeartTeam';
1010
// endregion
1111
// region 域名列表
1212
// npm 主域名
13-
export const NPM_URL = 'https://registry.npmjs.org/';
13+
export const NPM_URL = 'https://npmjs.org/';
14+
// npm 仓库域名
15+
export const NPM_REGISTRY_URL = 'https://registry.npmjs.org/';
16+
1417
// github raw 主域名
1518
export const GITHUB_RAW = 'https://raw.githubusercontent.com/';
1619
// github

common/utils/cli-utils/commonMode.js

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { easyLanguageView } from '#common/view/language.view.js';
66
import { logger } from '#common/utils/logger/logger.js';
77
import { rootPath } from '#common/utils/file/getRootPath.js';
88
import { currentEnv } from '#common/utils/etc/checkEnv.js';
9+
import { checkVisionInfo } from '#common/utils/etc/checkVisionInfo.js';
910

1011
/**
1112
* 执行逻辑:
@@ -45,10 +46,15 @@ export async function commonMode(cmdOpts, easyCallback) {
4546
}
4647
process.exit(0);
4748
}
49+
// 简单模式
4850
if (cmdOpts.easy) {
4951
await easyCallback(baseDir);
5052
process.exit(0);
5153
}
54+
if (cmdOpts.ver) {
55+
await checkVisionInfo();
56+
process.exit(0);
57+
}
5258
// 检测更新
5359
if (cmdOpts.update) {
5460
await easyUpdateView();

common/utils/etc/checkVisionInfo.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { DefaultVer, GITHUB_HOST, GITHUB_URL, NPM_URL, PackageName } from '#common/constants/question.const.js';
2+
import { rootPath } from '#common/utils/file/getRootPath.js';
3+
import { logger } from '#common/utils/logger/logger.js';
4+
import { getQuestionLanguage } from '#common/utils/question-handler/questionLanguage.js';
5+
import { url_join } from '#common/utils/http/urlJoin.js';
6+
import { aim } from '#resources/text/aim.js';
7+
8+
/**
9+
* 检查版本信息 加一些额外输出
10+
*/
11+
export async function checkVisionInfo() {
12+
const version = process.env.VERSION ?? DefaultVer;
13+
const location = rootPath;
14+
const lang = await getQuestionLanguage();
15+
logger.info(`version: ${version}\nlanguage: ${lang}\nlocation: file://${location}\ngithub: ${url_join(GITHUB_URL, GITHUB_HOST, PackageName)}\nnpm: ${url_join(NPM_URL, 'package', PackageName)}\n\n${aim}`);
16+
}

common/utils/logger/logger.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class LOGGER {
3434
*/
3535
info(message, ...args) {
3636
if (this.forbidden) return;
37-
console.log(chalk.blue(message, ...args));
37+
console.log(chalk.whiteBright(message, ...args));
3838
}
3939

4040
/**
@@ -44,7 +44,7 @@ class LOGGER {
4444
*/
4545
warn(message, ...args) {
4646
if (this.forbidden) return;
47-
console.log(chalk.yellow(message, ...args));
47+
console.log(chalk.yellowBright(message, ...args));
4848
}
4949

5050
/**
@@ -54,7 +54,7 @@ class LOGGER {
5454
*/
5555
error(message, ...args) {
5656
if (this.forbidden) return;
57-
console.log(chalk.red(message, ...args));
57+
console.log(chalk.redBright(message, ...args));
5858
}
5959
}
6060
const { env = null } = (await getStore('config')) ?? {};

common/utils/update/update.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
33
import { rootPath } from '#common/utils/file/getRootPath.js';
4-
import { GITEE_URL, GITHUB_HOST, GITHUB_RAW, NPM_URL, PackageName } from '#common/constants/question.const.js';
4+
import { GITEE_URL, GITHUB_HOST, GITHUB_RAW, NPM_REGISTRY_URL, PackageName } from '#common/constants/question.const.js';
55
import { url_join } from '#common/utils/http/urlJoin.js';
66
import { fetch_ } from '#common/utils/http/fetch_.js';
77

88
// npm 中的 包地址
9-
const npmUrl = url_join(NPM_URL, PackageName);
9+
const npmUrl = url_join(NPM_REGISTRY_URL, PackageName);
1010
const githubUrl = url_join(GITHUB_RAW, GITHUB_HOST, PackageName, 'master/package.json');
1111
const giteeUrl = url_join(GITEE_URL, GITHUB_HOST, PackageName, 'raw', 'master/package.json');
1212

resources/text/description.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { GITHUB_HOST, PackageName } from '#common/constants/question.const.js';
2+
13
export const description = `
24
A powerful practice platform for leetcode.
35
CLI / Template Project / Plugin, you can create question by any way you like.
4-
See https://github.com/wh131462/leetcode-practice
6+
See https://github.com/${GITHUB_HOST}/${PackageName}
57
`;

resources/text/examples.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Examples:
1313
$ lc -u // Check the version to determine whether to update to the latest one.
1414
$ lc -l // Get the code language of question.
1515
$ lc -l java // Set the code language of question.
16-
$ lc -v // Check the CLI version.
16+
$ lc -a // Fetch all questions from server and store them locally, prepare database for lf command.
17+
$ lc -v // Check the version info and some extra info about leetcode-practice.
1718
$ lc -h // Check the help information.
1819
1920
`;
@@ -33,24 +34,24 @@ Examples:
3334
$ lk -l // Get the code language of question.
3435
$ lk -l java // Set the code language of question.
3536
$ lk -u // Check the version to determine whether to update to the latest one.
36-
$ lk -v // Check the CLI version.
37+
$ lk -v // Check the version info and some extra info about leetcode-practice.
3738
$ lk -h // Display the help information.
3839
3940
`;
4041

4142
export const lfExamples = `
4243
Examples:
4344
# Command with no parameters
44-
45+
nothing...
4546
# Exclusive commands
46-
47+
nothing...
4748
# Other instructions
4849
$ lf -e // Easy mode to check a question.
4950
$ lf -d src // Use the relative path to the source folder.
5051
$ lf -l // Get the code language of question.
5152
$ lf -l java // Set the code language of question.
5253
$ lf -u // Check the version to determine whether to update to the latest one.
53-
$ lf -v // Check the CLI version.
54+
$ lf -v // Check the version info and some extra info about leetcode-practice.
5455
$ lf -h // Display the help information.
5556
5657
`;

0 commit comments

Comments
 (0)