import { readFile, outputJson, readFileSync } from 'fs-extra' import cpy from 'cpy' import trash from 'trash' import { Obj } from './type' // 用什么, 再导出什么, 不然 @microsoft/api-extractor 会有问题 export { copy, copySync, emptyDir, emptyDirSync, ensureFile, ensureFileSync, ensureDir, ensureDirSync, ensureLink, ensureLinkSync, ensureSymlink, ensureSymlinkSync, existsSync, mkdirp, mkdirpSync, mkdirs, mkdirsSync, move, moveSync, outputFile, outputFileSync, outputJson, outputJsonSync, pathExists, pathExistsSync, readdir, readdirSync, readJson, readJsonSync, remove, removeSync, stat, statSync, writeJson, writeJsonSync, } from 'fs-extra' export async function safeRemove(filepath: string): Promise { try { await trash(filepath) } catch (err) { // ignore err } } export function resolvePkgBin(pkg: string, bin: string): string { return require .resolve(pkg + '/package.json') .replace('package.json', 'bin/' + bin) } export async function readUTF8File(filepath: string): Promise { return readFile(filepath, 'utf-8') } export function readUTF8FileSync(filepath: string): string { return readFileSync(filepath, 'utf-8') } export async function outputJsonWithSpaces( filepath: string, json: Obj, ): Promise { return outputJson(filepath, json, { spaces: 2 }) } export async function copyGlob( from: string | string[], to: string, options: cpy.Options, ): Promise { return cpy(from, to, options) }