-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Xicheng Guo
committed
Aug 2, 2024
1 parent
1dd9a8d
commit f5ce682
Showing
26 changed files
with
109 additions
and
19 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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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,50 @@ | ||
import { releaseFile } from "../release-file"; | ||
import fs from "node:fs"; | ||
|
||
describe("Release File", () => { | ||
it("目录不存在", () => { | ||
expect(() => | ||
releaseFile({ apkPath: "scripts/__tests__/examples/not-exist", releasePath: "scripts/__tests__/examples/dist" }) | ||
).toThrow("apk path and release path should exist"); | ||
expect(() => | ||
releaseFile({ | ||
apkPath: "scripts/__tests__/examples/apk-multiple", | ||
releasePath: "scripts/__tests__/examples/not-exist", | ||
}) | ||
).toThrow("apk path and release path should exist"); | ||
}); | ||
it("apk 目录存在多个文件", () => { | ||
expect(() => | ||
releaseFile({ | ||
apkPath: "scripts/__tests__/examples/apk-multiple", | ||
releasePath: "scripts/__tests__/examples/dist", | ||
}) | ||
).toThrow("apk path should contain only one file"); | ||
}); | ||
it("apk 的文件不是以 .apk 结尾", () => { | ||
expect(() => | ||
releaseFile({ apkPath: "scripts/__tests__/examples/apk-not-apk", releasePath: "scripts/__tests__/examples/dist" }) | ||
).toThrow("apk file should end with .apk"); | ||
}); | ||
it("apk 的文件名不包含版本号", () => { | ||
expect(() => | ||
releaseFile({ | ||
apkPath: "scripts/__tests__/examples/apk-no-version", | ||
releasePath: "scripts/__tests__/examples/dist", | ||
}) | ||
).toThrow("apk file should contain version number"); | ||
}); | ||
it("apk 的文件名包含版本号", () => { | ||
expect(() => | ||
releaseFile({ | ||
apkPath: "scripts/__tests__/examples/apk-has-version", | ||
releasePath: "scripts/__tests__/examples/dist", | ||
}) | ||
).not.toThrow(); | ||
const apkVersion = fs.readFileSync("scripts/__tests__/examples/dist/latest_version.txt", "utf-8"); | ||
expect(apkVersion).toBe("2.1.1"); | ||
expect(() => fs.accessSync("scripts/__tests__/examples/dist/SKIP-v2.1.1.apk")).not.toThrow(); | ||
expect(() => fs.accessSync("scripts/__tests__/examples/dist/skip_config.yaml")).not.toThrow(); | ||
expect(() => fs.accessSync("scripts/__tests__/examples/dist/skip_config_v2.yaml")).not.toThrow(); | ||
}); | ||
}); |
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
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,13 @@ | ||
(() => { | ||
const args = process.argv.slice(2); | ||
const params: Record<string, string> = {}; | ||
args.forEach((arg) => { | ||
const [key, value] = arg.split("="); | ||
params[key.substring(2)] = value; | ||
}); | ||
|
||
if (params.func === "release-file") { | ||
const { releaseFile } = require("./release-file"); | ||
releaseFile(params); | ||
} | ||
})(); |
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,40 @@ | ||
import fs from "node:fs"; | ||
|
||
interface ReleaseFileOptions { | ||
apkPath: string; | ||
releasePath: string; | ||
} | ||
|
||
export function releaseFile(options: ReleaseFileOptions) { | ||
const { apkPath, releasePath } = options; | ||
if (!fs.existsSync(apkPath) || !fs.existsSync(releasePath)) { | ||
throw new Error("apk path and release path should exist"); | ||
} | ||
|
||
const apkFileList = fs.readdirSync(apkPath); | ||
|
||
if (apkFileList.length !== 1) { | ||
throw new Error("apk path should contain only one file"); | ||
} | ||
|
||
const apkFile = apkFileList[0]; | ||
if (!apkFile.endsWith(".apk")) { | ||
throw new Error("apk file should end with .apk"); | ||
} | ||
|
||
const regex = /SKIP-v(\d+\.\d+\.\d+)\.apk/; | ||
const match = apkFile.match(regex); | ||
if (!match) { | ||
throw new Error("apk file should contain version number"); | ||
} | ||
|
||
const apkVersion = match[1]; | ||
|
||
// 写入 apkVersion 到 releasePath | ||
fs.writeFileSync(`${releasePath}/latest_version.txt`, apkVersion); | ||
// 复制 apkFile 到 releasePath | ||
fs.copyFileSync(`${apkPath}/${apkFile}`, `${releasePath}/${apkFile}`); | ||
// 复制 config | ||
fs.copyFileSync("app/src/main/assets/skip_config.yaml", `${releasePath}/skip_config.yaml`); | ||
fs.copyFileSync("app/src/main/assets/skip_config_v2.yaml", `${releasePath}/skip_config_v2.yaml`); | ||
} |