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

process directories #789

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 13 additions & 7 deletions cli/lib/png2src.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,22 @@ function runAll(files, opts) {

let output = { "sprites": [] };
for (let ii = 0; ii < files.length; ++ii) {
const file = files[ii];

const filePath = files[ii];
try {
if (ii > 0) {
console.log();
const filePaths = !fs.statSync(filePath).isDirectory() ? [filePath] :
fs.readdirSync(filePath)
.filter(file => path.extname(file).toLowerCase() === '.png')
.map(file => path.join(filePath, file));

for (let iii = 0; iii < filePaths.length; ++iii) {
const pngFile = filePaths[iii];
if (ii | iii > 0) {
console.log();
}
output.sprites.push(run(pngFile));
}

output.sprites.push(run(file));
} catch (error) {
throw new Error("Error processing " + file + ": " + error.message);
throw new Error("Error processing " + filePath + ": " + error.message);
}
}

Expand Down
1 change: 1 addition & 0 deletions cli/lib/test/data_ok/smile_7x7_1BPP.png
1 change: 1 addition & 0 deletions cli/lib/test/data_ok/smile_7x7_2BPP.png
1 change: 1 addition & 0 deletions cli/lib/test/data_ok/smile_8x8_1BPP.png
1 change: 1 addition & 0 deletions cli/lib/test/data_ok/smile_8x8_2BPP.png
17 changes: 16 additions & 1 deletion cli/lib/test/png2src.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe("PNG2SRC", () => {
runAll(["/invalid/path"], {
lang: "rust",
output: "-",
})).toThrowError(/Error processing \/invalid\/path: ENOENT: no such file or directory, open '\/invalid\/path'/);
})).toThrowError(/Error processing \/invalid\/path: ENOENT: no such file or directory, stat '\/invalid\/path'/);
});

it("should console log one sprite", () => {
Expand Down Expand Up @@ -218,5 +218,20 @@ describe("PNG2SRC", () => {
expect(console.log).toHaveBeenCalledTimes(3);
expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
});

it("should process directories", () => {
runAll(
[
__dirname + "/data_ok",
],
{
lang: "c",
output: "output.h",
}
);

expect(console.log).toHaveBeenCalledTimes(3);
expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
});
});
});
Loading