react-native-bootsplash 7.0.0-beta.0 → 7.0.0-beta.1

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/src/generate.ts CHANGED
@@ -28,9 +28,7 @@ const PACKAGE_NAME = "react-native-bootsplash";
28
28
 
29
29
  let isExpo = false;
30
30
 
31
- export const workingPath =
32
- process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
33
-
31
+ const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
34
32
  const projectRoot = findProjectRoot(workingPath);
35
33
 
36
34
  export type Platforms = ("android" | "ios" | "web")[];
@@ -101,9 +99,8 @@ const parseColor = (value: string): Color => {
101
99
  return { hex: hex.toLowerCase(), rgb };
102
100
  };
103
101
 
104
- const getStoryboard = ({ props, extras }: { props: Props; extras: Extras }) => {
105
- const { background, logo } = props;
106
- const { fileNameSuffix, logoHeight } = extras;
102
+ const getStoryboard = (props: Props) => {
103
+ const { background, logo, fileNameSuffix } = props;
107
104
 
108
105
  const { R, G, B } = background.rgb;
109
106
  const frameWidth = 375;
@@ -130,7 +127,7 @@ const getStoryboard = ({ props, extras }: { props: Props; extras: Extras }) => {
130
127
  <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
131
128
  <subviews>
132
129
  <imageView autoresizesSubviews="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" image="BootSplashLogo-${fileNameSuffix}" translatesAutoresizingMaskIntoConstraints="NO" id="3lX-Ut-9ad">
133
- <rect key="frame" x="${(frameWidth - logo.width) / 2}" y="${(frameHeight - logoHeight) / 2}" width="${logo.width}" height="${logoHeight}"/>
130
+ <rect key="frame" x="${(frameWidth - logo.width) / 2}" y="${(frameHeight - logo.height) / 2}" width="${logo.width}" height="${logo.height}"/>
134
131
  <accessibility key="accessibilityConfiguration">
135
132
  <accessibilityTraits key="traits" image="YES" notEnabled="YES"/>
136
133
  </accessibility>
@@ -150,7 +147,7 @@ const getStoryboard = ({ props, extras }: { props: Props; extras: Extras }) => {
150
147
  </scene>
151
148
  </scenes>
152
149
  <resources>
153
- <image name="BootSplashLogo-${fileNameSuffix}" width="${logo.width}" height="${logoHeight}"/>
150
+ <image name="BootSplashLogo-${fileNameSuffix}" width="${logo.width}" height="${logo.height}"/>
154
151
  <namedColor name="BootSplashBackground-${fileNameSuffix}">
155
152
  <color red="${R}" green="${G}" blue="${B}" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
156
153
  </namedColor>
@@ -255,37 +252,6 @@ export const writeXmlLike = async (
255
252
  }
256
253
  };
257
254
 
258
- export type Asset = {
259
- path: string;
260
- image: Sharp;
261
- width: number;
262
- };
263
-
264
- const getAssetBase64 = async (
265
- name: string,
266
- asset: Asset | undefined,
267
- ): Promise<string> => {
268
- if (asset == null) {
269
- return "";
270
- }
271
-
272
- const { image, width } = asset;
273
- const { format } = await image.metadata();
274
-
275
- if (format !== "png" && format !== "svg") {
276
- log.error(`${name} image file format (${format}) is not supported`);
277
- process.exit(1);
278
- }
279
-
280
- const buffer = await image
281
- .clone()
282
- .resize(width)
283
- .png({ quality: 100 })
284
- .toBuffer();
285
-
286
- return buffer.toString("base64");
287
- };
288
-
289
255
  const getAndroidOutputPath = ({
290
256
  flavor,
291
257
  platforms,
@@ -390,20 +356,7 @@ const getInfoPlistPath = ({
390
356
  return path.resolve(iosOutputPath, "Info.plist");
391
357
  };
392
358
 
393
- const getAssetHeight = (asset: Asset | undefined): Promise<number> => {
394
- if (asset == null) {
395
- return Promise.resolve(0);
396
- }
397
-
398
- return asset.image
399
- .clone()
400
- .resize(asset.width)
401
- .toBuffer()
402
- .then((buffer) => sharp(buffer).metadata())
403
- .then(({ height = 0 }) => Math.round(height));
404
- };
405
-
406
- type Config = {
359
+ type RawProps = {
407
360
  logo: string;
408
361
  background: string;
409
362
  logoWidth: number;
@@ -421,57 +374,90 @@ type Config = {
421
374
  };
422
375
  };
423
376
 
424
- const getProps = ({ android = {}, licenseKey, ...config }: Config) => {
377
+ export type Asset = {
378
+ path: string;
379
+ image: Sharp;
380
+ hash: string;
381
+ height: number;
382
+ width: number;
383
+ };
384
+
385
+ const toAsset = async (filePath: string, width: number): Promise<Asset> => {
386
+ const image = sharp(filePath);
387
+ const { format } = await image.metadata();
388
+
389
+ if (format !== "png" && format !== "svg") {
390
+ log.error(
391
+ `${path.basename(filePath)} image file format (${format}) is not supported`,
392
+ );
393
+ process.exit(1);
394
+ }
395
+
396
+ const [height, hash] = await Promise.all([
397
+ image
398
+ .clone()
399
+ .resize(width)
400
+ .toBuffer()
401
+ .then((buffer) => sharp(buffer).metadata())
402
+ .then(({ height = 0 }) => Math.round(height)),
403
+
404
+ image
405
+ .clone()
406
+ .resize(width)
407
+ .png({ quality: 100 })
408
+ .toBuffer()
409
+ .then((buffer) => buffer.toString("base64")),
410
+ ]);
411
+
412
+ return {
413
+ path: filePath,
414
+ image,
415
+ hash,
416
+ height,
417
+ width,
418
+ };
419
+ };
420
+
421
+ const transformProps = async (
422
+ rootPath: string,
423
+ { android = {}, licenseKey, ...rawProps }: RawProps,
424
+ ) => {
425
425
  if (semver.lt(process.versions.node, "20.0.0")) {
426
426
  log.error("Requires Node 20 (or higher)");
427
427
  process.exit(1);
428
428
  }
429
429
 
430
- const assetsOutputPath = path.resolve(workingPath, config.assetsOutput);
431
- const logoPath = path.resolve(workingPath, config.logo);
430
+ const assetsOutputPath = path.resolve(rootPath, rawProps.assetsOutput);
431
+ const logoPath = path.resolve(rootPath, rawProps.logo);
432
432
 
433
433
  const darkLogoPath =
434
- config.darkLogo != null
435
- ? path.resolve(workingPath, config.darkLogo)
434
+ rawProps.darkLogo != null
435
+ ? path.resolve(rootPath, rawProps.darkLogo)
436
436
  : undefined;
437
437
 
438
438
  const brandPath =
439
- config.brand != null ? path.resolve(workingPath, config.brand) : undefined;
439
+ rawProps.brand != null ? path.resolve(rootPath, rawProps.brand) : undefined;
440
440
 
441
441
  const darkBrandPath =
442
- config.darkBrand != null
443
- ? path.resolve(workingPath, config.darkBrand)
442
+ rawProps.darkBrand != null
443
+ ? path.resolve(rootPath, rawProps.darkBrand)
444
444
  : undefined;
445
445
 
446
- const logoWidth = config.logoWidth - (config.logoWidth % 2);
447
- const brandWidth = config.brandWidth - (config.brandWidth % 2);
448
-
449
- const logo: Asset = {
450
- path: logoPath,
451
- image: sharp(logoPath),
452
- width: logoWidth,
453
- };
454
-
455
- const darkLogo: Asset | undefined =
456
- darkLogoPath != null
457
- ? { path: darkLogoPath, image: sharp(darkLogoPath), width: logoWidth }
458
- : undefined;
459
-
460
- const brand: Asset | undefined =
461
- brandPath != null
462
- ? { path: brandPath, image: sharp(brandPath), width: brandWidth }
463
- : undefined;
446
+ const logoWidth = rawProps.logoWidth - (rawProps.logoWidth % 2);
447
+ const brandWidth = rawProps.brandWidth - (rawProps.brandWidth % 2);
464
448
 
465
- const darkBrand: Asset | undefined =
466
- darkBrandPath != null
467
- ? { path: darkBrandPath, image: sharp(darkBrandPath), width: brandWidth }
468
- : undefined;
449
+ const [logo, darkLogo, brand, darkBrand] = await Promise.all([
450
+ toAsset(logoPath, logoWidth),
451
+ darkLogoPath != null ? toAsset(darkLogoPath, logoWidth) : undefined,
452
+ brandPath != null ? toAsset(brandPath, brandWidth) : undefined,
453
+ darkBrandPath != null ? toAsset(darkBrandPath, brandWidth) : undefined,
454
+ ]);
469
455
 
470
- const background = parseColor(config.background);
456
+ const background = parseColor(rawProps.background);
471
457
 
472
458
  const darkBackground =
473
- config.darkBackground != null
474
- ? parseColor(config.darkBackground)
459
+ rawProps.darkBackground != null
460
+ ? parseColor(rawProps.darkBackground)
475
461
  : undefined;
476
462
 
477
463
  const executeAddon =
@@ -515,66 +501,24 @@ const getProps = ({ android = {}, licenseKey, ...config }: Config) => {
515
501
  process.exit(1);
516
502
  }
517
503
 
518
- if (logoWidth < config.logoWidth) {
504
+ if (logoWidth < rawProps.logoWidth) {
519
505
  log.warn(
520
506
  `Logo width must be a multiple of 2. It has been rounded to ${logoWidth}dp.`,
521
507
  );
522
508
  }
523
- if (brandWidth < config.brandWidth) {
509
+ if (brandWidth < rawProps.brandWidth) {
524
510
  log.warn(
525
511
  `Brand width must be a multiple of 2. It has been rounded to ${brandWidth}dp.`,
526
512
  );
527
513
  }
528
514
 
529
- return {
530
- android,
531
- assetsOutputPath,
532
- licenseKey,
533
- executeAddon,
534
- background,
535
- darkBackground,
536
- logo,
537
- darkLogo,
538
- brand,
539
- darkBrand,
540
- };
541
- };
542
-
543
- export type Props = ReturnType<typeof getProps>;
544
-
545
- export const getExtras = async ({
546
- background,
547
- darkBackground,
548
- logo,
549
- darkLogo,
550
- brand,
551
- darkBrand,
552
- }: Props) => {
553
- const [
554
- logoHash,
555
- darkLogoHash,
556
- brandHash,
557
- darkBrandHash,
558
-
559
- logoHeight,
560
- brandHeight,
561
- ] = await Promise.all([
562
- getAssetBase64("Logo", logo),
563
- getAssetBase64("Dark logo", darkLogo),
564
- getAssetBase64("Brand", brand),
565
- getAssetBase64("Dark brand", darkBrand),
566
-
567
- getAssetHeight(logo),
568
- getAssetHeight(brand),
569
- ]);
570
-
571
515
  const record: Record<string, string> = {
572
516
  background: background.hex,
573
517
  darkBackground: darkBackground?.hex ?? "",
574
- logo: logoHash,
575
- darkLogo: darkLogoHash,
576
- brand: brandHash,
577
- darkBrand: darkBrandHash,
518
+ logo: logo.hash,
519
+ darkLogo: darkLogo?.hash ?? "",
520
+ brand: brand?.hash ?? "",
521
+ darkBrand: darkBrand?.hash ?? "",
578
522
  };
579
523
 
580
524
  const stableKey = Object.keys(record)
@@ -589,38 +533,44 @@ export const getExtras = async ({
589
533
  .toLowerCase();
590
534
 
591
535
  return {
536
+ android,
537
+ assetsOutputPath,
538
+ licenseKey,
539
+ executeAddon,
540
+ background,
541
+ darkBackground,
542
+ logo,
543
+ darkLogo,
544
+ brand,
545
+ darkBrand,
592
546
  fileNameSuffix,
593
- logoHeight,
594
- brandHeight,
595
547
  };
596
548
  };
597
549
 
598
- export type Extras = Awaited<ReturnType<typeof getExtras>>;
550
+ export type Props = Awaited<ReturnType<typeof transformProps>>;
599
551
 
600
- export const writeAndroidAssets = async ({
552
+ const writeAndroidAssets = async ({
601
553
  androidOutputPath,
602
554
  props,
603
- extras,
604
555
  }: {
605
556
  androidOutputPath: string;
606
557
  props: Props;
607
- extras: Extras;
608
558
  }) => {
609
559
  const { logo, brand } = props;
610
560
 
611
- if (logo.width > 192 || extras.logoHeight > 192) {
561
+ if (logo.width > 192 || logo.height > 192) {
612
562
  return log.warn(
613
563
  "Logo size exceeding 192x192dp will be cropped by Android. Skipping Android assets generation…",
614
564
  );
615
565
  }
616
566
 
617
- if (brand != null && (brand.width > 200 || extras.brandHeight > 80)) {
567
+ if (brand != null && (brand.width > 200 || brand.height > 80)) {
618
568
  return log.warn(
619
569
  "Brand size exceeding 200x80dp will be cropped by Android. Skipping Android assets generation…",
620
570
  );
621
571
  }
622
572
 
623
- if (logo.width > 134 || extras.logoHeight > 134) {
573
+ if (logo.width > 134 || logo.height > 134) {
624
574
  log.warn("Logo size exceeds 134x134dp. It might be cropped by Android.");
625
575
  }
626
576
 
@@ -679,16 +629,14 @@ export const writeAndroidAssets = async ({
679
629
  );
680
630
  };
681
631
 
682
- export const writeIOSAssets = async ({
632
+ const writeIOSAssets = async ({
683
633
  iosOutputPath,
684
634
  props,
685
- extras,
686
635
  }: {
687
636
  iosOutputPath: string;
688
637
  props: Props;
689
- extras: Extras;
690
638
  }) => {
691
- const { background, logo } = props;
639
+ const { background, logo, fileNameSuffix } = props;
692
640
 
693
641
  log.title("🍏", "iOS");
694
642
  hfs.ensureDir(iosOutputPath);
@@ -710,7 +658,7 @@ export const writeIOSAssets = async ({
710
658
 
711
659
  const storyboardPath = path.resolve(iosOutputPath, "BootSplash.storyboard");
712
660
 
713
- await writeXmlLike(storyboardPath, getStoryboard({ props, extras }), {
661
+ await writeXmlLike(storyboardPath, getStoryboard(props), {
714
662
  formatter: "xmlFormatter",
715
663
  whiteSpaceAtEndOfSelfclosingTag: false,
716
664
  });
@@ -718,7 +666,7 @@ export const writeIOSAssets = async ({
718
666
  const colorsSetPath = path.resolve(
719
667
  iosOutputPath,
720
668
  "Colors.xcassets",
721
- `BootSplashBackground-${extras.fileNameSuffix}.colorset`,
669
+ `BootSplashBackground-${fileNameSuffix}.colorset`,
722
670
  );
723
671
 
724
672
  hfs.ensureDir(colorsSetPath);
@@ -744,12 +692,12 @@ export const writeIOSAssets = async ({
744
692
  },
745
693
  });
746
694
 
747
- const logoFileName = `logo-${extras.fileNameSuffix}`;
695
+ const logoFileName = `logo-${fileNameSuffix}`;
748
696
 
749
697
  const imagesSetPath = path.resolve(
750
698
  iosOutputPath,
751
699
  "Images.xcassets",
752
- `BootSplashLogo-${extras.fileNameSuffix}.imageset`,
700
+ `BootSplashLogo-${fileNameSuffix}.imageset`,
753
701
  );
754
702
 
755
703
  hfs.ensureDir(imagesSetPath);
@@ -801,14 +749,12 @@ export const writeIOSAssets = async ({
801
749
  );
802
750
  };
803
751
 
804
- export const writeWebAssets = async ({
752
+ const writeWebAssets = async ({
805
753
  htmlTemplatePath,
806
754
  props,
807
- extras,
808
755
  }: {
809
756
  htmlTemplatePath: string;
810
757
  props: Props;
811
- extras: Extras;
812
758
  }) => {
813
759
  const { background, logo } = props;
814
760
 
@@ -847,7 +793,7 @@ export const writeWebAssets = async ({
847
793
  #bootsplash-logo {
848
794
  content: url("${dataURI}");
849
795
  width: ${logo.width}px;
850
- height: ${extras.logoHeight}px;
796
+ height: ${logo.height}px;
851
797
  }
852
798
  </style>
853
799
  `);
@@ -879,13 +825,7 @@ export const writeWebAssets = async ({
879
825
  });
880
826
  };
881
827
 
882
- export const writeGenericAssets = async ({
883
- props,
884
- extras,
885
- }: {
886
- props: Props;
887
- extras: Extras;
888
- }) => {
828
+ const writeGenericAssets = async ({ props }: { props: Props }) => {
889
829
  const { assetsOutputPath, background, logo } = props;
890
830
 
891
831
  log.title("📄", "Assets");
@@ -895,7 +835,7 @@ export const writeGenericAssets = async ({
895
835
  background: background.hex,
896
836
  logo: {
897
837
  width: logo.width,
898
- height: extras.logoHeight,
838
+ height: logo.height,
899
839
  },
900
840
  } satisfies Manifest);
901
841
 
@@ -923,28 +863,47 @@ export const writeGenericAssets = async ({
923
863
 
924
864
  export type AddonConfig = {
925
865
  props: Props;
926
- extras: Extras;
927
-
928
866
  androidOutputPath: string | void;
929
867
  iosOutputPath: string | void;
930
868
  htmlTemplatePath: string | void;
931
869
  };
932
870
 
933
- const requireAddon = ():
871
+ const requireAddon = ({
872
+ executeAddon,
873
+ licenseKey,
874
+ }: Props):
934
875
  | {
935
876
  execute: (config: AddonConfig) => Promise<void>;
936
877
 
937
- withAndroidAssets: Expo.ConfigPlugin<Props>;
938
- withAndroidColorsNight: Expo.ConfigPlugin<Props>;
939
- withIOSAssets: Expo.ConfigPlugin<Props>;
940
- withWebAssets: Expo.ConfigPlugin<Props>;
941
- withGenericAssets: Expo.ConfigPlugin<Props>;
878
+ writeAndroidAssets: (_: {
879
+ androidOutputPath: string;
880
+ props: Props;
881
+ }) => Promise<void>;
882
+
883
+ writeIOSAssets: (_: {
884
+ iosOutputPath: string;
885
+ props: Props;
886
+ }) => Promise<void>;
887
+
888
+ writeWebAssets: (_: {
889
+ htmlTemplatePath: string;
890
+ props: Props;
891
+ }) => Promise<void>;
892
+
893
+ writeGenericAssets: (_: { props: Props }) => Promise<void>;
894
+
895
+ withAndroidColorsNight: (_: {
896
+ config: Expo.ExportedConfigWithProps;
897
+ props: Props;
898
+ }) => Promise<Expo.ExportedConfigWithProps>;
942
899
  }
943
900
  | undefined => {
944
- try {
945
- return require("./addon");
946
- } catch {
947
- return;
901
+ if (licenseKey != null && executeAddon) {
902
+ try {
903
+ return require("./addon");
904
+ } catch {
905
+ return;
906
+ }
948
907
  }
949
908
  };
950
909
 
@@ -953,7 +912,7 @@ export const generate = async ({
953
912
  html,
954
913
  flavor,
955
914
  plist,
956
- ...config
915
+ ...rawProps
957
916
  }: {
958
917
  platforms: Platforms;
959
918
  html: string;
@@ -971,16 +930,17 @@ export const generate = async ({
971
930
  darkLogo?: string;
972
931
  darkBrand?: string;
973
932
  }) => {
974
- const props = getProps(config);
975
- const { background, brand, licenseKey, executeAddon } = props;
976
- const extras = await getExtras(props);
933
+ const props = await transformProps(workingPath, rawProps);
934
+ const addon = requireAddon(props);
935
+
936
+ const { background, brand } = props;
977
937
 
978
938
  const androidOutputPath = getAndroidOutputPath({ flavor, platforms });
979
939
  const iosOutputPath = getIOSOutputPath({ platforms });
980
940
  const htmlTemplatePath = getHtmlTemplatePath({ html, platforms });
981
941
 
982
942
  if (androidOutputPath != null) {
983
- await writeAndroidAssets({ androidOutputPath, props, extras });
943
+ await writeAndroidAssets({ androidOutputPath, props });
984
944
 
985
945
  const manifestXmlPath = path.resolve(
986
946
  androidOutputPath,
@@ -1103,7 +1063,7 @@ export const generate = async ({
1103
1063
  }
1104
1064
 
1105
1065
  if (iosOutputPath != null) {
1106
- await writeIOSAssets({ iosOutputPath, props, extras });
1066
+ await writeIOSAssets({ iosOutputPath, props });
1107
1067
 
1108
1068
  const infoPlistPath = getInfoPlistPath({ iosOutputPath, plist });
1109
1069
 
@@ -1157,18 +1117,14 @@ export const generate = async ({
1157
1117
  }
1158
1118
 
1159
1119
  if (htmlTemplatePath != null) {
1160
- await writeWebAssets({ htmlTemplatePath, props, extras });
1120
+ await writeWebAssets({ htmlTemplatePath, props });
1161
1121
  }
1162
1122
 
1163
- await writeGenericAssets({ props, extras });
1123
+ await writeGenericAssets({ props });
1164
1124
 
1165
- if (licenseKey != null && executeAddon) {
1166
- const addon = requireAddon();
1167
-
1168
- await addon?.execute({
1125
+ if (addon != null) {
1126
+ await addon.execute({
1169
1127
  props,
1170
- extras,
1171
-
1172
1128
  androidOutputPath,
1173
1129
  iosOutputPath,
1174
1130
  htmlTemplatePath,
@@ -1192,15 +1148,20 @@ ${pc.blue("┗━━━━━━━━━━━━━━━━━━━━━━
1192
1148
 
1193
1149
  // Expo plugin
1194
1150
 
1195
- const withoutExpoSplashScreen: Expo.ConfigPlugin<Props> =
1196
- Expo.createRunOncePlugin((config) => config, "expo-splash-screen", "skip");
1151
+ const withoutExpoSplashScreen: Expo.ConfigPlugin<RawProps> =
1152
+ Expo.createRunOncePlugin(
1153
+ (expoConfig) => expoConfig,
1154
+ "expo-splash-screen",
1155
+ "skip",
1156
+ );
1197
1157
 
1198
- const withAndroidAssets: Expo.ConfigPlugin<Props> = (config, props) =>
1199
- Expo.withDangerousMod(config, [
1158
+ const withAndroidAssets: Expo.ConfigPlugin<RawProps> = (expoConfig, rawProps) =>
1159
+ Expo.withDangerousMod(expoConfig, [
1200
1160
  "android",
1201
1161
  async (config) => {
1202
- const { platformProjectRoot } = config.modRequest;
1203
- const extras = await getExtras(props);
1162
+ const { platformProjectRoot, projectRoot } = config.modRequest;
1163
+ const props = await transformProps(projectRoot, rawProps);
1164
+ const addon = requireAddon(props);
1204
1165
 
1205
1166
  const androidOutputPath = path.resolve(
1206
1167
  platformProjectRoot,
@@ -1210,13 +1171,15 @@ const withAndroidAssets: Expo.ConfigPlugin<Props> = (config, props) =>
1210
1171
  "res",
1211
1172
  );
1212
1173
 
1213
- await writeAndroidAssets({ androidOutputPath, props, extras });
1174
+ await writeAndroidAssets({ androidOutputPath, props });
1175
+ await addon?.writeAndroidAssets({ androidOutputPath, props });
1176
+
1214
1177
  return config;
1215
1178
  },
1216
1179
  ]);
1217
1180
 
1218
- const withAndroidManifest: Expo.ConfigPlugin<Props> = (config) =>
1219
- Expo.withAndroidManifest(config, (config) => {
1181
+ const withAndroidManifest: Expo.ConfigPlugin<RawProps> = (expoConfig) =>
1182
+ Expo.withAndroidManifest(expoConfig, (config) => {
1220
1183
  config.modResults.manifest.application?.forEach((application) => {
1221
1184
  if (application.$["android:name"] === ".MainApplication") {
1222
1185
  const { activity } = application;
@@ -1232,8 +1195,8 @@ const withAndroidManifest: Expo.ConfigPlugin<Props> = (config) =>
1232
1195
  return config;
1233
1196
  });
1234
1197
 
1235
- const withMainActivity: Expo.ConfigPlugin<Props> = (config) =>
1236
- Expo.withMainActivity(config, (config) => {
1198
+ const withMainActivity: Expo.ConfigPlugin<RawProps> = (expoConfig) =>
1199
+ Expo.withMainActivity(expoConfig, (config) => {
1237
1200
  const { modResults } = config;
1238
1201
 
1239
1202
  const withImports = addImports(
@@ -1264,9 +1227,10 @@ const withMainActivity: Expo.ConfigPlugin<Props> = (config) =>
1264
1227
  };
1265
1228
  });
1266
1229
 
1267
- const withAndroidStyles: Expo.ConfigPlugin<Props> = (config, props) =>
1268
- Expo.withAndroidStyles(config, (config) => {
1269
- const { android, brand } = props;
1230
+ const withAndroidStyles: Expo.ConfigPlugin<RawProps> = (expoConfig, rawProps) =>
1231
+ Expo.withAndroidStyles(expoConfig, async (config) => {
1232
+ const { projectRoot } = config.modRequest;
1233
+ const { android, brand } = await transformProps(projectRoot, rawProps);
1270
1234
  const { darkContentBarsStyle } = android;
1271
1235
 
1272
1236
  const { modResults } = config;
@@ -1324,9 +1288,10 @@ const withAndroidStyles: Expo.ConfigPlugin<Props> = (config, props) =>
1324
1288
  };
1325
1289
  });
1326
1290
 
1327
- const withAndroidColors: Expo.ConfigPlugin<Props> = (config, props) =>
1328
- Expo.withAndroidColors(config, (config) => {
1329
- const { background } = props;
1291
+ const withAndroidColors: Expo.ConfigPlugin<RawProps> = (expoConfig, rawProps) =>
1292
+ Expo.withAndroidColors(expoConfig, async (config) => {
1293
+ const { projectRoot } = config.modRequest;
1294
+ const { background } = await transformProps(projectRoot, rawProps);
1330
1295
 
1331
1296
  config.modResults = assignColorValue(config.modResults, {
1332
1297
  name: "bootsplash_background",
@@ -1336,25 +1301,47 @@ const withAndroidColors: Expo.ConfigPlugin<Props> = (config, props) =>
1336
1301
  return config;
1337
1302
  });
1338
1303
 
1339
- const withIOSAssets: Expo.ConfigPlugin<Props> = (config, props) =>
1340
- Expo.withDangerousMod(config, [
1304
+ const withAndroidColorsNight: Expo.ConfigPlugin<RawProps> = (
1305
+ expoConfig,
1306
+ rawProps,
1307
+ ) =>
1308
+ Expo.withAndroidColorsNight(expoConfig, async (config) => {
1309
+ const { projectRoot } = config.modRequest;
1310
+ const props = await transformProps(projectRoot, rawProps);
1311
+ const addon = requireAddon(props);
1312
+
1313
+ return addon != null
1314
+ ? await addon.withAndroidColorsNight({ config, props })
1315
+ : config;
1316
+ });
1317
+
1318
+ const withIOSAssets: Expo.ConfigPlugin<RawProps> = (expoConfig, rawProps) =>
1319
+ Expo.withDangerousMod(expoConfig, [
1341
1320
  "ios",
1342
1321
  async (config) => {
1343
- const { platformProjectRoot, projectName = "" } = config.modRequest;
1344
- const extras = await getExtras(props);
1322
+ const {
1323
+ platformProjectRoot,
1324
+ projectName = "",
1325
+ projectRoot,
1326
+ } = config.modRequest;
1327
+
1328
+ const props = await transformProps(projectRoot, rawProps);
1329
+ const addon = requireAddon(props);
1345
1330
  const iosOutputPath = path.resolve(platformProjectRoot, projectName);
1346
1331
 
1347
- await writeIOSAssets({ iosOutputPath, props, extras });
1332
+ await writeIOSAssets({ iosOutputPath, props });
1333
+ await addon?.writeIOSAssets({ iosOutputPath, props });
1334
+
1348
1335
  return config;
1349
1336
  },
1350
1337
  ]);
1351
1338
 
1352
- const withAppDelegate: Expo.ConfigPlugin<Props> = (config) =>
1353
- Expo.withAppDelegate(config, (config) => {
1339
+ const withAppDelegate: Expo.ConfigPlugin<RawProps> = (expoConfig) =>
1340
+ Expo.withAppDelegate(expoConfig, (config) => {
1354
1341
  const { modResults } = config;
1355
1342
  const { language } = modResults;
1356
1343
 
1357
- if (language !== "objc" && language !== "objcpp" && language !== "swift") {
1344
+ if (language !== "swift") {
1358
1345
  throw new Error(
1359
1346
  `Cannot modify the project AppDelegate as it's not in a supported language: ${language}`,
1360
1347
  );
@@ -1392,14 +1379,14 @@ const withAppDelegate: Expo.ConfigPlugin<Props> = (config) =>
1392
1379
  };
1393
1380
  });
1394
1381
 
1395
- const withInfoPlist: Expo.ConfigPlugin<Props> = (config) =>
1396
- Expo.withInfoPlist(config, (config) => {
1382
+ const withInfoPlist: Expo.ConfigPlugin<RawProps> = (expoConfig) =>
1383
+ Expo.withInfoPlist(expoConfig, (config) => {
1397
1384
  config.modResults["UILaunchStoryboardName"] = "BootSplash";
1398
1385
  return config;
1399
1386
  });
1400
1387
 
1401
- const withXcodeProject: Expo.ConfigPlugin<Props> = (config) =>
1402
- Expo.withXcodeProject(config, (config) => {
1388
+ const withXcodeProject: Expo.ConfigPlugin<RawProps> = (expoConfig) =>
1389
+ Expo.withXcodeProject(expoConfig, (config) => {
1403
1390
  const { projectName = "" } = config.modRequest;
1404
1391
 
1405
1392
  Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
@@ -1419,59 +1406,52 @@ const withXcodeProject: Expo.ConfigPlugin<Props> = (config) =>
1419
1406
  return config;
1420
1407
  });
1421
1408
 
1422
- const withWebAssets: Expo.ConfigPlugin<Props> = (config, props) =>
1423
- Expo.withDangerousMod(config, [
1424
- config.platforms?.includes("ios") ? "ios" : "android",
1409
+ const withWebAssets: Expo.ConfigPlugin<RawProps> = (expoConfig, rawProps) =>
1410
+ Expo.withDangerousMod(expoConfig, [
1411
+ expoConfig.platforms?.includes("ios") ? "ios" : "android",
1425
1412
  async (config) => {
1426
- const extras = await getExtras(props);
1413
+ const { projectRoot } = config.modRequest;
1414
+ const props = await transformProps(projectRoot, rawProps);
1415
+ const addon = requireAddon(props);
1416
+
1427
1417
  const fileName = "public/index.html";
1428
- const htmlTemplatePath = path.resolve(workingPath, fileName);
1418
+ const htmlTemplatePath = path.resolve(projectRoot, fileName);
1429
1419
 
1430
1420
  if (!hfs.exists(htmlTemplatePath)) {
1431
1421
  await exec(`npx expo customize ${fileName}`);
1432
1422
  }
1433
1423
 
1434
- await writeWebAssets({ htmlTemplatePath, props, extras });
1424
+ await writeWebAssets({ htmlTemplatePath, props });
1425
+ await addon?.writeWebAssets({ htmlTemplatePath, props });
1426
+
1435
1427
  return config;
1436
1428
  },
1437
1429
  ]);
1438
1430
 
1439
- const withGenericAssets: Expo.ConfigPlugin<Props> = (config, props) =>
1440
- Expo.withDangerousMod(config, [
1441
- config.platforms?.includes("ios") ? "ios" : "android",
1431
+ const withGenericAssets: Expo.ConfigPlugin<RawProps> = (expoConfig, rawProps) =>
1432
+ Expo.withDangerousMod(expoConfig, [
1433
+ expoConfig.platforms?.includes("ios") ? "ios" : "android",
1442
1434
  async (config) => {
1443
- const extras = await getExtras(props);
1444
- await writeGenericAssets({ props, extras });
1435
+ const { projectRoot } = config.modRequest;
1436
+ const props = await transformProps(projectRoot, rawProps);
1437
+ const addon = requireAddon(props);
1438
+
1439
+ await writeGenericAssets({ props });
1440
+ await addon?.writeGenericAssets({ props });
1441
+
1445
1442
  return config;
1446
1443
  },
1447
1444
  ]);
1448
1445
 
1449
1446
  export const withBootSplash = Expo.createRunOncePlugin<
1450
- | {
1451
- logo: string;
1452
- background?: string;
1453
- logoWidth?: number;
1454
- assetsOutput?: string;
1455
-
1456
- licenseKey?: string;
1457
- brand?: string;
1458
- brandWidth?: number;
1459
- darkBackground?: string;
1460
- darkLogo?: string;
1461
- darkBrand?: string;
1462
-
1463
- android?: {
1464
- darkContentBarsStyle?: boolean;
1465
- };
1466
- }
1467
- | undefined
1447
+ (Partial<RawProps> & { logo: string }) | undefined
1468
1448
  >((config, baseProps) => {
1469
1449
  const { platforms = [], sdkVersion = "0.1.0" } = config;
1470
1450
 
1471
1451
  isExpo = true;
1472
1452
 
1473
- if (semver.lt(sdkVersion, "53.0.0")) {
1474
- log.error("Requires Expo 53.0.0 (or higher)");
1453
+ if (semver.lt(sdkVersion, "54.0.0")) {
1454
+ log.error("Requires Expo 54.0.0 (or higher)");
1475
1455
  process.exit(1);
1476
1456
  }
1477
1457
 
@@ -1480,39 +1460,33 @@ export const withBootSplash = Expo.createRunOncePlugin<
1480
1460
  process.exit(1);
1481
1461
  }
1482
1462
 
1483
- const props = getProps({
1463
+ const rawProps: RawProps = {
1484
1464
  assetsOutput: "assets/bootsplash",
1485
1465
  background: "#fff",
1486
1466
  brandWidth: 80,
1487
1467
  logoWidth: 100,
1488
1468
  ...baseProps,
1489
- });
1490
-
1491
- const { executeAddon } = props;
1492
- const addon = executeAddon ? requireAddon() : undefined;
1469
+ };
1493
1470
 
1494
- const plugins: Expo.ConfigPlugin<Props>[] = [
1471
+ const plugins: Expo.ConfigPlugin<RawProps>[] = [
1495
1472
  withoutExpoSplashScreen,
1496
- addon?.withGenericAssets ?? withGenericAssets,
1473
+ withGenericAssets,
1497
1474
  ];
1498
1475
 
1499
1476
  if (platforms.includes("android")) {
1500
1477
  plugins.push(
1501
- addon?.withAndroidAssets ?? withAndroidAssets,
1478
+ withAndroidAssets,
1502
1479
  withAndroidManifest,
1503
1480
  withMainActivity,
1504
1481
  withAndroidStyles,
1505
1482
  withAndroidColors,
1483
+ withAndroidColorsNight,
1506
1484
  );
1507
-
1508
- if (addon != null) {
1509
- plugins.push(addon.withAndroidColorsNight);
1510
- }
1511
1485
  }
1512
1486
 
1513
1487
  if (platforms.includes("ios")) {
1514
1488
  plugins.push(
1515
- addon?.withIOSAssets ?? withIOSAssets,
1489
+ withIOSAssets,
1516
1490
  withAppDelegate,
1517
1491
  withInfoPlist,
1518
1492
  withXcodeProject,
@@ -1520,11 +1494,11 @@ export const withBootSplash = Expo.createRunOncePlugin<
1520
1494
  }
1521
1495
 
1522
1496
  if (platforms.includes("web")) {
1523
- plugins.push(addon?.withWebAssets ?? withWebAssets);
1497
+ plugins.push(withWebAssets);
1524
1498
  }
1525
1499
 
1526
1500
  return Expo.withPlugins(
1527
1501
  config,
1528
- plugins.map((plugin) => [plugin, props]),
1502
+ plugins.map((plugin) => [plugin, rawProps]),
1529
1503
  );
1530
1504
  }, PACKAGE_NAME);