refactor: extract components to plugin repo (#1933)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import minimatch from 'minimatch'
|
||||
|
||||
export const doesDirExist = (dir) => {
|
||||
return fs.existsSync(dir)
|
||||
@@ -28,3 +30,33 @@ export const writeJson = (data, path) => {
|
||||
const string = JSON.stringify(data, null, 2)
|
||||
return fs.writeFileSync(path, string)
|
||||
}
|
||||
|
||||
export const copyRecursiveSync = (src, dest) => {
|
||||
fs.cpSync(src, dest, { recursive: true })
|
||||
}
|
||||
|
||||
export const copyFileOrDir = (src, dest, exludedFilesGlob) => {
|
||||
const isDir = fs.lstatSync(src).isDirectory()
|
||||
if (isDir) {
|
||||
ensureDirExists(dest)
|
||||
const entries = fs.readdirSync(src, { withFileTypes: true })
|
||||
|
||||
for (const entry of entries) {
|
||||
const srcPath = path.join(src, entry.name)
|
||||
|
||||
const excluded = exludedFilesGlob && minimatch(srcPath, exludedFilesGlob)
|
||||
if (excluded) {
|
||||
continue
|
||||
}
|
||||
const destPath = path.join(dest, entry.name)
|
||||
|
||||
entry.isDirectory() ? copyFileOrDir(srcPath, destPath) : fs.copyFileSync(srcPath, destPath)
|
||||
}
|
||||
} else {
|
||||
const excluded = exludedFilesGlob && minimatch(src, exludedFilesGlob)
|
||||
if (excluded) {
|
||||
return
|
||||
}
|
||||
fs.copyFileSync(src, dest)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user