@uxf/icons-generator 11.111.2 → 11.118.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
@@ -1,58 +1,70 @@
1
1
  # @uxf/icons-generator
2
+
2
3
  A well configurable tool for generating and managing custom SVG icons and sprites in web projects.
3
4
 
4
5
  ## Quick Start
5
6
 
6
7
  ### Installation
8
+
7
9
  Use npm or yarn to install:
10
+
8
11
  ```bash
9
12
  npm i -D @uxf/icons-generator
10
13
  ```
14
+
11
15
  ```bash
12
16
  yarn add -D @uxf/icons-generator
13
17
  ```
14
18
 
15
19
  ### Configuration
20
+
16
21
  Create a `icons.config.js` file in your project's root:
22
+
17
23
  ```ts
18
24
  module.exports = {
19
25
  icons: {
20
26
  test: {
21
27
  width: 24,
22
28
  height: 24,
23
- data: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`
24
- }
25
- }
26
- }
29
+ data: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`,
30
+ },
31
+ },
32
+ };
27
33
  ```
34
+
28
35
  See the full configuration options [here](#config).
29
36
 
30
37
  ### Generating Icons
38
+
31
39
  Run the generator:
40
+
32
41
  ```bash
33
42
  icons-gen
34
43
  ```
44
+
35
45
  For a custom config file name:
46
+
36
47
  ```bash
37
48
  icons-gen --configFile=yourConfigFileName.js
38
49
  ```
39
50
 
40
51
  ## Configuration Details
41
52
 
42
- | Key | Type | Default | Required | Description |
43
- |-------------------------|-----------------------------------------------|-----------------------------------------------------------------------|----------|----------------------------------|
44
- | typescript | `boolean` | `true` | No | - |
45
- | configDirectory | `string` | `"/src/config/"` | No | - |
46
- | generatedDirectory | `string` | `"/public/icons-generated/"` | No | - |
47
- | spriteFileName | `string` | `_icon-sprite.svg` | No | Specify custom sprite file name |
48
- | typeName | `string` | `IconsSet` | No | - |
49
- | customDefinitionContent | `string` | - | No | - |
50
- | icons | `Record<string, SimpleIcon \| SizedIcon \| IconFromAdapterFunction>` | - | Yes | More details [here](#icon-types) |
51
- | fallbackFilesDirectory | - | - | No | More details [here](#adapters) |
53
+ | Key | Type | Default | Required | Description |
54
+ | ----------------------- | -------------------------------------------------------------------- | ---------------------------- | -------- | -------------------------------- |
55
+ | typescript | `boolean` | `true` | No | - |
56
+ | configDirectory | `string` | `"/src/config/"` | No | - |
57
+ | generatedDirectory | `string` | `"/public/icons-generated/"` | No | - |
58
+ | spriteFileName | `string` | `_icon-sprite.svg` | No | Specify custom sprite file name |
59
+ | typeName | `string` | `IconsSet` | No | - |
60
+ | customDefinitionContent | `string` | - | No | - |
61
+ | icons | `Record<string, SimpleIcon \| SizedIcon \| IconFromAdapterFunction>` | - | Yes | More details [here](#icon-types) |
62
+ | fallbackFilesDirectory | - | - | No | More details [here](#adapters) |
52
63
 
53
64
  ## Icon Types
54
65
 
55
66
  ### SimpleIcon
67
+
56
68
  ```ts
57
69
  type SimpleIcon = {
58
70
  data: string;
@@ -60,7 +72,9 @@ type SimpleIcon = {
60
72
  width: number;
61
73
  };
62
74
  ```
75
+
63
76
  Example:
77
+
64
78
  ```js
65
79
  test: {
66
80
  width: 50,
@@ -70,10 +84,13 @@ test: {
70
84
  ```
71
85
 
72
86
  ### SizedIcon
87
+
73
88
  ```ts
74
89
  type SizedIcon = Record<number, string>;
75
90
  ```
91
+
76
92
  Example:
93
+
77
94
  ```js
78
95
  test: {
79
96
  24: `<path fill="#fecd09" d="M33.03 17.44c-1.68 0-3.12-.99-3.79-2.42h7.58a4.181 4.181 0 01-3.79 2.42z" />`,
@@ -84,17 +101,35 @@ test: {
84
101
  ## Predefined providers
85
102
 
86
103
  ### Font Awesome Pro Adapter
104
+
105
+ The adapter reads icons from per-style packages — install only the styles you actually use:
106
+
107
+ | Namespace | Package |
108
+ | --------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
109
+ | `brands.*` | `@fortawesome/free-brands-svg-icons` |
110
+ | `regular.*` | `@fortawesome/pro-regular-svg-icons` |
111
+ | `solid.*` | `@fortawesome/pro-solid-svg-icons` |
112
+ | `light.*` | `@fortawesome/pro-light-svg-icons` |
113
+ | `thin.*` | `@fortawesome/pro-thin-svg-icons` |
114
+ | `duotone.*`, `duotone-regular.*`, `duotone-light.*`, `duotone-thin.*` | `@fortawesome/pro-duotone[-{variant}]-svg-icons` |
115
+ | `sharp-regular.*`, `sharp-solid.*`, `sharp-light.*`, `sharp-thin.*` | `@fortawesome/sharp-{variant}-svg-icons` |
116
+ | `sharp-duotone-regular.*`, `sharp-duotone-solid.*`, `sharp-duotone-light.*`, `sharp-duotone-thin.*` | `@fortawesome/sharp-duotone-{variant}-svg-icons` |
117
+
118
+ The legacy `@fortawesome/fontawesome-pro` monolith is no longer supported — uninstall it if present.
119
+
87
120
  #### Local Development Setup
121
+
88
122
  ```bash
89
- // Set registry and token
123
+ # Set registry and token
90
124
  npm config set "@fortawesome:registry" https://npm.fontawesome.com/
91
125
  npm config set "//npm.fontawesome.com/:_authToken" YOUR_TOKEN
92
126
 
93
- // Install package
94
- npm install --save-dev @fortawesome/fontawesome-pro
127
+ # Install only the styles you use
128
+ npm install --save-dev @fortawesome/pro-regular-svg-icons @fortawesome/free-brands-svg-icons
95
129
  ```
96
130
 
97
131
  #### Usage
132
+
98
133
  ```js
99
134
  const { faPro } = require('@uxf/icons-generator/providers/fa-pro');
100
135
 
@@ -104,10 +139,11 @@ icons: {
104
139
  // to define custom name for an icon
105
140
  twitter: faPro.icon("brands.twitter"),
106
141
  }
107
- ````
142
+ ```
108
143
 
109
144
  #### Without Private Key
110
- If your project already contains generated icons, installing the Font Awesome Pro package is not necessary.
145
+
146
+ If your project already contains generated icons, installing the Font Awesome Pro packages is not necessary.
111
147
  The package automatically generates a 'fallback file' for the icons in use, ensuring functionality even without
112
148
  Font Awesome Pro. However, while this setup allows for the continued use of existing icons, adding new icons
113
149
  from the adapter will not be possible.
@@ -115,15 +151,19 @@ from the adapter will not be possible.
115
151
  ## Recommended Usage (Step-by-Step)
116
152
 
117
153
  ### 1. Configuration
154
+
118
155
  Create and configure your icon settings in a config file at the project's root.
119
156
 
120
157
  ### 2. Icon Generation
158
+
121
159
  Execute `icons-gen` to produce:
160
+
122
161
  - SVG sprite and individual files.
123
162
  - Definition file with icon list and sizes.
124
163
  - Config file with icon version and sprite path.
125
164
 
126
165
  ### 3. Icon Component Setup
166
+
127
167
  Incorporate the generated output into your project. Example for TypeScript and React:
128
168
 
129
169
  ```tsx
@@ -152,21 +192,17 @@ export const Icon: FC<IconProps> = ({ name }) => {
152
192
  ```
153
193
 
154
194
  ### 4. Sprite Preloading (Optional)
195
+
155
196
  ```tsx
156
197
  import { ICON_SPRITE, ICONS_VERSION } from "src/config/icons-config";
157
198
 
158
199
  // code here...
159
200
 
160
201
  <Head>
161
- <link
162
- as="image"
163
- href={`${ICON_SPRITE}?v=${ICONS_VERSION}`}
164
- rel="preload"
165
- type="image/svg+xml"
166
- />
167
- </Head>
202
+ <link as="image" href={`${ICON_SPRITE}?v=${ICONS_VERSION}`} rel="preload" type="image/svg+xml" />
203
+ </Head>;
168
204
  ```
169
205
 
170
206
  ### 5. Verification
171
- Run `icons-check` to ensure icon consistency with the config. It's recommended to integrate this check into your CI process.
172
207
 
208
+ Run `icons-check` to ensure icon consistency with the config. It's recommended to integrate this check into your CI process.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/icons-generator",
3
- "version": "11.111.2",
3
+ "version": "11.118.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,12 +22,28 @@
22
22
  "yargs": "18.0.0"
23
23
  },
24
24
  "peerDependencies": {
25
- "@uxf/core": "11.111.2"
25
+ "@uxf/core": "11.114.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@fortawesome/fontawesome-pro": "7.0.0",
28
+ "@fortawesome/duotone-light-svg-icons": "7.2.0",
29
+ "@fortawesome/duotone-regular-svg-icons": "7.2.0",
30
+ "@fortawesome/duotone-thin-svg-icons": "7.2.0",
31
+ "@fortawesome/free-brands-svg-icons": "7.2.0",
32
+ "@fortawesome/pro-duotone-svg-icons": "7.2.0",
33
+ "@fortawesome/pro-light-svg-icons": "7.2.0",
34
+ "@fortawesome/pro-regular-svg-icons": "7.2.0",
35
+ "@fortawesome/pro-solid-svg-icons": "7.2.0",
36
+ "@fortawesome/pro-thin-svg-icons": "7.2.0",
37
+ "@fortawesome/sharp-duotone-light-svg-icons": "7.2.0",
38
+ "@fortawesome/sharp-duotone-regular-svg-icons": "7.2.0",
39
+ "@fortawesome/sharp-duotone-solid-svg-icons": "7.2.0",
40
+ "@fortawesome/sharp-duotone-thin-svg-icons": "7.2.0",
41
+ "@fortawesome/sharp-light-svg-icons": "7.2.0",
42
+ "@fortawesome/sharp-regular-svg-icons": "7.2.0",
43
+ "@fortawesome/sharp-solid-svg-icons": "7.2.0",
44
+ "@fortawesome/sharp-thin-svg-icons": "7.2.0",
29
45
  "@types/node": "24",
30
- "@uxf/core": "11.111.2"
46
+ "@uxf/core": "11.114.0"
31
47
  },
32
48
  "author": "",
33
49
  "license": "ISC",
@@ -1,27 +1,93 @@
1
- const readdirSync = require("fs").readdirSync;
2
- const writeFileSync = require("fs").writeFileSync;
1
+ "use strict";
3
2
 
4
- const getFaProIconNamesType = () => {
5
- const dir = readdirSync(__dirname + "/../../../node_modules/@fortawesome/fontawesome-pro/svgs/");
3
+ const { existsSync, writeFileSync } = require("fs");
4
+ const path = require("path");
6
5
 
7
- if (!dir.length) {
8
- throw new Error("You need to install @fortawesome/fontawesome-pro first!");
9
- }
6
+ // Keep in sync with NAMESPACE_TO_PACKAGE in src/providers/fa-pro.ts.
7
+ const NAMESPACE_TO_PACKAGE = {
8
+ brands: "@fortawesome/free-brands-svg-icons",
9
+ duotone: "@fortawesome/pro-duotone-svg-icons",
10
+ "duotone-light": "@fortawesome/duotone-light-svg-icons",
11
+ "duotone-regular": "@fortawesome/duotone-regular-svg-icons",
12
+ "duotone-thin": "@fortawesome/duotone-thin-svg-icons",
13
+ light: "@fortawesome/pro-light-svg-icons",
14
+ regular: "@fortawesome/pro-regular-svg-icons",
15
+ "sharp-duotone-light": "@fortawesome/sharp-duotone-light-svg-icons",
16
+ "sharp-duotone-regular": "@fortawesome/sharp-duotone-regular-svg-icons",
17
+ "sharp-duotone-solid": "@fortawesome/sharp-duotone-solid-svg-icons",
18
+ "sharp-duotone-thin": "@fortawesome/sharp-duotone-thin-svg-icons",
19
+ "sharp-light": "@fortawesome/sharp-light-svg-icons",
20
+ "sharp-regular": "@fortawesome/sharp-regular-svg-icons",
21
+ "sharp-solid": "@fortawesome/sharp-solid-svg-icons",
22
+ "sharp-thin": "@fortawesome/sharp-thin-svg-icons",
23
+ solid: "@fortawesome/pro-solid-svg-icons",
24
+ thin: "@fortawesome/pro-thin-svg-icons",
25
+ };
26
+
27
+ const LEGACY_PACKAGE = "@fortawesome/fontawesome-pro";
28
+
29
+ const NODE_MODULES_PATH = process.env.NODE_MODULES_PATH ?? path.join(__dirname, "../../../node_modules");
10
30
 
11
- let names = [];
31
+ const collectIconNames = (pkgName) => {
32
+ const pkgPath = path.join(NODE_MODULES_PATH, pkgName);
33
+ if (!existsSync(pkgPath)) {
34
+ return null;
35
+ }
36
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
37
+ const pkgExports = require(pkgPath);
38
+ const names = new Set();
39
+ for (const value of Object.values(pkgExports)) {
40
+ if (value && typeof value === "object" && typeof value.iconName === "string") {
41
+ names.add(value.iconName);
42
+ }
43
+ }
44
+ return [...names].sort();
45
+ };
12
46
 
13
- for (const namespace of dir) {
14
- const icons = readdirSync(__dirname + `/../../../node_modules/@fortawesome/fontawesome-pro/svgs/${namespace}`);
47
+ const generate = () => {
48
+ if (existsSync(path.join(NODE_MODULES_PATH, LEGACY_PACKAGE))) {
49
+ throw new Error(
50
+ `Package "${LEGACY_PACKAGE}" is installed but no longer used. The faPro adapter reads from per-style packages instead. Run \`yarn remove ${LEGACY_PACKAGE}\`.`,
51
+ );
52
+ }
15
53
 
16
- for (const icon of icons) {
17
- const iconName = icon.replace(/\.svg$/, "");
54
+ const names = [];
55
+ const found = [];
56
+ const missing = [];
18
57
 
58
+ for (const [namespace, pkgName] of Object.entries(NAMESPACE_TO_PACKAGE)) {
59
+ const iconNames = collectIconNames(pkgName);
60
+ if (iconNames === null) {
61
+ missing.push(`${namespace} (${pkgName})`);
62
+ continue;
63
+ }
64
+ found.push(`${namespace}: ${iconNames.length}`);
65
+ for (const iconName of iconNames) {
19
66
  names.push(`"${namespace}.${iconName}"`);
20
67
  }
21
68
  }
22
69
 
23
- writeFileSync(__dirname + "/../src/fa-pro-types.ts", `export type FaProIconName = ${names.join(" | ")};\n`);
24
- console.log(`Great, generated ${names.length} FA Pro icon names!`);
70
+ if (names.length === 0) {
71
+ throw new Error(
72
+ "No Font Awesome per-style packages found. Install at least one, e.g. `yarn add -D @fortawesome/pro-regular-svg-icons`.",
73
+ );
74
+ }
75
+
76
+ writeFileSync(
77
+ path.join(__dirname, "../src/fa-pro-types.ts"),
78
+ `export type FaProIconName = ${names.join(" | ")};\n`,
79
+ );
80
+
81
+ console.log(`Generated ${names.length} FA Pro icon names from ${found.length} package(s).`);
82
+ for (const line of found) {
83
+ console.log(` ${line}`);
84
+ }
85
+ if (missing.length > 0) {
86
+ console.log(`Skipped (not installed):`);
87
+ for (const line of missing) {
88
+ console.log(` ${line}`);
89
+ }
90
+ }
25
91
  };
26
92
 
27
- getFaProIconNamesType();
93
+ generate();