Skip to content

Commit

Permalink
fix(capslockx): versioning
Browse files Browse the repository at this point in the history
versioning
  • Loading branch information
snomiao committed Nov 21, 2024
1 parent a535bcb commit 5881b05
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 226 deletions.
149 changes: 0 additions & 149 deletions DevTools/modulesTips.mjs

This file was deleted.

40 changes: 0 additions & 40 deletions DevTools/versioning.node.mjs

This file was deleted.

104 changes: 67 additions & 37 deletions DevTools/versioning.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,69 @@
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,
import { readFile, writeFile } from "fs/promises";

await versioning();

//
async function versioning() {
// get current version
const { version } = JSON.parse(await readFileUtf8("package.json"));

// console.log('get version', version)

//
(await fileContentReplace(
"./DevTools/setup.iss",
/AppVersion=.*/,
"AppVersion=" + version,
)) || console.warn("setup.iss version not changed");

// update version.txt
(await fileContentReplace("./Core/version.txt", /.*/, version)) ||
console.warn("txt版本号路径版本没有变化");

// update choco package version
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,
"",
);
console.assert(
choco包文 !== 新版本包文,
`警告:Choco包文版本没有变化,当前版本为${version}`,
);
await writeFile(choco包文件路径, 新版本包文);
//
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);
}

console.log("chore(release): " + version);
async function readFileUtf8(f: string) {
return await readFile(f, { encoding: "utf8" });
}
async function fileContentReplace(
filePath: string,
regexp: RegExp,
replacement: string,
) {
const content = await readFileUtf8(filePath);
const newContent = content.replace(regexp, replacement);
const replaced = newContent !== content;
if (replaced) await writeFile(filePath, newContent);
return replaced;
}

0 comments on commit 5881b05

Please sign in to comment.