mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-23 14:08:42 -05:00
3be72007fa
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com> Co-authored-by: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import fs from "fs-extra";
|
|
import path from "path";
|
|
import { Plugin, ResolvedConfig } from "vite";
|
|
|
|
interface CopyCompiledAssetsPluginOptions {
|
|
filename: string;
|
|
distDir: string;
|
|
}
|
|
|
|
export function copyCompiledAssetsPlugin(options: CopyCompiledAssetsPluginOptions): Plugin {
|
|
let config: ResolvedConfig;
|
|
|
|
return {
|
|
name: "copy-compiled-assets",
|
|
apply: "build",
|
|
|
|
configResolved(_config) {
|
|
config = _config;
|
|
},
|
|
|
|
async writeBundle() {
|
|
const outputDir = path.resolve(config.root, "../../apps/web/public/js");
|
|
const distDir = path.resolve(config.root, options.distDir);
|
|
|
|
// Create the output directory if it doesn't exist
|
|
fs.ensureDirSync(outputDir);
|
|
console.log(`Ensured directory exists: ${outputDir}`);
|
|
|
|
// Copy files from distDir to outputDir
|
|
const filesToCopy = fs.readdirSync(distDir);
|
|
filesToCopy.forEach((file) => {
|
|
const srcFile = path.resolve(distDir, file);
|
|
const destFile = path.resolve(outputDir, file.replace("index", options.filename));
|
|
fs.copyFileSync(srcFile, destFile);
|
|
});
|
|
|
|
console.log(`Copied ${filesToCopy.length} files to ${outputDir} (${options.filename})`);
|
|
},
|
|
};
|
|
}
|