From ce3e06c20863ad2080f1143ee576a91476e70393 Mon Sep 17 00:00:00 2001 From: Catherine Date: Sun, 14 Jul 2024 19:34:52 +0000 Subject: [PATCH] Add symlink support to `yowasp-pack-resources`. Only symlinks to directories are supported. --- bin/pack-resources.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/pack-resources.js b/bin/pack-resources.js index 001eba4..b2a2639 100644 --- a/bin/pack-resources.js +++ b/bin/pack-resources.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -import { readdir, readFile, writeFile, mkdir } from 'fs/promises'; +import { readdir, readlink, readFile, writeFile, mkdir } from 'fs/promises'; async function packModules(root, urlRoot) { const files = await readdir(root, { withFileTypes: true }); @@ -45,6 +45,9 @@ async function packDirectory(root, urlRoot, genRoot, dirPath = '', indent = 0) { await writeFile(`${genRoot}/${urlRoot}/${filePath}`, fileData); packedData.push(`new URL(${JSON.stringify(urlRoot + filePath)}, import.meta.url)`); } + } else if (file.isSymbolicLink()) { + const linkPath = await readlink(`${root}/${filePath}`); + packedData.push(await packDirectory(root, urlRoot, genRoot, linkPath, indent + 1)); } else { packedData.push('null'); }