@gen3/toolsff 0.10.49 → 0.10.51

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.
@@ -146,6 +146,11 @@ const main = ()=>{
146
146
  short: 'b',
147
147
  default: '#858585'
148
148
  },
149
+ navigation: {
150
+ type: 'string',
151
+ short: 'b',
152
+ default: '#eaeaea'
153
+ },
149
154
  out: {
150
155
  type: 'string',
151
156
  short: 'o',
@@ -154,11 +159,11 @@ const main = ()=>{
154
159
  }
155
160
  });
156
161
  if (!themeFile) {
157
- console.log('No themefile found. Please provide a themefile with \'-t\'.');
162
+ console.log("No theme file found. Please provide a theme file with '-t'.");
158
163
  return;
159
164
  }
160
165
  if (themeFile && !existsSync(themeFile)) {
161
- console.log('No themefile found. Please provide a themefile with \'-t\'.');
166
+ console.log("No theme file found. Please provide a theme file with '-t'.");
162
167
  return;
163
168
  }
164
169
  const themeData = readFileSync(themeFile, {
@@ -1,10 +1,21 @@
1
1
  import { promises } from 'fs';
2
+ import path from 'path';
2
3
  import { importDirectory } from '@iconify/tools/lib/import/directory';
3
4
  import { cleanupSVG } from '@iconify/tools/lib/svg/cleanup';
4
5
  import { runSVGO } from '@iconify/tools/lib/optimise/svgo';
5
6
  import { parseColors, isEmptyColor } from '@iconify/tools/lib/colors/parse';
7
+ import * as fs from 'node:fs';
6
8
 
7
- const getArgs = (defaults = {})=>{
9
+ const getSubdirectories = (dir)=>{
10
+ const files = fs.readdirSync(dir);
11
+ const subDirs = files.filter((file)=>{
12
+ const stats = fs.statSync(path.join(dir, file));
13
+ return stats.isDirectory();
14
+ });
15
+ return subDirs;
16
+ };
17
+
18
+ const getArgs = (defaults)=>{
8
19
  const args = defaults;
9
20
  process.argv.slice(2, process.argv.length).forEach((arg)=>{
10
21
  // long arg
@@ -22,12 +33,10 @@ const getArgs = (defaults = {})=>{
22
33
  });
23
34
  return args;
24
35
  };
25
- const build = async (inpath, outpath, prefix = 'gen3')=>{
26
- // Import icons
27
- console.log(inpath, outpath, prefix);
36
+ const processIconSet = async (inpath, prefix)=>{
28
37
  const iconSet = await importDirectory(inpath, {
29
38
  prefix: prefix,
30
- includeSubDirs: true
39
+ includeSubDirs: false
31
40
  });
32
41
  // Validate, clean up, fix palette and optimise
33
42
  await iconSet.forEach(async (name, type)=>{
@@ -59,12 +68,65 @@ const build = async (inpath, outpath, prefix = 'gen3')=>{
59
68
  // Update icon
60
69
  iconSet.fromSVG(name, svg);
61
70
  });
62
- // Export as IconifyJSON
63
- const exported = JSON.stringify(iconSet.export(), null, '\t') + '\n';
64
- // Save to file
65
- await promises.writeFile(`${outpath}/${iconSet.prefix}.json`, exported, 'utf8');
71
+ return iconSet;
66
72
  };
73
+ const build = async (inpath, outpath, prefix = 'gen3')=>{
74
+ // Import icons
75
+ const subdirs = getSubdirectories(inpath);
76
+ subdirs.forEach((setPrefix)=>{
77
+ processIconSet(path.join(inpath, setPrefix), setPrefix).then((iconSet)=>{
78
+ const exported = JSON.stringify(iconSet.export(), null, '\t') + '\n';
79
+ // Save to file
80
+ promises.writeFile(`${outpath}/${iconSet.prefix}.json`, exported, 'utf8');
81
+ });
82
+ });
83
+ /* ----
84
+ console.log('subDirs:build', subdirs);
85
+ const iconSet = await importDirectory(inpath, {
86
+ prefix: prefix,
87
+ includeSubDirs: false,
88
+ });
89
+
90
+ // Validate, clean up, fix palette and optimise
91
+ await iconSet.forEach(async (name, type) => {
92
+ if (type !== 'icon') {
93
+ return;
94
+ }
95
+
96
+ const svg = iconSet.toSVG(name);
97
+ if (!svg) {
98
+ // Invalid icon
99
+ iconSet.remove(name);
100
+ return;
101
+ }
102
+
103
+ // Clean up and optimise icons
104
+ try {
105
+ await cleanupSVG(svg);
106
+ await parseColors(svg, {
107
+ defaultColor: 'currentColor',
108
+ callback: (attr, colorStr, color) => {
109
+ return !color || isEmptyColor(color) ? colorStr : 'currentColor';
110
+ },
111
+ });
112
+ await runSVGO(svg);
113
+ } catch (err) {
114
+ // Invalid icon
115
+ console.error(`Error parsing ${name}:`, err);
116
+ iconSet.remove(name);
117
+ return;
118
+ }
119
+
120
+ // Update icon
121
+ iconSet.fromSVG(name, svg);
122
+ });
123
+ ---*/ };
67
124
  const { inpath, outpath, prefix } = getArgs({
125
+ inpath: './',
126
+ outpath: './',
68
127
  prefix: 'gen3'
69
128
  });
70
- build(inpath, outpath, prefix);
129
+ const main = async ()=>{
130
+ await build(inpath, outpath, prefix);
131
+ };
132
+ main();
File without changes
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@gen3/toolsff",
3
- "version": "0.10.49",
3
+ "version": "0.10.51",
4
4
  "description": "tools for processing portal content",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "engines": {
8
- "npm": ">=10.2.3",
8
+ "npm": ">=10.8.2",
9
9
  "node": ">=20.11.0"
10
10
  },
11
11
  "scripts": {