@react-native-vector-icons/common 0.0.1-alpha.2 → 0.0.1-alpha.20

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.
Files changed (46) hide show
  1. package/README.md +410 -0
  2. package/android/build.gradle +4 -4
  3. package/ios/VectorIcons.mm +83 -69
  4. package/lib/commonjs/NativeVectorIcons.js.map +1 -1
  5. package/lib/commonjs/NativeVectorIcons.web.js.map +1 -1
  6. package/lib/commonjs/create-icon-set.js +7 -19
  7. package/lib/commonjs/create-icon-set.js.map +1 -1
  8. package/lib/commonjs/create-icon-source-cache.js.map +1 -1
  9. package/lib/commonjs/ensure-native-module-available.js +1 -1
  10. package/lib/commonjs/ensure-native-module-available.js.map +1 -1
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/scripts/common.js +49 -0
  13. package/lib/commonjs/scripts/common.js.map +1 -0
  14. package/lib/commonjs/scripts/getFonts.js +6 -40
  15. package/lib/commonjs/scripts/getFonts.js.map +1 -1
  16. package/lib/commonjs/scripts/updatePlist.js +54 -0
  17. package/lib/commonjs/scripts/updatePlist.js.map +1 -0
  18. package/lib/module/NativeVectorIcons.js.map +1 -1
  19. package/lib/module/NativeVectorIcons.web.js.map +1 -1
  20. package/lib/module/create-icon-set.js +6 -18
  21. package/lib/module/create-icon-set.js.map +1 -1
  22. package/lib/module/create-icon-source-cache.js.map +1 -1
  23. package/lib/module/ensure-native-module-available.js.map +1 -1
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/scripts/common.js +41 -0
  26. package/lib/module/scripts/common.js.map +1 -0
  27. package/lib/module/scripts/getFonts.js +6 -39
  28. package/lib/module/scripts/getFonts.js.map +1 -1
  29. package/lib/module/scripts/updatePlist.js +49 -0
  30. package/lib/module/scripts/updatePlist.js.map +1 -0
  31. package/lib/typescript/src/NativeVectorIcons.d.ts.map +1 -1
  32. package/lib/typescript/src/create-icon-set.d.ts.map +1 -1
  33. package/lib/typescript/src/create-icon-source-cache.d.ts.map +1 -1
  34. package/lib/typescript/src/scripts/common.d.ts +2 -0
  35. package/lib/typescript/src/scripts/common.d.ts.map +1 -0
  36. package/lib/typescript/src/scripts/updatePlist.d.ts +3 -0
  37. package/lib/typescript/src/scripts/updatePlist.d.ts.map +1 -0
  38. package/package.json +20 -51
  39. package/react-native-vector-icons.podspec +54 -10
  40. package/src/NativeVectorIcons.ts +2 -12
  41. package/src/create-icon-set.tsx +19 -43
  42. package/src/create-icon-source-cache.ts +3 -7
  43. package/src/ensure-native-module-available.ts +1 -1
  44. package/src/scripts/common.ts +52 -0
  45. package/src/scripts/getFonts.ts +6 -47
  46. package/src/scripts/updatePlist.ts +58 -0
@@ -0,0 +1,52 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { resolveNodeModuleDir } from '@react-native-community/cli-tools';
4
+
5
+ const getPackageJson = (filename: string) => {
6
+ const packageData = fs.readFileSync(filename, 'utf-8');
7
+ const packageJson = JSON.parse(packageData);
8
+
9
+ return packageJson;
10
+ };
11
+
12
+ const getPackageFontDirectories = (packageJsonFilename: string) => {
13
+ const rootPackageJson = getPackageJson(packageJsonFilename);
14
+ const dependencies = Object.keys(rootPackageJson.dependencies || {});
15
+
16
+ const packageDirs: string[] = [];
17
+ dependencies.forEach((dependency) => {
18
+ const dir = resolveNodeModuleDir(packageJsonFilename, dependency);
19
+ const packageJson = getPackageJson(`${dir}/package.json`);
20
+ if (packageJson.keywords?.includes?.('react-native-vector-icons-icon')) {
21
+ packageDirs.push(`${dir}/fonts`);
22
+ }
23
+ });
24
+
25
+ return packageDirs;
26
+ };
27
+
28
+ const getLocalFontsDir = (packageJsonFilename: string) => {
29
+ const rootPackageJson = getPackageJson(packageJsonFilename);
30
+ const config = rootPackageJson.reactNativeVectorIcons || {};
31
+
32
+ return `${path.dirname(packageJsonFilename)}/${config.fontDir || 'rnvi-fonts'}`;
33
+ };
34
+
35
+ const getFonts = (fontDir: string) => {
36
+ if (!fs.existsSync(fontDir)) {
37
+ return [];
38
+ }
39
+
40
+ const fonts = fs.readdirSync(fontDir);
41
+ const fontPaths = fonts.map((font) => `${fontDir}/${font}`);
42
+
43
+ return fontPaths;
44
+ };
45
+
46
+ export const getFontPaths = (packageJsonFilename: string) => {
47
+ const packageDirs = getPackageFontDirectories(packageJsonFilename);
48
+ packageDirs.push(getLocalFontsDir(packageJsonFilename));
49
+ const fonts = packageDirs.map(getFonts);
50
+
51
+ return fonts.flat();
52
+ };
@@ -1,52 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import { resolveNodeModuleDir } from '@react-native-community/cli-tools';
3
+ import { getFontPaths } from "./common";
6
4
 
7
- const rootDir = process.argv[2];
8
- if (!rootDir) {
9
- throw new Error('Need rootDir as first argument');
5
+ const packageJsonFilename = process.argv[2];
6
+ if (!packageJsonFilename) {
7
+ throw new Error('Need the path to the roo package.json as the first argument');
10
8
  }
11
9
 
12
- const getPackageJson = (dir: string) => {
13
- const packageData = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8');
14
- const packageJson = JSON.parse(packageData);
15
-
16
- return packageJson;
17
- };
18
-
19
- const getPackages = () => {
20
- const rootPackageJson = getPackageJson(rootDir);
21
- const dependencies = Object.keys(rootPackageJson.dependencies || {});
22
-
23
- const packageDirs: string[] = [];
24
- dependencies.forEach((dependency) => {
25
- const dir = resolveNodeModuleDir(rootDir, dependency);
26
- const packageJson = getPackageJson(dir);
27
- if (packageJson.keywords?.includes?.('react-native-vector-icons-icon')) {
28
- packageDirs.push(dir);
29
- }
30
- });
31
- return packageDirs;
32
- };
33
-
34
- const getFonts = (dir: string) => {
35
- const fontDirs = [`${dir}/fonts`];
36
-
37
- const rootPackageJson = getPackageJson(rootDir);
38
- const config = rootPackageJson.reactNativeVectorIcons || {};
39
- fontDirs.push(`${rootDir}/${config.fontDir || 'rnvi-fonts'}`);
40
-
41
- fontDirs.forEach((fontDir) => {
42
- if (!fs.existsSync(fontDir)) {
43
- return;
44
- }
45
-
46
- const fonts = fs.readdirSync(fontDir);
47
- fonts.forEach((font) => console.log(`${fontDir}/${font}`));
48
- });
49
- };
50
-
51
- const packageDirs = getPackages();
52
- packageDirs.forEach((dir) => getFonts(dir));
10
+ const fonts = getFontPaths(packageJsonFilename);
11
+ fonts.map((font) => console.log(font)); // eslint-disable-line no-console
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+
4
+ import fs from 'node:fs';
5
+ import * as path from 'node:path';
6
+ import pc from 'picocolors';
7
+ import * as plist from 'plist';
8
+
9
+ import { getFontPaths } from './common';
10
+
11
+ const getFontName = (fontPath: string) => path.basename(fontPath);
12
+
13
+ const packageJsonFilename = process.argv[2];
14
+ if (!packageJsonFilename) {
15
+ throw new Error('Need the path to the root package.json as the first argument');
16
+ }
17
+
18
+ const infoPlistFilename = process.argv[3];
19
+ if (!infoPlistFilename) {
20
+ throw new Error('Need the path to the Info.plist as the second argument');
21
+ }
22
+
23
+ const fonts = getFontPaths(packageJsonFilename);
24
+ console.log(`Found ${fonts.length} fonts`);
25
+
26
+ const infoPlistContent = fs.readFileSync(infoPlistFilename, 'utf8');
27
+ const infoPlist = plist.parse(infoPlistContent) as Record<string, string[]>;
28
+
29
+ const plistFonts = new Set(infoPlist.UIAppFonts || []);
30
+ const providedFonts = new Set(fonts.map(getFontName));
31
+
32
+ let hasChanges = false;
33
+
34
+ // Check for missing fonts and add them
35
+ providedFonts.forEach((font) => {
36
+ if (!plistFonts.has(font)) {
37
+ plistFonts.add(font);
38
+ console.log(pc.green(`Added ${font}`));
39
+ hasChanges = true;
40
+ } else {
41
+ console.log(`Existing ${font}`);
42
+ }
43
+ });
44
+
45
+ // Check for extra fonts in Info.plist
46
+ plistFonts.forEach((font) => {
47
+ if (!providedFonts.has(font)) {
48
+ console.log(pc.red(`Extra ${font} (Please remove manually if not needed)`));
49
+ }
50
+ });
51
+
52
+ // Update Info.plist if there were changes
53
+ if (hasChanges) {
54
+ infoPlist.UIAppFonts = Array.from(plistFonts);
55
+ const updatedInfoPlistContent = plist.build(infoPlist).replace(/^ {2}/gm, '').replace(/ {2}/gm, '\t');
56
+
57
+ fs.writeFileSync(infoPlistFilename, updatedInfoPlistContent, 'utf8');
58
+ }