Skip to content
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ npm install -g gen-ext
gen-ext
```

### Update logo

```sh
cd your_extension_folder
gen-ext logo path/to/your/new/logo.svg
```

## License

[MIT](LICENSE)
18 changes: 16 additions & 2 deletions generate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#!/usr/bin/env node

import { Command } from "commander";
import fs from "fs-extra";
import ignore from "ignore";
import inquirer from "inquirer";
import { fileURLToPath } from "node:url";
import path from "path";
import { generateIcons } from "./logo.js";

const program = new Command();

program
.command("logo")
.description("Generate logo icons")
.argument("<svg_path>", "path to svg icon")
.action((path) => {
generateIcons(path);
});

program.action(() => generateProject().catch(console.error));

program.parse(process.argv);

async function generateProject() {
const answers = await inquirer.prompt([
Expand Down Expand Up @@ -70,5 +86,3 @@ async function generateProject() {
6. Select the build/ directory that was created.
`);
}

generateProject().catch(console.error);
37 changes: 37 additions & 0 deletions logo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { copySync } from "fs-extra/esm";
import path from "path";
import sharp from "sharp";

const dests = [
{ size: 16, path: path.join(process.cwd(), "public", "img", "logo-16.png") },
{ size: 32, path: path.join(process.cwd(), "public", "img", "logo-32.png") },
{ size: 48, path: path.join(process.cwd(), "public", "img", "logo-48.png") },
{
size: 128,
path: path.join(process.cwd(), "public", "img", "logo-128.png"),
},
{ size: 256, path: path.join(process.cwd(), "public", "icons", "logo.ico") },
];

async function generateIcons(inputPath) {
if (!inputPath) {
console.error("Please provide a path to the svg logo.");
process.exit(1);
}

try {
for (const { size, path } of dests) {
await sharp(inputPath).resize(size, size).toFile(path);
console.log(`Generated: ${path}`);
}
copySync(
inputPath,
path.join(process.cwd(), "public", "icons", "logo.svg")
);
console.log("All icons generated successfully!");
} catch (error) {
console.error("Error generating icons:", error);
}
}

export { generateIcons };
Loading