@ffflorian/electron-icon-generator 1.5.5 → 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.5.2"
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.5",
52
- "gitHead": "f7a6a79286e4eb85392b5f2d33942ab166142109"
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,81 +0,0 @@
1
- #!/usr/bin/env node
2
- import * as fs from 'fs-extra';
3
- 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');
8
- // eslint-disable-next-line no-magic-numbers
9
- const pngSizes = [16, 24, 32, 48, 64, 128, 256, 512, 1024];
10
- export class IconGenerator {
11
- constructor(options) {
12
- this.options = options;
13
- this.logConsole(options);
14
- this.options.input = path.resolve(this.options.input);
15
- this.options.output = path.resolve(this.options.output);
16
- this.iconsDir = path.join(this.options.output, 'icons');
17
- this.PNGoutputDir = path.join(this.iconsDir, 'png');
18
- }
19
- async start() {
20
- await this.createPNGs(0);
21
- }
22
- async createPNG(size) {
23
- const fileName = `${size.toString()}.png`;
24
- await fs.ensureDir(this.options.output);
25
- await fs.ensureDir(this.iconsDir);
26
- await fs.ensureDir(this.PNGoutputDir);
27
- const image = await Jimp.read(this.options.input);
28
- const resizeFile = path.join(this.PNGoutputDir, fileName);
29
- await new Promise((resolve, reject) => image.resize(size, size, (error, result) => (error ? reject(error) : resolve(result))));
30
- await image.writeAsync(resizeFile);
31
- return `Created "${resizeFile}"`;
32
- }
33
- async createPNGs(position) {
34
- const info = await this.createPNG(pngSizes[position]);
35
- this.logConsole(info);
36
- if (position < pngSizes.length - 1) {
37
- await this.createPNGs(position + 1);
38
- }
39
- else {
40
- const macIconsDir = path.join(this.iconsDir, 'mac');
41
- const winIconsDir = path.join(this.iconsDir, 'win');
42
- await fs.ensureDir(macIconsDir);
43
- await icongen(this.PNGoutputDir, macIconsDir, {
44
- icns: {
45
- name: 'icon',
46
- sizes: pngSizes,
47
- },
48
- report: !this.options.silent,
49
- });
50
- await fs.ensureDir(winIconsDir);
51
- await icongen(this.PNGoutputDir, winIconsDir, {
52
- icns: {
53
- name: 'icon',
54
- sizes: pngSizes,
55
- },
56
- report: !this.options.silent,
57
- });
58
- this.logConsole('Renaming PNGs to Electron Format');
59
- await this.renamePNGs(0);
60
- }
61
- }
62
- logConsole(...messages) {
63
- if (!this.options.silent) {
64
- console.info(...messages);
65
- }
66
- }
67
- async renamePNGs(position) {
68
- const startName = `${pngSizes[position]}.png`;
69
- const endName = `${pngSizes[position]}x${pngSizes[position]}.png`;
70
- const startFile = path.join(this.PNGoutputDir, startName);
71
- const endFile = path.join(this.PNGoutputDir, endName);
72
- await fs.rename(startFile, endFile);
73
- this.logConsole(`Renamed "${startName}" to "${endName}".`);
74
- if (position < pngSizes.length - 1) {
75
- await this.renamePNGs(position + 1);
76
- }
77
- else {
78
- this.logConsole('\nAll done');
79
- }
80
- }
81
- }
@@ -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