Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/webgal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "4.5.17",
"scripts": {
"dev": "vite --host --port 3000",
"build": "cross-env NODE_ENV=production tsc && vite build --base=./",
"build": "node scripts/update-engine-version.js && cross-env NODE_ENV=production tsc && vite build --base=./",
"preview": "vite preview",
"lint": "eslint src/** --fix",
"prepublishOnly": "npm run build"
Expand Down
25 changes: 25 additions & 0 deletions packages/webgal/public/webgal-engine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "WebGAL",
"version": "4.5.17",
"type": "official",
"webgalVersion": "4.5.17",
"description": "界面美观、功能强大、易于开发的全新网页端视觉小说引擎",
"descriptions": {
"en": "A brand new web Visual Novel engine with a beautiful interface, powerful features, and easy development",
"ja": "美しいインターフェース、強力な機能、簡単な開発を備えた全く新しいウェブビジュアルノベルエンジン"
},
"author": {
"name": "Mahiru",
"email": "Mahiru_@outlook.com"
},
"license": "MPL-2.0",
"icon": "icons/icon-512.png",
"urls": {
"homepage": "https://openwebgal.com",
"repository": "https://github.com/OpenWebGAL/WebGAL",
"bugs": "https://github.com/OpenWebGAL/WebGAL/issues",
"documentation": "https://docs.openwebgal.com",
"demo": "https://demo.openwebgal.com",
"discord": "https://discord.gg/kPrQkJttJy"
}
}
42 changes: 42 additions & 0 deletions packages/webgal/scripts/update-engine-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node

/**
* 自动更新 webgal-engine.json 中的版本号
* 从 package.json 读取版本号并同步到 webgal-engine.json
*/

const fs = require('fs');
const path = require('path');

// 文件路径
const packageJsonPath = path.resolve(__dirname, '../package.json');
const engineJsonPath = path.resolve(__dirname, '../public/webgal-engine.json');

try {
// 读取 package.json
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const version = packageJson.version;

if (!version) {
console.error('❌ 错误: package.json 中未找到版本号');
process.exit(1);
}

// 读取 webgal-engine.json
const engineJson = JSON.parse(fs.readFileSync(engineJsonPath, 'utf-8'));

// 更新版本号
const oldVersion = engineJson.version;
engineJson.version = version;
engineJson.webgalVersion = version;

// 写回文件(保持格式化)
fs.writeFileSync(engineJsonPath, JSON.stringify(engineJson, null, 2) + '\n', 'utf-8');

console.log('✅ 成功更新引擎描述文件版本号');
console.log(` ${oldVersion} → ${version}`);
console.log(` 文件: ${path.relative(process.cwd(), engineJsonPath)}`);
Comment on lines +29 to +38
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

脚本目前即使版本号没有变化也会执行文件写操作。建议增加一个判断,当版本号相同时,跳过文件写入,并打印提示信息。这样可以避免不必要的文件 I/O 操作,并使脚本在版本未变更时也能提供清晰的输出。

  const oldVersion = engineJson.version;

  if (oldVersion === version && engineJson.webgalVersion === version) {
    console.log(`ℹ️ 引擎描述文件版本号已是最新 (${version}),无需更新。`);
    console.log(`   文件: ${path.relative(process.cwd(), engineJsonPath)}`);
  } else {
    engineJson.version = version;
    engineJson.webgalVersion = version;

    // 写回文件(保持格式化)
    fs.writeFileSync(engineJsonPath, JSON.stringify(engineJson, null, 2) + '\n', 'utf-8');

    console.log('✅ 成功更新引擎描述文件版本号');
    console.log(`   ${oldVersion}${version}`);
    console.log(`   文件: ${path.relative(process.cwd(), engineJsonPath)}`);
  }

} catch (error) {
console.error('❌ 更新版本号失败:', error.message);
process.exit(1);
}