data
This commit is contained in:
parent
b5a2c52dde
commit
7f975d5d43
@ -77,67 +77,15 @@ function buildPortableApp() {
|
||||
console.log('Windows 7便携应用构建完成!');
|
||||
console.log('构建产物位于 dist_electron 目录');
|
||||
|
||||
// ===== 添加文件复制逻辑,确保data目录与可执行文件同级 =====
|
||||
console.log('开始准备data目录结构...');
|
||||
|
||||
// 定义路径
|
||||
const projectRoot = __dirname;
|
||||
const buildDir = path.join(projectRoot, 'dist_electron');
|
||||
const portableAppDir = path.join(buildDir, 'portable-app');
|
||||
// 修改:data目录放入portable-app目录内
|
||||
const destDataDir = path.join(portableAppDir, 'data');
|
||||
|
||||
// 确保目标data目录存在
|
||||
if (!fs.existsSync(destDataDir)) {
|
||||
fs.mkdirSync(destDataDir, { recursive: true });
|
||||
console.log(`创建目标data目录: ${destDataDir}`);
|
||||
}
|
||||
|
||||
// 复制.gitignore文件(如果存在)
|
||||
const gitignoreSrc = path.join(projectRoot, 'data', '.gitignore');
|
||||
const gitignoreDest = path.join(destDataDir, '.gitignore');
|
||||
if (fs.existsSync(gitignoreSrc)) {
|
||||
fs.copyFileSync(gitignoreSrc, gitignoreDest);
|
||||
console.log('已复制.gitignore文件');
|
||||
}
|
||||
|
||||
// 创建空的system.db和user.db文件(如果不存在)
|
||||
const systemDbPath = path.join(destDataDir, 'system.db');
|
||||
const userDbPath = path.join(destDataDir, 'user.db');
|
||||
|
||||
if (!fs.existsSync(systemDbPath)) {
|
||||
fs.writeFileSync(systemDbPath, '');
|
||||
console.log('已创建空的system.db文件');
|
||||
}
|
||||
|
||||
if (!fs.existsSync(userDbPath)) {
|
||||
fs.writeFileSync(userDbPath, '');
|
||||
console.log('已创建空的user.db文件');
|
||||
}
|
||||
|
||||
// 可选:如果项目中已有数据库文件,可以复制它们
|
||||
const projectSystemDb = path.join(projectRoot, 'data', 'system.db');
|
||||
const projectUserDb = path.join(projectRoot, 'data', 'user.db');
|
||||
|
||||
if (fs.existsSync(projectSystemDb)) {
|
||||
fs.copyFileSync(projectSystemDb, systemDbPath);
|
||||
console.log('已复制项目中的system.db文件');
|
||||
}
|
||||
|
||||
if (fs.existsSync(projectUserDb)) {
|
||||
fs.copyFileSync(projectUserDb, userDbPath);
|
||||
console.log('已复制项目中的user.db文件');
|
||||
}
|
||||
// ===== 移除data目录复制逻辑 =====
|
||||
|
||||
// 构建完成后的其他处理(如果有)
|
||||
console.log('便携应用构建流程完成');
|
||||
console.log('data目录结构准备完成!');
|
||||
console.log('最终目录结构:');
|
||||
console.log(`- dist_electron/`);
|
||||
console.log(` - portable-app/`);
|
||||
console.log(` - StatExamPortable_${require('./package.json').version}_*.exe`);
|
||||
console.log(` - data/`);
|
||||
console.log(` - system.db`);
|
||||
console.log(` - user.db`);
|
||||
console.log(` - .gitignore`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('构建失败:', error);
|
||||
|
Loading…
Reference in New Issue
Block a user