typescript-file-copy-plugin
Version:
[](https://www.npmjs.com/package/typescript-file-copy-plugin)  [ • 1.9 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
var _fs = require('fs');
var _path = require('path');
var _cpx2 = require('cpx2');
var _mkdirp = require('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 = _path.resolve.call(void 0, config.dest);
if (!copiedPaths.has(resolvedDest)) {
if (_fs.existsSync.call(void 0, config.src) && _fs.statSync.call(void 0, config.src).isFile() && _path.extname.call(void 0, config.dest)) {
_mkdirp.mkdirpSync.call(void 0, _path.dirname.call(void 0, resolvedDest));
_fs.copyFileSync.call(void 0, config.src, resolvedDest);
} else {
_cpx2.copySync.call(void 0, config.src, config.dest);
}
copiedPaths.add(resolvedDest);
}
}
return result;
};
}
function src_default(program, pluginOptions) {
validateOptions(pluginOptions);
copyFilesPostCompilation(program, pluginOptions);
return createCopyFilesTransformer(program, pluginOptions);
}
exports.default = src_default;
//# sourceMappingURL=index.js.map