chore(docs): copy vue flow files on dev build

This commit is contained in:
braks
2023-11-08 13:55:00 +01:00
parent 1016cc5587
commit 529d90a3be
+47 -38
View File
@@ -2,48 +2,57 @@ import { existsSync, readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import type { Plugin } from 'vite'
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}`)
if (!existsSync(filePath)) {
throw new Error(`${pkgName} not built. ` + `Run "pnpm -w build" first.`)
}
emit({
type: 'asset',
fileName: pkgName,
source: readFileSync(filePath, 'utf-8'),
})
console.log(`Copied ${filePath} to ${resolve(__dirname, `../../src/public/${pkgName}`)}`)
})
console.log('Copied vue-flow files')
}
export function copyVueFlowPlugin(): Plugin {
return {
name: 'copy-vue-flow',
buildStart() {
copyFiles((file: any) => this.emitFile(file))
},
watchChange() {
copyFiles((file: any) => this.emitFile(file))
},
generateBundle() {
;[
{ 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}`)
if (!existsSync(filePath)) {
throw new Error(`${pkgName} not built. ` + `Run "pnpm -w build" first.`)
}
;(this as any).emitFile({
type: 'asset',
fileName: pkgName,
source: readFileSync(filePath, 'utf-8'),
})
console.log(`Copied ${filePath} to ${resolve(__dirname, `../../src/public/${pkgName}`)}`)
})
console.log('Copied vue-flow files')
copyFiles((file: any) => this.emitFile(file))
},
}
}