同步模板维护脚本的资源路径
This commit is contained in:
@@ -3,9 +3,10 @@ const path = require('path');
|
||||
|
||||
const repoRoot = path.join(__dirname, '..');
|
||||
const tsSourcePath = path.join(repoRoot, 'src', 'config', 'systemSubtitleTemplates.ts');
|
||||
const packagingResourceRoot = path.join(repoRoot, 'packaging', 'resources');
|
||||
const runtimeDatabasePath = path.join(repoRoot, 'data', 'database.db');
|
||||
const runtimeExportPath = path.join(repoRoot, 'build', 'runtime-system-subtitle-templates.json');
|
||||
const previewAssetDir = path.join(repoRoot, 'electron', 'resources', 'extra', 'common', 'cover-templates');
|
||||
const previewAssetDir = path.join(packagingResourceRoot, 'common', 'cover-templates');
|
||||
const packagedPreviewPrefix = 'extra/common/cover-templates';
|
||||
const inlineTemplateIds = new Set([
|
||||
'template_system_11',
|
||||
@@ -27,12 +28,12 @@ const defaultTriggeredSoundConfig = {
|
||||
|
||||
const systemTemplateJsonPaths = [
|
||||
path.join(repoRoot, 'electron', 'config', 'system-templates.json'),
|
||||
path.join(repoRoot, 'electron', 'resources', 'extra', 'common', 'config', 'system-templates.json'),
|
||||
path.join(packagingResourceRoot, 'common', 'config', 'system-templates.json'),
|
||||
];
|
||||
|
||||
const defaultSubtitleTemplateJsonPaths = [
|
||||
path.join(repoRoot, 'electron', 'config', 'default-subtitle-templates.json'),
|
||||
path.join(repoRoot, 'electron', 'resources', 'extra', 'common', 'config', 'default-subtitle-templates.json'),
|
||||
path.join(packagingResourceRoot, 'common', 'config', 'default-subtitle-templates.json'),
|
||||
];
|
||||
|
||||
const isAbsoluteLocalPath = (value) => /^[a-zA-Z]:[\\/]/.test(value) || value.startsWith('\\\\');
|
||||
@@ -148,6 +149,19 @@ const readTemplatesFromTsSource = () => {
|
||||
return templates;
|
||||
};
|
||||
|
||||
const readTemplatesFromJsonFile = (filePath) => {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const json = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
const templates = json.subtitleTemplates;
|
||||
if (!Array.isArray(templates) || templates.length !== 16) {
|
||||
return null;
|
||||
}
|
||||
return templates;
|
||||
};
|
||||
|
||||
const readCanonicalTemplates = () => {
|
||||
const dbTemplates = readTemplatesFromRuntimeDatabase();
|
||||
if (dbTemplates) {
|
||||
@@ -157,6 +171,16 @@ const readCanonicalTemplates = () => {
|
||||
};
|
||||
}
|
||||
|
||||
for (const filePath of systemTemplateJsonPaths) {
|
||||
const jsonTemplates = readTemplatesFromJsonFile(filePath);
|
||||
if (jsonTemplates) {
|
||||
return {
|
||||
source: filePath,
|
||||
templates: jsonTemplates.map(normalizeTemplateForPackaging),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
source: 'ts-source',
|
||||
templates: readTemplatesFromTsSource().map(normalizeTemplateForPackaging),
|
||||
|
||||
Reference in New Issue
Block a user