mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-02-21 00:44:41 +08:00
@@ -3,28 +3,34 @@
|
||||
// AUTO-GENERATED SCRIPT: Converts config.json to TypeScript definition.
|
||||
// Usage: node scripts/convert-config.js
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname } from "path";
|
||||
|
||||
// Get __dirname equivalent for ES modules
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// Resolve project root (one level up from scripts folder)
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
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');
|
||||
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 已删除');
|
||||
console.log("旧的 runtime.ts 已删除");
|
||||
}
|
||||
|
||||
// Read and parse config.json
|
||||
let rawConfig;
|
||||
try {
|
||||
rawConfig = fs.readFileSync(configPath, 'utf8');
|
||||
rawConfig = fs.readFileSync(configPath, "utf8");
|
||||
} catch (err) {
|
||||
console.error(`无法读取 ${configPath}:`, err);
|
||||
process.exit(1);
|
||||
@@ -34,7 +40,7 @@ let config;
|
||||
try {
|
||||
config = JSON.parse(rawConfig);
|
||||
} catch (err) {
|
||||
console.error('config.json 不是有效的 JSON:', err);
|
||||
console.error("config.json 不是有效的 JSON:", err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -53,9 +59,9 @@ if (!fs.existsSync(libDir)) {
|
||||
|
||||
// Write to runtime.ts
|
||||
try {
|
||||
fs.writeFileSync(newRuntimePath, tsContent, 'utf8');
|
||||
console.log('已生成 src/lib/runtime.ts');
|
||||
fs.writeFileSync(newRuntimePath, tsContent, "utf8");
|
||||
console.log("已生成 src/lib/runtime.ts");
|
||||
} catch (err) {
|
||||
console.error('写入 runtime.ts 失败:', err);
|
||||
console.error("写入 runtime.ts 失败:", err);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -2,50 +2,56 @@
|
||||
/* eslint-disable */
|
||||
// 根据 SITE_NAME 动态生成 manifest.json
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname } from "path";
|
||||
|
||||
// Get __dirname equivalent for ES modules
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// 获取项目根目录
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
const publicDir = path.join(projectRoot, 'public');
|
||||
const manifestPath = path.join(publicDir, 'manifest.json');
|
||||
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';
|
||||
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",
|
||||
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": [
|
||||
icons: [
|
||||
{
|
||||
"src": "/icons/icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
src: "/icons/icon-192x192.png",
|
||||
sizes: "192x192",
|
||||
type: "image/png",
|
||||
},
|
||||
{
|
||||
"src": "/icons/icon-256x256.png",
|
||||
"sizes": "256x256",
|
||||
"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-384x384.png",
|
||||
sizes: "384x384",
|
||||
type: "image/png",
|
||||
},
|
||||
{
|
||||
"src": "/icons/icon-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
]
|
||||
src: "/icons/icon-512x512.png",
|
||||
sizes: "512x512",
|
||||
type: "image/png",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -58,6 +64,6 @@ try {
|
||||
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);
|
||||
console.error("❌ Error generating manifest.json:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user