Skip to content

Commit

Permalink
Create target folder if it doesn't exist in the postinstall script.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jan 9, 2025
1 parent 7b25d7e commit 37e4f7c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions npm-postinstall.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { copyFileSync } from 'fs';
import { copyFileSync, existsSync, mkdirSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const filename = fileURLToPath(import.meta.url);
const folder = dirname(filename);

function copyFile(src, dest) {
copyFileSync(resolve(folder, src), resolve(folder, dest));
const target = resolve(folder, dest);
const targetFolder = dirname(target);
if (!existsSync(targetFolder))
mkdirSync(targetFolder, { recursive: true });

copyFileSync(resolve(folder, src), target);
console.log(`Copied ${src} to ${dest}`);
};

Expand Down

0 comments on commit 37e4f7c

Please sign in to comment.