Skip to content

Commit 8c72382

Browse files
authored
chore: Allow specifying build type on Android (#95)
1 parent cea94c6 commit 8c72382

10 files changed

Lines changed: 40 additions & 25 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# react-native-owl
1+
# react-native-owl
2+
23
[![github][github-image]][github-url] [![npm][npm-image]][npm-url] [![docs][docs-image]][docs-url] [![Maintenance Status][maintenance-image]](#maintenance-status)
34

45
> **Work In Progress**: Visual regression testing for React Native

docs/introduction/config-file.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@ The config file - which unless specified in the cli should live in `./owl.config
88

99
### Options
1010

11-
| Name | Required | Default | Description |
12-
| ---------------------- | -------- | ------- | ----------------------------------------------------------------------- |
13-
| **general** | | | |
14-
| `debug` | false | `false` | Prevents the CLI/library from printing any logs/output. |
15-
| `report` | false | `true` | Generate an HTML report, displaying the baseline, latest & diff images. |
16-
| **ios config** | | | |
17-
| `ios.workspace` | true | | Path to the `.xcworkspace` file of your react-native project |
18-
| `ios.scheme` | true | | The name of the scheme you would like to use for building the app |
19-
| `ios.configuration` | true | `Debug` | The build configuration that should be used. |
20-
| `ios.buildCommand` | false | | Overrides the `xcodebuild` command making the above options obselete |
21-
| `ios.binaryPath` | false | | The path to the binary, if you are using a custom build command |
22-
| `ios.quiet` | false | | Passes the quiet flag to `xcode builds` |
23-
| **android config** | | | |
24-
| `android.buildCommand` | false | | Overrides the `assembleDebug` gradle command. Should build the apk |
25-
| `android.binaryPath` | false | | The path to the binary, if you are using a custom build command |
26-
| `android.packageName` | | | The package name/unique identifier of the app |
27-
| `android.quiet` | false | | Passes the quiet flag to `gradlew` |
11+
| Name | Required | Default | Description |
12+
| ---------------------- | -------- | --------- | -------------------------------------------------------------------------------------------- |
13+
| **general** | | | |
14+
| `debug` | false | `false` | Prevents the CLI/library from printing any logs/output. |
15+
| `report` | false | `true` | Generate an HTML report, displaying the baseline, latest & diff images. |
16+
| **ios config** | | | |
17+
| `ios.workspace` | true | | Path to the `.xcworkspace` file of your react-native project |
18+
| `ios.scheme` | true | | The name of the scheme you would like to use for building the app |
19+
| `ios.configuration` | true | `Debug` | The build configuration that should be used. |
20+
| `ios.buildCommand` | false | | Overrides the `xcodebuild` command making the above options obselete |
21+
| `ios.binaryPath` | false | | The path to the binary, if you are using a custom build command |
22+
| `ios.quiet` | false | | Passes the quiet flag to `xcode builds` |
23+
| **android config** | | | |
24+
| `android.buildCommand` | false | | Overrides the `assembleDebug` gradle command. Should build the apk |
25+
| `android.buildType` | false | `Release` | Can be one of `debug` or `release`. Used to call either `assembleDebug` or `assembleRelease` |
26+
| `android.binaryPath` | false | | The path to the binary, if you are using a custom build command |
27+
| `android.packageName` | | | The package name/unique identifier of the app |
28+
| `android.quiet` | false | | Passes the quiet flag to `gradlew` |
2829

2930
### Example
3031

@@ -39,4 +40,4 @@ The config file - which unless specified in the cli should live in `./owl.config
3940
"packageName": "com.owldemoapp"
4041
}
4142
}
42-
```
43+
```

example/owl.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"android": {
1010
"packageName": "com.owldemo",
11+
"buildType": "Release",
1112
"quiet": true
1213
},
1314
"debug": true,

lib/cli/build.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('build.ts', () => {
9191

9292
expect(execMock).toHaveBeenCalledTimes(1);
9393
expect(execMock).toHaveBeenCalledWith(
94-
`./gradlew assembleRelease -PisOwlBuild=true`,
94+
`./gradlew assembleRelease --console plain -PisOwlBuild=true`,
9595
{
9696
stdio: 'inherit',
9797
cwd: path.join(process.cwd(), 'android'),
@@ -113,7 +113,7 @@ describe('build.ts', () => {
113113

114114
expect(execMock).toHaveBeenCalledTimes(1);
115115
expect(execMock).toHaveBeenCalledWith(
116-
`./gradlew assembleRelease --quiet -PisOwlBuild=true`,
116+
`./gradlew assembleRelease --console plain --quiet -PisOwlBuild=true`,
117117
{
118118
stdio: 'inherit',
119119
cwd: path.join(process.cwd(), 'android'),

lib/cli/build.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ export const buildAndroid = async (
4343
): Promise<void> => {
4444
const buildCommand = config.android?.buildCommand
4545
? [config.android?.buildCommand]
46-
: [`./gradlew`, `assembleRelease`];
46+
: [
47+
`./gradlew`,
48+
config.android?.buildType === 'Debug'
49+
? `assembleDebug`
50+
: 'assembleRelease',
51+
'--console plain',
52+
];
4753

4854
if (!config.android?.buildCommand && config.android?.quiet) {
4955
buildCommand.push('--quiet');
@@ -55,7 +61,7 @@ export const buildAndroid = async (
5561

5662
const cwd = config.android?.buildCommand
5763
? undefined
58-
: path.join(process.cwd(), '/android');
64+
: path.join(process.cwd(), 'android');
5965

6066
logger.info(`[OWL - CLI] Building the app with: ${buildCommand.join(' ')}.`);
6167

lib/cli/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ describe('config.ts', () => {
181181
},
182182
android: {
183183
packageName: 'com.rndemo',
184+
buildType: 'Debug',
184185
},
185186
debug: false,
186187
report: true,

lib/cli/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const validateSchema = (config: {}): Promise<Config> => {
3131
properties: {
3232
packageName: { type: 'string' },
3333
buildCommand: { type: 'string', nullable: true },
34+
buildType: { type: 'string', nullable: true, default: 'Release' },
3435
binaryPath: { type: 'string', nullable: true },
3536
quiet: { type: 'boolean', nullable: true },
3637
},

lib/cli/run.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ describe('run.ts', () => {
149149
const config: Config = {
150150
android: {
151151
packageName: 'com.rndemo',
152+
buildType: 'Release',
152153
},
153154
};
154155

lib/cli/run.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ export const restoreIOSUI = async (config: Config, logger: Logger) => {
6060

6161
export const runAndroid = async (config: Config, logger: Logger) => {
6262
const stdio = config.debug ? 'inherit' : 'ignore';
63-
const DEFAULT_APK_DIR = '/android/app/build/outputs/apk/release/';
63+
const buildType = config.android?.buildType?.toLowerCase();
64+
const DEFAULT_APK_DIR = `/android/app/build/outputs/apk/${buildType}/`;
6465
const cwd = config.android?.binaryPath
6566
? path.dirname(config.android?.binaryPath)
6667
: path.join(process.cwd(), DEFAULT_APK_DIR);
6768

6869
const appFilename = config.android!.binaryPath
6970
? path.basename(config.android!.binaryPath)
70-
: 'app-release.apk';
71+
: `app-${buildType}.apk`;
7172
const appPath = path.join(cwd, appFilename);
7273
const { packageName } = config.android!;
7374

lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type ConfigAndroid = {
3939
packageName: string;
4040
/** Overrides the `assembleDebug` gradle command. Should build the apk. */
4141
buildCommand?: string;
42+
/** Used to decided which build command it should call. */
43+
buildType?: 'Debug' | 'Release';
4244
/** Path to the .apk that will get generated by a custom build command. Ignored when not using a custom build command. */
4345
binaryPath?: string;
4446
/** Passes the quiet flag to `gradlew`. */

0 commit comments

Comments
 (0)