refactor: extract components to plugin repo (#1933)

This commit is contained in:
Mo
2022-11-04 11:04:53 -05:00
committed by GitHub
parent 5bba4820e4
commit 77d5093f14
1927 changed files with 1655 additions and 167892 deletions

View File

@@ -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)
}
}