From 34f2a9d74f4f3b36726046e008c34c548876c374 Mon Sep 17 00:00:00 2001 From: Borber Date: Wed, 22 Nov 2023 00:19:49 +0800 Subject: [PATCH] [mod] form lua to deno --- .github/workflows/release.yml | 16 +++++++++------- justfile | 2 +- script/lang.lua | 34 ---------------------------------- script/lang.ts | 30 ++++++++++++++++++++++++++++++ script/tag.lua | 1 - script/tag.ts | 16 ++++++++++++++++ script/util.lua | 16 ---------------- script/version.lua | 22 ---------------------- script/version.ts | 19 +++++++++++++++++++ 9 files changed, 75 insertions(+), 81 deletions(-) delete mode 100644 script/lang.lua create mode 100644 script/lang.ts delete mode 100644 script/tag.lua create mode 100644 script/tag.ts delete mode 100644 script/util.lua delete mode 100644 script/version.lua create mode 100644 script/version.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1dd4e1a..3b9ac9c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,17 +35,19 @@ jobs: version: latest - name: Install frontend dependencies run: pnpm install - - name: Install lua - uses: leafo/gh-actions-lua@v10 - with: - buildCache: false + - name: Install deno + uses: denoland/setup-deno@v1 + with: + deno-version: canary - name: Confirm language env: MATRIX_LANG: ${{ matrix.lang }} - run: | - cd script - lua lang.lua + run: deno run -A script/lang.ts - name: Build uses: tauri-apps/tauri-action@v0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Add tag + env: + MATRIX_LANG: ${{ matrix.lang }} + run: deno run -A script/tag.ts diff --git a/justfile b/justfile index 5a15490..ebb1386 100644 --- a/justfile +++ b/justfile @@ -12,7 +12,7 @@ d: # 更新版本 v: - lua ./script/version.lua + deno run -A script/version.ts # 更新 GUI 依赖 up: diff --git a/script/lang.lua b/script/lang.lua deleted file mode 100644 index f019fa0..0000000 --- a/script/lang.lua +++ /dev/null @@ -1,34 +0,0 @@ -require("util") - -print("Lua script start") - -local lang_short = { "zh", "en", "jp", } -local lang_long = { "Chinese", "English", "Japanese", } - -local Lang = os.getenv("MATRIX_LANG") -local Langs = Util.split(Lang, "_") - -FirstShort = Langs[1] -FirstLong = lang_long[Util.indexOf(lang_short, FirstShort)] -FirstLongLower = string.lower(FirstLong) -SecondShort = Langs[2] -SecondLong = lang_long[Util.indexOf(lang_short, SecondShort)] -SecondLongLower = string.lower(SecondLong) - -Root = io.popen("git rev-parse --show-toplevel"):read("*l") - -File = Root .. "/src-tauri/Cargo.toml" -Context = io.open(File, "r"):read("*a") -Context = string.gsub(Context, 'chinese', FirstLongLower) -Context = string.gsub(Context, 'english', SecondLongLower) -io.open(File, "w"):write(Context) - -File = Root .. "/src-tauri/src/lang.rs" -Context = io.open(File, "r"):read("*a") -Context = string.gsub(Context, 'zh', FirstShort) -Context = string.gsub(Context, 'en', SecondShort) -Context = string.gsub(Context, 'Chinese', FirstLong) -Context = string.gsub(Context, 'English', SecondLong) -io.open(File, "w"):write(Context) - -print("Lua script end") diff --git a/script/lang.ts b/script/lang.ts new file mode 100644 index 0000000..07786ee --- /dev/null +++ b/script/lang.ts @@ -0,0 +1,30 @@ +console.log("Start confirm language"); + +const lang_short = ["zh", "en", "jp",] +const lang_long = ["Chinese", "English", "Japanese",] + +const lang = Deno.env.get("MATRIX_LANG") +const langs = lang!.split("_") + +const first_short = langs[0] +const first_long = lang_long[lang_short.indexOf(first_short)] +const first_long_lower = first_long.toLowerCase() + +const second_short = langs[1] +const second_long = lang_long[lang_short.indexOf(second_short)] +const second_long_lower = second_long.toLowerCase() + +let context = await Deno.readTextFile("src-tauri/Cargo.toml"); +context = context.replace("chinese", first_long_lower); +context = context.replace("english", second_long_lower); +await Deno.writeTextFile("src-tauri/Cargo.toml", context); + +context = await Deno.readTextFile("src-tauri/src/lang.rs"); +context = context.replace("zh", first_short); +context = context.replace("en", second_short); +context = context.replaceAll("Chinese", first_long); +context = context.replaceAll("English", second_long); +await Deno.writeTextFile("src-tauri/src/lang.rs", context); + +console.log("End confirm language"); + diff --git a/script/tag.lua b/script/tag.lua deleted file mode 100644 index 2ffda3e..0000000 --- a/script/tag.lua +++ /dev/null @@ -1 +0,0 @@ --- { "msi", "nsis", "deb", "appimage", "dmg", "macos", } diff --git a/script/tag.ts b/script/tag.ts new file mode 100644 index 0000000..58fa77b --- /dev/null +++ b/script/tag.ts @@ -0,0 +1,16 @@ +const dirs = ["msi", "nsis", "deb", "appimage", "dmg", "macos",] + +const lang = Deno.env.get("MATRIX_LANG") + +for (const dir of dirs) { + if (Deno.statSync(`./${dir}`).isDirectory) { + for await (const file of Deno.readDir(dir)) { + if (file.isFile && file.name.startsWith("tran")) { + let name = file.name + name = name.replace("tran", "tran" + "_" + lang) + Deno.renameSync(`./${dir}/${file.name}`, `./${dir}/${name}`) + console.log(`./${dir}/${name}`) + } + } + } +} \ No newline at end of file diff --git a/script/util.lua b/script/util.lua deleted file mode 100644 index 68713ae..0000000 --- a/script/util.lua +++ /dev/null @@ -1,16 +0,0 @@ -Util = {} - -function Util.split(str, sep) - local sep, res = sep or '%s', {} - string.gsub(str, '[^' .. sep .. ']+', function(x) res[#res + 1] = x end) - return res -end - -function Util.indexOf(array, value) - for i, v in ipairs(array) do - if v == value then - return i - end - end - return nil -end diff --git a/script/version.lua b/script/version.lua deleted file mode 100644 index e2b04cf..0000000 --- a/script/version.lua +++ /dev/null @@ -1,22 +0,0 @@ -Root = io.popen("git rev-parse --show-toplevel"):read("*l") -File = Root .. "/src-tauri/tauri.conf.json" -Context = io.open(File, "r"):read("*a") -LastVersion = string.match(Context, '"version": "([%d+.]*%d+)"') -io.write("Last version: " .. LastVersion .. "\n" .. "NewVersion: ") -NewVersion = io.read() - ---- 更新 tauri.conf.json 文件中的版本号 -Context = string.gsub(Context, '"version": "([%d+.]*%d+)"', '"version": "' .. NewVersion .. '"', 1) -io.open(File, "w"):write(Context) - ---- 更新 Cargo.toml 文件中的版本号 -File = Root .. "/src-tauri/Cargo.toml" -Context = io.open(File, "r"):read("*a") -Context = string.gsub(Context, 'version = "([%d+.]*%d+)"', 'version = "' .. NewVersion .. '"', 1) -io.open(File, "w"):write(Context) - ---- 更新 package.json 文件中的版本号 -File = Root .. "/package.json" -Context = io.open(File, "r"):read("*a") -Context = string.gsub(Context, '"version": "([%d+.]*%d+)"', '"version": "' .. NewVersion .. '"', 1) -io.open(File, "w"):write(Context) diff --git a/script/version.ts b/script/version.ts new file mode 100644 index 0000000..c1d20a3 --- /dev/null +++ b/script/version.ts @@ -0,0 +1,19 @@ +let context = await Deno.readTextFile("src-tauri/tauri.conf.json"); +const last_version = context.match(/"version": "([\d+.]*\d+)"/)?.[1]; + +console.log("Last version: " + last_version); +const new_version = prompt("New version:") + +// 更新 tauri.conf.json 文件中的版本号 +context = context.replace(/"version": "([\d+.]*\d+)"/, `"version": "${new_version}"`); +await Deno.writeTextFile("src-tauri/tauri.conf.json", context); + +// 更新 Cargo.toml 文件中的版本号 +context = await Deno.readTextFile("src-tauri/Cargo.toml"); +context = context.replace(/version = "([\d+.]*\d+)"/, `version = "${new_version}"`); +await Deno.writeTextFile("src-tauri/Cargo.toml", context); + +// 更新 package.json 文件中的版本号 +context = await Deno.readTextFile("package.json"); +context = context.replace(/"version": "([\d+.]*\d+)"/, `"version": "${new_version}"`); +await Deno.writeTextFile("package.json", context);