From 66badcf6fcd0ddb1af045a35f19879291136cd94 Mon Sep 17 00:00:00 2001 From: Sergei Butko Date: Mon, 3 Feb 2025 17:10:34 +0100 Subject: [PATCH 1/4] Change cmd location --- src/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index e590a4f..caaea89 100644 --- a/src/index.js +++ b/src/index.js @@ -6,11 +6,6 @@ const path = require("path"); const commandLineArgs = require("command-line-args"); const commandLineUsage = require("command-line-usage"); - -run() - .then(() => console.log("Done")) - .catch((error) => console.error(`Error happened while generating resources:\n${error}`)); - const optionDefinitions = [ {name: "dir", alias: "d", type: String, description: "Relative directory path with images"}, {name: "out", alias: "o", type: String, description: "Output file path"}, @@ -26,6 +21,10 @@ const optionDefinitions = [ const cmdOptions = commandLineArgs(optionDefinitions); const cmdUsage = commandLineUsage([{header: "Options", optionList: optionDefinitions}]); +run() + .then(() => console.log("Done")) + .catch((error) => console.error(`Error happened while generating resources:\n${error}`)); + /** * @param {string} dir * @param {string} out From 13c6ffb67f69eb73b49fa93c91968919c7bd1f34 Mon Sep 17 00:00:00 2001 From: Sergei Butko Date: Mon, 3 Feb 2025 17:14:52 +0100 Subject: [PATCH 2/4] Simplify code --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index caaea89..6e209c7 100644 --- a/src/index.js +++ b/src/index.js @@ -21,6 +21,8 @@ const optionDefinitions = [ const cmdOptions = commandLineArgs(optionDefinitions); const cmdUsage = commandLineUsage([{header: "Options", optionList: optionDefinitions}]); +const entriesRegex = new RegExp("^((?!@).)*$"); + run() .then(() => console.log("Done")) .catch((error) => console.error(`Error happened while generating resources:\n${error}`)); @@ -85,14 +87,12 @@ async function collectEntries(dir, out, isRoot, result) { entries: [], }; - const regex = new RegExp("^((?!@).)*$"); - for (const file of files) { const joinedPath = path.join(dir, file); if (fs.lstatSync(joinedPath).isDirectory()) { await collectEntries(joinedPath, out, false, result); - } else if (regex.exec(file)) { + } else if (entriesRegex.exec(file)) { item.entries.push(assembleFileEntry(dir, out, file)); } } @@ -174,7 +174,7 @@ async function prepareFiles(dir) { } else { const escapedFile = transliteration.transliterate(file, transliterationOptions) .replace(/[,]/g, ".") - .replace(/[^A-Za-z_@.]/g, "_"); + .replace(/[^A-Za-z0-9_@.]/g, "_"); if (escapedFile !== file) { fs.renameSync(joinedPath, path.join(dir, escapedFile)); From 20450e3042a63dc21b3f4e432dc3127a8ce2b750 Mon Sep 17 00:00:00 2001 From: Sergei Butko Date: Mon, 3 Feb 2025 17:20:14 +0100 Subject: [PATCH 3/4] Minor assembly adjustment --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index 6e209c7..964daef 100644 --- a/src/index.js +++ b/src/index.js @@ -39,7 +39,6 @@ function assembleFileEntry(dir, out, fileName) { variableName: fileName .toLowerCase() .replace(/(.*)(.(png|jpg|jpeg|gif|bmp|svg))$/, "$1") - .replace(/^\d+/, ($0) => new Array($0.length + 1).join("_")) .replace(/\W+/g, "_"), }; } From a06212ec017b772dcdbd30866a8484b68ff2e457 Mon Sep 17 00:00:00 2001 From: Sergei Butko Date: Mon, 3 Feb 2025 17:25:45 +0100 Subject: [PATCH 4/4] Prevent DS Store addition --- src/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.js b/src/index.js index 964daef..33e0c06 100644 --- a/src/index.js +++ b/src/index.js @@ -87,6 +87,10 @@ async function collectEntries(dir, out, isRoot, result) { }; for (const file of files) { + if (file === '.DS_Store') { + continue; + } + const joinedPath = path.join(dir, file); if (fs.lstatSync(joinedPath).isDirectory()) {