fix: 去除 migrate-config.js 久配置迁移工具的支持

This commit is contained in:
coolzr
2025-10-24 01:26:32 +08:00
parent ad3cba549b
commit 6359829298
2 changed files with 0 additions and 162 deletions

View File

@@ -10,7 +10,6 @@
"clean": "node ./scripts/clean.js",
"build": "npm run clean && npm run generate",
"restructure": "node restructure.js",
"migrate-config": "node src/migrate-config.js",
"import-bookmarks": "node src/bookmark-processor.js"
},
"keywords": [

View File

@@ -1,161 +0,0 @@
/**
* MeNav 配置迁移工具
* 将旧版双文件配置转换为新版模块化配置
*/
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
// 配置文件路径
const LEGACY_CONFIG_FILE = 'config.yml';
const LEGACY_USER_CONFIG_FILE = 'config.user.yml';
const LEGACY_BOOKMARKS_FILE = 'bookmarks.yml';
const LEGACY_USER_BOOKMARKS_FILE = 'bookmarks.user.yml';
// 模块化配置目录
const CONFIG_USER_DIR = 'config/user';
const CONFIG_USER_PAGES_DIR = path.join(CONFIG_USER_DIR, 'pages');
/**
* 迁移旧式配置文件到模块化格式
*/
function migrateConfiguration() {
console.log('MeNav 配置迁移工具');
// 检查是否存在旧式配置文件
const hasUserConfig = fs.existsSync(LEGACY_USER_CONFIG_FILE);
const hasDefaultConfig = fs.existsSync(LEGACY_CONFIG_FILE);
const hasUserBookmarks = fs.existsSync(LEGACY_USER_BOOKMARKS_FILE);
const hasDefaultBookmarks = fs.existsSync(LEGACY_BOOKMARKS_FILE);
if (!hasUserConfig && !hasDefaultConfig && !hasUserBookmarks && !hasDefaultBookmarks) {
console.log('未找到任何旧式配置文件,无需迁移。');
return;
}
// 确保目标目录存在
if (!fs.existsSync(CONFIG_USER_DIR)) {
fs.mkdirSync(CONFIG_USER_DIR, { recursive: true });
}
if (!fs.existsSync(CONFIG_USER_PAGES_DIR)) {
fs.mkdirSync(CONFIG_USER_PAGES_DIR, { recursive: true });
}
// 优先使用用户配置,如果不存在则使用默认配置
const configFile = hasUserConfig ? LEGACY_USER_CONFIG_FILE : hasDefaultConfig ? LEGACY_CONFIG_FILE : null;
// 迁移主配置文件
if (configFile) {
try {
const configContent = fs.readFileSync(configFile, 'utf8');
const config = yaml.load(configContent);
// 提取站点配置
if (config.site) {
const siteConfig = {
title: config.site.title || '',
description: config.site.description || '',
author: config.site.author || '',
favicon: config.site.favicon || 'favicon.ico'
};
// 添加字体配置
if (config.fonts) {
siteConfig.fonts = config.fonts;
}
// 添加个人资料配置
if (config.profile) {
siteConfig.profile = config.profile;
}
// 添加社交媒体配置
if (config.social && config.social.length > 0) {
siteConfig.social = config.social;
}
// 写入站点配置
const siteYaml = yaml.dump(siteConfig, { indent: 2, lineWidth: -1, quotingType: '"' });
fs.writeFileSync(
path.join(CONFIG_USER_DIR, 'site.yml'),
`# 由migrate-config.js从${configFile}迁移\n# 生成于 ${new Date().toISOString()}\n\n${siteYaml}`,
'utf8'
);
}
// 提取导航配置
if (config.navigation && config.navigation.length > 0) {
const navigationYaml = yaml.dump(config.navigation, { indent: 2, lineWidth: -1, quotingType: '"' });
fs.writeFileSync(
path.join(CONFIG_USER_DIR, 'navigation.yml'),
`# 由migrate-config.js从${configFile}迁移\n# 生成于 ${new Date().toISOString()}\n\n${navigationYaml}`,
'utf8'
);
}
// 提取所有页面配置
const pageIds = config.navigation ? config.navigation.map(nav => nav.id) : [];
pageIds.forEach(pageId => {
if (config[pageId]) {
const pageConfig = { ...config[pageId] };
// 特殊处理首页的categories
if (pageId === 'home' && !pageConfig.categories && config.categories) {
pageConfig.categories = config.categories;
}
const pageYaml = yaml.dump(pageConfig, { indent: 2, lineWidth: -1, quotingType: '"' });
fs.writeFileSync(
path.join(CONFIG_USER_PAGES_DIR, `${pageId}.yml`),
`# 由migrate-config.js从${configFile}迁移\n# 生成于 ${new Date().toISOString()}\n\n${pageYaml}`,
'utf8'
);
}
});
// 如果首页不在pageIds中但存在categories创建一个home.yml
if (!pageIds.includes('home') && config.categories) {
const homeConfig = {
title: '我的导航',
subtitle: '个人收藏网址',
categories: config.categories
};
const homeYaml = yaml.dump(homeConfig, { indent: 2, lineWidth: -1, quotingType: '"' });
fs.writeFileSync(
path.join(CONFIG_USER_PAGES_DIR, 'home.yml'),
`# 由migrate-config.js从${configFile}迁移\n# 生成于 ${new Date().toISOString()}\n\n${homeYaml}`,
'utf8'
);
}
} catch (error) {
console.error(`迁移配置文件${configFile}时出错:`, error);
}
}
// 迁移书签配置文件
const bookmarksFile = hasUserBookmarks ? LEGACY_USER_BOOKMARKS_FILE : hasDefaultBookmarks ? LEGACY_BOOKMARKS_FILE : null;
if (bookmarksFile) {
try {
// 直接复制书签配置文件
fs.copyFileSync(
bookmarksFile,
path.join(CONFIG_USER_PAGES_DIR, 'bookmarks.yml')
);
} catch (error) {
console.error(`迁移书签配置文件${bookmarksFile}时出错:`, error);
}
}
console.log('迁移完成!');
}
// 如果直接运行该脚本,则执行迁移
if (require.main === module) {
migrateConfiguration();
}
module.exports = { migrateConfiguration };