-
-
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.
versioning
- Loading branch information
Showing
3 changed files
with
67 additions
and
226 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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; | ||
} |