knife4j-swagger-vue3/packages/nestjs-knife4j/scripts/copy-ui.mjs

24 lines
883 B
JavaScript

import { cpSync, existsSync, mkdirSync, rmSync, renameSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const currentDir = dirname(fileURLToPath(import.meta.url));
const packageDir = resolve(currentDir, '..');
const workspaceDir = resolve(packageDir, '../..');
const playgroundDist = resolve(workspaceDir, 'apps/playground/dist');
const packageUi = resolve(packageDir, 'ui');
const indexHtml = resolve(packageUi, 'index.html');
const docHtml = resolve(packageUi, 'doc.html');
if (!existsSync(playgroundDist)) {
throw new Error('Playground dist not found. Run playground build before packaging.');
}
rmSync(packageUi, { force: true, recursive: true });
mkdirSync(packageUi, { recursive: true });
cpSync(playgroundDist, packageUi, { recursive: true });
if (existsSync(indexHtml)) {
renameSync(indexHtml, docHtml);
}