UNPKG

typescript-file-copy-plugin

Version:

[![NPM version](https://img.shields.io/npm/v/typescript-file-copy-plugin.svg?style=flat-square)](https://www.npmjs.com/package/typescript-file-copy-plugin) ![NPM Downloads](https://img.shields.io/npm/dm/typescript-file-copy-plugin) [![TypeScript](https://

52 lines 1.74 kB
// src/index.ts import { copyFileSync, existsSync, statSync } from "fs"; import { dirname, extname, resolve } from "path"; import { copySync } from "cpx2"; import { mkdirpSync } from "mkdirp"; function validateOptions(options) { if (!options.copy || !Array.isArray(options.copy)) { throw new Error("The 'copy' parameter must be defined and be an array."); } options.copy.forEach((config, index) => { if (!config.src) { throw new Error(`The 'src' property is missing in the copy config at index ${index}.`); } if (!config.dest) { throw new Error(`The 'dest' property is missing in the copy config at index ${index}.`); } }); } function createCopyFilesTransformer(program, options) { return (context) => (sourceFile) => { return sourceFile; }; } function copyFilesPostCompilation(program, options) { const copiedPaths = /* @__PURE__ */ new Set(); const origEmit = program.emit; program.emit = (...args) => { const result = origEmit(...args); for (const config of options.copy) { const resolvedDest = resolve(config.dest); if (!copiedPaths.has(resolvedDest)) { if (existsSync(config.src) && statSync(config.src).isFile() && extname(config.dest)) { mkdirpSync(dirname(resolvedDest)); copyFileSync(config.src, resolvedDest); } else { copySync(config.src, config.dest); } copiedPaths.add(resolvedDest); } } return result; }; } function src_default(program, pluginOptions) { validateOptions(pluginOptions); copyFilesPostCompilation(program, pluginOptions); return createCopyFilesTransformer(program, pluginOptions); } export { src_default as default }; //# sourceMappingURL=index.mjs.map