Update
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable */
|
||||
// AUTO-GENERATED SCRIPT: Converts config.json to TypeScript definition.
|
||||
// Usage: node scripts/convert-config.js
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Resolve project root (one level up from scripts folder)
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
|
||||
// Paths
|
||||
const configPath = path.join(projectRoot, 'config.json');
|
||||
const libDir = path.join(projectRoot, 'src', 'lib');
|
||||
const oldRuntimePath = path.join(libDir, 'runtime.ts');
|
||||
const newRuntimePath = path.join(libDir, 'runtime.ts');
|
||||
|
||||
// Delete the old runtime.ts file if it exists
|
||||
if (fs.existsSync(oldRuntimePath)) {
|
||||
fs.unlinkSync(oldRuntimePath);
|
||||
console.log('旧的 runtime.ts 已删除');
|
||||
}
|
||||
|
||||
// Read and parse config.json
|
||||
let rawConfig;
|
||||
try {
|
||||
rawConfig = fs.readFileSync(configPath, 'utf8');
|
||||
} catch (err) {
|
||||
console.error(`无法读取 ${configPath}:`, err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let config;
|
||||
try {
|
||||
config = JSON.parse(rawConfig);
|
||||
} catch (err) {
|
||||
console.error('config.json 不是有效的 JSON:', err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Prepare TypeScript file content
|
||||
const tsContent =
|
||||
`// 该文件由 scripts/convert-config.js 自动生成,请勿手动修改\n` +
|
||||
`/* eslint-disable */\n\n` +
|
||||
`export const config = ${JSON.stringify(config, null, 2)} as const;\n\n` +
|
||||
`export type RuntimeConfig = typeof config;\n\n` +
|
||||
`export default config;\n`;
|
||||
|
||||
// Ensure lib directory exists
|
||||
if (!fs.existsSync(libDir)) {
|
||||
fs.mkdirSync(libDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Write to runtime.ts
|
||||
try {
|
||||
fs.writeFileSync(newRuntimePath, tsContent, 'utf8');
|
||||
console.log('已生成 src/lib/runtime.ts');
|
||||
} catch (err) {
|
||||
console.error('写入 runtime.ts 失败:', err);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable */
|
||||
// 根据 SITE_NAME 动态生成 manifest.json
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 获取项目根目录
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
const publicDir = path.join(projectRoot, 'public');
|
||||
const manifestPath = path.join(publicDir, 'manifest.json');
|
||||
|
||||
// 从环境变量获取站点名称
|
||||
const siteName = process.env.SITE_NAME || 'MoonTV';
|
||||
|
||||
// manifest.json 模板
|
||||
const manifestTemplate = {
|
||||
"name": siteName,
|
||||
"short_name": siteName,
|
||||
"description": "影视聚合",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#000000",
|
||||
"apple-mobile-web-app-capable": "yes",
|
||||
"apple-mobile-web-app-status-bar-style": "black",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icons/icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/icons/icon-256x256.png",
|
||||
"sizes": "256x256",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/icons/icon-384x384.png",
|
||||
"sizes": "384x384",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/icons/icon-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
try {
|
||||
// 确保 public 目录存在
|
||||
if (!fs.existsSync(publicDir)) {
|
||||
fs.mkdirSync(publicDir, { recursive: true });
|
||||
}
|
||||
|
||||
// 写入 manifest.json
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifestTemplate, null, 2));
|
||||
console.log(`✅ Generated manifest.json with site name: ${siteName}`);
|
||||
} catch (error) {
|
||||
console.error('❌ Error generating manifest.json:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable */
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 获取当前时间并格式化为 YYYYMMDDHHMMSS 格式
|
||||
function generateVersion() {
|
||||
const now = new Date();
|
||||
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
|
||||
const version = `${year}${month}${day}${hours}${minutes}${seconds}`;
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
// 生成版本号
|
||||
const currentVersion = generateVersion();
|
||||
|
||||
// 读取现有的 version.ts 文件
|
||||
const versionFilePath = path.join(__dirname, '..', 'src', 'lib', 'version.ts');
|
||||
let fileContent = fs.readFileSync(versionFilePath, 'utf8');
|
||||
|
||||
// 使用正则表达式替换 CURRENT_VERSION 的值
|
||||
const updatedContent = fileContent.replace(
|
||||
/const CURRENT_VERSION = '.*?'/,
|
||||
`const CURRENT_VERSION = '${currentVersion}'`
|
||||
);
|
||||
|
||||
// 写入更新后的内容
|
||||
fs.writeFileSync(versionFilePath, updatedContent, 'utf8');
|
||||
|
||||
// 将版本号写入根目录下的 VERSION.txt 文件
|
||||
const versionTxtPath = path.join(__dirname, '..', 'VERSION.txt');
|
||||
fs.writeFileSync(versionTxtPath, currentVersion, 'utf8');
|
||||
|
||||
console.log(`版本号已更新为: ${currentVersion}`);
|
||||
console.log(`文件已更新: ${versionFilePath}`);
|
||||
console.log(`VERSION.txt 已更新: ${versionTxtPath}`);
|
||||
Reference in New Issue
Block a user