@uxf/icons-generator 11.15.1 → 11.23.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 +26 -47
- package/package.json +2 -2
- package/scripts/generate-fa-pro-types.js +27 -0
- package/src/fa-pro-types.d.ts +1 -1
- package/src/providers/fa-pro.d.ts +3 -0
- package/src/{adapters → providers}/fa-pro.js +21 -8
- package/src/scripts/index.js +0 -3
- package/src/types.d.ts +12 -21
- package/src/utils/_createDefinitionFileContent.js +16 -14
- package/src/utils/_createIconContent.d.ts +2 -2
- package/src/utils/_createSpriteContent.js +22 -33
- package/src/utils/_generateAdapterFallback.d.ts +6 -0
- package/src/utils/_generateAdapterFallback.js +15 -0
- package/src/utils/_generateSeparateIconFiles.js +29 -39
- package/src/utils/_getConfig.d.ts +1 -1
- package/src/utils/_getConfig.js +0 -1
- package/src/utils/_getIconNameForProvider.d.ts +1 -0
- package/src/utils/_getIconNameForProvider.js +5 -0
- package/src/utils/_iconTypeResolver.d.ts +6 -0
- package/src/utils/_iconTypeResolver.js +9 -0
- package/src/utils/_removeUnusedSeparateIconFiles.js +0 -10
- package/src/utils/_validateSourceData.js +23 -20
- package/tests/icons.config.js +10 -10
- package/src/adapters/fa-pro.d.ts +0 -6
- package/src/utils/_generateAdaptersFallbackFiles.d.ts +0 -2
- package/src/utils/_generateAdaptersFallbackFiles.js +0 -25
- package/src/utils/_getIconFromAdapterName.d.ts +0 -1
- package/src/utils/_getIconFromAdapterName.js +0 -5
- package/tests/icons.config.d.ts +0 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ yarn add -D @uxf/icons-generator
|
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
### Configuration
|
|
16
|
-
Create a `icons.config.
|
|
16
|
+
Create a `icons.config.js` file in your project's root:
|
|
17
17
|
```ts
|
|
18
18
|
module.exports = {
|
|
19
19
|
icons: {
|
|
@@ -39,22 +39,20 @@ icons-gen --configFile=yourConfigFileName.js
|
|
|
39
39
|
|
|
40
40
|
## Configuration Details
|
|
41
41
|
|
|
42
|
-
| Key | Type
|
|
43
|
-
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
| adapters | - | - | No | More details [here](#adapters) |
|
|
53
|
-
| fallbackFilesDirectory | - | - | No | More details [here](#adapters) |
|
|
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) |
|
|
54
52
|
|
|
55
53
|
## Icon Types
|
|
56
54
|
|
|
57
|
-
### SimpleIcon
|
|
55
|
+
### SimpleIcon
|
|
58
56
|
```ts
|
|
59
57
|
type SimpleIcon = {
|
|
60
58
|
data: string;
|
|
@@ -71,7 +69,7 @@ test: {
|
|
|
71
69
|
}
|
|
72
70
|
```
|
|
73
71
|
|
|
74
|
-
### SizedIcon
|
|
72
|
+
### SizedIcon
|
|
75
73
|
```ts
|
|
76
74
|
type SizedIcon = Record<number, string>;
|
|
77
75
|
```
|
|
@@ -83,38 +81,7 @@ test: {
|
|
|
83
81
|
}
|
|
84
82
|
```
|
|
85
83
|
|
|
86
|
-
##
|
|
87
|
-
Extend icon generation with adapters for external sources.
|
|
88
|
-
|
|
89
|
-
### Adapter Structure
|
|
90
|
-
An adapter in this context is a function designed to retrieve specific icon information, such as size and SVG path, based on the icon's name.
|
|
91
|
-
|
|
92
|
-
#### Example
|
|
93
|
-
```ts
|
|
94
|
-
export const getIconFromMyCustomAdapter = (iconName: string) => {
|
|
95
|
-
const icon = findIconDefinition({ iconName });
|
|
96
|
-
return { width: icon.width, height: icon.height, path: icon.data };
|
|
97
|
-
};
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Integration into your icons configuration is straightforward:
|
|
101
|
-
```ts
|
|
102
|
-
import { getIconFromMyCustomAdapter } from "./my-custom-adapter";
|
|
103
|
-
|
|
104
|
-
adapters: {
|
|
105
|
-
myAdapter: {
|
|
106
|
-
icons: ["user"],
|
|
107
|
-
getIcon: getIconFromMyCustomAdapter,
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
For type safety, you can create a typed configuration. Use a generated type from your icon list as a generic for the icons configuration:
|
|
113
|
-
```ts
|
|
114
|
-
const iconConfig: IconsConfig<{ myAdapter: MyAdapterIconNames; }> = {};
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
## Predefined adapters
|
|
84
|
+
## Predefined providers
|
|
118
85
|
|
|
119
86
|
### Font Awesome Pro Adapter
|
|
120
87
|
#### Local Development Setup
|
|
@@ -127,6 +94,18 @@ npm config set "//npm.fontawesome.com/:_authToken" YOUR_TOKEN
|
|
|
127
94
|
npm install --save-dev @fortawesome/fontawesome-pro
|
|
128
95
|
```
|
|
129
96
|
|
|
97
|
+
#### Usage
|
|
98
|
+
```js
|
|
99
|
+
const { faPro } = require('@uxf/icons-generator/providers/fa-pro');
|
|
100
|
+
|
|
101
|
+
icons: {
|
|
102
|
+
// for icons with default name (preferred)
|
|
103
|
+
...faPro.adapter(["brands.linkedin"]),
|
|
104
|
+
// to define custom name for an icon
|
|
105
|
+
twitter: faPro.icon("brands.twitter"),
|
|
106
|
+
}
|
|
107
|
+
````
|
|
108
|
+
|
|
130
109
|
#### Without Private Key
|
|
131
110
|
If your project already contains generated icons, installing the Font Awesome Pro package is not necessary.
|
|
132
111
|
The package automatically generates a 'fallback file' for the icons in use, ensuring functionality even without
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/icons-generator",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.23.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "npm run-script clean && npm run-script compile",
|
|
8
8
|
"clean": "rm -rf ./dist",
|
|
9
9
|
"compile": "tsc -P tsconfig.json",
|
|
10
|
-
"test": "NODE_MODULES_PATH=../../node_modules ts-node ./bin/icons-gen.ts --configFile=tests/icons.config.
|
|
10
|
+
"test": "NODE_MODULES_PATH=../../node_modules ts-node ./bin/icons-gen.ts --configFile=tests/icons.config.js",
|
|
11
11
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
12
12
|
},
|
|
13
13
|
"publishConfig": {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const readdirSync = require("fs").readdirSync;
|
|
2
|
+
const writeFileSync = require("fs").writeFileSync;
|
|
3
|
+
|
|
4
|
+
const getFaProIconNamesType = () => {
|
|
5
|
+
const dir = readdirSync(__dirname + "/../../../node_modules/@fortawesome/fontawesome-pro/svgs/");
|
|
6
|
+
|
|
7
|
+
if (!dir.length) {
|
|
8
|
+
throw new Error("You need to install @fortawesome/fontawesome-pro first!");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let names = [];
|
|
12
|
+
|
|
13
|
+
for (const namespace of dir) {
|
|
14
|
+
const icons = readdirSync(__dirname + `/../../../node_modules/@fortawesome/fontawesome-pro/svgs/${namespace}`);
|
|
15
|
+
|
|
16
|
+
for (const icon of icons) {
|
|
17
|
+
const iconName = icon.replace(/\.svg$/, "");
|
|
18
|
+
|
|
19
|
+
names.push(`"${namespace}.${iconName}"`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
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!`);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
getFaProIconNamesType();
|