react-native-bootsplash 5.0.0-beta.2 → 5.0.0-beta.4
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/dist/commonjs/addon/index.js +1 -1
- package/dist/commonjs/addon/index.js.map +1 -1
- package/dist/commonjs/generate.js +68 -40
- package/dist/commonjs/generate.js.map +1 -1
- package/dist/commonjs/index.js +1 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/module/addon/index.js +1 -1
- package/dist/module/addon/index.js.map +1 -1
- package/dist/module/generate.js +64 -39
- package/dist/module/generate.js.map +1 -1
- package/dist/module/index.js +1 -1
- package/dist/module/index.js.map +1 -1
- package/dist/typescript/addon/index.d.ts.map +1 -1
- package/dist/typescript/generate.d.ts +8 -1
- package/dist/typescript/generate.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/generate.ts +77 -78
- package/src/index.ts +1 -1
package/src/generate.ts
CHANGED
|
@@ -3,26 +3,24 @@ import {
|
|
|
3
3
|
CommandFunction,
|
|
4
4
|
IOSProjectConfig,
|
|
5
5
|
} from "@react-native-community/cli-types";
|
|
6
|
+
import detectIndent from "detect-indent";
|
|
6
7
|
import fs from "fs-extra";
|
|
7
8
|
import path from "path";
|
|
8
9
|
import pc from "picocolors";
|
|
9
10
|
import type { Sharp } from "sharp";
|
|
10
11
|
import sharp from "sharp";
|
|
12
|
+
import xmlFormat, { XMLFormatterOptions } from "xml-formatter";
|
|
11
13
|
import type { Manifest } from ".";
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
hex: string;
|
|
15
|
-
rgb: {
|
|
16
|
-
R: string;
|
|
17
|
-
G: string;
|
|
18
|
-
B: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
15
|
+
const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
|
|
21
16
|
|
|
22
17
|
export const androidColorRegex =
|
|
23
18
|
/<color name="bootsplash_background">#\w+<\/color>/g;
|
|
24
19
|
|
|
25
|
-
|
|
20
|
+
export type Color = {
|
|
21
|
+
hex: string;
|
|
22
|
+
rgb: { R: string; G: string; B: string };
|
|
23
|
+
};
|
|
26
24
|
|
|
27
25
|
const parseColor = (value: string): Color => {
|
|
28
26
|
const up = value.toUpperCase().replace(/[^0-9A-F]/g, "");
|
|
@@ -42,31 +40,6 @@ const parseColor = (value: string): Color => {
|
|
|
42
40
|
return { hex, rgb };
|
|
43
41
|
};
|
|
44
42
|
|
|
45
|
-
const ContentsJson = `{
|
|
46
|
-
"images": [
|
|
47
|
-
{
|
|
48
|
-
"idiom": "universal",
|
|
49
|
-
"filename": "bootsplash_logo.png",
|
|
50
|
-
"scale": "1x"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"idiom": "universal",
|
|
54
|
-
"filename": "bootsplash_logo@2x.png",
|
|
55
|
-
"scale": "2x"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"idiom": "universal",
|
|
59
|
-
"filename": "bootsplash_logo@3x.png",
|
|
60
|
-
"scale": "3x"
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
"info": {
|
|
64
|
-
"author": "xcode",
|
|
65
|
-
"version": 1
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
69
|
-
|
|
70
43
|
const getStoryboard = ({
|
|
71
44
|
logoHeight,
|
|
72
45
|
logoWidth,
|
|
@@ -143,6 +116,44 @@ export const logWrite = (
|
|
|
143
116
|
(dimensions != null ? ` (${dimensions.width}x${dimensions.height})` : ""),
|
|
144
117
|
);
|
|
145
118
|
|
|
119
|
+
export const writeJson = (file: string, json: object) => {
|
|
120
|
+
fs.writeFileSync(file, JSON.stringify(json, null, 2) + "\n", "utf-8");
|
|
121
|
+
logWrite(file);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const readXml = (file: string) => {
|
|
125
|
+
const xml = fs.readFileSync(file, "utf-8");
|
|
126
|
+
|
|
127
|
+
const minified = xmlFormat(xml, {
|
|
128
|
+
collapseContent: true,
|
|
129
|
+
forceSelfClosingEmptyTag: true,
|
|
130
|
+
indentation: "",
|
|
131
|
+
lineSeparator: "",
|
|
132
|
+
whiteSpaceAtEndOfSelfclosingTag: true,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const indentation = detectIndent(xml).indent || " ";
|
|
136
|
+
return { minified, indentation };
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const writeXml = (
|
|
140
|
+
file: string,
|
|
141
|
+
xml: string,
|
|
142
|
+
options?: XMLFormatterOptions,
|
|
143
|
+
) => {
|
|
144
|
+
const formatted = xmlFormat(xml, {
|
|
145
|
+
collapseContent: true,
|
|
146
|
+
forceSelfClosingEmptyTag: true,
|
|
147
|
+
indentation: " ",
|
|
148
|
+
lineSeparator: "\n",
|
|
149
|
+
whiteSpaceAtEndOfSelfclosingTag: true,
|
|
150
|
+
...options,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
fs.writeFileSync(file, formatted + "\n", "utf-8");
|
|
154
|
+
logWrite(file);
|
|
155
|
+
};
|
|
156
|
+
|
|
146
157
|
const ensureSupportedFormat = async (
|
|
147
158
|
name: string,
|
|
148
159
|
image: Sharp | undefined,
|
|
@@ -408,34 +419,17 @@ export const generate: CommandFunction<{
|
|
|
408
419
|
const colorsXmlEntry = `<color name="bootsplash_background">${background.hex}</color>`;
|
|
409
420
|
|
|
410
421
|
if (fs.existsSync(colorsXmlPath)) {
|
|
411
|
-
const colorsXml =
|
|
422
|
+
const { minified: colorsXml, indentation } = readXml(colorsXmlPath);
|
|
412
423
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
);
|
|
419
|
-
} else {
|
|
420
|
-
fs.writeFileSync(
|
|
421
|
-
colorsXmlPath,
|
|
422
|
-
colorsXml.replace(
|
|
423
|
-
/<\/resources>/g,
|
|
424
|
-
` ${colorsXmlEntry}\n</resources>`,
|
|
425
|
-
),
|
|
426
|
-
"utf-8",
|
|
427
|
-
);
|
|
428
|
-
}
|
|
424
|
+
const nextXml = colorsXml.match(androidColorRegex)
|
|
425
|
+
? colorsXml.replace(androidColorRegex, colorsXmlEntry)
|
|
426
|
+
: colorsXml.replace(/<\/resources>/g, `${colorsXmlEntry}</resources>`);
|
|
427
|
+
|
|
428
|
+
writeXml(colorsXmlPath, nextXml, { indentation });
|
|
429
429
|
} else {
|
|
430
|
-
|
|
431
|
-
colorsXmlPath,
|
|
432
|
-
`<resources>\n ${colorsXmlEntry}\n</resources>\n`,
|
|
433
|
-
"utf-8",
|
|
434
|
-
);
|
|
430
|
+
writeXml(colorsXmlPath, `<resources>${colorsXmlEntry}</resources>`);
|
|
435
431
|
}
|
|
436
432
|
|
|
437
|
-
logWrite(colorsXmlPath);
|
|
438
|
-
|
|
439
433
|
await Promise.all(
|
|
440
434
|
[
|
|
441
435
|
{ ratio: 1, suffix: "mdpi" },
|
|
@@ -519,11 +513,29 @@ export const generate: CommandFunction<{
|
|
|
519
513
|
|
|
520
514
|
fs.ensureDirSync(imageSetPath);
|
|
521
515
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
516
|
+
writeJson(path.resolve(imageSetPath, "Contents.json"), {
|
|
517
|
+
images: [
|
|
518
|
+
{
|
|
519
|
+
idiom: "universal",
|
|
520
|
+
filename: "bootsplash_logo.png",
|
|
521
|
+
scale: "1x",
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
idiom: "universal",
|
|
525
|
+
filename: "bootsplash_logo@2x.png",
|
|
526
|
+
scale: "2x",
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
idiom: "universal",
|
|
530
|
+
filename: "bootsplash_logo@3x.png",
|
|
531
|
+
scale: "3x",
|
|
532
|
+
},
|
|
533
|
+
],
|
|
534
|
+
info: {
|
|
535
|
+
author: "xcode",
|
|
536
|
+
version: 1,
|
|
537
|
+
},
|
|
538
|
+
});
|
|
527
539
|
|
|
528
540
|
await Promise.all(
|
|
529
541
|
[
|
|
@@ -553,26 +565,13 @@ export const generate: CommandFunction<{
|
|
|
553
565
|
|
|
554
566
|
fs.ensureDirSync(assetsOutputPath);
|
|
555
567
|
|
|
556
|
-
|
|
568
|
+
writeJson(path.resolve(assetsOutputPath, "bootsplash_manifest.json"), {
|
|
557
569
|
background: background.hex,
|
|
558
570
|
logo: {
|
|
559
571
|
width: logoWidth,
|
|
560
572
|
height: logoHeight,
|
|
561
573
|
},
|
|
562
|
-
};
|
|
563
|
-
|
|
564
|
-
const manifestPath = path.resolve(
|
|
565
|
-
assetsOutputPath,
|
|
566
|
-
"bootsplash_manifest.json",
|
|
567
|
-
);
|
|
568
|
-
|
|
569
|
-
fs.writeFileSync(
|
|
570
|
-
manifestPath,
|
|
571
|
-
JSON.stringify(manifest, null, 2) + "\n",
|
|
572
|
-
"utf-8",
|
|
573
|
-
);
|
|
574
|
-
|
|
575
|
-
logWrite(manifestPath);
|
|
574
|
+
} satisfies Manifest);
|
|
576
575
|
|
|
577
576
|
await Promise.all(
|
|
578
577
|
[
|
package/src/index.ts
CHANGED
|
@@ -158,7 +158,7 @@ export function useHideAnimation(config: UseHideAnimationConfig) {
|
|
|
158
158
|
source: brandFinalSrc,
|
|
159
159
|
style: {
|
|
160
160
|
position: "absolute",
|
|
161
|
-
bottom: brandBottom,
|
|
161
|
+
bottom: Platform.OS === "web" ? 60 : brandBottom,
|
|
162
162
|
width: brandWidth,
|
|
163
163
|
height: brandHeight,
|
|
164
164
|
},
|