react-native-nano-icons 0.1.1 → 0.1.2
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/lib/commonjs/plugin/src/buildFonts.d.ts +1 -0
- package/lib/commonjs/plugin/src/buildFonts.js +9 -0
- package/lib/commonjs/plugin/src/index.js +1 -34
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +6 -6
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +11 -15
- package/package.json +1 -1
- package/plugin/src/buildFonts.ts +13 -0
- package/plugin/src/index.ts +3 -50
- package/plugin/src/withNanoIconsFontLinking.ts +22 -24
|
@@ -5,3 +5,4 @@ import type { IconSetConfig, BuiltFont } from './types.js';
|
|
|
5
5
|
* unless EXPO_DEBUG is set, in which case the full error is re-thrown.
|
|
6
6
|
*/
|
|
7
7
|
export declare function buildAllFonts(iconSets: IconSetConfig[], projectRoot: string): Promise<BuiltFont[]>;
|
|
8
|
+
export declare function getOrBuildFonts(projectRoot: string, iconSets: IconSetConfig[]): Promise<BuiltFont[]>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildAllFonts = buildAllFonts;
|
|
4
|
+
exports.getOrBuildFonts = getOrBuildFonts;
|
|
4
5
|
const index_js_1 = require("../../cli/index.js");
|
|
5
6
|
/**
|
|
6
7
|
* Build TTF + glyphmap for all icon sets.
|
|
@@ -21,3 +22,11 @@ async function buildAllFonts(iconSets, projectRoot) {
|
|
|
21
22
|
return [];
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
// Single build run per process; reused across ios/android mods.
|
|
26
|
+
let _buildPromise = null;
|
|
27
|
+
function getOrBuildFonts(projectRoot, iconSets) {
|
|
28
|
+
if (!_buildPromise) {
|
|
29
|
+
_buildPromise = buildAllFonts(iconSets, projectRoot);
|
|
30
|
+
}
|
|
31
|
+
return _buildPromise;
|
|
32
|
+
}
|
|
@@ -1,43 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const config_plugins_1 = require("@expo/config-plugins");
|
|
4
|
-
const buildFonts_js_1 = require("./buildFonts.js");
|
|
5
3
|
const withNanoIconsFontLinking_js_1 = require("./withNanoIconsFontLinking.js");
|
|
6
|
-
const BUILT_FONTS_KEY = '_nanoIconsBuilt';
|
|
7
|
-
// Single Pyodide/PathKit run for the whole prebuild; reused across ios/android mods.
|
|
8
|
-
let _builtFontsCache = null;
|
|
9
|
-
function getOrBuildFonts(projectRoot, iconSets) {
|
|
10
|
-
if (_builtFontsCache)
|
|
11
|
-
return Promise.resolve(_builtFontsCache);
|
|
12
|
-
return (0, buildFonts_js_1.buildAllFonts)(iconSets, projectRoot).then((built) => {
|
|
13
|
-
_builtFontsCache = built;
|
|
14
|
-
return built;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
4
|
const withNanoIcons = (config, options) => {
|
|
18
5
|
if (!options?.iconSets?.length)
|
|
19
6
|
return config;
|
|
20
|
-
|
|
21
|
-
config = (0, config_plugins_1.withDangerousMod)(config, [
|
|
22
|
-
'ios',
|
|
23
|
-
async (config) => {
|
|
24
|
-
const projectRoot = config.modRequest.projectRoot;
|
|
25
|
-
const built = await getOrBuildFonts(projectRoot, options.iconSets);
|
|
26
|
-
config[BUILT_FONTS_KEY] = built;
|
|
27
|
-
return config;
|
|
28
|
-
},
|
|
29
|
-
]);
|
|
30
|
-
config = (0, config_plugins_1.withDangerousMod)(config, [
|
|
31
|
-
'android',
|
|
32
|
-
async (config) => {
|
|
33
|
-
const projectRoot = config.modRequest.projectRoot;
|
|
34
|
-
const built = await getOrBuildFonts(projectRoot, options.iconSets);
|
|
35
|
-
config[BUILT_FONTS_KEY] = built;
|
|
36
|
-
return config;
|
|
37
|
-
},
|
|
38
|
-
]);
|
|
39
|
-
// Link built TTFs into native projects (reads _nanoIconsBuilt from config).
|
|
40
|
-
config = (0, withNanoIconsFontLinking_js_1.withNanoIconsFontLinking)(config);
|
|
7
|
+
config = (0, withNanoIconsFontLinking_js_1.withNanoIconsFontLinking)(config, options.iconSets);
|
|
41
8
|
return config;
|
|
42
9
|
};
|
|
43
10
|
exports.default = withNanoIcons;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { withXcodeProject, withDangerousMod } from '@expo/config-plugins';
|
|
2
|
+
import type { IconSetConfig } from './types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Add TTFs to the iOS project (Resources group + UIAppFonts in Info.plist).
|
|
4
|
-
* Reads cached built font paths from config._nanoIconsBuilt (set by the build mod) to prevent redundant builds for iOS and Android.
|
|
5
5
|
*/
|
|
6
|
-
export declare function withNanoIconsIos(config: Parameters<typeof withXcodeProject>[0]): ReturnType<typeof withXcodeProject>;
|
|
6
|
+
export declare function withNanoIconsIos(config: Parameters<typeof withXcodeProject>[0], iconSets: IconSetConfig[]): ReturnType<typeof withXcodeProject>;
|
|
7
7
|
/**
|
|
8
|
-
* Copy TTFs to Android assets/fonts.
|
|
8
|
+
* Copy TTFs to Android assets/fonts.
|
|
9
9
|
*/
|
|
10
|
-
export declare function withNanoIconsAndroid(config: Parameters<typeof withDangerousMod>[0]): ReturnType<typeof withDangerousMod>;
|
|
10
|
+
export declare function withNanoIconsAndroid(config: Parameters<typeof withDangerousMod>[0], iconSets: IconSetConfig[]): ReturnType<typeof withDangerousMod>;
|
|
11
11
|
/**
|
|
12
|
-
* Apply iOS and Android font linking.
|
|
12
|
+
* Apply iOS and Android font linking.
|
|
13
13
|
*/
|
|
14
|
-
export declare function withNanoIconsFontLinking(config: Parameters<typeof withNanoIconsIos>[0]): ReturnType<typeof withNanoIconsAndroid>;
|
|
14
|
+
export declare function withNanoIconsFontLinking(config: Parameters<typeof withNanoIconsIos>[0], iconSets: IconSetConfig[]): ReturnType<typeof withNanoIconsAndroid>;
|
|
@@ -9,18 +9,14 @@ exports.withNanoIconsFontLinking = withNanoIconsFontLinking;
|
|
|
9
9
|
const config_plugins_1 = require("@expo/config-plugins");
|
|
10
10
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const buildFonts_js_1 = require("./buildFonts.js");
|
|
12
13
|
const ANDROID_ASSETS_FONTS_DIR = 'app/src/main/assets/fonts';
|
|
13
|
-
const BUILT_FONTS_KEY = '_nanoIconsBuilt';
|
|
14
|
-
function getBuiltFonts(config) {
|
|
15
|
-
return config[BUILT_FONTS_KEY];
|
|
16
|
-
}
|
|
17
14
|
/**
|
|
18
15
|
* Add TTFs to the iOS project (Resources group + UIAppFonts in Info.plist).
|
|
19
|
-
* Reads cached built font paths from config._nanoIconsBuilt (set by the build mod) to prevent redundant builds for iOS and Android.
|
|
20
16
|
*/
|
|
21
|
-
function withNanoIconsIos(config) {
|
|
17
|
+
function withNanoIconsIos(config, iconSets) {
|
|
22
18
|
config = (0, config_plugins_1.withXcodeProject)(config, async (config) => {
|
|
23
|
-
const built =
|
|
19
|
+
const built = await (0, buildFonts_js_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
|
|
24
20
|
if (!built?.length)
|
|
25
21
|
return config;
|
|
26
22
|
const ttfPaths = built.map((b) => b.ttfPath);
|
|
@@ -40,7 +36,7 @@ function withNanoIconsIos(config) {
|
|
|
40
36
|
return config;
|
|
41
37
|
});
|
|
42
38
|
config = (0, config_plugins_1.withInfoPlist)(config, async (config) => {
|
|
43
|
-
const built =
|
|
39
|
+
const built = await (0, buildFonts_js_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
|
|
44
40
|
if (!built?.length)
|
|
45
41
|
return config;
|
|
46
42
|
const ttfPaths = built.map((b) => b.ttfPath);
|
|
@@ -62,13 +58,13 @@ function getUIAppFonts(infoPlist) {
|
|
|
62
58
|
return [];
|
|
63
59
|
}
|
|
64
60
|
/**
|
|
65
|
-
* Copy TTFs to Android assets/fonts.
|
|
61
|
+
* Copy TTFs to Android assets/fonts.
|
|
66
62
|
*/
|
|
67
|
-
function withNanoIconsAndroid(config) {
|
|
63
|
+
function withNanoIconsAndroid(config, iconSets) {
|
|
68
64
|
return (0, config_plugins_1.withDangerousMod)(config, [
|
|
69
65
|
'android',
|
|
70
66
|
async (config) => {
|
|
71
|
-
const built =
|
|
67
|
+
const built = await (0, buildFonts_js_1.getOrBuildFonts)(config.modRequest.projectRoot, iconSets);
|
|
72
68
|
if (!built?.length)
|
|
73
69
|
return config;
|
|
74
70
|
const fontsDir = path_1.default.join(config.modRequest.platformProjectRoot, ANDROID_ASSETS_FONTS_DIR);
|
|
@@ -83,10 +79,10 @@ function withNanoIconsAndroid(config) {
|
|
|
83
79
|
]);
|
|
84
80
|
}
|
|
85
81
|
/**
|
|
86
|
-
* Apply iOS and Android font linking.
|
|
82
|
+
* Apply iOS and Android font linking.
|
|
87
83
|
*/
|
|
88
|
-
function withNanoIconsFontLinking(config) {
|
|
89
|
-
config = withNanoIconsIos(config);
|
|
90
|
-
config = withNanoIconsAndroid(config);
|
|
84
|
+
function withNanoIconsFontLinking(config, iconSets) {
|
|
85
|
+
config = withNanoIconsIos(config, iconSets);
|
|
86
|
+
config = withNanoIconsAndroid(config, iconSets);
|
|
91
87
|
return config;
|
|
92
88
|
}
|
package/package.json
CHANGED
package/plugin/src/buildFonts.ts
CHANGED
|
@@ -27,3 +27,16 @@ export async function buildAllFonts(
|
|
|
27
27
|
return [];
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
// Single build run per process; reused across ios/android mods.
|
|
32
|
+
let _buildPromise: Promise<BuiltFont[]> | null = null;
|
|
33
|
+
|
|
34
|
+
export function getOrBuildFonts(
|
|
35
|
+
projectRoot: string,
|
|
36
|
+
iconSets: IconSetConfig[]
|
|
37
|
+
): Promise<BuiltFont[]> {
|
|
38
|
+
if (!_buildPromise) {
|
|
39
|
+
_buildPromise = buildAllFonts(iconSets, projectRoot);
|
|
40
|
+
}
|
|
41
|
+
return _buildPromise;
|
|
42
|
+
}
|
package/plugin/src/index.ts
CHANGED
|
@@ -1,31 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ConfigPlugin,
|
|
3
|
-
ExportedConfigWithProps,
|
|
4
|
-
} from '@expo/config-plugins';
|
|
5
|
-
import { withDangerousMod } from '@expo/config-plugins';
|
|
6
|
-
import { buildAllFonts } from './buildFonts.js';
|
|
1
|
+
import type { ConfigPlugin } from '@expo/config-plugins';
|
|
7
2
|
import { withNanoIconsFontLinking } from './withNanoIconsFontLinking.js';
|
|
8
|
-
import type {
|
|
9
|
-
NanoIconsPluginOptions,
|
|
10
|
-
IconSetConfig,
|
|
11
|
-
BuiltFont,
|
|
12
|
-
} from './types.js';
|
|
13
|
-
|
|
14
|
-
const BUILT_FONTS_KEY = '_nanoIconsBuilt';
|
|
15
|
-
|
|
16
|
-
// Single Pyodide/PathKit run for the whole prebuild; reused across ios/android mods.
|
|
17
|
-
let _builtFontsCache: BuiltFont[] | null = null;
|
|
18
|
-
|
|
19
|
-
function getOrBuildFonts(
|
|
20
|
-
projectRoot: string,
|
|
21
|
-
iconSets: IconSetConfig[]
|
|
22
|
-
): Promise<BuiltFont[]> {
|
|
23
|
-
if (_builtFontsCache) return Promise.resolve(_builtFontsCache);
|
|
24
|
-
return buildAllFonts(iconSets, projectRoot).then((built: BuiltFont[]) => {
|
|
25
|
-
_builtFontsCache = built;
|
|
26
|
-
return built;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
3
|
+
import type { NanoIconsPluginOptions } from './types.js';
|
|
29
4
|
|
|
30
5
|
const withNanoIcons: ConfigPlugin<NanoIconsPluginOptions> = (
|
|
31
6
|
config,
|
|
@@ -33,29 +8,7 @@ const withNanoIcons: ConfigPlugin<NanoIconsPluginOptions> = (
|
|
|
33
8
|
) => {
|
|
34
9
|
if (!options?.iconSets?.length) return config;
|
|
35
10
|
|
|
36
|
-
|
|
37
|
-
config = withDangerousMod(config, [
|
|
38
|
-
'ios',
|
|
39
|
-
async (config: ExportedConfigWithProps<unknown>) => {
|
|
40
|
-
const projectRoot = config.modRequest.projectRoot;
|
|
41
|
-
const built = await getOrBuildFonts(projectRoot, options.iconSets);
|
|
42
|
-
(config as unknown as Record<string, unknown>)[BUILT_FONTS_KEY] = built;
|
|
43
|
-
return config;
|
|
44
|
-
},
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
config = withDangerousMod(config, [
|
|
48
|
-
'android',
|
|
49
|
-
async (config: ExportedConfigWithProps<unknown>) => {
|
|
50
|
-
const projectRoot = config.modRequest.projectRoot;
|
|
51
|
-
const built = await getOrBuildFonts(projectRoot, options.iconSets);
|
|
52
|
-
(config as unknown as Record<string, unknown>)[BUILT_FONTS_KEY] = built;
|
|
53
|
-
return config;
|
|
54
|
-
},
|
|
55
|
-
]);
|
|
56
|
-
|
|
57
|
-
// Link built TTFs into native projects (reads _nanoIconsBuilt from config).
|
|
58
|
-
config = withNanoIconsFontLinking(config);
|
|
11
|
+
config = withNanoIconsFontLinking(config, options.iconSets);
|
|
59
12
|
|
|
60
13
|
return config;
|
|
61
14
|
};
|
|
@@ -4,31 +4,25 @@ import {
|
|
|
4
4
|
withXcodeProject,
|
|
5
5
|
withDangerousMod,
|
|
6
6
|
} from '@expo/config-plugins';
|
|
7
|
+
import type { InfoPlist } from '@expo/config-plugins';
|
|
7
8
|
import fs from 'fs/promises';
|
|
8
9
|
import path from 'path';
|
|
9
|
-
import
|
|
10
|
-
type
|
|
10
|
+
import { getOrBuildFonts } from './buildFonts.js';
|
|
11
|
+
import type { IconSetConfig } from './types.js';
|
|
11
12
|
|
|
12
13
|
const ANDROID_ASSETS_FONTS_DIR = 'app/src/main/assets/fonts';
|
|
13
14
|
|
|
14
|
-
const BUILT_FONTS_KEY = '_nanoIconsBuilt' as const;
|
|
15
|
-
|
|
16
|
-
function getBuiltFonts(config: {
|
|
17
|
-
[key: string]: unknown;
|
|
18
|
-
}): BuiltFont[] | undefined {
|
|
19
|
-
return config[BUILT_FONTS_KEY] as BuiltFont[] | undefined;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
15
|
/**
|
|
23
16
|
* Add TTFs to the iOS project (Resources group + UIAppFonts in Info.plist).
|
|
24
|
-
* Reads cached built font paths from config._nanoIconsBuilt (set by the build mod) to prevent redundant builds for iOS and Android.
|
|
25
17
|
*/
|
|
26
18
|
export function withNanoIconsIos(
|
|
27
|
-
config: Parameters<typeof withXcodeProject>[0]
|
|
19
|
+
config: Parameters<typeof withXcodeProject>[0],
|
|
20
|
+
iconSets: IconSetConfig[]
|
|
28
21
|
): ReturnType<typeof withXcodeProject> {
|
|
29
22
|
config = withXcodeProject(config, async (config) => {
|
|
30
|
-
const built =
|
|
31
|
-
config
|
|
23
|
+
const built = await getOrBuildFonts(
|
|
24
|
+
config.modRequest.projectRoot,
|
|
25
|
+
iconSets
|
|
32
26
|
);
|
|
33
27
|
if (!built?.length) return config;
|
|
34
28
|
const ttfPaths = built.map((b) => b.ttfPath);
|
|
@@ -51,8 +45,9 @@ export function withNanoIconsIos(
|
|
|
51
45
|
config = withInfoPlist(
|
|
52
46
|
config as Parameters<typeof withInfoPlist>[0],
|
|
53
47
|
async (config) => {
|
|
54
|
-
const built =
|
|
55
|
-
config
|
|
48
|
+
const built = await getOrBuildFonts(
|
|
49
|
+
config.modRequest.projectRoot,
|
|
50
|
+
iconSets
|
|
56
51
|
);
|
|
57
52
|
if (!built?.length) return config;
|
|
58
53
|
const ttfPaths = built.map((b) => b.ttfPath);
|
|
@@ -80,16 +75,18 @@ function getUIAppFonts(infoPlist: InfoPlist): string[] {
|
|
|
80
75
|
}
|
|
81
76
|
|
|
82
77
|
/**
|
|
83
|
-
* Copy TTFs to Android assets/fonts.
|
|
78
|
+
* Copy TTFs to Android assets/fonts.
|
|
84
79
|
*/
|
|
85
80
|
export function withNanoIconsAndroid(
|
|
86
|
-
config: Parameters<typeof withDangerousMod>[0]
|
|
81
|
+
config: Parameters<typeof withDangerousMod>[0],
|
|
82
|
+
iconSets: IconSetConfig[]
|
|
87
83
|
): ReturnType<typeof withDangerousMod> {
|
|
88
84
|
return withDangerousMod(config, [
|
|
89
85
|
'android',
|
|
90
86
|
async (config) => {
|
|
91
|
-
const built =
|
|
92
|
-
config
|
|
87
|
+
const built = await getOrBuildFonts(
|
|
88
|
+
config.modRequest.projectRoot,
|
|
89
|
+
iconSets
|
|
93
90
|
);
|
|
94
91
|
if (!built?.length) return config;
|
|
95
92
|
const fontsDir = path.join(
|
|
@@ -108,12 +105,13 @@ export function withNanoIconsAndroid(
|
|
|
108
105
|
}
|
|
109
106
|
|
|
110
107
|
/**
|
|
111
|
-
* Apply iOS and Android font linking.
|
|
108
|
+
* Apply iOS and Android font linking.
|
|
112
109
|
*/
|
|
113
110
|
export function withNanoIconsFontLinking(
|
|
114
|
-
config: Parameters<typeof withNanoIconsIos>[0]
|
|
111
|
+
config: Parameters<typeof withNanoIconsIos>[0],
|
|
112
|
+
iconSets: IconSetConfig[]
|
|
115
113
|
): ReturnType<typeof withNanoIconsAndroid> {
|
|
116
|
-
config = withNanoIconsIos(config);
|
|
117
|
-
config = withNanoIconsAndroid(config);
|
|
114
|
+
config = withNanoIconsIos(config, iconSets);
|
|
115
|
+
config = withNanoIconsAndroid(config, iconSets);
|
|
118
116
|
return config;
|
|
119
117
|
}
|