Skip to content

Commit a6dda7b

Browse files
committed
Add react-native-bootsplash generate command
1 parent 0512c0d commit a6dda7b

9 files changed

+193
-41
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
ignorePatterns: [
66
"app.plugin.js",
77
".eslintrc.js",
8+
"cli.js",
89
"react-native.config.js",
910
"dist",
1011
"example",

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ _⚠️  Don't forget going into the `ios` directory to execute a `pod install
3737
In order to speed up the setup, we provide a **CLI** to generate assets, create the Android Drawable XML file and the iOS Storyboard file automatically ✨.
3838

3939
```bash
40-
$ npx react-native generate-bootsplash --help
40+
$ npx react-native-bootsplash generate --help
4141
# --- or ---
42-
$ yarn react-native generate-bootsplash --help
42+
$ yarn react-native-bootsplash generate --help
4343
```
4444

4545
The command can take multiple arguments:
4646

4747
```bash
48-
Usage: react-native generate-bootsplash [options] <logo>
48+
Usage: react-native-bootsplash generate [options] <logo>
4949

5050
Generate a launch screen using a logo file path (PNG or SVG)
5151

@@ -82,7 +82,7 @@ _📍 This license key grants unlimited and unrestricted usage of the generator
8282

8383
```bash
8484
# Without license key
85-
yarn react-native generate-bootsplash svgs/light-logo.svg \
85+
yarn react-native-bootsplash generate svgs/light-logo.svg \
8686
--platforms=android,ios,web \
8787
--background=F5FCFF \
8888
--logo-width=100 \
@@ -91,7 +91,7 @@ yarn react-native generate-bootsplash svgs/light-logo.svg \
9191
--html=public/index.html
9292

9393
# With license key 🔑
94-
yarn react-native generate-bootsplash svgs/light-logo.svg \
94+
yarn react-native-bootsplash generate svgs/light-logo.svg \
9595
--platforms=android,ios,web \
9696
--background=F5FCFF \
9797
--logo-width=100 \

cli.js

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env node
2+
3+
const { Command } = require("commander");
4+
5+
const program = new Command();
6+
const pkg = require("./package.json");
7+
8+
const validProjectTypes = ["detect", "bare", "expo"];
9+
const validPlatforms = ["android", "ios", "web"];
10+
11+
program
12+
.name(pkg.name)
13+
.description(pkg.description)
14+
.version(pkg.version)
15+
.command("generate", { isDefault: true })
16+
.description("Generate a launch screen using a logo file path (PNG or SVG)")
17+
.argument("<logo>", "Logo file path (PNG or SVG)")
18+
.option(
19+
"--project-type <string>",
20+
'Project type ("detect", "bare" or "expo")',
21+
"detect",
22+
)
23+
.option(
24+
"--platforms <list>",
25+
"Platforms to generate for, separated by a comma",
26+
validPlatforms.join(","),
27+
)
28+
.option(
29+
"--background <string>",
30+
"Background color (in hexadecimal format)",
31+
"#fff",
32+
)
33+
.option(
34+
"--logo-width <number>",
35+
"Logo width at @1x (in dp - we recommend approximately ~100)",
36+
100,
37+
)
38+
.option(
39+
"--assets-output <string>",
40+
"Assets output directory path",
41+
"assets/bootsplash",
42+
)
43+
.option(
44+
"--flavor <string>",
45+
"Android flavor build variant (where your resource directory is)",
46+
"main",
47+
)
48+
.option(
49+
"--html <string>",
50+
"HTML template file path (your web app entry point)",
51+
"public/index.html",
52+
)
53+
.option(
54+
"--license-key <string>",
55+
"License key to enable brand and dark mode assets generation",
56+
)
57+
.option("--brand <string>", "Brand file path (PNG or SVG)")
58+
.option(
59+
"--brand-width <number>",
60+
"Brand width at @1x (in dp - we recommend approximately ~80)",
61+
80,
62+
)
63+
.option(
64+
"--dark-background <string>",
65+
"[dark mode] Background color (in hexadecimal format)",
66+
)
67+
.option("--dark-logo <string>", "[dark mode] Logo file path (PNG or SVG)")
68+
.option("--dark-brand <string>", "[dark mode] Brand file path (PNG or SVG)")
69+
.action((logo, options) => {
70+
const { projectType, platforms, logoWidth, brandWidth, ...rest } = options;
71+
72+
const args = {
73+
...rest,
74+
75+
projectType: validProjectTypes.includes(projectType.toLowerCase())
76+
? projectType.toLowerCase()
77+
: "detect",
78+
79+
platforms: [
80+
...new Set(
81+
platforms
82+
.toLowerCase()
83+
.split(/[ ,;|]/)
84+
.map((platform) => platform.trim())
85+
.filter((item) => validPlatforms.includes(item)),
86+
),
87+
],
88+
89+
logoWidth: Number.parseInt(logoWidth, 10),
90+
brandWidth: Number.parseInt(brandWidth, 10),
91+
};
92+
93+
const { generate } = require("./dist/commonjs/generate");
94+
95+
generate({ logo, ...args }).catch((error) => {
96+
console.error(error);
97+
process.exit(1);
98+
});
99+
});
100+
101+
program.parse(process.argv);

example/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ PODS:
15091509
- React-logger (= 0.76.1)
15101510
- React-perflogger (= 0.76.1)
15111511
- React-utils (= 0.76.1)
1512-
- RNBootSplash (6.2.6):
1512+
- RNBootSplash (6.3.0):
15131513
- DoubleConversion
15141514
- glog
15151515
- hermes-engine
@@ -1799,7 +1799,7 @@ SPEC CHECKSUMS:
17991799
React-utils: 0c825829a8e2ca39bb049d95f270a2dbf39ecb05
18001800
ReactCodegen: 3b0ff1c9015e3ebcf2bd2f8559995c74bfacf8a1
18011801
ReactCommon: c21a3d6a8d3e98b6e99730139a52f59f0beea89d
1802-
RNBootSplash: fadbf027011dbd9e5b8b9989800de20dc3d1a068
1802+
RNBootSplash: de964357c89eacce30bc5f26bc663eb34567b894
18031803
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
18041804
Yoga: db69236006b8b1c6d55ab453390c882306cbf219
18051805

example/yarn.lock

+22-2
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,26 @@
13531353
execa "^5.0.0"
13541354
fast-glob "^3.3.2"
13551355

1356+
"@react-native-community/cli-config-android@^15.0.0":
1357+
version "15.1.2"
1358+
resolved "https://registry.yarnpkg.com/@react-native-community/cli-config-android/-/cli-config-android-15.1.2.tgz#623d8d4a6693ed9c28e0d6fa41372466ebc32a7a"
1359+
integrity sha512-A6YQPl+0pTG0vuTcYLHJODkLy8qgZ2YIfy5XiZEAyxAbkSFbyOf7XR7hzjTw6S0BUJzF+eizHeAsKQ2b1bO75A==
1360+
dependencies:
1361+
"@react-native-community/cli-tools" "15.1.2"
1362+
chalk "^4.1.2"
1363+
fast-glob "^3.3.2"
1364+
fast-xml-parser "^4.4.1"
1365+
1366+
"@react-native-community/cli-config-apple@^15.0.0":
1367+
version "15.1.2"
1368+
resolved "https://registry.yarnpkg.com/@react-native-community/cli-config-apple/-/cli-config-apple-15.1.2.tgz#2a9f245f6f158eff60495f9e3cce698b35adb4ea"
1369+
integrity sha512-BoCLHAFyPwYV9GcbXd9tzrmjJbuRFhuMQ808+gR9exGqVhcK16z60V71z44I5tvOcwvnOtu5fmiVMC5FvcxyNA==
1370+
dependencies:
1371+
"@react-native-community/cli-tools" "15.1.2"
1372+
chalk "^4.1.2"
1373+
execa "^5.0.0"
1374+
fast-glob "^3.3.2"
1375+
13561376
"@react-native-community/[email protected]":
13571377
version "15.0.0"
13581378
resolved "https://registry.yarnpkg.com/@react-native-community/cli-config/-/cli-config-15.0.0.tgz#c49b1f6b0cc374175a827467bbaf3cee9e9f4ceb"
@@ -1457,7 +1477,7 @@
14571477
shell-quote "^1.7.3"
14581478
sudo-prompt "^9.0.0"
14591479

1460-
"@react-native-community/cli-tools@^15.0.0":
1480+
"@react-native-community/cli-tools@15.1.2", "@react-native-community/cli-tools@^15.0.0":
14611481
version "15.1.2"
14621482
resolved "https://registry.yarnpkg.com/@react-native-community/cli-tools/-/cli-tools-15.1.2.tgz#31e0456171f161870f725fd13f9e9ac79f58d344"
14631483
integrity sha512-eShBHf/K1e2xJTumiy7CF/akh0DiKfW3YSJ/jpp0RVBgwaXPK6JMrVdGRdbSVad6VqaXVFVtPOe3gSDRa5GDKg==
@@ -2852,7 +2872,7 @@ commander@^10.0.1:
28522872
resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06"
28532873
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==
28542874

2855-
commander@^12.0.0:
2875+
commander@^12.0.0, commander@^12.1.0:
28562876
version "12.1.0"
28572877
resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3"
28582878
integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-bootsplash",
3-
"version": "6.2.6",
3+
"version": "6.3.0",
44
"license": "MIT",
55
"description": "Display a bootsplash on your app starts. Hide it when you want.",
66
"author": "Mathieu Acthernoene <[email protected]>",
@@ -20,8 +20,12 @@
2020
"!src/addon",
2121
"RNBootSplash.podspec",
2222
"app.plugin.js",
23+
"cli.js",
2324
"react-native.config.js"
2425
],
26+
"bin": {
27+
"react-native-bootsplash": "./cli.js"
28+
},
2529
"repository": {
2630
"type": "git",
2731
"url": "https://github.com/zoontek/react-native-bootsplash.git"
@@ -66,7 +70,10 @@
6670
},
6771
"dependencies": {
6872
"@expo/config-plugins": "^8.0.4",
73+
"@react-native-community/cli-config-android": "^15.0.0",
74+
"@react-native-community/cli-config-apple": "^15.0.0",
6975
"@react-native-community/cli-tools": "^15.0.0",
76+
"commander": "^12.1.0",
7077
"detect-indent": "^6.1.0",
7178
"fs-extra": "^11.2.0",
7279
"node-html-parser": "^6.1.13",

react-native.config.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const platforms = ["android", "ios", "web"];
2-
const projectTypes = ["detect", "bare", "expo"];
1+
const validProjectTypes = ["detect", "bare", "expo"];
2+
const validPlatforms = ["android", "ios", "web"];
33

44
/** @type {import("@react-native-community/cli-types").Command} */
55
const generateBootSplash = {
@@ -10,22 +10,22 @@ const generateBootSplash = {
1010
name: "--project-type <string>",
1111
description: 'Project type ("detect", "bare" or "expo")',
1212
default: "detect",
13-
parse: (value) => {
14-
const type = value.toLowerCase();
15-
return projectTypes.includes(type) ? type : "detect";
16-
},
13+
parse: (projectType) =>
14+
validProjectTypes.includes(projectType.toLowerCase())
15+
? projectType.toLowerCase()
16+
: "detect",
1717
},
1818
{
1919
name: "--platforms <list>",
2020
description: "Platforms to generate for, separated by a comma",
21-
default: platforms.join(","),
22-
parse: (value) => [
21+
default: validPlatforms.join(","),
22+
parse: (platforms) => [
2323
...new Set(
24-
value
24+
platforms
2525
.toLowerCase()
2626
.split(/[ ,;|]/)
2727
.map((platform) => platform.trim())
28-
.filter((item) => platforms.includes(item)),
28+
.filter((item) => validPlatforms.includes(item)),
2929
),
3030
],
3131
},
@@ -39,7 +39,7 @@ const generateBootSplash = {
3939
description:
4040
"Logo width at @1x (in dp - we recommend approximately ~100)",
4141
default: 100,
42-
parse: (value) => Number.parseInt(value, 10),
42+
parse: (logoWidth) => Number.parseInt(logoWidth, 10),
4343
},
4444
{
4545
name: "--assets-output <string>",
@@ -71,7 +71,7 @@ const generateBootSplash = {
7171
description:
7272
"Brand width at @1x (in dp - we recommend approximately ~80)",
7373
default: 80,
74-
parse: (value) => Number.parseInt(value, 10),
74+
parse: (brandWidth) => Number.parseInt(brandWidth, 10),
7575
},
7676
{
7777
name: "--dark-background <string>",
@@ -86,10 +86,10 @@ const generateBootSplash = {
8686
description: "[dark mode] Brand file path (PNG or SVG)",
8787
},
8888
],
89-
func: ([logo], { project: { android, ios } }, args) => {
89+
func: ([logo], _config, args) => {
9090
const { generate } = require("./dist/commonjs/generate");
9191

92-
generate({ android, ios, logo, ...args }).catch((error) => {
92+
generate({ logo, ...args }).catch((error) => {
9393
console.error(error);
9494
process.exit(1);
9595
});

src/generate.ts

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import * as Expo from "@expo/config-plugins";
22
import plist from "@expo/plist";
3+
import { projectConfig as getAndroidProjectConfig } from "@react-native-community/cli-config-android";
4+
import { getProjectConfig as getAppleProjectConfig } from "@react-native-community/cli-config-apple";
35
import { findProjectRoot } from "@react-native-community/cli-tools";
4-
import {
5-
AndroidProjectConfig,
6-
IOSProjectConfig,
7-
} from "@react-native-community/cli-types";
86
import childProcess from "child_process";
97
import crypto from "crypto";
108
import detectIndent from "detect-indent";
@@ -26,6 +24,10 @@ import { Manifest } from ".";
2624
const workingPath = process.env.INIT_CWD ?? process.env.PWD ?? process.cwd();
2725
const projectRoot = findProjectRoot(workingPath);
2826

27+
const getIOSProjectConfig = getAppleProjectConfig({ platformName: "ios" });
28+
const ios = getIOSProjectConfig(projectRoot, {});
29+
const android = getAndroidProjectConfig(projectRoot);
30+
2931
type PackageJson = {
3032
version?: string;
3133
dependencies?: Record<string, string>;
@@ -416,7 +418,6 @@ const ensureSupportedFormat = async (
416418
};
417419

418420
const getAndroidOutputPath = ({
419-
android,
420421
assetsOutputPath,
421422
brandHeight,
422423
brandWidth,
@@ -426,7 +427,6 @@ const getAndroidOutputPath = ({
426427
logoWidth,
427428
platforms,
428429
}: {
429-
android: AndroidProjectConfig | undefined;
430430
assetsOutputPath: string;
431431
brandHeight: number;
432432
brandWidth: number;
@@ -487,12 +487,10 @@ const getAndroidOutputPath = ({
487487
};
488488

489489
const getIOSOutputPath = ({
490-
ios,
491490
assetsOutputPath,
492491
isExpo,
493492
platforms,
494493
}: {
495-
ios: IOSProjectConfig | undefined;
496494
assetsOutputPath: string;
497495
isExpo: boolean;
498496
platforms: Platforms;
@@ -627,18 +625,13 @@ const requireAddon = ():
627625
};
628626

629627
export const generate = async ({
630-
android,
631-
ios,
632628
projectType,
633629
platforms,
634630
html,
635631
flavor,
636632
licenseKey,
637633
...args
638634
}: {
639-
android?: AndroidProjectConfig;
640-
ios?: IOSProjectConfig;
641-
642635
logo: string;
643636
projectType: ProjectType;
644637
platforms: Platforms;
@@ -756,7 +749,6 @@ export const generate = async ({
756749
});
757750

758751
const androidOutputPath = getAndroidOutputPath({
759-
android,
760752
assetsOutputPath,
761753
brandHeight,
762754
brandWidth,
@@ -769,7 +761,6 @@ export const generate = async ({
769761

770762
const iosOutputPath = getIOSOutputPath({
771763
assetsOutputPath,
772-
ios,
773764
isExpo,
774765
platforms,
775766
});

0 commit comments

Comments
 (0)