@ffflorian/electron-icon-generator 1.5.4 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@ Based on https://github.com/jaretburkett/electron-icon-maker.
9
9
 
10
10
  ## Installation
11
11
 
12
- ℹ️ This is a hybrid [CommonJS](https://nodejs.org/docs/latest/api/modules.html#modules-commonjs-modules) / [ESM](https://nodejs.org/api/esm.html#introduction) module.
12
+ ℹ️ This is a pure [ESM](https://nodejs.org/api/esm.html#introduction) module.
13
13
 
14
14
  Run `yarn global add @ffflorian/electron-icon-generator` or `npm i -g @ffflorian/electron-icon-generator`
15
15
 
@@ -1,9 +1,13 @@
1
1
  #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
2
5
  import { program as commander } from 'commander';
3
- import { createRequire } from 'module';
4
- const require = createRequire(import.meta.url);
5
6
  import { IconGenerator } from './index.js';
6
- const { bin, description, version } = require('../package.json');
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const packageJsonPath = path.join(__dirname, '../package.json');
10
+ const { bin, description, version } = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
7
11
  commander
8
12
  .description(description)
9
13
  .name(Object.keys(bin)[0])
@@ -1,10 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ import path from 'node:path';
2
3
  import * as fs from 'fs-extra';
3
4
  import Jimp from 'jimp';
4
- import path from 'path';
5
- import { createRequire } from 'module';
6
- const require = createRequire(import.meta.url);
7
- const icongen = require('icon-gen');
5
+ import icongen from 'icon-gen';
8
6
  // eslint-disable-next-line no-magic-numbers
9
7
  const pngSizes = [16, 24, 32, 48, 64, 128, 256, 512, 1024];
10
8
  export class IconGenerator {
@@ -40,7 +38,7 @@ export class IconGenerator {
40
38
  const macIconsDir = path.join(this.iconsDir, 'mac');
41
39
  const winIconsDir = path.join(this.iconsDir, 'win');
42
40
  await fs.ensureDir(macIconsDir);
43
- await icongen(this.PNGoutputDir, macIconsDir, {
41
+ await icongen.default(this.PNGoutputDir, macIconsDir, {
44
42
  icns: {
45
43
  name: 'icon',
46
44
  sizes: pngSizes,
@@ -48,7 +46,7 @@ export class IconGenerator {
48
46
  report: !this.options.silent,
49
47
  });
50
48
  await fs.ensureDir(winIconsDir);
51
- await icongen(this.PNGoutputDir, winIconsDir, {
49
+ await icongen.default(this.PNGoutputDir, winIconsDir, {
52
50
  icns: {
53
51
  name: 'icon',
54
52
  sizes: pngSizes,
package/package.json CHANGED
@@ -1,27 +1,22 @@
1
1
  {
2
2
  "author": "Florian Imdahl <git@ffflorian.de>",
3
- "bin": "dist/cjs/index.js",
3
+ "bin": "dist/index.js",
4
4
  "dependencies": {
5
5
  "commander": "12.1.0",
6
6
  "fs-extra": "11.2.0",
7
- "icon-gen": "4.0.0",
7
+ "icon-gen": "5.0.0",
8
8
  "jimp": "0.22.12"
9
9
  },
10
10
  "description": "An icon generator to generate all the icon files needed for electron packaging",
11
11
  "devDependencies": {
12
12
  "@types/fs-extra": "11.0.4",
13
- "rimraf": "5.0.7",
14
- "typescript": "5.4.5"
13
+ "rimraf": "6.0.1",
14
+ "typescript": "5.5.4"
15
15
  },
16
16
  "engines": {
17
17
  "node": ">= 18.0"
18
18
  },
19
- "exports": {
20
- ".": {
21
- "import": "./dist/esm/index.js",
22
- "require": "./dist/cjs/index.js"
23
- }
24
- },
19
+ "exports": "./dist/index.js",
25
20
  "files": [
26
21
  "dist"
27
22
  ],
@@ -33,21 +28,17 @@
33
28
  "ico"
34
29
  ],
35
30
  "license": "GPL-3.0",
36
- "main": "dist/cjs/index.js",
37
- "module": "dist/esm/index.js",
31
+ "module": "dist/index.js",
38
32
  "name": "@ffflorian/electron-icon-generator",
39
33
  "repository": "https://github.com/ffflorian/node-packages/tree/main/packages/electron-icon-generator",
40
34
  "scripts": {
41
- "build": "yarn build:cjs && yarn build:esm && yarn generate:packagejson",
42
- "build:cjs": "tsc -p tsconfig.cjs.json",
43
- "build:esm": "tsc -p tsconfig.json",
35
+ "build": "tsc -p tsconfig.json",
44
36
  "clean": "rimraf dist",
45
37
  "dist": "yarn clean && yarn build",
46
- "generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
47
38
  "start": "node --loader ts-node/esm src/cli.ts",
48
39
  "test": "exit 0"
49
40
  },
50
41
  "type": "module",
51
- "version": "1.5.4",
52
- "gitHead": "28c184f53a87d8eb082cc27c923ef7b352bbe875"
42
+ "version": "1.6.0",
43
+ "gitHead": "f1a74d8ec9721d5b52a00e41b2ec73278e048290"
53
44
  }
package/dist/cjs/cli.js DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program as commander } from 'commander';
3
- import { createRequire } from 'module';
4
- const require = createRequire(import.meta.url);
5
- import { IconGenerator } from './index.js';
6
- const { bin, description, version } = require('../package.json');
7
- commander
8
- .description(description)
9
- .name(Object.keys(bin)[0])
10
- .version(version)
11
- .option('-i, --input <file>', 'Input PNG file (recommended size: 1024x1024)', './icon.png')
12
- .option('-o, --output <folder>', 'Folder to output new icons folder', './')
13
- .option('-s, --silent', `Don't log anything beside errors`, false)
14
- .parse(process.argv);
15
- const commanderOptions = commander.opts();
16
- new IconGenerator({
17
- input: commanderOptions.input,
18
- output: commanderOptions.output,
19
- silent: commanderOptions.silent,
20
- })
21
- .start()
22
- .then(() => process.exit())
23
- .catch(error => {
24
- console.error(error);
25
- process.exit(1);
26
- });
package/dist/cjs/index.js DELETED
@@ -1,98 +0,0 @@
1
- #!/usr/bin/env node
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- import * as fs from 'fs-extra';
12
- import Jimp from 'jimp';
13
- import path from 'path';
14
- import { createRequire } from 'module';
15
- const require = createRequire(import.meta.url);
16
- const icongen = require('icon-gen');
17
- // eslint-disable-next-line no-magic-numbers
18
- const pngSizes = [16, 24, 32, 48, 64, 128, 256, 512, 1024];
19
- export class IconGenerator {
20
- constructor(options) {
21
- this.options = options;
22
- this.logConsole(options);
23
- this.options.input = path.resolve(this.options.input);
24
- this.options.output = path.resolve(this.options.output);
25
- this.iconsDir = path.join(this.options.output, 'icons');
26
- this.PNGoutputDir = path.join(this.iconsDir, 'png');
27
- }
28
- start() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- yield this.createPNGs(0);
31
- });
32
- }
33
- createPNG(size) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const fileName = `${size.toString()}.png`;
36
- yield fs.ensureDir(this.options.output);
37
- yield fs.ensureDir(this.iconsDir);
38
- yield fs.ensureDir(this.PNGoutputDir);
39
- const image = yield Jimp.read(this.options.input);
40
- const resizeFile = path.join(this.PNGoutputDir, fileName);
41
- yield new Promise((resolve, reject) => image.resize(size, size, (error, result) => (error ? reject(error) : resolve(result))));
42
- yield image.writeAsync(resizeFile);
43
- return `Created "${resizeFile}"`;
44
- });
45
- }
46
- createPNGs(position) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const info = yield this.createPNG(pngSizes[position]);
49
- this.logConsole(info);
50
- if (position < pngSizes.length - 1) {
51
- yield this.createPNGs(position + 1);
52
- }
53
- else {
54
- const macIconsDir = path.join(this.iconsDir, 'mac');
55
- const winIconsDir = path.join(this.iconsDir, 'win');
56
- yield fs.ensureDir(macIconsDir);
57
- yield icongen(this.PNGoutputDir, macIconsDir, {
58
- icns: {
59
- name: 'icon',
60
- sizes: pngSizes,
61
- },
62
- report: !this.options.silent,
63
- });
64
- yield fs.ensureDir(winIconsDir);
65
- yield icongen(this.PNGoutputDir, winIconsDir, {
66
- icns: {
67
- name: 'icon',
68
- sizes: pngSizes,
69
- },
70
- report: !this.options.silent,
71
- });
72
- this.logConsole('Renaming PNGs to Electron Format');
73
- yield this.renamePNGs(0);
74
- }
75
- });
76
- }
77
- logConsole(...messages) {
78
- if (!this.options.silent) {
79
- console.info(...messages);
80
- }
81
- }
82
- renamePNGs(position) {
83
- return __awaiter(this, void 0, void 0, function* () {
84
- const startName = `${pngSizes[position]}.png`;
85
- const endName = `${pngSizes[position]}x${pngSizes[position]}.png`;
86
- const startFile = path.join(this.PNGoutputDir, startName);
87
- const endFile = path.join(this.PNGoutputDir, endName);
88
- yield fs.rename(startFile, endFile);
89
- this.logConsole(`Renamed "${startName}" to "${endName}".`);
90
- if (position < pngSizes.length - 1) {
91
- yield this.renamePNGs(position + 1);
92
- }
93
- else {
94
- this.logConsole('\nAll done');
95
- }
96
- });
97
- }
98
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
package/dist/esm/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env node
2
- export interface Options {
3
- input: string;
4
- output: string;
5
- silent?: boolean;
6
- }
7
- export declare class IconGenerator {
8
- private readonly iconsDir;
9
- private readonly options;
10
- private readonly PNGoutputDir;
11
- constructor(options: Options);
12
- start(): Promise<void>;
13
- private createPNG;
14
- private createPNGs;
15
- private logConsole;
16
- private renamePNGs;
17
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
File without changes
File without changes