Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent DS Store addition, minor simplifications #5

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -26,6 +21,12 @@ 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}`));

/**
* @param {string} dir
* @param {string} out
Expand All @@ -38,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, "_"),
};
}
Expand Down Expand Up @@ -86,14 +86,16 @@ async function collectEntries(dir, out, isRoot, result) {
entries: [],
};

const regex = new RegExp("^((?!@).)*$");

for (const file of files) {
if (file === '.DS_Store') {
continue;
}

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));
}
}
Expand Down Expand Up @@ -175,7 +177,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));
Expand Down