react-native-bootsplash 7.0.0-beta.0 → 7.0.0-beta.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.
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  import * as Expo from "@expo/config-plugins";
4
- import { assignColorValue } from "@expo/config-plugins/build/android/Colors";
5
- import { addImports } from "@expo/config-plugins/build/android/codeMod";
6
- import { mergeContents } from "@expo/config-plugins/build/utils/generateCode";
7
4
  import ExpoPlist from "@expo/plist";
8
5
  import { projectConfig as getAndroidProjectConfig } from "@react-native-community/cli-config-android";
9
6
  import { getProjectConfig as getAppleProjectConfig } from "@react-native-community/cli-config-apple";
10
7
  import { findProjectRoot } from "@react-native-community/cli-tools";
11
- import childProcess from "child_process";
12
8
  import crypto from "crypto";
13
9
  import detectIndent from "detect-indent";
14
10
  import fs from "fs-extra";
@@ -21,20 +17,17 @@ import * as prettier from "prettier/standalone";
21
17
  import semver from "semver";
22
18
  import sharp from "sharp";
23
19
  import { dedent } from "ts-dedent";
24
- import util from "util";
25
20
  import formatXml from "xml-formatter";
26
- const PACKAGE_NAME = "react-native-bootsplash";
27
- let isExpo = false;
28
- export const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
21
+ export const packageName = "react-native-bootsplash";
22
+ const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
29
23
  const projectRoot = findProjectRoot(workingPath);
30
- const promisifiedExec = util.promisify(childProcess.exec);
31
- const exec = cmd => promisifiedExec(cmd).then(({
32
- stdout,
33
- stderr
34
- }) => stdout || stderr);
24
+ let isExpo = false;
25
+ export const setIsExpo = value => {
26
+ isExpo = value;
27
+ };
35
28
  export const log = {
36
29
  error: text => {
37
- console.log(pc.red(isExpo ? `❌ [${PACKAGE_NAME}] ${text}` : `❌ ${text}`));
30
+ console.log(pc.red(isExpo ? `❌ [${packageName}] ${text}` : `❌ ${text}`));
38
31
  },
39
32
  title: (emoji, text) => {
40
33
  if (!isExpo) {
@@ -42,7 +35,7 @@ export const log = {
42
35
  }
43
36
  },
44
37
  warn: text => {
45
- console.log(pc.yellow(isExpo ? `⚠️ [${PACKAGE_NAME}] ${text}` : `⚠️ ${text}`));
38
+ console.log(pc.yellow(isExpo ? `⚠️ [${packageName}] ${text}` : `⚠️ ${text}`));
46
39
  },
47
40
  write: (filePath, dimensions) => {
48
41
  if (!isExpo) {
@@ -67,18 +60,12 @@ const parseColor = value => {
67
60
  rgb
68
61
  };
69
62
  };
70
- const getStoryboard = ({
71
- props,
72
- extras
73
- }) => {
63
+ const getStoryboard = props => {
74
64
  const {
75
65
  background,
76
- logo
66
+ logo,
67
+ fileNameSuffix
77
68
  } = props;
78
- const {
79
- fileNameSuffix,
80
- logoHeight
81
- } = extras;
82
69
  const {
83
70
  R,
84
71
  G,
@@ -107,7 +94,7 @@ const getStoryboard = ({
107
94
  <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
108
95
  <subviews>
109
96
  <imageView autoresizesSubviews="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" image="BootSplashLogo-${fileNameSuffix}" translatesAutoresizingMaskIntoConstraints="NO" id="3lX-Ut-9ad">
110
- <rect key="frame" x="${(frameWidth - logo.width) / 2}" y="${(frameHeight - logoHeight) / 2}" width="${logo.width}" height="${logoHeight}"/>
97
+ <rect key="frame" x="${(frameWidth - logo.width) / 2}" y="${(frameHeight - logo.height) / 2}" width="${logo.width}" height="${logo.height}"/>
111
98
  <accessibility key="accessibilityConfiguration">
112
99
  <accessibilityTraits key="traits" image="YES" notEnabled="YES"/>
113
100
  </accessibility>
@@ -127,7 +114,7 @@ const getStoryboard = ({
127
114
  </scene>
128
115
  </scenes>
129
116
  <resources>
130
- <image name="BootSplashLogo-${fileNameSuffix}" width="${logo.width}" height="${logoHeight}"/>
117
+ <image name="BootSplashLogo-${fileNameSuffix}" width="${logo.width}" height="${logo.height}"/>
131
118
  <namedColor name="BootSplashBackground-${fileNameSuffix}">
132
119
  <color red="${R}" green="${G}" blue="${B}" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
133
120
  </namedColor>
@@ -211,26 +198,6 @@ export const writeXmlLike = async (filePath, content, {
211
198
  log.write(filePath);
212
199
  }
213
200
  };
214
- const getAssetBase64 = async (name, asset) => {
215
- if (asset == null) {
216
- return "";
217
- }
218
- const {
219
- image,
220
- width
221
- } = asset;
222
- const {
223
- format
224
- } = await image.metadata();
225
- if (format !== "png" && format !== "svg") {
226
- log.error(`${name} image file format (${format}) is not supported`);
227
- process.exit(1);
228
- }
229
- const buffer = await image.clone().resize(width).png({
230
- quality: 100
231
- }).toBuffer();
232
- return buffer.toString("base64");
233
- };
234
201
  const getAndroidOutputPath = ({
235
202
  flavor,
236
203
  platforms
@@ -289,52 +256,47 @@ const getInfoPlistPath = ({
289
256
  }
290
257
  return path.resolve(iosOutputPath, "Info.plist");
291
258
  };
292
- const getAssetHeight = asset => {
293
- if (asset == null) {
294
- return Promise.resolve(0);
259
+ const toAsset = async (filePath, width) => {
260
+ const image = sharp(filePath);
261
+ const {
262
+ format
263
+ } = await image.metadata();
264
+ if (format !== "png" && format !== "svg") {
265
+ log.error(`${path.basename(filePath)} image file format (${format}) is not supported`);
266
+ process.exit(1);
295
267
  }
296
- return asset.image.clone().resize(asset.width).toBuffer().then(buffer => sharp(buffer).metadata()).then(({
268
+ const [height, hash] = await Promise.all([image.clone().resize(width).toBuffer().then(buffer => sharp(buffer).metadata()).then(({
297
269
  height = 0
298
- }) => Math.round(height));
270
+ }) => Math.round(height)), image.clone().resize(width).png({
271
+ quality: 100
272
+ }).toBuffer().then(buffer => buffer.toString("base64"))]);
273
+ return {
274
+ path: filePath,
275
+ image,
276
+ hash,
277
+ height,
278
+ width
279
+ };
299
280
  };
300
- const getProps = ({
281
+ export const transformProps = async (rootPath, {
301
282
  android = {},
302
283
  licenseKey,
303
- ...config
284
+ ...rawProps
304
285
  }) => {
305
286
  if (semver.lt(process.versions.node, "20.0.0")) {
306
287
  log.error("Requires Node 20 (or higher)");
307
288
  process.exit(1);
308
289
  }
309
- const assetsOutputPath = path.resolve(workingPath, config.assetsOutput);
310
- const logoPath = path.resolve(workingPath, config.logo);
311
- const darkLogoPath = config.darkLogo != null ? path.resolve(workingPath, config.darkLogo) : undefined;
312
- const brandPath = config.brand != null ? path.resolve(workingPath, config.brand) : undefined;
313
- const darkBrandPath = config.darkBrand != null ? path.resolve(workingPath, config.darkBrand) : undefined;
314
- const logoWidth = config.logoWidth - config.logoWidth % 2;
315
- const brandWidth = config.brandWidth - config.brandWidth % 2;
316
- const logo = {
317
- path: logoPath,
318
- image: sharp(logoPath),
319
- width: logoWidth
320
- };
321
- const darkLogo = darkLogoPath != null ? {
322
- path: darkLogoPath,
323
- image: sharp(darkLogoPath),
324
- width: logoWidth
325
- } : undefined;
326
- const brand = brandPath != null ? {
327
- path: brandPath,
328
- image: sharp(brandPath),
329
- width: brandWidth
330
- } : undefined;
331
- const darkBrand = darkBrandPath != null ? {
332
- path: darkBrandPath,
333
- image: sharp(darkBrandPath),
334
- width: brandWidth
335
- } : undefined;
336
- const background = parseColor(config.background);
337
- const darkBackground = config.darkBackground != null ? parseColor(config.darkBackground) : undefined;
290
+ const assetsOutputPath = path.resolve(rootPath, rawProps.assetsOutput);
291
+ const logoPath = path.resolve(rootPath, rawProps.logo);
292
+ const darkLogoPath = rawProps.darkLogo != null ? path.resolve(rootPath, rawProps.darkLogo) : undefined;
293
+ const brandPath = rawProps.brand != null ? path.resolve(rootPath, rawProps.brand) : undefined;
294
+ const darkBrandPath = rawProps.darkBrand != null ? path.resolve(rootPath, rawProps.darkBrand) : undefined;
295
+ const logoWidth = rawProps.logoWidth - rawProps.logoWidth % 2;
296
+ const brandWidth = rawProps.brandWidth - rawProps.brandWidth % 2;
297
+ const [logo, darkLogo, brand, darkBrand] = await Promise.all([toAsset(logoPath, logoWidth), darkLogoPath != null ? toAsset(darkLogoPath, logoWidth) : undefined, brandPath != null ? toAsset(brandPath, brandWidth) : undefined, darkBrandPath != null ? toAsset(darkBrandPath, brandWidth) : undefined]);
298
+ const background = parseColor(rawProps.background);
299
+ const darkBackground = rawProps.darkBackground != null ? parseColor(rawProps.darkBackground) : undefined;
338
300
  const executeAddon = brand != null || darkBackground != null || darkLogo != null || darkBrand != null;
339
301
  if (licenseKey != null && !executeAddon) {
340
302
  log.warn("You specified a license key but none of the options that requires it.");
@@ -354,12 +316,24 @@ const getProps = ({
354
316
  log.error(`${optionNames.darkBrand} option couldn't be used without ${optionNames.brand}.`);
355
317
  process.exit(1);
356
318
  }
357
- if (logoWidth < config.logoWidth) {
319
+ if (logoWidth < rawProps.logoWidth) {
358
320
  log.warn(`Logo width must be a multiple of 2. It has been rounded to ${logoWidth}dp.`);
359
321
  }
360
- if (brandWidth < config.brandWidth) {
322
+ if (brandWidth < rawProps.brandWidth) {
361
323
  log.warn(`Brand width must be a multiple of 2. It has been rounded to ${brandWidth}dp.`);
362
324
  }
325
+ const record = {
326
+ background: background.hex,
327
+ darkBackground: darkBackground?.hex ?? "",
328
+ logo: logo.hash,
329
+ darkLogo: darkLogo?.hash ?? "",
330
+ brand: brand?.hash ?? "",
331
+ darkBrand: darkBrand?.hash ?? ""
332
+ };
333
+ const stableKey = Object.keys(record).sort().map(key => record[key]).join();
334
+ const fileNameSuffix = crypto.createHash("shake256", {
335
+ outputLength: 3
336
+ }).update(stableKey).digest("hex").toLowerCase();
363
337
  return {
364
338
  android,
365
339
  assetsOutputPath,
@@ -370,52 +344,25 @@ const getProps = ({
370
344
  logo,
371
345
  darkLogo,
372
346
  brand,
373
- darkBrand
374
- };
375
- };
376
- export const getExtras = async ({
377
- background,
378
- darkBackground,
379
- logo,
380
- darkLogo,
381
- brand,
382
- darkBrand
383
- }) => {
384
- const [logoHash, darkLogoHash, brandHash, darkBrandHash, logoHeight, brandHeight] = await Promise.all([getAssetBase64("Logo", logo), getAssetBase64("Dark logo", darkLogo), getAssetBase64("Brand", brand), getAssetBase64("Dark brand", darkBrand), getAssetHeight(logo), getAssetHeight(brand)]);
385
- const record = {
386
- background: background.hex,
387
- darkBackground: darkBackground?.hex ?? "",
388
- logo: logoHash,
389
- darkLogo: darkLogoHash,
390
- brand: brandHash,
391
- darkBrand: darkBrandHash
392
- };
393
- const stableKey = Object.keys(record).sort().map(key => record[key]).join();
394
- const fileNameSuffix = crypto.createHash("shake256", {
395
- outputLength: 3
396
- }).update(stableKey).digest("hex").toLowerCase();
397
- return {
398
- fileNameSuffix,
399
- logoHeight,
400
- brandHeight
347
+ darkBrand,
348
+ fileNameSuffix
401
349
  };
402
350
  };
403
351
  export const writeAndroidAssets = async ({
404
352
  androidOutputPath,
405
- props,
406
- extras
353
+ props
407
354
  }) => {
408
355
  const {
409
356
  logo,
410
357
  brand
411
358
  } = props;
412
- if (logo.width > 192 || extras.logoHeight > 192) {
359
+ if (logo.width > 192 || logo.height > 192) {
413
360
  return log.warn("Logo size exceeding 192x192dp will be cropped by Android. Skipping Android assets generation…");
414
361
  }
415
- if (brand != null && (brand.width > 200 || extras.brandHeight > 80)) {
362
+ if (brand != null && (brand.width > 200 || brand.height > 80)) {
416
363
  return log.warn("Brand size exceeding 200x80dp will be cropped by Android. Skipping Android assets generation…");
417
364
  }
418
- if (logo.width > 134 || extras.logoHeight > 134) {
365
+ if (logo.width > 134 || logo.height > 134) {
419
366
  log.warn("Logo size exceeds 134x134dp. It might be cropped by Android.");
420
367
  }
421
368
  log.title("🤖", "Android");
@@ -474,12 +421,12 @@ export const writeAndroidAssets = async ({
474
421
  };
475
422
  export const writeIOSAssets = async ({
476
423
  iosOutputPath,
477
- props,
478
- extras
424
+ props
479
425
  }) => {
480
426
  const {
481
427
  background,
482
- logo
428
+ logo,
429
+ fileNameSuffix
483
430
  } = props;
484
431
  log.title("🍏", "iOS");
485
432
  hfs.ensureDir(iosOutputPath);
@@ -489,14 +436,11 @@ export const writeIOSAssets = async ({
489
436
  hfs.rm(file);
490
437
  });
491
438
  const storyboardPath = path.resolve(iosOutputPath, "BootSplash.storyboard");
492
- await writeXmlLike(storyboardPath, getStoryboard({
493
- props,
494
- extras
495
- }), {
439
+ await writeXmlLike(storyboardPath, getStoryboard(props), {
496
440
  formatter: "xmlFormatter",
497
441
  whiteSpaceAtEndOfSelfclosingTag: false
498
442
  });
499
- const colorsSetPath = path.resolve(iosOutputPath, "Colors.xcassets", `BootSplashBackground-${extras.fileNameSuffix}.colorset`);
443
+ const colorsSetPath = path.resolve(iosOutputPath, "Colors.xcassets", `BootSplashBackground-${fileNameSuffix}.colorset`);
500
444
  hfs.ensureDir(colorsSetPath);
501
445
  writeJson(path.resolve(colorsSetPath, "Contents.json"), {
502
446
  colors: [{
@@ -516,8 +460,8 @@ export const writeIOSAssets = async ({
516
460
  version: 1
517
461
  }
518
462
  });
519
- const logoFileName = `logo-${extras.fileNameSuffix}`;
520
- const imagesSetPath = path.resolve(iosOutputPath, "Images.xcassets", `BootSplashLogo-${extras.fileNameSuffix}.imageset`);
463
+ const logoFileName = `logo-${fileNameSuffix}`;
464
+ const imagesSetPath = path.resolve(iosOutputPath, "Images.xcassets", `BootSplashLogo-${fileNameSuffix}.imageset`);
521
465
  hfs.ensureDir(imagesSetPath);
522
466
  writeJson(path.resolve(imagesSetPath, "Contents.json"), {
523
467
  images: [{
@@ -567,8 +511,7 @@ export const writeIOSAssets = async ({
567
511
  };
568
512
  export const writeWebAssets = async ({
569
513
  htmlTemplatePath,
570
- props,
571
- extras
514
+ props
572
515
  }) => {
573
516
  const {
574
517
  background,
@@ -601,7 +544,7 @@ export const writeWebAssets = async ({
601
544
  #bootsplash-logo {
602
545
  content: url("${dataURI}");
603
546
  width: ${logo.width}px;
604
- height: ${extras.logoHeight}px;
547
+ height: ${logo.height}px;
605
548
  }
606
549
  </style>
607
550
  `);
@@ -628,8 +571,7 @@ export const writeWebAssets = async ({
628
571
  });
629
572
  };
630
573
  export const writeGenericAssets = async ({
631
- props,
632
- extras
574
+ props
633
575
  }) => {
634
576
  const {
635
577
  assetsOutputPath,
@@ -642,7 +584,7 @@ export const writeGenericAssets = async ({
642
584
  background: background.hex,
643
585
  logo: {
644
586
  width: logo.width,
645
- height: extras.logoHeight
587
+ height: logo.height
646
588
  }
647
589
  });
648
590
  await Promise.all([{
@@ -678,11 +620,17 @@ export const writeGenericAssets = async ({
678
620
  });
679
621
  }));
680
622
  };
681
- const requireAddon = () => {
682
- try {
683
- return require("./addon");
684
- } catch {
685
- return;
623
+ export const requireAddon = ({
624
+ executeAddon,
625
+ licenseKey
626
+ }) => {
627
+ if (licenseKey != null && executeAddon) {
628
+ try {
629
+ const addon = require("./dist/commonjs/addon");
630
+ return "default" in addon ? addon.default : addon;
631
+ } catch {
632
+ return;
633
+ }
686
634
  }
687
635
  };
688
636
  export const generate = async ({
@@ -690,16 +638,14 @@ export const generate = async ({
690
638
  html,
691
639
  flavor,
692
640
  plist,
693
- ...config
641
+ ...rawProps
694
642
  }) => {
695
- const props = getProps(config);
643
+ const props = await transformProps(workingPath, rawProps);
644
+ const addon = requireAddon(props);
696
645
  const {
697
646
  background,
698
- brand,
699
- licenseKey,
700
- executeAddon
647
+ brand
701
648
  } = props;
702
- const extras = await getExtras(props);
703
649
  const androidOutputPath = getAndroidOutputPath({
704
650
  flavor,
705
651
  platforms
@@ -714,8 +660,7 @@ export const generate = async ({
714
660
  if (androidOutputPath != null) {
715
661
  await writeAndroidAssets({
716
662
  androidOutputPath,
717
- props,
718
- extras
663
+ props
719
664
  });
720
665
  const manifestXmlPath = path.resolve(androidOutputPath, "..", "AndroidManifest.xml");
721
666
  if (hfs.exists(manifestXmlPath)) {
@@ -790,26 +735,8 @@ export const generate = async ({
790
735
  if (iosOutputPath != null) {
791
736
  await writeIOSAssets({
792
737
  iosOutputPath,
793
- props,
794
- extras
738
+ props
795
739
  });
796
- const infoPlistPath = getInfoPlistPath({
797
- iosOutputPath,
798
- plist
799
- });
800
- if (infoPlistPath != null) {
801
- const infoPlist = ExpoPlist.parse(hfs.text(infoPlistPath));
802
- infoPlist["UILaunchStoryboardName"] = "BootSplash";
803
- const formatted = formatXml(ExpoPlist.build(infoPlist), {
804
- collapseContent: true,
805
- forceSelfClosingEmptyTag: false,
806
- indentation: "\t",
807
- lineSeparator: "\n",
808
- whiteSpaceAtEndOfSelfclosingTag: false
809
- }).replace(/<string\/>/gm, "<string></string>").replace(/^\t/gm, "");
810
- hfs.write(infoPlistPath, formatted);
811
- log.write(infoPlistPath);
812
- }
813
740
  const pbxprojectPath = Expo.IOSConfig.Paths.getPBXProjectPath(projectRoot);
814
741
  const xcodeProjectPath = Expo.IOSConfig.Paths.getXcodeProjectPath(projectRoot);
815
742
  const project = Expo.IOSConfig.XcodeUtils.getPbxproj(projectRoot);
@@ -829,23 +756,36 @@ export const generate = async ({
829
756
  });
830
757
  hfs.write(pbxprojectPath, project.writeSync());
831
758
  log.write(pbxprojectPath);
759
+ const infoPlistPath = getInfoPlistPath({
760
+ iosOutputPath,
761
+ plist
762
+ });
763
+ if (infoPlistPath != null) {
764
+ const infoPlist = ExpoPlist.parse(hfs.text(infoPlistPath));
765
+ infoPlist["UILaunchStoryboardName"] = "BootSplash";
766
+ const formatted = formatXml(ExpoPlist.build(infoPlist), {
767
+ collapseContent: true,
768
+ forceSelfClosingEmptyTag: false,
769
+ indentation: "\t",
770
+ lineSeparator: "\n",
771
+ whiteSpaceAtEndOfSelfclosingTag: false
772
+ }).replace(/<string\/>/gm, "<string></string>").replace(/^\t/gm, "");
773
+ hfs.write(infoPlistPath, formatted);
774
+ log.write(infoPlistPath);
775
+ }
832
776
  }
833
777
  if (htmlTemplatePath != null) {
834
778
  await writeWebAssets({
835
779
  htmlTemplatePath,
836
- props,
837
- extras
780
+ props
838
781
  });
839
782
  }
840
783
  await writeGenericAssets({
841
- props,
842
- extras
784
+ props
843
785
  });
844
- if (licenseKey != null && executeAddon) {
845
- const addon = requireAddon();
846
- await addon?.execute({
786
+ if (addon != null) {
787
+ await addon.execute({
847
788
  props,
848
- extras,
849
789
  androidOutputPath,
850
790
  iosOutputPath,
851
791
  htmlTemplatePath
@@ -859,275 +799,4 @@ ${pc.blue("┗━━━━━━━━━━━━━━━━━━━━━━
859
799
  }
860
800
  console.log(`\n💖 Thanks for using ${pc.underline("react-native-bootsplash")}`);
861
801
  };
862
-
863
- // Expo plugin
864
-
865
- const withoutExpoSplashScreen = Expo.createRunOncePlugin(config => config, "expo-splash-screen", "skip");
866
- const withAndroidAssets = (config, props) => Expo.withDangerousMod(config, ["android", async config => {
867
- const {
868
- platformProjectRoot
869
- } = config.modRequest;
870
- const extras = await getExtras(props);
871
- const androidOutputPath = path.resolve(platformProjectRoot, "app", "src", "main", "res");
872
- await writeAndroidAssets({
873
- androidOutputPath,
874
- props,
875
- extras
876
- });
877
- return config;
878
- }]);
879
- const withAndroidManifest = config => Expo.withAndroidManifest(config, config => {
880
- config.modResults.manifest.application?.forEach(application => {
881
- if (application.$["android:name"] === ".MainApplication") {
882
- const {
883
- activity
884
- } = application;
885
- activity?.forEach(activity => {
886
- if (activity.$["android:name"] === ".MainActivity") {
887
- activity.$["android:theme"] = "@style/BootTheme";
888
- }
889
- });
890
- }
891
- });
892
- return config;
893
- });
894
- const withMainActivity = config => Expo.withMainActivity(config, config => {
895
- const {
896
- modResults
897
- } = config;
898
- const withImports = addImports(modResults.contents.replace(/(\/\/ )?setTheme\(R\.style\.AppTheme\)/, "// setTheme(R.style.AppTheme)"), ["android.os.Bundle", "com.zoontek.rnbootsplash.RNBootSplash"], false);
899
-
900
- // indented with 4 spaces
901
- const withInit = mergeContents({
902
- src: withImports,
903
- comment: " //",
904
- tag: "bootsplash-init",
905
- offset: 0,
906
- anchor: /super\.onCreate\(null\)/,
907
- newSrc: " RNBootSplash.init(this, R.style.BootTheme)"
908
- });
909
- return {
910
- ...config,
911
- modResults: {
912
- ...modResults,
913
- contents: withInit.contents
914
- }
915
- };
916
- });
917
- const withAndroidStyles = (config, props) => Expo.withAndroidStyles(config, config => {
918
- const {
919
- android,
920
- brand
921
- } = props;
922
- const {
923
- darkContentBarsStyle
924
- } = android;
925
- const {
926
- modResults
927
- } = config;
928
- const {
929
- resources
930
- } = modResults;
931
- const {
932
- style = []
933
- } = resources;
934
- const item = [{
935
- $: {
936
- name: "postBootSplashTheme"
937
- },
938
- _: "@style/AppTheme"
939
- }, {
940
- $: {
941
- name: "bootSplashBackground"
942
- },
943
- _: "@color/bootsplash_background"
944
- }, {
945
- $: {
946
- name: "bootSplashLogo"
947
- },
948
- _: "@drawable/bootsplash_logo"
949
- }];
950
- if (brand != null) {
951
- item.push({
952
- $: {
953
- name: "bootSplashBrand"
954
- },
955
- _: "@drawable/bootsplash_brand"
956
- });
957
- }
958
- if (darkContentBarsStyle != null) {
959
- item.push({
960
- $: {
961
- name: "darkContentBarsStyle"
962
- },
963
- _: String(darkContentBarsStyle)
964
- });
965
- }
966
- const withBootTheme = [...style.filter(({
967
- $
968
- }) => $.name !== "BootTheme"), {
969
- $: {
970
- name: "BootTheme",
971
- parent: "Theme.BootSplash"
972
- },
973
- item
974
- }];
975
- return {
976
- ...config,
977
- modResults: {
978
- ...modResults,
979
- resources: {
980
- ...resources,
981
- style: withBootTheme
982
- }
983
- }
984
- };
985
- });
986
- const withAndroidColors = (config, props) => Expo.withAndroidColors(config, config => {
987
- const {
988
- background
989
- } = props;
990
- config.modResults = assignColorValue(config.modResults, {
991
- name: "bootsplash_background",
992
- value: background.hex
993
- });
994
- return config;
995
- });
996
- const withIOSAssets = (config, props) => Expo.withDangerousMod(config, ["ios", async config => {
997
- const {
998
- platformProjectRoot,
999
- projectName = ""
1000
- } = config.modRequest;
1001
- const extras = await getExtras(props);
1002
- const iosOutputPath = path.resolve(platformProjectRoot, projectName);
1003
- await writeIOSAssets({
1004
- iosOutputPath,
1005
- props,
1006
- extras
1007
- });
1008
- return config;
1009
- }]);
1010
- const withAppDelegate = config => Expo.withAppDelegate(config, config => {
1011
- const {
1012
- modResults
1013
- } = config;
1014
- const {
1015
- language
1016
- } = modResults;
1017
- if (language !== "objc" && language !== "objcpp" && language !== "swift") {
1018
- throw new Error(`Cannot modify the project AppDelegate as it's not in a supported language: ${language}`);
1019
- }
1020
- const withHeader = mergeContents({
1021
- src: modResults.contents,
1022
- comment: "//",
1023
- tag: "bootsplash-header",
1024
- offset: 1,
1025
- anchor: /import Expo/,
1026
- newSrc: "import RNBootSplash"
1027
- });
1028
- const withRootView = mergeContents({
1029
- src: withHeader.contents,
1030
- comment: "//",
1031
- tag: "bootsplash-init",
1032
- offset: 1,
1033
- anchor: /class ReactNativeDelegate: ExpoReactNativeFactoryDelegate {/,
1034
- newSrc: dedent`
1035
- public override func customize(_ rootView: UIView) {
1036
- super.customize(rootView)
1037
- RNBootSplash.initWithStoryboard("BootSplash", rootView: rootView)
1038
- }
1039
- `
1040
- });
1041
- return {
1042
- ...config,
1043
- modResults: {
1044
- ...modResults,
1045
- contents: withRootView.contents
1046
- }
1047
- };
1048
- });
1049
- const withInfoPlist = config => Expo.withInfoPlist(config, config => {
1050
- config.modResults["UILaunchStoryboardName"] = "BootSplash";
1051
- return config;
1052
- });
1053
- const withXcodeProject = config => Expo.withXcodeProject(config, config => {
1054
- const {
1055
- projectName = ""
1056
- } = config.modRequest;
1057
- Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
1058
- filepath: path.join(projectName, "BootSplash.storyboard"),
1059
- groupName: projectName,
1060
- project: config.modResults,
1061
- isBuildFile: true
1062
- });
1063
- Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
1064
- filepath: path.join(projectName, "Colors.xcassets"),
1065
- groupName: projectName,
1066
- project: config.modResults,
1067
- isBuildFile: true
1068
- });
1069
- return config;
1070
- });
1071
- const withWebAssets = (config, props) => Expo.withDangerousMod(config, [config.platforms?.includes("ios") ? "ios" : "android", async config => {
1072
- const extras = await getExtras(props);
1073
- const fileName = "public/index.html";
1074
- const htmlTemplatePath = path.resolve(workingPath, fileName);
1075
- if (!hfs.exists(htmlTemplatePath)) {
1076
- await exec(`npx expo customize ${fileName}`);
1077
- }
1078
- await writeWebAssets({
1079
- htmlTemplatePath,
1080
- props,
1081
- extras
1082
- });
1083
- return config;
1084
- }]);
1085
- const withGenericAssets = (config, props) => Expo.withDangerousMod(config, [config.platforms?.includes("ios") ? "ios" : "android", async config => {
1086
- const extras = await getExtras(props);
1087
- await writeGenericAssets({
1088
- props,
1089
- extras
1090
- });
1091
- return config;
1092
- }]);
1093
- export const withBootSplash = Expo.createRunOncePlugin((config, baseProps) => {
1094
- const {
1095
- platforms = [],
1096
- sdkVersion = "0.1.0"
1097
- } = config;
1098
- isExpo = true;
1099
- if (semver.lt(sdkVersion, "53.0.0")) {
1100
- log.error("Requires Expo 53.0.0 (or higher)");
1101
- process.exit(1);
1102
- }
1103
- if (!baseProps?.logo) {
1104
- log.error("Missing required parameter 'logo'");
1105
- process.exit(1);
1106
- }
1107
- const props = getProps({
1108
- assetsOutput: "assets/bootsplash",
1109
- background: "#fff",
1110
- brandWidth: 80,
1111
- logoWidth: 100,
1112
- ...baseProps
1113
- });
1114
- const {
1115
- executeAddon
1116
- } = props;
1117
- const addon = executeAddon ? requireAddon() : undefined;
1118
- const plugins = [withoutExpoSplashScreen, addon?.withGenericAssets ?? withGenericAssets];
1119
- if (platforms.includes("android")) {
1120
- plugins.push(addon?.withAndroidAssets ?? withAndroidAssets, withAndroidManifest, withMainActivity, withAndroidStyles, withAndroidColors);
1121
- if (addon != null) {
1122
- plugins.push(addon.withAndroidColorsNight);
1123
- }
1124
- }
1125
- if (platforms.includes("ios")) {
1126
- plugins.push(addon?.withIOSAssets ?? withIOSAssets, withAppDelegate, withInfoPlist, withXcodeProject);
1127
- }
1128
- if (platforms.includes("web")) {
1129
- plugins.push(addon?.withWebAssets ?? withWebAssets);
1130
- }
1131
- return Expo.withPlugins(config, plugins.map(plugin => [plugin, props]));
1132
- }, PACKAGE_NAME);
1133
802
  //# sourceMappingURL=generate.js.map