node文件复制--可用于复制d.ts文件

27 阅读1分钟

copy-typing-file.js

import fg from 'fast-glob'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import { copyFileSync } from 'fs'

const __filenameNew = fileURLToPath(import.meta.url)
const __dirnameNew = dirname(__filenameNew)

const libRootDir = 'lib'
const libRootDirNameLength = libRootDir.length
const entries = await fg(`${libRootDir}/**/*.d.ts`)
console.log(__dirnameNew)
console.log(entries)

entries.forEach(async val => {
  const typingFileFullPath = join(__dirnameNew, val)
  const targetFilePath = join(
    __dirnameNew,
    'dist',
    val.substring(libRootDirNameLength)
  )
  await copyFileSync(typingFileFullPath, targetFilePath)
})