Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[configure-splash-screen] Refactor and integrate with @expo/config #2297

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
86fddc0
[configure-splash-screen] feat: move utils from ./helpers to ./utils
bbarthec Jun 22, 2020
0172fa0
[configure-splash-screen] fix: make one pbxproj propoerty opional
bbarthec Jun 22, 2020
7ba4a37
[configure-splash-screen] feat: clean-up js constants
bbarthec Jun 22, 2020
987a354
[configure-splash-screen] feat: create types.ts with SplashScreenConf…
bbarthec Jun 22, 2020
75f35f1
[configure-splash-screen] feat: create Validator for ConfigJson
bbarthec Jun 22, 2020
ba09414
[configure-splash-screen] feat: create external API
bbarthec Jun 22, 2020
aa090b5
[configure-splash-screen] feat: update CLI command and package.json w…
bbarthec Jun 22, 2020
bd8474e
[configure-splash-screen] feat: update and write missing tests
bbarthec Jun 22, 2020
3e15875
[config] feat: add configure-splash-screen and remove warning
bbarthec Jun 22, 2020
4ba291f
[config] fix: rebase with master
bbarthec Jun 22, 2020
755420d
[configure-splash-screen] Simplify config validator & adjust PR sugge…
bbarthec Sep 4, 2020
8481c9c
[configure-splash-screen] Rename imagePath into image in internally &…
bbarthec Sep 4, 2020
cc77d1c
[configure-splash-screen] Remove TODO comment, because it's already done
bbarthec Sep 4, 2020
560d054
Merge branch 'master' into @bbarthec/configure-splash-screen-integrat…
EvanBacon Sep 10, 2020
8abf170
Merge branch 'master' into @bbarthec/configure-splash-screen-integrat…
EvanBacon Sep 10, 2020
d8f539a
Merge branch 'master' into @bbarthec/configure-splash-screen-integrat…
EvanBacon Sep 16, 2020
2b63608
[splash-screen] Fix config not being applied
bbarthec Sep 17, 2020
c94dcb5
Merge branch 'master' into @bbarthec/configure-splash-screen-integrat…
brentvatne Sep 18, 2020
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[configure-splash-screen] feat: update CLI command and package.json w…
…ith new bin and main entries
  • Loading branch information
bbarthec committed Sep 4, 2020
commit aa090b537b39c3d4b80ffb772bfa54afb920f8d8
9 changes: 6 additions & 3 deletions packages/configure-splash-screen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "0.1.14",
"description": "Supplementary module for 'expo-splash-screen' providing cli configuration command",
"bin": {
"configure-splash-screen": "./build/configure.js",
"expo-splash-screen": "./build/configure.js"
"configure-splash-screen": "./build/index-cli.js",
"expo-splash-screen": "./build/index-cli.js"
},
"main": "./build/index.js",
"scripts": {
"start": "yarn run prepare",
"build": "tsc",
Expand Down Expand Up @@ -44,6 +45,7 @@
"core-js": "^3.6.5",
"deep-equal": "^2.0.3",
"fs-extra": "^9.0.0",
"lodash": "^4.17.15",
"pngjs": "^5.0.0",
"xcode": "^3.0.0",
"xml-js": "^1.6.11"
Expand All @@ -57,7 +59,8 @@
"@types/color-string": "^1.5.0",
"@types/deep-equal": "^1.0.1",
"@types/fs-extra": "^9.0.1",
"@types/jest": "^26.0.8",
"@types/jest": "^25.2.2",
"@types/lodash": "^4.14.155",
"babel-jest": "^26.2.2",
"eslint": "^6.8.0",
"jest": "^26.2.2",
Expand Down
196 changes: 196 additions & 0 deletions packages/configure-splash-screen/src/cli-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import { Command } from 'commander';
import path from 'path';

import configureAndroid from './android';
import configureIos from './ios';
import {
SplashScreenImageResizeMode,
SplashScreenStatusBarStyle,
Platform,
PlatformType,
} from './constants';
import { AndroidSplashScreenJsonConfig, IosSplashScreenJsonConfig } from './types';
import { validateEnumValue } from './validators';

const AVAILABLE_OPTIONS_NAMES = [
'imageResizeMode',
'platform',
'backgroundColor',
'imagePath',
'darkModeBackgroundColor',
'darkModeImagePath',
'statusBarHidden',
'statusBarStyle',
'darkModeStatusBarStyle',
'statusBarTranslucent',
'statusBarBackgroundColor',
'darkModeStatusBarBackgroundColor',
] as const;

type CLIOptionName = typeof AVAILABLE_OPTIONS_NAMES[number];
Comment on lines +14 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this sophisticated const AVAILABLE_OPTIONS_NAMES and then this typeof instead of a simple enum or a union type?


type CLIOptions = Partial<Record<CLIOptionName, string>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't type of statusBarTranslucent be boolean?


interface Configuration {
platform: PlatformType;
android: AndroidSplashScreenJsonConfig;
ios: IosSplashScreenJsonConfig;
}

async function action(configuration: Configuration) {
const { platform, android, ios } = configuration;
const rootDir = path.resolve();
bbarthec marked this conversation as resolved.
Show resolved Hide resolved
switch (platform) {
case Platform.ANDROID:
await configureAndroid(rootDir, android);
break;
case Platform.IOS:
await configureIos(rootDir, ios);
break;
case Platform.ALL:
default:
await configureAndroid(rootDir, android);
await configureIos(rootDir, ios);
break;
}
}

function configurationFromOptions({
platform,
imageResizeMode,
backgroundColor,
imagePath,
statusBarHidden,
statusBarStyle,
statusBarTranslucent,
statusBarBackgroundColor,
darkModeBackgroundColor,
darkModeImagePath,
darkModeStatusBarStyle,
darkModeStatusBarBackgroundColor,
}: CLIOptions): Configuration {
let resolvedPlatform: PlatformType = Platform.ALL;
try {
resolvedPlatform = (platform && validateEnumValue(platform, Platform)) || Platform.ALL;
} catch (e) {
throw new Error(`'platform': ${e.message}`);
}

if (!backgroundColor) {
throw new Error(
`'backgroundColor': Required option is not provided. Provide a valid color string.`
);
}
Comment on lines +78 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think recent releases of commander.js allow usage of requiredOption if that's something we may want to look into

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it does, but I couldn't get this option covered by tests then 😞 Commander.js simply kills the process with exit code 1 once the option is not provided. Maybe it does not need to be tested then? 🤔 Dunno 🤷


const resolvedStatusBarHidden =
statusBarHidden === undefined ? undefined : Boolean(statusBarHidden);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing undefined in a variable called resolved seems icky to me. Is there a specific reason for passing undefined down? Does it say "do not modify anything related to this setting"?

Actually while writing this comment I had deja vu, so if we already talked about this then sorry

const resolvedStatusBarTranslucent =
statusBarTranslucent === undefined ? undefined : Boolean(statusBarTranslucent);

const genericConfig = {
imageResizeMode,
backgroundColor,
imagePath,
};
const genericStatusBarConfig = {
hidden: resolvedStatusBarHidden,
style: statusBarStyle,
};
const genericDarkModeConfig = {
backgroundColor: darkModeBackgroundColor,
imagePath: darkModeImagePath,
};

const result: Configuration = {
platform: resolvedPlatform,
android: {
...genericConfig,
statusBar: {
...genericStatusBarConfig,
translucent: resolvedStatusBarTranslucent,
backgroundColor: statusBarBackgroundColor,
},
darkMode: {
...genericDarkModeConfig,
statusBar: {
style: darkModeStatusBarStyle,
backgroundColor: darkModeStatusBarBackgroundColor,
},
},
},
ios: {
...genericConfig,
statusBar: genericStatusBarConfig,
darkMode: genericDarkModeConfig,
},
};

return result;
}

function getAvailableOptions(o: object) {
return Object.values(o)
.map(v => `"${v}"`)
.join(' | ');
}

export default () =>
new Command()
.description(
'Idempotent operation that configures native splash screens using provided backgroundColor and optional .png file. Supports light and dark modes configuration. Dark mode is supported only on iOS 13+ and Android 10+.'
bbarthec marked this conversation as resolved.
Show resolved Hide resolved
)
.allowUnknownOption(false)
.passCommandToAction(false)
.option(
'-p, --platform <platform>',
`Selected platform to configure. Available values: ${getAvailableOptions(Platform)}.`
)
.option(
'-b, --background-color <color>',
`Valid css-formatted color (hex (#RRGGBB[AA]), rgb[a], hsl[a], named color (https://drafts.csswg.org/css-color/#named-colors)) that would be used as the background color for native splash screen view.`
)
.option(
'-i, --image-path <path>',
'Path to valid .png image that will be displayed in native splash screen.'
)
.option(
'-r, --image-resize-mode <resizeMode>',
`ResizeMode to be used for native splash screen image. Available values: ${getAvailableOptions(
SplashScreenImageResizeMode
)} (only available for android platform)).`
)
.option(
'--dark-mode-background-color <color>',
`Color (see 'background-color' supported formats) that would be used as the background color for native splash screen in dark mode.`
)
.option(
'--dark-mode-image-path <path>',
'Path to valid .png image that will be displayed in native splash screen in dark mode only.'
)
.option(
'--status-bar-style <style>',
`Customizes the color of the StatusBar icons. Available values: ${getAvailableOptions(
SplashScreenStatusBarStyle
)}.`
)
.option('--status-bar-hidden', `Hides the StatusBar.`)
.option(
'--status-bar-background-color <color>',
`(only for Android platform) Customizes the background color of the StatusBar. Accepts a valid color (see 'background-color' supported formats).`
)
.option(
'--status-bar-translucent',
`(only for Android platform) Makes the StatusBar translucent (enables drawing under the StatusBar area).`
)
.option(
'--dark-mode-status-bar-style <style>',
`(only for Android platform) The very same as 'statusbar-style' option, but applied only in dark mode. Available only if 'statusbar-style' is provided.`
)
.option(
'--dark-mode-status-bar-background-color <color>',
`(only for Android platform) The very same as 'status-bar-background-color', but applied only in the dark mode. Available only if 'statusbar-style' is provided.`
)
.action(async (options: CLIOptions) => {
const configuration = configurationFromOptions(options);
await action(configuration);
});
Loading