Skip to content

Commit

Permalink
[mod] form lua to deno
Browse files Browse the repository at this point in the history
  • Loading branch information
Borber committed Nov 21, 2023
1 parent 1ce28eb commit 34f2a9d
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 81 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ d:

# 更新版本
v:
lua ./script/version.lua
deno run -A script/version.ts

# 更新 GUI 依赖
up:
Expand Down
34 changes: 0 additions & 34 deletions script/lang.lua

This file was deleted.

30 changes: 30 additions & 0 deletions script/lang.ts
Original file line number Diff line number Diff line change
@@ -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");

1 change: 0 additions & 1 deletion script/tag.lua

This file was deleted.

16 changes: 16 additions & 0 deletions script/tag.ts
Original file line number Diff line number Diff line change
@@ -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}`)
}
}
}
}
16 changes: 0 additions & 16 deletions script/util.lua

This file was deleted.

22 changes: 0 additions & 22 deletions script/version.lua

This file was deleted.

19 changes: 19 additions & 0 deletions script/version.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 34f2a9d

Please sign in to comment.