diff --git a/npm-postinstall.mjs b/npm-postinstall.mjs index 27b7b30..2b825e0 100644 --- a/npm-postinstall.mjs +++ b/npm-postinstall.mjs @@ -1,4 +1,4 @@ -import { copyFileSync } from 'fs'; +import { copyFileSync, existsSync, mkdirSync } from 'fs'; import { resolve, dirname } from 'path'; import { fileURLToPath } from 'url'; @@ -6,7 +6,12 @@ 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}`); };