Skip to content

Commit

Permalink
fix(capslockx): cli
Browse files Browse the repository at this point in the history
cli
  • Loading branch information
snomiao committed Apr 16, 2023
1 parent 09e5f13 commit 9fd4500
Show file tree
Hide file tree
Showing 25 changed files with 3,607 additions and 0 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": ["@commitlint/config-conventional"] }
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
15 changes: 15 additions & 0 deletions .eslintrc.json
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": {}
}
11 changes: 11 additions & 0 deletions .prettierrc.json
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"
]
}
130 changes: 130 additions & 0 deletions DevTools/modulesTips.ts
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(条件热键表);
39 changes: 39 additions & 0 deletions DevTools/versioning.ts
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);
15 changes: 15 additions & 0 deletions docker-compose.yml
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
Loading

0 comments on commit 9fd4500

Please sign in to comment.