-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli
- Loading branch information
Showing
25 changed files
with
3,607 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": ["@commitlint/config-conventional"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": ["plugin:react/recommended", "standard-with-typescript"], | ||
"overrides": [], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["react"], | ||
"rules": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"trailingComma": "all", | ||
"endOfLine": "lf", | ||
"plugins": [ | ||
"./node_modules/prettier-plugin-packagejson", | ||
"./node_modules/prettier-plugin-organize-imports", | ||
"./node_modules/prettier-plugin-tsconfig" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import callerPath from "caller-path"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import pkg from "rambda"; | ||
const { filter, pipe, sortBy, dissoc } = pkg; | ||
const caller = callerPath({ depth: 1 }); | ||
if (!caller) throw new Error(`Cannot find caller`); | ||
process.chdir( | ||
path.dirname(path.resolve(caller.replace("file:///", ""), "../")), | ||
); | ||
const replaceMapper = (s = "", 表: Record<string, RegExp>) => | ||
Object.entries(表).reduce((s, [k, v]) => s.replace(RegExp(v, v.flags), k), s); | ||
const hkp = (s = "") => | ||
replaceMapper(s, { | ||
// & | ||
"_ _": /&/g, | ||
// sort | ||
"^#": /#\^/g, | ||
"#+": /\+#/g, | ||
"^!": /!\^/g, | ||
"#!": /!#/g, | ||
"+!": /\+!/g, | ||
"+^": /\^\+/g, | ||
// convert | ||
_Win_: /#/g, | ||
_Alt_: /!/g, | ||
_Shift_: /\+/g, | ||
_Ctrl_: /\^/g, | ||
"": /[~\$]/g, | ||
}) | ||
.replace(/_+/g, " ") | ||
.trim() | ||
.replace(/\s+/g, " + "); | ||
// .replace(, "ctrl"+alt) | ||
const 热键列提取 = (文件内容: string) => { | ||
// const 函数列 = 全部提取(文件内容, /^(\S+)\(\)\s*?{/); | ||
const conds = [ | ||
...文件内容.matchAll( | ||
/(?<=\n|^)(#if\w*)[ \t]*(.*)\s*([\s\S]*?)(?:$|(?=#if))/gi, | ||
), | ||
]; | ||
const 热键列 = conds.flatMap(([_, head, rawCond, code]) => { | ||
let trimedCond = rawCond.trim().replace(/;.*/, ""); | ||
const cond = | ||
(head.match(/^#IfWinActive/) && `WinActive("${trimedCond}")`) || | ||
(head.match(/^#IfWinExist/) && `WinExist("${trimedCond}")`) || | ||
trimedCond; | ||
// console.log("条件", 条件, "\n", code.slice(0, 10)); | ||
const ent = pipe( | ||
() => [ | ||
...[...code.matchAll(/^(?!;)(.*?)::\s*?(\S+)\(\)/gm)] | ||
.filter(([, hk]) => !hk.match(/Up$/)) | ||
.map(([, hk, fn]) => [fn, hkp(hk)]), | ||
...[...code.matchAll(/^(?!;)(.*?)::.*?;+\s*?(\S+)$/gm)] | ||
.filter(([, hk]) => !hk.match(/Up$/)) | ||
.map(([, hk, de]) => [de, hkp(hk)]), | ||
], | ||
sortBy(([k, v]) => k), | ||
)(); | ||
if (!Object.entries(Object.fromEntries(ent)).length) { | ||
return []; | ||
} | ||
return [[cond, Object.fromEntries(ent)]]; | ||
}); | ||
return 热键列; | ||
}; | ||
const ModulesPath = "Modules"; | ||
const moduleFiles = await fs.promises.readdir(ModulesPath); | ||
const 条件热键对表列 = ( | ||
await Promise.all( | ||
moduleFiles | ||
.filter((e) => e.match(/.ahk$/)) | ||
.map(async (文件名) => { | ||
return 热键列提取( | ||
await fs.promises.readFile(`${ModulesPath}/${文件名}`, "utf8"), | ||
); | ||
}), | ||
) | ||
).flat(); | ||
const 条件热键表 = (function () { | ||
return 条件热键对表列.reduce((表, [条件, 热键补表]) => { | ||
表[条件] = { ...表[条件], ...热键补表 }; | ||
return 表; | ||
}, {}); | ||
})(); | ||
const 函数条件热键表 = filter((v, k) => !!k.match(/^\S+\(\)$/), 条件热键表); | ||
const 非函数条件热键表 = filter((v, k) => !k.match(/^\S+\(\)$/), 条件热键表); | ||
|
||
console.error(JSON.stringify(dissoc("", 非函数条件热键表), null, 4)); | ||
|
||
const QuickTipsUpdate = async (条件热键表) => { | ||
const prefix = ` msg := ""`; | ||
const ahkFuncTry = | ||
(动作生成函数) => | ||
([条件, 热键表]) => | ||
` | ||
try{ | ||
if (Func("${条件.replace(/\(\)$/, "")}").Call()) {\n | ||
${Object.entries(热键表).map(动作生成函数).join("\n ")} | ||
} | ||
}`; | ||
const ahkTryIf = | ||
(动作生成函数) => | ||
([条件, 热键表]) => | ||
` | ||
try{ | ||
if (${条件 || "True"}) { | ||
${Object.entries(热键表).map(动作生成函数).join("\n ")} | ||
} | ||
}`; | ||
const msgAppend = ([描述, 热键]) => | ||
`msg .= "|\t${热键 + "\t|\t" + 描述}\t|\`n"`; | ||
const content = [ | ||
...Object.entries(非函数条件热键表).map(ahkTryIf(msgAppend)), | ||
...Object.entries(函数条件热键表).map(ahkFuncTry(msgAppend)), | ||
].join("\n"); | ||
const suffix = " return msg"; | ||
const QuickTips = [prefix, content, suffix].join("\n"); | ||
const QuickTipsAHK = "Core/CapsLockX-QuickTips.ahk"; | ||
const src = await fs.promises.readFile(QuickTipsAHK, "utf8"); | ||
const dst = `\uFEFF${src | ||
.replace(/^\uFEFF/, "") | ||
.replace( | ||
/^QuickTips\(\)\s*?{[\s\S]*?^}/gim, | ||
`QuickTips(){\n${QuickTips}\n}`, | ||
)}`; | ||
await fs.promises.writeFile(QuickTipsAHK, dst); | ||
}; | ||
|
||
await QuickTipsUpdate(条件热键表); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { writeFile } from "fs/promises"; | ||
import readFileUtf8 from "read-file-utf8"; | ||
const { version } = JSON.parse(await readFileUtf8("package.json")); | ||
// console.log('get version', version) | ||
// 更新版本号txt | ||
const txt版本号路径 = "./Core/version.txt"; | ||
const txt版本号 = await readFileUtf8(txt版本号路径); | ||
console.assert( | ||
txt版本号 !== version, | ||
`警告:版本号txt文件版本没有变化,当前版本为${version}`, | ||
); | ||
await writeFile(txt版本号路径, version); | ||
|
||
// 更新choco包文件 | ||
const choco包文件路径 = "./DevTools/choco/CapsLockX.nuspec"; | ||
const choco包文 = await readFileUtf8(choco包文件路径); | ||
const CDATA包装 = (文本) => | ||
`<![CDATA[${文本.slice(0, 3888).split(/\r?\n/g).slice(0, -1).join("\n")}]]>`; | ||
const CHANGELOG = CDATA包装(await readFileUtf8("CHANGELOG.MD")).replace( | ||
/[一-龥]+/g, | ||
"", | ||
); | ||
const 新版本包文 = choco包文 | ||
.replace( | ||
/(<version>)(.*?)(<\/version>)/, | ||
(_, $1, $2, $3) => $1 + version + $3, | ||
) | ||
// .replace(/(<description>)([\s\S]*?)(<\/description>)/, (_, $1, $2, $3) => $1 + README + $3) | ||
.replace( | ||
/(<releaseNotes>)([\s\S]*?)(<\/releaseNotes>)/, | ||
(_, $1, $2, $3) => $1 + CHANGELOG + $3, | ||
); | ||
console.assert( | ||
choco包文 !== 新版本包文, | ||
`警告:Choco包文版本没有变化,当前版本为${version}`, | ||
); | ||
await writeFile(choco包文件路径, 新版本包文); | ||
|
||
console.log("chore(release): " + version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: '3' | ||
services: | ||
# code-clx-go: | ||
# build: go/code | ||
# volumes: | ||
# - ./.vscode/.vscode-server/:/root/.vscode-server/ | ||
# - ./.vscode/.go:/go | ||
# - ./go:/code | ||
# ports: | ||
# - 127.0.0.1:35882:8000 | ||
clx-go-build: | ||
build: go | ||
volumes: | ||
- ./.vscode/.go:/go | ||
- ./go:/code |
Oops, something went wrong.