Skip to content

Commit 9240e84

Browse files
committed
feat:add -l language
1 parent 5b306a2 commit 9240e84

File tree

9 files changed

+21
-22
lines changed

9 files changed

+21
-22
lines changed

bin/lc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import {description} from "#resources/text/description.js";
2020
import {easyUpdateView} from "#common/view/update.view.js";
2121
import {getQuestionLanguage} from "#common/utils/question-handler/questionLanguage.js";
2222
import {easyLanguageView} from "#common/view/language.view.js";
23+
import {DefaultVer} from "#common/constants/question.const.js";
2324

24-
const version = process.env.VERSION??'0.0.0';
25+
const version = process.env.VERSION??DefaultVer;
2526
program
2627
.version(version)
2728
.description(`${description}\n${artFontLogo}\n${aim}`)

bin/lf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {love} from "#resources/text/love.js";
88
import {easyUpdateView} from "#common/view/update.view.js";
99
import {easyLanguageView} from "#common/view/language.view.js";
1010
import {getQuestionLanguage} from "#common/utils/question-handler/questionLanguage.js";
11+
import {getCode} from "#common/utils/question-handler/getCode.js";
12+
import {DefaultVer} from "#common/constants/question.const.js";
1113

12-
const version = process.env.VERSION ?? '0.0.0';
14+
const version = process.env.VERSION ?? DefaultVer;
1315
program
1416
.version(version)
1517
.description(`${description}\n${artFontLogo}\n${aim}`)

bin/lk.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import {getQuestionChineseName} from "#common/utils/question-handler/getQuestion
1616
import {easyCheckView} from "#common/view/check.view.js";
1717
import {description} from "#resources/text/description.js";
1818
import {easyUpdateView} from "#common/view/update.view.js";
19+
import {getQuestionFileExtension} from "#common/utils/question-handler/questionLanguage.js";
20+
import {DefaultVer} from "#common/constants/question.const.js";
1921

20-
const version = process.env.VERSION ?? '0.0.0';
22+
const version = process.env.VERSION ?? DefaultVer;
2123
program
2224
.version(version)
2325
.description(`${description}\n${artFontLogo}\n${aim}`)
@@ -67,7 +69,7 @@ if(cmdOpts.update){
6769
}
6870
// 检测函数
6971
const check = async (mode, question) => {
70-
const filePath = path.join(baseDir, getQuestionFileName(question), 'index.js');
72+
const filePath = path.join(baseDir, getQuestionFileName(question), `question${getQuestionFileExtension(question.lang)}`);
7173
if (!fs.existsSync(filePath)) {
7274
console.log(`文件[${filePath}]不存在,请确保已经创建!`)
7375
} else {

common/constants/question.const.js

Whitespace-only changes.

common/utils/question-getter/getQuestionCodeList.js

Whitespace-only changes.

common/utils/question-handler/getCode.js

Whitespace-only changes.

common/utils/question-handler/getJSCode.js

-15
This file was deleted.

common/utils/question-handler/questionLanguage.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {getStore, setStore} from "#common/utils/store/controller/store.js";
2+
import {DefaultLang} from "#common/constants/question.const.js";
23

34
/**
45
* 设置编程主语言
@@ -11,7 +12,15 @@ export const setQuestionLanguage = async (lang) => {
1112
*/
1213
export const getQuestionLanguage = async ()=>{
1314
const lang = await getStore("language")
14-
return lang ?? "javascript";
15+
return lang ?? DefaultLang;
16+
}
17+
/**
18+
* 获取文件后缀
19+
* @param lang
20+
*/
21+
export const getQuestionFileExtension = (lang)=>{
22+
const detail = LANGUAGES.find(o=>o.name.toLowerCase()===lang.toLowerCase());
23+
return detail?.extension ?? '.js'
1524
}
1625
/**
1726
* 语言
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export function getCodeDetailJson(todayQuestionEnName) {
1+
export function getCodeListJson(slug) {
22
return {
33
headers: { "content-type": "application/json" },
4-
body: `{"query":"\\n query questionEditorData($titleSlug: String!) {\\n question(titleSlug: $titleSlug) {\\n questionId\\n questionFrontendId\\n codeSnippets {\\n lang\\n langSlug\\n code\\n }\\n envInfo\\n enableRunCode\\n hasFrontendPreview\\n frontendPreviews\\n }\\n}\\n ","variables":{"titleSlug":"${todayQuestionEnName}"},"operationName":"questionEditorData"}`,
4+
body: `{"query":"\\n query questionEditorData($titleSlug: String!) {\\n question(titleSlug: $titleSlug) {\\n questionId\\n questionFrontendId\\n codeSnippets {\\n lang\\n langSlug\\n code\\n }\\n envInfo\\n enableRunCode\\n hasFrontendPreview\\n frontendPreviews\\n }\\n}\\n ","variables":{"titleSlug":"${slug}"},"operationName":"questionEditorData"}`,
55
method: 'POST',
66
};
77
}

0 commit comments

Comments
 (0)