react-native-bootsplash 6.0.0-beta.0 → 6.0.0-beta.10
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/README.md +33 -88
- package/android/src/main/res/values/public.xml +1 -0
- package/android/src/main/res/values/styles.xml +9 -6
- package/android/src/main/res/values-night/styles.xml +1 -1
- package/android/src/main/res/values-v23/styles.xml +6 -1
- package/android/src/main/res/values-v27/styles.xml +1 -1
- package/android/src/main/res/values-v29/styles.xml +1 -1
- package/android/src/main/res/values-v30/styles.xml +1 -1
- package/app.plugin.js +2 -2
- package/dist/commonjs/addon/index.js +43 -38
- package/dist/commonjs/addon/index.js.map +1 -1
- package/dist/commonjs/expo.js +283 -0
- package/dist/commonjs/expo.js.map +1 -0
- package/dist/commonjs/generate.js +165 -323
- package/dist/commonjs/generate.js.map +1 -1
- package/dist/commonjs/index.js +3 -3
- package/dist/commonjs/index.js.map +1 -1
- package/dist/module/addon/index.js +43 -38
- package/dist/module/addon/index.js.map +1 -1
- package/dist/module/expo.js +273 -0
- package/dist/module/expo.js.map +1 -0
- package/dist/module/generate.js +162 -317
- package/dist/module/generate.js.map +1 -1
- package/dist/module/index.js +2 -2
- package/dist/module/index.js.map +1 -1
- package/dist/typescript/addon/index.d.ts.map +1 -1
- package/dist/typescript/expo.d.ts +11 -0
- package/dist/typescript/expo.d.ts.map +1 -0
- package/dist/typescript/generate.d.ts +27 -21
- package/dist/typescript/generate.d.ts.map +1 -1
- package/dist/typescript/index.d.ts +22 -4
- package/dist/typescript/index.d.ts.map +1 -1
- package/ios/RNBootSplash.mm +33 -37
- package/package.json +8 -8
- package/src/expo.ts +368 -0
- package/src/generate.ts +235 -403
- package/src/index.ts +32 -10
|
@@ -3,15 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var _hash = _interopRequireDefault(require("@emotion/hash"));
|
|
8
|
-
var _config = require("@expo/config");
|
|
6
|
+
exports.writeXmlLike = exports.writeJson = exports.readXmlLike = exports.log = exports.hfs = exports.getExpoConfig = exports.generate = exports.cleanIOSAssets = void 0;
|
|
9
7
|
var Expo = _interopRequireWildcard(require("@expo/config-plugins"));
|
|
10
|
-
var _Colors = require("@expo/config-plugins/build/android/Colors");
|
|
11
|
-
var _codeMod = require("@expo/config-plugins/build/android/codeMod");
|
|
12
|
-
var _generateCode = require("@expo/config-plugins/build/utils/generateCode");
|
|
13
8
|
var _plist = _interopRequireDefault(require("@expo/plist"));
|
|
14
9
|
var _cliTools = require("@react-native-community/cli-tools");
|
|
10
|
+
var _child_process = _interopRequireDefault(require("child_process"));
|
|
11
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
15
12
|
var _detectIndent = _interopRequireDefault(require("detect-indent"));
|
|
16
13
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
17
14
|
var _nodeHtmlParser = require("node-html-parser");
|
|
@@ -20,14 +17,21 @@ var _picocolors = _interopRequireDefault(require("picocolors"));
|
|
|
20
17
|
var htmlPlugin = _interopRequireWildcard(require("prettier/plugins/html"));
|
|
21
18
|
var cssPlugin = _interopRequireWildcard(require("prettier/plugins/postcss"));
|
|
22
19
|
var prettier = _interopRequireWildcard(require("prettier/standalone"));
|
|
20
|
+
var _semver = _interopRequireDefault(require("semver"));
|
|
23
21
|
var _sharp = _interopRequireDefault(require("sharp"));
|
|
24
22
|
var _tsDedent = require("ts-dedent");
|
|
23
|
+
var _util = _interopRequireDefault(require("util"));
|
|
25
24
|
var _xmlFormatter = _interopRequireDefault(require("xml-formatter"));
|
|
25
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
26
26
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
27
27
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
28
|
const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
|
|
30
29
|
const projectRoot = (0, _cliTools.findProjectRoot)(workingPath);
|
|
30
|
+
const promisifiedExec = _util.default.promisify(_child_process.default.exec);
|
|
31
|
+
const exec = cmd => promisifiedExec(cmd).then(({
|
|
32
|
+
stdout,
|
|
33
|
+
stderr
|
|
34
|
+
}) => stdout || stderr);
|
|
31
35
|
const log = exports.log = {
|
|
32
36
|
error: text => {
|
|
33
37
|
console.log(_picocolors.default.red(`❌ ${text}`));
|
|
@@ -59,7 +63,6 @@ const parseColor = value => {
|
|
|
59
63
|
rgb
|
|
60
64
|
};
|
|
61
65
|
};
|
|
62
|
-
exports.parseColor = parseColor;
|
|
63
66
|
const getStoryboard = ({
|
|
64
67
|
logoHeight,
|
|
65
68
|
logoWidth,
|
|
@@ -161,71 +164,85 @@ const hfs = exports.hfs = {
|
|
|
161
164
|
_fsExtra.default.writeFileSync(path, trimmed === "" ? trimmed : trimmed + "\n", "utf-8");
|
|
162
165
|
}
|
|
163
166
|
};
|
|
167
|
+
const getExpoConfig = projectRoot => {
|
|
168
|
+
try {
|
|
169
|
+
const pkg = hfs.json(_path.default.resolve(projectRoot, "node_modules", "expo", "package.json"));
|
|
170
|
+
const version = pkg.version;
|
|
171
|
+
if (version == null || _semver.default.lt(version, "51.0.20")) {
|
|
172
|
+
log.error("Requires Expo 51.0.20 (or higher)");
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
isExpo: true
|
|
177
|
+
};
|
|
178
|
+
} catch {
|
|
179
|
+
return {
|
|
180
|
+
isExpo: false
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
exports.getExpoConfig = getExpoConfig;
|
|
164
185
|
const writeJson = (filePath, content) => {
|
|
165
186
|
hfs.write(filePath, JSON.stringify(content, null, 2));
|
|
166
187
|
log.write(filePath);
|
|
167
188
|
};
|
|
168
189
|
exports.writeJson = writeJson;
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
const {
|
|
172
|
-
indent
|
|
173
|
-
} = (0, _detectIndent.default)(xml);
|
|
174
|
-
const formatOptions = {
|
|
175
|
-
indentation: indent || " "
|
|
176
|
-
};
|
|
177
|
-
return {
|
|
178
|
-
root: (0, _nodeHtmlParser.parse)(xml),
|
|
179
|
-
formatOptions
|
|
180
|
-
};
|
|
181
|
-
};
|
|
182
|
-
exports.readXml = readXml;
|
|
183
|
-
const writeXml = (filePath, content, options) => {
|
|
184
|
-
const formatted = (0, _xmlFormatter.default)(content, {
|
|
185
|
-
collapseContent: true,
|
|
186
|
-
forceSelfClosingEmptyTag: true,
|
|
187
|
-
indentation: " ",
|
|
188
|
-
lineSeparator: "\n",
|
|
189
|
-
whiteSpaceAtEndOfSelfclosingTag: true,
|
|
190
|
-
...options
|
|
191
|
-
});
|
|
192
|
-
hfs.write(filePath, formatted);
|
|
193
|
-
log.write(filePath);
|
|
194
|
-
};
|
|
195
|
-
exports.writeXml = writeXml;
|
|
196
|
-
const readHtml = filePath => {
|
|
197
|
-
const html = hfs.text(filePath);
|
|
198
|
-
const {
|
|
199
|
-
type,
|
|
200
|
-
amount
|
|
201
|
-
} = (0, _detectIndent.default)(html);
|
|
202
|
-
const formatOptions = {
|
|
203
|
-
useTabs: type === "tab",
|
|
204
|
-
tabWidth: amount || 2
|
|
205
|
-
};
|
|
190
|
+
const readXmlLike = filePath => {
|
|
191
|
+
const content = hfs.text(filePath);
|
|
206
192
|
return {
|
|
207
|
-
root: (0, _nodeHtmlParser.parse)(
|
|
208
|
-
formatOptions
|
|
193
|
+
root: (0, _nodeHtmlParser.parse)(content),
|
|
194
|
+
formatOptions: {
|
|
195
|
+
indent: (0, _detectIndent.default)(content)
|
|
196
|
+
}
|
|
209
197
|
};
|
|
210
198
|
};
|
|
211
|
-
exports.
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
199
|
+
exports.readXmlLike = readXmlLike;
|
|
200
|
+
const writeXmlLike = async (filePath, content, {
|
|
201
|
+
indent,
|
|
202
|
+
...formatOptions
|
|
203
|
+
}) => {
|
|
204
|
+
if (formatOptions.formatter === "prettier") {
|
|
205
|
+
const {
|
|
206
|
+
formatter,
|
|
207
|
+
useCssPlugin = false,
|
|
208
|
+
selfClosingTags = false,
|
|
209
|
+
...options
|
|
210
|
+
} = formatOptions;
|
|
211
|
+
const formatted = await prettier.format(content, {
|
|
212
|
+
parser: "html",
|
|
213
|
+
bracketSameLine: true,
|
|
214
|
+
printWidth: 10000,
|
|
215
|
+
plugins: [htmlPlugin, ...(useCssPlugin ? [cssPlugin] : [])],
|
|
216
|
+
useTabs: indent?.type === "tab",
|
|
217
|
+
tabWidth: (indent?.amount ?? 0) || 2,
|
|
218
|
+
...options
|
|
219
|
+
});
|
|
220
|
+
hfs.write(filePath, selfClosingTags ? formatted.replace(/><\/[a-z-0-9]+>/gi, " />") : formatted);
|
|
221
|
+
log.write(filePath);
|
|
222
|
+
} else {
|
|
223
|
+
const {
|
|
224
|
+
formatter,
|
|
225
|
+
...options
|
|
226
|
+
} = formatOptions;
|
|
227
|
+
const formatted = (0, _xmlFormatter.default)(content, {
|
|
228
|
+
collapseContent: true,
|
|
229
|
+
forceSelfClosingEmptyTag: true,
|
|
230
|
+
lineSeparator: "\n",
|
|
231
|
+
whiteSpaceAtEndOfSelfclosingTag: true,
|
|
232
|
+
indentation: (indent?.indent ?? "") || " ",
|
|
233
|
+
...options
|
|
234
|
+
});
|
|
235
|
+
hfs.write(filePath, formatted);
|
|
236
|
+
log.write(filePath);
|
|
237
|
+
}
|
|
222
238
|
};
|
|
223
|
-
exports.
|
|
224
|
-
const
|
|
239
|
+
exports.writeXmlLike = writeXmlLike;
|
|
240
|
+
const cleanIOSAssets = dir => {
|
|
225
241
|
hfs.readDir(dir).filter(file => file === "Colors.xcassets" || file === "Images.xcassets").map(file => _path.default.join(dir, file)).flatMap(dir => hfs.readDir(dir).filter(file => file.startsWith("BootSplash")).map(file => _path.default.join(dir, file))).forEach(file => {
|
|
226
242
|
hfs.rm(file);
|
|
227
243
|
});
|
|
228
244
|
};
|
|
245
|
+
exports.cleanIOSAssets = cleanIOSAssets;
|
|
229
246
|
const getImageBase64 = async (image, width) => {
|
|
230
247
|
if (image == null) {
|
|
231
248
|
return "";
|
|
@@ -255,7 +272,9 @@ const getFileNameSuffix = async ({
|
|
|
255
272
|
darkBrand: darkBrandHash
|
|
256
273
|
};
|
|
257
274
|
const stableKey = Object.keys(record).sort().map(key => record[key]).join();
|
|
258
|
-
return (
|
|
275
|
+
return _crypto.default.createHash("shake256", {
|
|
276
|
+
outputLength: 3
|
|
277
|
+
}).update(stableKey).digest("hex").toLowerCase();
|
|
259
278
|
};
|
|
260
279
|
const ensureSupportedFormat = async (name, image) => {
|
|
261
280
|
if (image == null) {
|
|
@@ -305,8 +324,8 @@ const getAndroidOutputPath = ({
|
|
|
305
324
|
return androidOutputPath;
|
|
306
325
|
};
|
|
307
326
|
const getIOSOutputPath = ({
|
|
308
|
-
assetsOutputPath,
|
|
309
327
|
ios,
|
|
328
|
+
assetsOutputPath,
|
|
310
329
|
isExpo,
|
|
311
330
|
platforms
|
|
312
331
|
}) => {
|
|
@@ -328,13 +347,23 @@ const getIOSOutputPath = ({
|
|
|
328
347
|
}
|
|
329
348
|
return iosOutputPath;
|
|
330
349
|
};
|
|
331
|
-
const getHtmlTemplatePath = ({
|
|
350
|
+
const getHtmlTemplatePath = async ({
|
|
351
|
+
isExpo,
|
|
332
352
|
html,
|
|
333
353
|
platforms
|
|
334
354
|
}) => {
|
|
335
355
|
if (!platforms.includes("web")) {
|
|
336
356
|
return;
|
|
337
357
|
}
|
|
358
|
+
if (isExpo) {
|
|
359
|
+
const htmlTemplatePath = _path.default.resolve(workingPath, html);
|
|
360
|
+
const htmlTemplateRelativePath = _path.default.relative(workingPath, htmlTemplatePath);
|
|
361
|
+
if (htmlTemplateRelativePath === "public/index.html" && !hfs.exists(htmlTemplatePath)) {
|
|
362
|
+
const cmd = `npx expo customize ${htmlTemplateRelativePath}`;
|
|
363
|
+
console.log(_picocolors.default.dim(`Running ${cmd}`));
|
|
364
|
+
await exec(cmd);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
338
367
|
const htmlTemplatePath = _path.default.resolve(workingPath, html);
|
|
339
368
|
if (!hfs.exists(htmlTemplatePath)) {
|
|
340
369
|
return log.warn(`No ${_path.default.relative(workingPath, htmlTemplatePath)} file found. Skipping HTML + CSS generation…`);
|
|
@@ -349,7 +378,6 @@ const getImageHeight = (image, width) => {
|
|
|
349
378
|
height = 0
|
|
350
379
|
}) => Math.round(height));
|
|
351
380
|
};
|
|
352
|
-
exports.getImageHeight = getImageHeight;
|
|
353
381
|
const requireAddon = () => {
|
|
354
382
|
try {
|
|
355
383
|
return require("./addon"); // eslint-disable-line
|
|
@@ -366,12 +394,10 @@ const generate = async ({
|
|
|
366
394
|
licenseKey,
|
|
367
395
|
...args
|
|
368
396
|
}) => {
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const nodeVersion = Number.parseInt(nodeStringVersion, 10);
|
|
374
|
-
if (!Number.isNaN(nodeVersion) && nodeVersion < 18) {
|
|
397
|
+
const {
|
|
398
|
+
isExpo
|
|
399
|
+
} = getExpoConfig(workingPath);
|
|
400
|
+
if (_semver.default.lt(process.versions.node, "18.0.0")) {
|
|
375
401
|
log.error("Requires Node 18 (or higher)");
|
|
376
402
|
process.exit(1);
|
|
377
403
|
}
|
|
@@ -440,7 +466,8 @@ const generate = async ({
|
|
|
440
466
|
isExpo,
|
|
441
467
|
platforms
|
|
442
468
|
});
|
|
443
|
-
const htmlTemplatePath = getHtmlTemplatePath({
|
|
469
|
+
const htmlTemplatePath = await getHtmlTemplatePath({
|
|
470
|
+
isExpo,
|
|
444
471
|
html,
|
|
445
472
|
platforms
|
|
446
473
|
});
|
|
@@ -499,43 +526,85 @@ const generate = async ({
|
|
|
499
526
|
});
|
|
500
527
|
}));
|
|
501
528
|
if (!isExpo) {
|
|
529
|
+
const manifestXmlPath = _path.default.resolve(androidOutputPath, "..", "AndroidManifest.xml");
|
|
530
|
+
const manifestXml = readXmlLike(manifestXmlPath);
|
|
531
|
+
const activities = manifestXml.root.querySelectorAll("activity");
|
|
532
|
+
for (const activity of activities) {
|
|
533
|
+
if (activity.getAttribute("android:name") === ".MainActivity") {
|
|
534
|
+
activity.setAttribute("android:theme", "@style/BootTheme");
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
await writeXmlLike(manifestXmlPath, manifestXml.root.toString(), {
|
|
538
|
+
...manifestXml.formatOptions,
|
|
539
|
+
formatter: "prettier",
|
|
540
|
+
htmlWhitespaceSensitivity: "ignore",
|
|
541
|
+
selfClosingTags: true,
|
|
542
|
+
singleAttributePerLine: true
|
|
543
|
+
});
|
|
502
544
|
const valuesPath = _path.default.resolve(androidOutputPath, "values");
|
|
503
545
|
hfs.ensureDir(valuesPath);
|
|
504
546
|
const colorsXmlPath = _path.default.resolve(valuesPath, "colors.xml");
|
|
505
547
|
const colorsXmlEntry = `<color name="bootsplash_background">${background.hex}</color>`;
|
|
506
548
|
if (hfs.exists(colorsXmlPath)) {
|
|
507
|
-
const
|
|
508
|
-
root,
|
|
509
|
-
formatOptions
|
|
510
|
-
} = readXml(colorsXmlPath);
|
|
549
|
+
const colorsXml = readXmlLike(colorsXmlPath);
|
|
511
550
|
const nextColor = (0, _nodeHtmlParser.parse)(colorsXmlEntry);
|
|
512
|
-
const prevColor = root.querySelector('color[name="bootsplash_background"]');
|
|
551
|
+
const prevColor = colorsXml.root.querySelector('color[name="bootsplash_background"]');
|
|
513
552
|
if (prevColor != null) {
|
|
514
553
|
prevColor.replaceWith(nextColor);
|
|
515
554
|
} else {
|
|
516
|
-
root.querySelector("resources")?.appendChild(nextColor);
|
|
555
|
+
colorsXml.root.querySelector("resources")?.appendChild(nextColor);
|
|
517
556
|
}
|
|
518
|
-
|
|
557
|
+
await writeXmlLike(colorsXmlPath, colorsXml.root.toString(), {
|
|
558
|
+
...colorsXml.formatOptions,
|
|
559
|
+
formatter: "xmlFormatter"
|
|
560
|
+
});
|
|
519
561
|
} else {
|
|
520
|
-
|
|
562
|
+
await writeXmlLike(colorsXmlPath, `<resources>${colorsXmlEntry}</resources>`, {
|
|
563
|
+
formatter: "xmlFormatter"
|
|
564
|
+
});
|
|
521
565
|
}
|
|
566
|
+
const stylesXmlPath = _path.default.resolve(valuesPath, "styles.xml");
|
|
567
|
+
const stylesXml = readXmlLike(stylesXmlPath);
|
|
568
|
+
const prevStyle = stylesXml.root.querySelector('style[name="BootTheme"]');
|
|
569
|
+
const parent = prevStyle?.getAttribute("parent") ?? "Theme.BootSplash";
|
|
570
|
+
const extraItems = (0, _nodeHtmlParser.parse)(prevStyle?.text.split("\n").map(line => line.trim()).join("") ?? "").childNodes.filter(node => {
|
|
571
|
+
if (!(node instanceof _nodeHtmlParser.HTMLElement)) {
|
|
572
|
+
return true;
|
|
573
|
+
}
|
|
574
|
+
const name = node.getAttribute("name");
|
|
575
|
+
return name !== "bootSplashBackground" && name !== "bootSplashLogo" && name !== "bootSplashBrand" && name !== "postBootSplashTheme";
|
|
576
|
+
}).map(node => node.toString());
|
|
577
|
+
const styleItems = [...(extraItems.length > 0 ? [...extraItems, ""] : []), '<item name="bootSplashBackground">@color/bootsplash_background</item>', '<item name="bootSplashLogo">@drawable/bootsplash_logo</item>', ...(brand != null && brandPath != null ? ['<item name="bootSplashBrand">@drawable/bootsplash_brand</item>'] : []), '<item name="postBootSplashTheme">@style/AppTheme</item>'];
|
|
578
|
+
const nextStyle = (0, _nodeHtmlParser.parse)((0, _tsDedent.dedent)`
|
|
579
|
+
<style name="BootTheme" parent="${parent}">
|
|
580
|
+
${styleItems.join("\n")}
|
|
581
|
+
</style>
|
|
582
|
+
`);
|
|
583
|
+
prevStyle?.remove(); // remove the existing style
|
|
584
|
+
stylesXml.root.querySelector("resources")?.appendChild(nextStyle);
|
|
585
|
+
await writeXmlLike(stylesXmlPath, stylesXml.root.toString(), {
|
|
586
|
+
...stylesXml.formatOptions,
|
|
587
|
+
formatter: "prettier",
|
|
588
|
+
htmlWhitespaceSensitivity: "ignore"
|
|
589
|
+
});
|
|
522
590
|
}
|
|
523
591
|
}
|
|
524
592
|
if (iosOutputPath != null) {
|
|
525
593
|
log.title("🍏", "iOS");
|
|
526
594
|
hfs.ensureDir(iosOutputPath);
|
|
527
|
-
|
|
595
|
+
cleanIOSAssets(iosOutputPath);
|
|
528
596
|
const storyboardPath = _path.default.resolve(iosOutputPath, "BootSplash.storyboard");
|
|
529
597
|
const colorsSetPath = _path.default.resolve(iosOutputPath, "Colors.xcassets", `BootSplashBackground-${fileNameSuffix}.colorset`);
|
|
530
598
|
const imageSetPath = _path.default.resolve(iosOutputPath, "Images.xcassets", `BootSplashLogo-${fileNameSuffix}.imageset`);
|
|
531
599
|
hfs.ensureDir(colorsSetPath);
|
|
532
600
|
hfs.ensureDir(imageSetPath);
|
|
533
|
-
|
|
601
|
+
await writeXmlLike(storyboardPath, getStoryboard({
|
|
534
602
|
logoHeight,
|
|
535
603
|
logoWidth,
|
|
536
604
|
background: background.rgb,
|
|
537
605
|
fileNameSuffix
|
|
538
606
|
}), {
|
|
607
|
+
formatter: "xmlFormatter",
|
|
539
608
|
whiteSpaceAtEndOfSelfclosingTag: false
|
|
540
609
|
});
|
|
541
610
|
writeJson(_path.default.resolve(colorsSetPath, "Contents.json"), {
|
|
@@ -619,16 +688,17 @@ const generate = async ({
|
|
|
619
688
|
const xcodeProjectPath = Expo.IOSConfig.Paths.getXcodeProjectPath(projectRoot);
|
|
620
689
|
const project = Expo.IOSConfig.XcodeUtils.getPbxproj(projectRoot);
|
|
621
690
|
const projectName = _path.default.basename(iosOutputPath);
|
|
691
|
+
const groupName = _path.default.parse(xcodeProjectPath).name;
|
|
622
692
|
Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
|
|
623
|
-
filepath: _path.default.join(projectName, "BootSplash.storyboard"),
|
|
624
|
-
groupName: _path.default.parse(xcodeProjectPath).name,
|
|
625
693
|
project,
|
|
694
|
+
filepath: _path.default.join(projectName, "BootSplash.storyboard"),
|
|
695
|
+
groupName,
|
|
626
696
|
isBuildFile: true
|
|
627
697
|
});
|
|
628
698
|
Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
|
|
629
|
-
filepath: _path.default.join(projectName, "Colors.xcassets"),
|
|
630
|
-
groupName: _path.default.parse(xcodeProjectPath).name,
|
|
631
699
|
project,
|
|
700
|
+
filepath: _path.default.join(projectName, "Colors.xcassets"),
|
|
701
|
+
groupName,
|
|
632
702
|
isBuildFile: true
|
|
633
703
|
});
|
|
634
704
|
hfs.write(pbxprojectPath, project.writeSync());
|
|
@@ -637,14 +707,11 @@ const generate = async ({
|
|
|
637
707
|
}
|
|
638
708
|
if (htmlTemplatePath != null) {
|
|
639
709
|
log.title("🌐", "Web");
|
|
640
|
-
const
|
|
641
|
-
root,
|
|
642
|
-
formatOptions
|
|
643
|
-
} = readHtml(htmlTemplatePath);
|
|
710
|
+
const htmlTemplate = readXmlLike(htmlTemplatePath);
|
|
644
711
|
const {
|
|
645
712
|
format
|
|
646
713
|
} = await logo.metadata();
|
|
647
|
-
const prevStyle = root.querySelector("#bootsplash-style");
|
|
714
|
+
const prevStyle = htmlTemplate.root.querySelector("#bootsplash-style");
|
|
648
715
|
const base64 = (format === "svg" ? hfs.buffer(logoPath) : await logo.clone().resize(Math.round(logoWidth * 2)).png({
|
|
649
716
|
quality: 100
|
|
650
717
|
}).toBuffer()).toString("base64");
|
|
@@ -673,9 +740,9 @@ const generate = async ({
|
|
|
673
740
|
if (prevStyle != null) {
|
|
674
741
|
prevStyle.replaceWith(nextStyle);
|
|
675
742
|
} else {
|
|
676
|
-
root.querySelector("head")?.appendChild(nextStyle);
|
|
743
|
+
htmlTemplate.root.querySelector("head")?.appendChild(nextStyle);
|
|
677
744
|
}
|
|
678
|
-
const prevDiv = root.querySelector("#bootsplash");
|
|
745
|
+
const prevDiv = htmlTemplate.root.querySelector("#bootsplash");
|
|
679
746
|
const nextDiv = (0, _nodeHtmlParser.parse)((0, _tsDedent.dedent)`
|
|
680
747
|
<div id="bootsplash">
|
|
681
748
|
<div id="bootsplash-logo"></div>
|
|
@@ -684,9 +751,13 @@ const generate = async ({
|
|
|
684
751
|
if (prevDiv != null) {
|
|
685
752
|
prevDiv.replaceWith(nextDiv);
|
|
686
753
|
} else {
|
|
687
|
-
root.querySelector("body")?.appendChild(nextDiv);
|
|
754
|
+
htmlTemplate.root.querySelector("body")?.appendChild(nextDiv);
|
|
688
755
|
}
|
|
689
|
-
await
|
|
756
|
+
await writeXmlLike(htmlTemplatePath, htmlTemplate.root.toString(), {
|
|
757
|
+
...htmlTemplate.formatOptions,
|
|
758
|
+
formatter: "prettier",
|
|
759
|
+
useCssPlugin: true
|
|
760
|
+
});
|
|
690
761
|
}
|
|
691
762
|
log.title("📄", "Assets");
|
|
692
763
|
hfs.ensureDir(assetsOutputPath);
|
|
@@ -764,233 +835,4 @@ ${_picocolors.default.blue("┗━━━━━━━━━━━━━━━━
|
|
|
764
835
|
console.log(`\n💖 Thanks for using ${_picocolors.default.underline("react-native-bootsplash")}`);
|
|
765
836
|
};
|
|
766
837
|
exports.generate = generate;
|
|
767
|
-
const withAndroidAssets = (config, props) => Expo.withDangerousMod(config, ["android", config => {
|
|
768
|
-
const {
|
|
769
|
-
assetsDir = "assets/bootsplash"
|
|
770
|
-
} = props;
|
|
771
|
-
const {
|
|
772
|
-
platformProjectRoot
|
|
773
|
-
} = config.modRequest;
|
|
774
|
-
const srcDir = _path.default.resolve(workingPath, assetsDir, "android");
|
|
775
|
-
const destDir = _path.default.resolve(platformProjectRoot, "app", "src", "main", "res");
|
|
776
|
-
for (const drawableDir of hfs.readDir(srcDir)) {
|
|
777
|
-
const srcDrawableDir = _path.default.join(srcDir, drawableDir);
|
|
778
|
-
const destDrawableDir = _path.default.join(destDir, drawableDir);
|
|
779
|
-
hfs.ensureDir(destDrawableDir);
|
|
780
|
-
for (const file of hfs.readDir(srcDrawableDir)) {
|
|
781
|
-
hfs.copy(_path.default.join(srcDrawableDir, file), _path.default.join(destDrawableDir, file));
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
return config;
|
|
785
|
-
}]);
|
|
786
|
-
const withAndroidManifest = config => Expo.withAndroidManifest(config, config => {
|
|
787
|
-
config.modResults.manifest.application?.forEach(application => {
|
|
788
|
-
if (application.$["android:name"] === ".MainApplication") {
|
|
789
|
-
const {
|
|
790
|
-
activity
|
|
791
|
-
} = application;
|
|
792
|
-
activity?.forEach(activity => {
|
|
793
|
-
if (activity.$["android:name"] === ".MainActivity") {
|
|
794
|
-
activity.$["android:theme"] = "@style/BootTheme";
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
return config;
|
|
800
|
-
});
|
|
801
|
-
const withMainActivity = config => Expo.withMainActivity(config, config => {
|
|
802
|
-
const {
|
|
803
|
-
modResults
|
|
804
|
-
} = config;
|
|
805
|
-
const {
|
|
806
|
-
language
|
|
807
|
-
} = modResults;
|
|
808
|
-
const withImports = (0, _codeMod.addImports)(modResults.contents.replace(/(\/\/ )?setTheme\(R\.style\.AppTheme\)/, "// setTheme(R.style.AppTheme)"), ["android.os.Bundle", "com.zoontek.rnbootsplash.RNBootSplash"], language === "java");
|
|
809
|
-
|
|
810
|
-
// indented with 4 spaces
|
|
811
|
-
const withInit = (0, _generateCode.mergeContents)({
|
|
812
|
-
src: withImports,
|
|
813
|
-
comment: " //",
|
|
814
|
-
tag: "bootsplash-init",
|
|
815
|
-
offset: 0,
|
|
816
|
-
anchor: /super\.onCreate\(null\)/,
|
|
817
|
-
newSrc: " RNBootSplash.init(this, R.style.BootTheme)" + (language === "java" ? ";" : "")
|
|
818
|
-
});
|
|
819
|
-
return {
|
|
820
|
-
...config,
|
|
821
|
-
modResults: {
|
|
822
|
-
...modResults,
|
|
823
|
-
contents: withInit.contents
|
|
824
|
-
}
|
|
825
|
-
};
|
|
826
|
-
});
|
|
827
|
-
const withAndroidStyles = (config, props) => Expo.withAndroidStyles(config, async config => {
|
|
828
|
-
const {
|
|
829
|
-
assetsDir = "assets/bootsplash",
|
|
830
|
-
edgeToEdge = false
|
|
831
|
-
} = props;
|
|
832
|
-
const manifest = await hfs.json(_path.default.resolve(workingPath, assetsDir, "manifest.json"));
|
|
833
|
-
const item = [{
|
|
834
|
-
$: {
|
|
835
|
-
name: "postBootSplashTheme"
|
|
836
|
-
},
|
|
837
|
-
_: "@style/AppTheme"
|
|
838
|
-
}, {
|
|
839
|
-
$: {
|
|
840
|
-
name: "bootSplashBackground"
|
|
841
|
-
},
|
|
842
|
-
_: "@color/bootsplash_background"
|
|
843
|
-
}, {
|
|
844
|
-
$: {
|
|
845
|
-
name: "bootSplashLogo"
|
|
846
|
-
},
|
|
847
|
-
_: "@drawable/bootsplash_logo"
|
|
848
|
-
}];
|
|
849
|
-
if (manifest.brand != null) {
|
|
850
|
-
item.push({
|
|
851
|
-
$: {
|
|
852
|
-
name: "bootSplashBrand"
|
|
853
|
-
},
|
|
854
|
-
_: "@drawable/bootsplash_brand"
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
config.modResults.resources.style?.filter(({
|
|
858
|
-
$
|
|
859
|
-
}) => $.name !== "BootTheme").push({
|
|
860
|
-
item,
|
|
861
|
-
$: {
|
|
862
|
-
name: "BootTheme",
|
|
863
|
-
parent: edgeToEdge ? "Theme.BootSplash" : "Theme.BootSplash.EdgeToEdge"
|
|
864
|
-
}
|
|
865
|
-
});
|
|
866
|
-
return config;
|
|
867
|
-
});
|
|
868
|
-
const withAndroidColors = (config, props) => Expo.withAndroidColors(config, async config => {
|
|
869
|
-
const {
|
|
870
|
-
assetsDir = "assets/bootsplash"
|
|
871
|
-
} = props;
|
|
872
|
-
const manifest = await hfs.json(_path.default.resolve(workingPath, assetsDir, "manifest.json"));
|
|
873
|
-
config.modResults = (0, _Colors.assignColorValue)(config.modResults, {
|
|
874
|
-
name: "bootsplash_background",
|
|
875
|
-
value: manifest.background
|
|
876
|
-
});
|
|
877
|
-
return config;
|
|
878
|
-
});
|
|
879
|
-
const withAndroidColorsNight = (config, props) => Expo.withAndroidColorsNight(config, async config => {
|
|
880
|
-
const {
|
|
881
|
-
assetsDir = "assets/bootsplash"
|
|
882
|
-
} = props;
|
|
883
|
-
const manifest = await hfs.json(_path.default.resolve(workingPath, assetsDir, "manifest.json"));
|
|
884
|
-
if (manifest.darkBackground != null) {
|
|
885
|
-
config.modResults = (0, _Colors.assignColorValue)(config.modResults, {
|
|
886
|
-
name: "bootsplash_background",
|
|
887
|
-
value: manifest.darkBackground
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
return config;
|
|
891
|
-
});
|
|
892
|
-
const withIOSAssets = (config, props) => Expo.withDangerousMod(config, ["ios", config => {
|
|
893
|
-
const {
|
|
894
|
-
assetsDir = "assets/bootsplash"
|
|
895
|
-
} = props;
|
|
896
|
-
const {
|
|
897
|
-
platformProjectRoot,
|
|
898
|
-
projectName = ""
|
|
899
|
-
} = config.modRequest;
|
|
900
|
-
const srcDir = _path.default.resolve(workingPath, assetsDir, "ios");
|
|
901
|
-
const destDir = _path.default.resolve(platformProjectRoot, projectName);
|
|
902
|
-
cleanIOS(destDir);
|
|
903
|
-
hfs.copy(_path.default.join(srcDir, "BootSplash.storyboard"), _path.default.join(destDir, "BootSplash.storyboard"));
|
|
904
|
-
for (const xcassetsDir of ["Colors.xcassets", "Images.xcassets"]) {
|
|
905
|
-
const srcXcassetsDir = _path.default.join(srcDir, xcassetsDir);
|
|
906
|
-
const destXcassetsDir = _path.default.join(destDir, xcassetsDir);
|
|
907
|
-
hfs.ensureDir(destXcassetsDir);
|
|
908
|
-
for (const file of hfs.readDir(srcXcassetsDir)) {
|
|
909
|
-
hfs.copy(_path.default.join(srcXcassetsDir, file), _path.default.join(destXcassetsDir, file));
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
return config;
|
|
913
|
-
}]);
|
|
914
|
-
const withAppDelegate = config => Expo.withAppDelegate(config, config => {
|
|
915
|
-
const [sdkStringVersion = ""] = config.sdkVersion?.split(".") ?? "";
|
|
916
|
-
const isAtLeastExpo51 = Number.parseInt(sdkStringVersion, 10) >= 51;
|
|
917
|
-
const {
|
|
918
|
-
modResults
|
|
919
|
-
} = config;
|
|
920
|
-
const {
|
|
921
|
-
language
|
|
922
|
-
} = modResults;
|
|
923
|
-
if (language !== "objc" && language !== "objcpp") {
|
|
924
|
-
throw new Error(`Cannot modify the project AppDelegate as it's not in a supported language: ${language}`);
|
|
925
|
-
}
|
|
926
|
-
const withHeader = (0, _generateCode.mergeContents)({
|
|
927
|
-
src: modResults.contents,
|
|
928
|
-
comment: "//",
|
|
929
|
-
tag: "bootsplash-header",
|
|
930
|
-
offset: 1,
|
|
931
|
-
anchor: /#import "AppDelegate\.h"/,
|
|
932
|
-
newSrc: '#import "RNBootSplash.h"'
|
|
933
|
-
});
|
|
934
|
-
const withRootView = (0, _generateCode.mergeContents)({
|
|
935
|
-
src: withHeader.contents,
|
|
936
|
-
comment: "//",
|
|
937
|
-
tag: "bootsplash-init",
|
|
938
|
-
offset: 0,
|
|
939
|
-
anchor: /@end/,
|
|
940
|
-
newSrc: isAtLeastExpo51 ? (0, _tsDedent.dedent)`
|
|
941
|
-
- (void)customizeRootView:(RCTRootView *)rootView {
|
|
942
|
-
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView];
|
|
943
|
-
}
|
|
944
|
-
` : (0, _tsDedent.dedent)`
|
|
945
|
-
- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initProps:(NSDictionary *)initProps {
|
|
946
|
-
UIView *rootView = [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps];
|
|
947
|
-
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView];
|
|
948
|
-
return rootView;
|
|
949
|
-
}
|
|
950
|
-
`
|
|
951
|
-
});
|
|
952
|
-
return {
|
|
953
|
-
...config,
|
|
954
|
-
modResults: {
|
|
955
|
-
...modResults,
|
|
956
|
-
contents: withRootView.contents
|
|
957
|
-
}
|
|
958
|
-
};
|
|
959
|
-
});
|
|
960
|
-
const withInfoPlist = config => Expo.withInfoPlist(config, config => {
|
|
961
|
-
config.modResults["UILaunchStoryboardName"] = "BootSplash";
|
|
962
|
-
return config;
|
|
963
|
-
});
|
|
964
|
-
const withXcodeProject = config => Expo.withXcodeProject(config, config => {
|
|
965
|
-
const {
|
|
966
|
-
projectName = ""
|
|
967
|
-
} = config.modRequest;
|
|
968
|
-
Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
|
|
969
|
-
filepath: _path.default.join(projectName, "BootSplash.storyboard"),
|
|
970
|
-
groupName: projectName,
|
|
971
|
-
project: config.modResults,
|
|
972
|
-
isBuildFile: true
|
|
973
|
-
});
|
|
974
|
-
Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
|
|
975
|
-
filepath: _path.default.join(projectName, "Colors.xcassets"),
|
|
976
|
-
groupName: projectName,
|
|
977
|
-
project: config.modResults,
|
|
978
|
-
isBuildFile: true
|
|
979
|
-
});
|
|
980
|
-
return config;
|
|
981
|
-
});
|
|
982
|
-
const withGenerate = (config, props = {}) => {
|
|
983
|
-
const plugins = [];
|
|
984
|
-
const {
|
|
985
|
-
platforms = []
|
|
986
|
-
} = config;
|
|
987
|
-
if (platforms.includes("android")) {
|
|
988
|
-
plugins.push(withAndroidAssets, withAndroidManifest, withMainActivity, withAndroidStyles, withAndroidColors, withAndroidColorsNight);
|
|
989
|
-
}
|
|
990
|
-
if (platforms.includes("ios")) {
|
|
991
|
-
plugins.push(withIOSAssets, withAppDelegate, withInfoPlist, withXcodeProject);
|
|
992
|
-
}
|
|
993
|
-
return Expo.withPlugins(config, plugins.map(plugin => [plugin, props]));
|
|
994
|
-
};
|
|
995
|
-
exports.withGenerate = withGenerate;
|
|
996
838
|
//# sourceMappingURL=generate.js.map
|