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

Commit

Permalink
feat(expo-cli): add menu for build type
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Jan 25, 2020
1 parent fab5b00 commit 7638f11
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
21 changes: 11 additions & 10 deletions packages/expo-cli/src/commands/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import IOSBuilder from './ios/IOSBuilder';
import AndroidBuilder from './AndroidBuilder';
import log from '../../log';
import CommandError from '../../CommandError';
import { askBuildType } from './utils';

export default (program: any) => {
program
Expand Down Expand Up @@ -53,7 +54,7 @@ export default (program: any) => {
.description(
'Build a standalone IPA for your project, signed and ready for submission to the Apple App Store.'
)
.asyncActionProjectDir((projectDir, options) => {
.asyncActionProjectDir(async (projectDir, options) => {
if (options.publicUrl && !UrlUtils.isHttps(options.publicUrl)) {
throw new CommandError('INVALID_PUBLIC_URL', '--public-url must be a valid HTTPS URL.');
}
Expand All @@ -64,14 +65,10 @@ export default (program: any) => {
);
process.exit(1);
}
if (
options.type !== undefined &&
options.type !== 'archive' &&
options.type !== 'simulator'
) {
log.error('Build type must be one of {archive, simulator}');
process.exit(1);
}
options.type = await askBuildType(options.type, {
archive: 'Deploy the build to the store',
simulator: 'Run the build on a simulator',
});
const iosBuilder = new IOSBuilder(projectDir, options);
return iosBuilder.command();
});
Expand All @@ -91,7 +88,7 @@ export default (program: any) => {
.description(
'Build a standalone APK or App Bundle for your project, signed and ready for submission to the Google Play Store.'
)
.asyncActionProjectDir((projectDir, options) => {
.asyncActionProjectDir(async (projectDir, options) => {
if (options.publicUrl && !UrlUtils.isHttps(options.publicUrl)) {
throw new CommandError('INVALID_PUBLIC_URL', '--public-url must be a valid HTTPS URL.');
}
Expand All @@ -102,6 +99,10 @@ export default (program: any) => {
);
process.exit(1);
}
options.type = await askBuildType(options.type, {
apk: 'Build a package to deploy to the store or install directly on Android devices',
'app-bundle': 'Build an optimized bundle for the store',
});
const androidBuilder = new AndroidBuilder(projectDir, options);
return androidBuilder.command();
});
Expand Down
34 changes: 33 additions & 1 deletion packages/expo-cli/src/commands/build/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Versions } from '@expo/xdl';
import chalk from 'chalk';
import program from 'commander';

import log from '../../log';
import prompt from '../../prompt';

async function checkIfSdkIsSupported(sdkVersion, platform) {
const isSupported = await Versions.canTurtleBuildSdkVersion(sdkVersion, platform);
Expand All @@ -16,4 +18,34 @@ async function checkIfSdkIsSupported(sdkVersion, platform) {
}
}

export { checkIfSdkIsSupported };
async function askBuildType(typeFromFlag, availableTypes) {
const allowedTypes = Object.keys(availableTypes);
const typeIsInvalid = typeFromFlag !== undefined && !allowedTypes.includes(typeFromFlag);

if (typeFromFlag && !typeIsInvalid) {
return typeFromFlag;
}

if (typeIsInvalid) {
log.error(`Build type must be one of (${allowedTypes.join(', ')})`);

if (program.nonInteractive) {
process.exit(1);
}
}

const { answer } = await prompt({
type: 'list',
name: 'answer',
message: 'Choose the build type you would like:',
choices: allowedTypes.map(type => ({
value: type,
short: type,
name: `${type} ${chalk.gray(`- ${availableTypes[type]}`)}`,
})),
});

return answer;
}

export { checkIfSdkIsSupported, askBuildType };

0 comments on commit 7638f11

Please sign in to comment.