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.
@@ -3,16 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.writeXmlLike = exports.writeWebAssets = exports.writeJson = exports.writeIOSAssets = exports.writeGenericAssets = exports.writeAndroidAssets = exports.workingPath = exports.withBootSplash = exports.readXmlLike = exports.log = exports.hfs = exports.getExtras = exports.generate = void 0;
6
+ exports.writeXmlLike = exports.writeWebAssets = exports.writeJson = exports.writeIOSAssets = exports.writeGenericAssets = exports.writeAndroidAssets = exports.transformProps = exports.setIsExpo = exports.requireAddon = exports.readXmlLike = exports.packageName = exports.log = exports.hfs = exports.generate = void 0;
7
7
  var Expo = _interopRequireWildcard(require("@expo/config-plugins"));
8
- var _Colors = require("@expo/config-plugins/build/android/Colors");
9
- var _codeMod = require("@expo/config-plugins/build/android/codeMod");
10
- var _generateCode = require("@expo/config-plugins/build/utils/generateCode");
11
8
  var _plist = _interopRequireDefault(require("@expo/plist"));
12
9
  var _cliConfigAndroid = require("@react-native-community/cli-config-android");
13
10
  var _cliConfigApple = require("@react-native-community/cli-config-apple");
14
11
  var _cliTools = require("@react-native-community/cli-tools");
15
- var _child_process = _interopRequireDefault(require("child_process"));
16
12
  var _crypto = _interopRequireDefault(require("crypto"));
17
13
  var _detectIndent = _interopRequireDefault(require("detect-indent"));
18
14
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
@@ -25,22 +21,20 @@ var prettier = _interopRequireWildcard(require("prettier/standalone"));
25
21
  var _semver = _interopRequireDefault(require("semver"));
26
22
  var _sharp = _interopRequireDefault(require("sharp"));
27
23
  var _tsDedent = require("ts-dedent");
28
- var _util = _interopRequireDefault(require("util"));
29
24
  var _xmlFormatter = _interopRequireDefault(require("xml-formatter"));
30
25
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
31
26
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
32
- const PACKAGE_NAME = "react-native-bootsplash";
33
- let isExpo = false;
34
- const workingPath = exports.workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
27
+ const packageName = exports.packageName = "react-native-bootsplash";
28
+ const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
35
29
  const projectRoot = (0, _cliTools.findProjectRoot)(workingPath);
36
- const promisifiedExec = _util.default.promisify(_child_process.default.exec);
37
- const exec = cmd => promisifiedExec(cmd).then(({
38
- stdout,
39
- stderr
40
- }) => stdout || stderr);
30
+ let isExpo = false;
31
+ const setIsExpo = value => {
32
+ isExpo = value;
33
+ };
34
+ exports.setIsExpo = setIsExpo;
41
35
  const log = exports.log = {
42
36
  error: text => {
43
- console.log(_picocolors.default.red(isExpo ? `❌ [${PACKAGE_NAME}] ${text}` : `❌ ${text}`));
37
+ console.log(_picocolors.default.red(isExpo ? `❌ [${packageName}] ${text}` : `❌ ${text}`));
44
38
  },
45
39
  title: (emoji, text) => {
46
40
  if (!isExpo) {
@@ -48,7 +42,7 @@ const log = exports.log = {
48
42
  }
49
43
  },
50
44
  warn: text => {
51
- console.log(_picocolors.default.yellow(isExpo ? `⚠️ [${PACKAGE_NAME}] ${text}` : `⚠️ ${text}`));
45
+ console.log(_picocolors.default.yellow(isExpo ? `⚠️ [${packageName}] ${text}` : `⚠️ ${text}`));
52
46
  },
53
47
  write: (filePath, dimensions) => {
54
48
  if (!isExpo) {
@@ -73,18 +67,12 @@ const parseColor = value => {
73
67
  rgb
74
68
  };
75
69
  };
76
- const getStoryboard = ({
77
- props,
78
- extras
79
- }) => {
70
+ const getStoryboard = props => {
80
71
  const {
81
72
  background,
82
- logo
73
+ logo,
74
+ fileNameSuffix
83
75
  } = props;
84
- const {
85
- fileNameSuffix,
86
- logoHeight
87
- } = extras;
88
76
  const {
89
77
  R,
90
78
  G,
@@ -113,7 +101,7 @@ const getStoryboard = ({
113
101
  <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
114
102
  <subviews>
115
103
  <imageView autoresizesSubviews="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" image="BootSplashLogo-${fileNameSuffix}" translatesAutoresizingMaskIntoConstraints="NO" id="3lX-Ut-9ad">
116
- <rect key="frame" x="${(frameWidth - logo.width) / 2}" y="${(frameHeight - logoHeight) / 2}" width="${logo.width}" height="${logoHeight}"/>
104
+ <rect key="frame" x="${(frameWidth - logo.width) / 2}" y="${(frameHeight - logo.height) / 2}" width="${logo.width}" height="${logo.height}"/>
117
105
  <accessibility key="accessibilityConfiguration">
118
106
  <accessibilityTraits key="traits" image="YES" notEnabled="YES"/>
119
107
  </accessibility>
@@ -133,7 +121,7 @@ const getStoryboard = ({
133
121
  </scene>
134
122
  </scenes>
135
123
  <resources>
136
- <image name="BootSplashLogo-${fileNameSuffix}" width="${logo.width}" height="${logoHeight}"/>
124
+ <image name="BootSplashLogo-${fileNameSuffix}" width="${logo.width}" height="${logo.height}"/>
137
125
  <namedColor name="BootSplashBackground-${fileNameSuffix}">
138
126
  <color red="${R}" green="${G}" blue="${B}" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
139
127
  </namedColor>
@@ -220,26 +208,6 @@ const writeXmlLike = async (filePath, content, {
220
208
  }
221
209
  };
222
210
  exports.writeXmlLike = writeXmlLike;
223
- const getAssetBase64 = async (name, asset) => {
224
- if (asset == null) {
225
- return "";
226
- }
227
- const {
228
- image,
229
- width
230
- } = asset;
231
- const {
232
- format
233
- } = await image.metadata();
234
- if (format !== "png" && format !== "svg") {
235
- log.error(`${name} image file format (${format}) is not supported`);
236
- process.exit(1);
237
- }
238
- const buffer = await image.clone().resize(width).png({
239
- quality: 100
240
- }).toBuffer();
241
- return buffer.toString("base64");
242
- };
243
211
  const getAndroidOutputPath = ({
244
212
  flavor,
245
213
  platforms
@@ -298,52 +266,47 @@ const getInfoPlistPath = ({
298
266
  }
299
267
  return _path.default.resolve(iosOutputPath, "Info.plist");
300
268
  };
301
- const getAssetHeight = asset => {
302
- if (asset == null) {
303
- return Promise.resolve(0);
269
+ const toAsset = async (filePath, width) => {
270
+ const image = (0, _sharp.default)(filePath);
271
+ const {
272
+ format
273
+ } = await image.metadata();
274
+ if (format !== "png" && format !== "svg") {
275
+ log.error(`${_path.default.basename(filePath)} image file format (${format}) is not supported`);
276
+ process.exit(1);
304
277
  }
305
- return asset.image.clone().resize(asset.width).toBuffer().then(buffer => (0, _sharp.default)(buffer).metadata()).then(({
278
+ const [height, hash] = await Promise.all([image.clone().resize(width).toBuffer().then(buffer => (0, _sharp.default)(buffer).metadata()).then(({
306
279
  height = 0
307
- }) => Math.round(height));
280
+ }) => Math.round(height)), image.clone().resize(width).png({
281
+ quality: 100
282
+ }).toBuffer().then(buffer => buffer.toString("base64"))]);
283
+ return {
284
+ path: filePath,
285
+ image,
286
+ hash,
287
+ height,
288
+ width
289
+ };
308
290
  };
309
- const getProps = ({
291
+ const transformProps = async (rootPath, {
310
292
  android = {},
311
293
  licenseKey,
312
- ...config
294
+ ...rawProps
313
295
  }) => {
314
296
  if (_semver.default.lt(process.versions.node, "20.0.0")) {
315
297
  log.error("Requires Node 20 (or higher)");
316
298
  process.exit(1);
317
299
  }
318
- const assetsOutputPath = _path.default.resolve(workingPath, config.assetsOutput);
319
- const logoPath = _path.default.resolve(workingPath, config.logo);
320
- const darkLogoPath = config.darkLogo != null ? _path.default.resolve(workingPath, config.darkLogo) : undefined;
321
- const brandPath = config.brand != null ? _path.default.resolve(workingPath, config.brand) : undefined;
322
- const darkBrandPath = config.darkBrand != null ? _path.default.resolve(workingPath, config.darkBrand) : undefined;
323
- const logoWidth = config.logoWidth - config.logoWidth % 2;
324
- const brandWidth = config.brandWidth - config.brandWidth % 2;
325
- const logo = {
326
- path: logoPath,
327
- image: (0, _sharp.default)(logoPath),
328
- width: logoWidth
329
- };
330
- const darkLogo = darkLogoPath != null ? {
331
- path: darkLogoPath,
332
- image: (0, _sharp.default)(darkLogoPath),
333
- width: logoWidth
334
- } : undefined;
335
- const brand = brandPath != null ? {
336
- path: brandPath,
337
- image: (0, _sharp.default)(brandPath),
338
- width: brandWidth
339
- } : undefined;
340
- const darkBrand = darkBrandPath != null ? {
341
- path: darkBrandPath,
342
- image: (0, _sharp.default)(darkBrandPath),
343
- width: brandWidth
344
- } : undefined;
345
- const background = parseColor(config.background);
346
- const darkBackground = config.darkBackground != null ? parseColor(config.darkBackground) : undefined;
300
+ const assetsOutputPath = _path.default.resolve(rootPath, rawProps.assetsOutput);
301
+ const logoPath = _path.default.resolve(rootPath, rawProps.logo);
302
+ const darkLogoPath = rawProps.darkLogo != null ? _path.default.resolve(rootPath, rawProps.darkLogo) : undefined;
303
+ const brandPath = rawProps.brand != null ? _path.default.resolve(rootPath, rawProps.brand) : undefined;
304
+ const darkBrandPath = rawProps.darkBrand != null ? _path.default.resolve(rootPath, rawProps.darkBrand) : undefined;
305
+ const logoWidth = rawProps.logoWidth - rawProps.logoWidth % 2;
306
+ const brandWidth = rawProps.brandWidth - rawProps.brandWidth % 2;
307
+ 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]);
308
+ const background = parseColor(rawProps.background);
309
+ const darkBackground = rawProps.darkBackground != null ? parseColor(rawProps.darkBackground) : undefined;
347
310
  const executeAddon = brand != null || darkBackground != null || darkLogo != null || darkBrand != null;
348
311
  if (licenseKey != null && !executeAddon) {
349
312
  log.warn("You specified a license key but none of the options that requires it.");
@@ -363,12 +326,24 @@ const getProps = ({
363
326
  log.error(`${optionNames.darkBrand} option couldn't be used without ${optionNames.brand}.`);
364
327
  process.exit(1);
365
328
  }
366
- if (logoWidth < config.logoWidth) {
329
+ if (logoWidth < rawProps.logoWidth) {
367
330
  log.warn(`Logo width must be a multiple of 2. It has been rounded to ${logoWidth}dp.`);
368
331
  }
369
- if (brandWidth < config.brandWidth) {
332
+ if (brandWidth < rawProps.brandWidth) {
370
333
  log.warn(`Brand width must be a multiple of 2. It has been rounded to ${brandWidth}dp.`);
371
334
  }
335
+ const record = {
336
+ background: background.hex,
337
+ darkBackground: darkBackground?.hex ?? "",
338
+ logo: logo.hash,
339
+ darkLogo: darkLogo?.hash ?? "",
340
+ brand: brand?.hash ?? "",
341
+ darkBrand: darkBrand?.hash ?? ""
342
+ };
343
+ const stableKey = Object.keys(record).sort().map(key => record[key]).join();
344
+ const fileNameSuffix = _crypto.default.createHash("shake256", {
345
+ outputLength: 3
346
+ }).update(stableKey).digest("hex").toLowerCase();
372
347
  return {
373
348
  android,
374
349
  assetsOutputPath,
@@ -379,53 +354,26 @@ const getProps = ({
379
354
  logo,
380
355
  darkLogo,
381
356
  brand,
382
- darkBrand
357
+ darkBrand,
358
+ fileNameSuffix
383
359
  };
384
360
  };
385
- const getExtras = async ({
386
- background,
387
- darkBackground,
388
- logo,
389
- darkLogo,
390
- brand,
391
- darkBrand
392
- }) => {
393
- 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)]);
394
- const record = {
395
- background: background.hex,
396
- darkBackground: darkBackground?.hex ?? "",
397
- logo: logoHash,
398
- darkLogo: darkLogoHash,
399
- brand: brandHash,
400
- darkBrand: darkBrandHash
401
- };
402
- const stableKey = Object.keys(record).sort().map(key => record[key]).join();
403
- const fileNameSuffix = _crypto.default.createHash("shake256", {
404
- outputLength: 3
405
- }).update(stableKey).digest("hex").toLowerCase();
406
- return {
407
- fileNameSuffix,
408
- logoHeight,
409
- brandHeight
410
- };
411
- };
412
- exports.getExtras = getExtras;
361
+ exports.transformProps = transformProps;
413
362
  const writeAndroidAssets = async ({
414
363
  androidOutputPath,
415
- props,
416
- extras
364
+ props
417
365
  }) => {
418
366
  const {
419
367
  logo,
420
368
  brand
421
369
  } = props;
422
- if (logo.width > 192 || extras.logoHeight > 192) {
370
+ if (logo.width > 192 || logo.height > 192) {
423
371
  return log.warn("Logo size exceeding 192x192dp will be cropped by Android. Skipping Android assets generation…");
424
372
  }
425
- if (brand != null && (brand.width > 200 || extras.brandHeight > 80)) {
373
+ if (brand != null && (brand.width > 200 || brand.height > 80)) {
426
374
  return log.warn("Brand size exceeding 200x80dp will be cropped by Android. Skipping Android assets generation…");
427
375
  }
428
- if (logo.width > 134 || extras.logoHeight > 134) {
376
+ if (logo.width > 134 || logo.height > 134) {
429
377
  log.warn("Logo size exceeds 134x134dp. It might be cropped by Android.");
430
378
  }
431
379
  log.title("🤖", "Android");
@@ -485,12 +433,12 @@ const writeAndroidAssets = async ({
485
433
  exports.writeAndroidAssets = writeAndroidAssets;
486
434
  const writeIOSAssets = async ({
487
435
  iosOutputPath,
488
- props,
489
- extras
436
+ props
490
437
  }) => {
491
438
  const {
492
439
  background,
493
- logo
440
+ logo,
441
+ fileNameSuffix
494
442
  } = props;
495
443
  log.title("🍏", "iOS");
496
444
  hfs.ensureDir(iosOutputPath);
@@ -500,14 +448,11 @@ const writeIOSAssets = async ({
500
448
  hfs.rm(file);
501
449
  });
502
450
  const storyboardPath = _path.default.resolve(iosOutputPath, "BootSplash.storyboard");
503
- await writeXmlLike(storyboardPath, getStoryboard({
504
- props,
505
- extras
506
- }), {
451
+ await writeXmlLike(storyboardPath, getStoryboard(props), {
507
452
  formatter: "xmlFormatter",
508
453
  whiteSpaceAtEndOfSelfclosingTag: false
509
454
  });
510
- const colorsSetPath = _path.default.resolve(iosOutputPath, "Colors.xcassets", `BootSplashBackground-${extras.fileNameSuffix}.colorset`);
455
+ const colorsSetPath = _path.default.resolve(iosOutputPath, "Colors.xcassets", `BootSplashBackground-${fileNameSuffix}.colorset`);
511
456
  hfs.ensureDir(colorsSetPath);
512
457
  writeJson(_path.default.resolve(colorsSetPath, "Contents.json"), {
513
458
  colors: [{
@@ -527,8 +472,8 @@ const writeIOSAssets = async ({
527
472
  version: 1
528
473
  }
529
474
  });
530
- const logoFileName = `logo-${extras.fileNameSuffix}`;
531
- const imagesSetPath = _path.default.resolve(iosOutputPath, "Images.xcassets", `BootSplashLogo-${extras.fileNameSuffix}.imageset`);
475
+ const logoFileName = `logo-${fileNameSuffix}`;
476
+ const imagesSetPath = _path.default.resolve(iosOutputPath, "Images.xcassets", `BootSplashLogo-${fileNameSuffix}.imageset`);
532
477
  hfs.ensureDir(imagesSetPath);
533
478
  writeJson(_path.default.resolve(imagesSetPath, "Contents.json"), {
534
479
  images: [{
@@ -579,8 +524,7 @@ const writeIOSAssets = async ({
579
524
  exports.writeIOSAssets = writeIOSAssets;
580
525
  const writeWebAssets = async ({
581
526
  htmlTemplatePath,
582
- props,
583
- extras
527
+ props
584
528
  }) => {
585
529
  const {
586
530
  background,
@@ -613,7 +557,7 @@ const writeWebAssets = async ({
613
557
  #bootsplash-logo {
614
558
  content: url("${dataURI}");
615
559
  width: ${logo.width}px;
616
- height: ${extras.logoHeight}px;
560
+ height: ${logo.height}px;
617
561
  }
618
562
  </style>
619
563
  `);
@@ -641,8 +585,7 @@ const writeWebAssets = async ({
641
585
  };
642
586
  exports.writeWebAssets = writeWebAssets;
643
587
  const writeGenericAssets = async ({
644
- props,
645
- extras
588
+ props
646
589
  }) => {
647
590
  const {
648
591
  assetsOutputPath,
@@ -655,7 +598,7 @@ const writeGenericAssets = async ({
655
598
  background: background.hex,
656
599
  logo: {
657
600
  width: logo.width,
658
- height: extras.logoHeight
601
+ height: logo.height
659
602
  }
660
603
  });
661
604
  await Promise.all([{
@@ -692,28 +635,33 @@ const writeGenericAssets = async ({
692
635
  }));
693
636
  };
694
637
  exports.writeGenericAssets = writeGenericAssets;
695
- const requireAddon = () => {
696
- try {
697
- return require("./addon");
698
- } catch {
699
- return;
638
+ const requireAddon = ({
639
+ executeAddon,
640
+ licenseKey
641
+ }) => {
642
+ if (licenseKey != null && executeAddon) {
643
+ try {
644
+ const addon = require("./dist/commonjs/addon");
645
+ return "default" in addon ? addon.default : addon;
646
+ } catch {
647
+ return;
648
+ }
700
649
  }
701
650
  };
651
+ exports.requireAddon = requireAddon;
702
652
  const generate = async ({
703
653
  platforms,
704
654
  html,
705
655
  flavor,
706
656
  plist,
707
- ...config
657
+ ...rawProps
708
658
  }) => {
709
- const props = getProps(config);
659
+ const props = await transformProps(workingPath, rawProps);
660
+ const addon = requireAddon(props);
710
661
  const {
711
662
  background,
712
- brand,
713
- licenseKey,
714
- executeAddon
663
+ brand
715
664
  } = props;
716
- const extras = await getExtras(props);
717
665
  const androidOutputPath = getAndroidOutputPath({
718
666
  flavor,
719
667
  platforms
@@ -728,8 +676,7 @@ const generate = async ({
728
676
  if (androidOutputPath != null) {
729
677
  await writeAndroidAssets({
730
678
  androidOutputPath,
731
- props,
732
- extras
679
+ props
733
680
  });
734
681
  const manifestXmlPath = _path.default.resolve(androidOutputPath, "..", "AndroidManifest.xml");
735
682
  if (hfs.exists(manifestXmlPath)) {
@@ -804,26 +751,8 @@ const generate = async ({
804
751
  if (iosOutputPath != null) {
805
752
  await writeIOSAssets({
806
753
  iosOutputPath,
807
- props,
808
- extras
809
- });
810
- const infoPlistPath = getInfoPlistPath({
811
- iosOutputPath,
812
- plist
754
+ props
813
755
  });
814
- if (infoPlistPath != null) {
815
- const infoPlist = _plist.default.parse(hfs.text(infoPlistPath));
816
- infoPlist["UILaunchStoryboardName"] = "BootSplash";
817
- const formatted = (0, _xmlFormatter.default)(_plist.default.build(infoPlist), {
818
- collapseContent: true,
819
- forceSelfClosingEmptyTag: false,
820
- indentation: "\t",
821
- lineSeparator: "\n",
822
- whiteSpaceAtEndOfSelfclosingTag: false
823
- }).replace(/<string\/>/gm, "<string></string>").replace(/^\t/gm, "");
824
- hfs.write(infoPlistPath, formatted);
825
- log.write(infoPlistPath);
826
- }
827
756
  const pbxprojectPath = Expo.IOSConfig.Paths.getPBXProjectPath(projectRoot);
828
757
  const xcodeProjectPath = Expo.IOSConfig.Paths.getXcodeProjectPath(projectRoot);
829
758
  const project = Expo.IOSConfig.XcodeUtils.getPbxproj(projectRoot);
@@ -843,23 +772,36 @@ const generate = async ({
843
772
  });
844
773
  hfs.write(pbxprojectPath, project.writeSync());
845
774
  log.write(pbxprojectPath);
775
+ const infoPlistPath = getInfoPlistPath({
776
+ iosOutputPath,
777
+ plist
778
+ });
779
+ if (infoPlistPath != null) {
780
+ const infoPlist = _plist.default.parse(hfs.text(infoPlistPath));
781
+ infoPlist["UILaunchStoryboardName"] = "BootSplash";
782
+ const formatted = (0, _xmlFormatter.default)(_plist.default.build(infoPlist), {
783
+ collapseContent: true,
784
+ forceSelfClosingEmptyTag: false,
785
+ indentation: "\t",
786
+ lineSeparator: "\n",
787
+ whiteSpaceAtEndOfSelfclosingTag: false
788
+ }).replace(/<string\/>/gm, "<string></string>").replace(/^\t/gm, "");
789
+ hfs.write(infoPlistPath, formatted);
790
+ log.write(infoPlistPath);
791
+ }
846
792
  }
847
793
  if (htmlTemplatePath != null) {
848
794
  await writeWebAssets({
849
795
  htmlTemplatePath,
850
- props,
851
- extras
796
+ props
852
797
  });
853
798
  }
854
799
  await writeGenericAssets({
855
- props,
856
- extras
800
+ props
857
801
  });
858
- if (licenseKey != null && executeAddon) {
859
- const addon = requireAddon();
860
- await addon?.execute({
802
+ if (addon != null) {
803
+ await addon.execute({
861
804
  props,
862
- extras,
863
805
  androidOutputPath,
864
806
  iosOutputPath,
865
807
  htmlTemplatePath
@@ -873,275 +815,5 @@ ${_picocolors.default.blue("┗━━━━━━━━━━━━━━━━
873
815
  }
874
816
  console.log(`\n💖 Thanks for using ${_picocolors.default.underline("react-native-bootsplash")}`);
875
817
  };
876
-
877
- // Expo plugin
878
818
  exports.generate = generate;
879
- const withoutExpoSplashScreen = Expo.createRunOncePlugin(config => config, "expo-splash-screen", "skip");
880
- const withAndroidAssets = (config, props) => Expo.withDangerousMod(config, ["android", async config => {
881
- const {
882
- platformProjectRoot
883
- } = config.modRequest;
884
- const extras = await getExtras(props);
885
- const androidOutputPath = _path.default.resolve(platformProjectRoot, "app", "src", "main", "res");
886
- await writeAndroidAssets({
887
- androidOutputPath,
888
- props,
889
- extras
890
- });
891
- return config;
892
- }]);
893
- const withAndroidManifest = config => Expo.withAndroidManifest(config, config => {
894
- config.modResults.manifest.application?.forEach(application => {
895
- if (application.$["android:name"] === ".MainApplication") {
896
- const {
897
- activity
898
- } = application;
899
- activity?.forEach(activity => {
900
- if (activity.$["android:name"] === ".MainActivity") {
901
- activity.$["android:theme"] = "@style/BootTheme";
902
- }
903
- });
904
- }
905
- });
906
- return config;
907
- });
908
- const withMainActivity = config => Expo.withMainActivity(config, config => {
909
- const {
910
- modResults
911
- } = config;
912
- const withImports = (0, _codeMod.addImports)(modResults.contents.replace(/(\/\/ )?setTheme\(R\.style\.AppTheme\)/, "// setTheme(R.style.AppTheme)"), ["android.os.Bundle", "com.zoontek.rnbootsplash.RNBootSplash"], false);
913
-
914
- // indented with 4 spaces
915
- const withInit = (0, _generateCode.mergeContents)({
916
- src: withImports,
917
- comment: " //",
918
- tag: "bootsplash-init",
919
- offset: 0,
920
- anchor: /super\.onCreate\(null\)/,
921
- newSrc: " RNBootSplash.init(this, R.style.BootTheme)"
922
- });
923
- return {
924
- ...config,
925
- modResults: {
926
- ...modResults,
927
- contents: withInit.contents
928
- }
929
- };
930
- });
931
- const withAndroidStyles = (config, props) => Expo.withAndroidStyles(config, config => {
932
- const {
933
- android,
934
- brand
935
- } = props;
936
- const {
937
- darkContentBarsStyle
938
- } = android;
939
- const {
940
- modResults
941
- } = config;
942
- const {
943
- resources
944
- } = modResults;
945
- const {
946
- style = []
947
- } = resources;
948
- const item = [{
949
- $: {
950
- name: "postBootSplashTheme"
951
- },
952
- _: "@style/AppTheme"
953
- }, {
954
- $: {
955
- name: "bootSplashBackground"
956
- },
957
- _: "@color/bootsplash_background"
958
- }, {
959
- $: {
960
- name: "bootSplashLogo"
961
- },
962
- _: "@drawable/bootsplash_logo"
963
- }];
964
- if (brand != null) {
965
- item.push({
966
- $: {
967
- name: "bootSplashBrand"
968
- },
969
- _: "@drawable/bootsplash_brand"
970
- });
971
- }
972
- if (darkContentBarsStyle != null) {
973
- item.push({
974
- $: {
975
- name: "darkContentBarsStyle"
976
- },
977
- _: String(darkContentBarsStyle)
978
- });
979
- }
980
- const withBootTheme = [...style.filter(({
981
- $
982
- }) => $.name !== "BootTheme"), {
983
- $: {
984
- name: "BootTheme",
985
- parent: "Theme.BootSplash"
986
- },
987
- item
988
- }];
989
- return {
990
- ...config,
991
- modResults: {
992
- ...modResults,
993
- resources: {
994
- ...resources,
995
- style: withBootTheme
996
- }
997
- }
998
- };
999
- });
1000
- const withAndroidColors = (config, props) => Expo.withAndroidColors(config, config => {
1001
- const {
1002
- background
1003
- } = props;
1004
- config.modResults = (0, _Colors.assignColorValue)(config.modResults, {
1005
- name: "bootsplash_background",
1006
- value: background.hex
1007
- });
1008
- return config;
1009
- });
1010
- const withIOSAssets = (config, props) => Expo.withDangerousMod(config, ["ios", async config => {
1011
- const {
1012
- platformProjectRoot,
1013
- projectName = ""
1014
- } = config.modRequest;
1015
- const extras = await getExtras(props);
1016
- const iosOutputPath = _path.default.resolve(platformProjectRoot, projectName);
1017
- await writeIOSAssets({
1018
- iosOutputPath,
1019
- props,
1020
- extras
1021
- });
1022
- return config;
1023
- }]);
1024
- const withAppDelegate = config => Expo.withAppDelegate(config, config => {
1025
- const {
1026
- modResults
1027
- } = config;
1028
- const {
1029
- language
1030
- } = modResults;
1031
- if (language !== "objc" && language !== "objcpp" && language !== "swift") {
1032
- throw new Error(`Cannot modify the project AppDelegate as it's not in a supported language: ${language}`);
1033
- }
1034
- const withHeader = (0, _generateCode.mergeContents)({
1035
- src: modResults.contents,
1036
- comment: "//",
1037
- tag: "bootsplash-header",
1038
- offset: 1,
1039
- anchor: /import Expo/,
1040
- newSrc: "import RNBootSplash"
1041
- });
1042
- const withRootView = (0, _generateCode.mergeContents)({
1043
- src: withHeader.contents,
1044
- comment: "//",
1045
- tag: "bootsplash-init",
1046
- offset: 1,
1047
- anchor: /class ReactNativeDelegate: ExpoReactNativeFactoryDelegate {/,
1048
- newSrc: (0, _tsDedent.dedent)`
1049
- public override func customize(_ rootView: UIView) {
1050
- super.customize(rootView)
1051
- RNBootSplash.initWithStoryboard("BootSplash", rootView: rootView)
1052
- }
1053
- `
1054
- });
1055
- return {
1056
- ...config,
1057
- modResults: {
1058
- ...modResults,
1059
- contents: withRootView.contents
1060
- }
1061
- };
1062
- });
1063
- const withInfoPlist = config => Expo.withInfoPlist(config, config => {
1064
- config.modResults["UILaunchStoryboardName"] = "BootSplash";
1065
- return config;
1066
- });
1067
- const withXcodeProject = config => Expo.withXcodeProject(config, config => {
1068
- const {
1069
- projectName = ""
1070
- } = config.modRequest;
1071
- Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
1072
- filepath: _path.default.join(projectName, "BootSplash.storyboard"),
1073
- groupName: projectName,
1074
- project: config.modResults,
1075
- isBuildFile: true
1076
- });
1077
- Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
1078
- filepath: _path.default.join(projectName, "Colors.xcassets"),
1079
- groupName: projectName,
1080
- project: config.modResults,
1081
- isBuildFile: true
1082
- });
1083
- return config;
1084
- });
1085
- const withWebAssets = (config, props) => Expo.withDangerousMod(config, [config.platforms?.includes("ios") ? "ios" : "android", async config => {
1086
- const extras = await getExtras(props);
1087
- const fileName = "public/index.html";
1088
- const htmlTemplatePath = _path.default.resolve(workingPath, fileName);
1089
- if (!hfs.exists(htmlTemplatePath)) {
1090
- await exec(`npx expo customize ${fileName}`);
1091
- }
1092
- await writeWebAssets({
1093
- htmlTemplatePath,
1094
- props,
1095
- extras
1096
- });
1097
- return config;
1098
- }]);
1099
- const withGenericAssets = (config, props) => Expo.withDangerousMod(config, [config.platforms?.includes("ios") ? "ios" : "android", async config => {
1100
- const extras = await getExtras(props);
1101
- await writeGenericAssets({
1102
- props,
1103
- extras
1104
- });
1105
- return config;
1106
- }]);
1107
- const withBootSplash = exports.withBootSplash = Expo.createRunOncePlugin((config, baseProps) => {
1108
- const {
1109
- platforms = [],
1110
- sdkVersion = "0.1.0"
1111
- } = config;
1112
- isExpo = true;
1113
- if (_semver.default.lt(sdkVersion, "53.0.0")) {
1114
- log.error("Requires Expo 53.0.0 (or higher)");
1115
- process.exit(1);
1116
- }
1117
- if (!baseProps?.logo) {
1118
- log.error("Missing required parameter 'logo'");
1119
- process.exit(1);
1120
- }
1121
- const props = getProps({
1122
- assetsOutput: "assets/bootsplash",
1123
- background: "#fff",
1124
- brandWidth: 80,
1125
- logoWidth: 100,
1126
- ...baseProps
1127
- });
1128
- const {
1129
- executeAddon
1130
- } = props;
1131
- const addon = executeAddon ? requireAddon() : undefined;
1132
- const plugins = [withoutExpoSplashScreen, addon?.withGenericAssets ?? withGenericAssets];
1133
- if (platforms.includes("android")) {
1134
- plugins.push(addon?.withAndroidAssets ?? withAndroidAssets, withAndroidManifest, withMainActivity, withAndroidStyles, withAndroidColors);
1135
- if (addon != null) {
1136
- plugins.push(addon.withAndroidColorsNight);
1137
- }
1138
- }
1139
- if (platforms.includes("ios")) {
1140
- plugins.push(addon?.withIOSAssets ?? withIOSAssets, withAppDelegate, withInfoPlist, withXcodeProject);
1141
- }
1142
- if (platforms.includes("web")) {
1143
- plugins.push(addon?.withWebAssets ?? withWebAssets);
1144
- }
1145
- return Expo.withPlugins(config, plugins.map(plugin => [plugin, props]));
1146
- }, PACKAGE_NAME);
1147
819
  //# sourceMappingURL=generate.js.map