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 { resolve } from 'node:path'
|
||||||
import type { Plugin } from 'vite'
|
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) {
|
function copyFiles(emit: any) {
|
||||||
;[
|
;['core', 'background', 'controls', 'minimap', 'node-resizer', 'node-toolbar'].forEach((name) => {
|
||||||
{ path: '../../../node_modules/@vue-flow/core/dist/', pkgName: 'vue-flow-core.mjs' },
|
const fileName = `vue-flow-${name}.mjs`
|
||||||
{
|
|
||||||
path: '../../../node_modules/@vue-flow/background/dist/',
|
const filePath = resolve(__dirname, getPkgPath(name, fileName))
|
||||||
pkgName: 'vue-flow-background.mjs',
|
|
||||||
},
|
console.log(filePath)
|
||||||
{
|
|
||||||
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}`)
|
|
||||||
if (!existsSync(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({
|
emit({
|
||||||
type: 'asset',
|
type: 'asset',
|
||||||
fileName: pkgName,
|
fileName,
|
||||||
filePath,
|
filePath,
|
||||||
source: readFileSync(filePath, 'utf-8'),
|
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')
|
console.log('Copied vue-flow files')
|
||||||
@@ -49,13 +40,23 @@ export function copyVueFlowPlugin(): Plugin {
|
|||||||
buildStart() {
|
buildStart() {
|
||||||
// use fs to copy files
|
// use fs to copy files
|
||||||
copyFiles((file: any) => {
|
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() {
|
watchChange() {
|
||||||
// use fs to copy files
|
// use fs to copy files
|
||||||
copyFiles((file: any) => {
|
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() {
|
generateBundle() {
|
||||||
|
|||||||
Reference in New Issue
Block a user