From 91683d367fc449e2e7bd3b51e865907ff6c98b5a Mon Sep 17 00:00:00 2001 From: Catherine Date: Sat, 20 Jan 2024 05:00:55 +0000 Subject: [PATCH] Allow using `yowasp-pack-resources` without a share directory. --- bin/pack-resources.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/pack-resources.js b/bin/pack-resources.js index 6af57e9..30b47ab 100644 --- a/bin/pack-resources.js +++ b/bin/pack-resources.js @@ -55,8 +55,8 @@ async function packDirectory(root, urlRoot, genRoot, dirPath = '', indent = 0) { } const args = process.argv.slice(2); -if (args.length !== 3) { - console.error(`Usage: yowasp-pack-resources `); +if (!(args.length >= 2 && args.length <= 3)) { + console.error(`Usage: yowasp-pack-resources []`); process.exit(1); } @@ -64,10 +64,17 @@ const resourceFileName = args[0]; const genDirectory = args[1]; const shareDirectory = args[2]; -await writeFile(resourceFileName, `\ +let output = `\ export const modules = ${(await packModules(genDirectory, './')).flat(Infinity).join('')}; - +`; +if (shareDirectory) + output += `\ export const filesystem = { share: ${(await packDirectory(shareDirectory, './share', genDirectory, '', 1)).flat(Infinity).join('')} }; -`); +`; +else + output += `\ +export const filesystem = {}; +`; +await writeFile(resourceFileName, output);