mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 23:26:38 +08:00
[优化] 优化静态导出流程,添加重命名功能以简化目录处理
This commit is contained in:
@@ -1,14 +1,19 @@
|
|||||||
import { cpSync, existsSync, mkdirSync, rmSync } from 'node:fs';
|
import { cpSync, existsSync, mkdirSync, renameSync, rmSync } from 'node:fs';
|
||||||
import { resolve } from 'node:path';
|
import { resolve } from 'node:path';
|
||||||
|
|
||||||
const root = process.cwd();
|
const root = process.cwd();
|
||||||
const outDir = resolve(root, 'out');
|
const outDir = resolve(root, 'out');
|
||||||
const buildDir = resolve(root, 'build');
|
const buildDir = resolve(root, 'build');
|
||||||
|
|
||||||
if (!existsSync(outDir)) {
|
if (!existsSync(outDir)) {
|
||||||
throw new Error('Missing Next.js export output: out/');
|
throw new Error('Missing Next.js export output: out/');
|
||||||
}
|
}
|
||||||
|
|
||||||
rmSync(buildDir, { recursive: true, force: true });
|
rmSync(buildDir, { recursive: true, force: true });
|
||||||
mkdirSync(buildDir, { recursive: true });
|
|
||||||
cpSync(outDir, buildDir, { recursive: true });
|
try {
|
||||||
|
renameSync(outDir, buildDir);
|
||||||
|
} catch (error) {
|
||||||
|
mkdirSync(buildDir, { recursive: true });
|
||||||
|
cpSync(outDir, buildDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user