update
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
"scripts": {
|
||||
"dev": "bun run --watch --hot src/index.ts",
|
||||
"start": "bun run src/index.ts",
|
||||
"prestart": "bun src/test/check-code.ts",
|
||||
"build": "NODE_ENV=production bun bun.config.ts"
|
||||
},
|
||||
"keywords": [],
|
||||
|
||||
@@ -3,6 +3,7 @@ import { proxyRoute, initProxy } from '@kevisual/local-proxy/proxy.ts';
|
||||
initProxy({
|
||||
pagesDir: './demo',
|
||||
watch: true,
|
||||
home: '/root/light-code-center',
|
||||
});
|
||||
|
||||
import { app } from './app.ts'
|
||||
|
||||
37
server/src/test/check-code.ts
Normal file
37
server/src/test/check-code.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import path from 'node:path'
|
||||
import fs from 'node:fs'
|
||||
const main = async () => {
|
||||
const root = path.join(process.cwd(), 'code');
|
||||
const buckupRoot = path.join(process.cwd(), 'code-backup');
|
||||
|
||||
// 如果 code 文件夹不存在或文件夹列表长度等于0,则从 code-backup 复制
|
||||
let shouldCopy = false;
|
||||
|
||||
if (!fs.existsSync(root)) {
|
||||
console.log('code 文件夹不存在');
|
||||
shouldCopy = true;
|
||||
} else {
|
||||
// 检查 code 文件夹下的文件夹列表
|
||||
const items = await fs.promises.readdir(root, { withFileTypes: true });
|
||||
const folders = items.filter(item => item.isDirectory());
|
||||
|
||||
if (folders.length === 0) {
|
||||
console.log('code 文件夹存在但为空(无子文件夹)');
|
||||
shouldCopy = true;
|
||||
} else {
|
||||
console.log(`code 文件夹已存在且包含 ${folders.length} 个子文件夹`);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldCopy) {
|
||||
if (fs.existsSync(buckupRoot)) {
|
||||
console.log('正在从 code-backup 复制...');
|
||||
await fs.promises.cp(buckupRoot, root, { recursive: true });
|
||||
console.log('复制完成!');
|
||||
} else {
|
||||
console.log('code-backup 文件夹不存在,无法复制');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
Reference in New Issue
Block a user