fix: copy file if it does not exist

This commit is contained in:
18alantom 2024-10-09 10:33:58 +05:30
parent f19aac1763
commit cd2dabc4d9
No known key found for this signature in database
GPG key ID: B50A06E34CEC58DD

View file

@ -158,12 +158,23 @@ async function update_assets_obj(app, assets, assets_rtl) {
const app_path = path.join(apps_path, app, app);
const dist_path = path.join(app_path, "public", "dist");
const files = await glob("**/*.bundle.*.{js,css}", { cwd: dist_path });
const prefix = path.join("/", "assets", app, "dist");
const assets_dist = path.join("assets", app, "dist");
const prefix = path.join("/", assets_dist);
// eg: "js/marketplace.bundle.6SCSPSGQ.js"
for (const file of files) {
const source_path = path.join(dist_path, file);
const dest_path = path.join(sites_path, assets_dist, file);
// Copy asset file from app/public to sites/assets
if (!fs.existsSync(dest_path)) {
const dest_dir = path.dirname(dest_path);
fs.mkdirSync(dest_dir, { recursive: true });
fs.copyFileSync(source_path, dest_path);
}
// eg: [ "marketplace", "bundle", "6SCSPSGQ", "js" ]
const parts = path.parse(file).base.split(".");
const parts = path.basename(file).split(".");
// eg: "marketplace.bundle.js"
const key = [...parts.slice(0, -2), parts.at(-1)].join(".");