chore(docs): cleanup copy plugin
This commit is contained in:
@@ -2,43 +2,34 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import type { Plugin } from 'vite'
|
||||
|
||||
function getPkgPath(pkgName: string, fileName) {
|
||||
return resolve(__dirname, `../../../node_modules/@vue-flow/${pkgName}/dist/${fileName}`)
|
||||
}
|
||||
|
||||
function getPublicPath(fileName: string) {
|
||||
return resolve(__dirname, `../../public/${fileName}`)
|
||||
}
|
||||
|
||||
function copyFiles(emit: any) {
|
||||
;[
|
||||
{ path: '../../../node_modules/@vue-flow/core/dist/', pkgName: 'vue-flow-core.mjs' },
|
||||
{
|
||||
path: '../../../node_modules/@vue-flow/background/dist/',
|
||||
pkgName: 'vue-flow-background.mjs',
|
||||
},
|
||||
{
|
||||
path: '../../../node_modules/@vue-flow/controls/dist/',
|
||||
pkgName: 'vue-flow-controls.mjs',
|
||||
},
|
||||
{
|
||||
path: '../../../node_modules/@vue-flow/minimap/dist/',
|
||||
pkgName: 'vue-flow-minimap.mjs',
|
||||
},
|
||||
{
|
||||
path: '../../../node_modules/@vue-flow/node-resizer/dist/',
|
||||
pkgName: 'vue-flow-node-resizer.mjs',
|
||||
},
|
||||
{
|
||||
path: '../../../node_modules/@vue-flow/node-toolbar/dist/',
|
||||
pkgName: 'vue-flow-node-toolbar.mjs',
|
||||
},
|
||||
].forEach(({ path, pkgName }) => {
|
||||
const filePath = resolve(__dirname, `${path}/${pkgName}`)
|
||||
;['core', 'background', 'controls', 'minimap', 'node-resizer', 'node-toolbar'].forEach((name) => {
|
||||
const fileName = `vue-flow-${name}.mjs`
|
||||
|
||||
const filePath = resolve(__dirname, getPkgPath(name, fileName))
|
||||
|
||||
console.log(filePath)
|
||||
|
||||
if (!existsSync(filePath)) {
|
||||
throw new Error(`${pkgName} not built. ` + `Run "pnpm -w build" first.`)
|
||||
throw new Error(`${name} not built. ` + `Run "pnpm -w build" first.`)
|
||||
}
|
||||
|
||||
emit({
|
||||
type: 'asset',
|
||||
fileName: pkgName,
|
||||
fileName,
|
||||
filePath,
|
||||
source: readFileSync(filePath, 'utf-8'),
|
||||
})
|
||||
|
||||
console.log(`Copied ${filePath} to ${resolve(__dirname, `../../public/${pkgName}`)}`)
|
||||
console.log(`Copied ${filePath} to ${getPublicPath(fileName)}`)
|
||||
})
|
||||
|
||||
console.log('Copied vue-flow files')
|
||||
@@ -49,13 +40,23 @@ export function copyVueFlowPlugin(): Plugin {
|
||||
buildStart() {
|
||||
// use fs to copy files
|
||||
copyFiles((file: any) => {
|
||||
writeFileSync(resolve(__dirname, `../../public/${file.fileName}`), file.source)
|
||||
// remove existing files
|
||||
if (existsSync(getPublicPath(file.fileName))) {
|
||||
writeFileSync(getPublicPath(file.fileName), '')
|
||||
}
|
||||
|
||||
writeFileSync(getPublicPath(file.fileName), file.source)
|
||||
})
|
||||
},
|
||||
watchChange() {
|
||||
// use fs to copy files
|
||||
copyFiles((file: any) => {
|
||||
writeFileSync(resolve(__dirname, `../../public/${file.fileName}`), file.source)
|
||||
// remove existing files
|
||||
if (existsSync(getPublicPath(file.fileName))) {
|
||||
writeFileSync(getPublicPath(file.fileName), '')
|
||||
}
|
||||
|
||||
writeFileSync(getPublicPath(file.fileName), file.source)
|
||||
})
|
||||
},
|
||||
generateBundle() {
|
||||
|
||||
Reference in New Issue
Block a user