From c795e0e967e82dbe6711ad81bbdb3136f9138a96 Mon Sep 17 00:00:00 2001 From: Joyce Toh Date: Tue, 8 Sep 2020 13:52:51 -0700 Subject: [PATCH] Modify flow to install JDK to default path --- packages/cli/src/lib/config.ts | 44 +++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/lib/config.ts b/packages/cli/src/lib/config.ts index b6598a31..089fbca0 100644 --- a/packages/cli/src/lib/config.ts +++ b/packages/cli/src/lib/config.ts @@ -28,34 +28,44 @@ export const DEFAULT_CONFIG_FILE_PATH = join(DEFAULT_CONFIG_FOLDER, DEFAULT_CONF const LEGACY_CONFIG_FOLDER = join(homedir(), '.llama-pack'); const LEGACY_CONFIG_NAME = 'llama-pack-config.json'; const LEGACY_CONFIG_FILE_PATH = join(LEGACY_CONFIG_FOLDER, LEGACY_CONFIG_NAME); +const DEFAULT_JDK_FOLDER = join(DEFAULT_CONFIG_FOLDER, 'jdk'); async function createConfig(): Promise { - const result = await inquirer.prompt([ + const installRequest = await inquirer.prompt([ { type: 'confirm', - name: 'jdkExists', - message: 'Do you have JDK 8 installed?', - default: false, + name: 'jdk', + message: 'Do you want Bubblewrap to install JDK? (Enter "No" to use your JDK installation)', + default: true, }, + ]); + + let jdkPath; + if (!installRequest.jdk) { + const jdk = await inquirer.prompt([ + { + name: 'path', + message: 'Path to your existing JDK:', + validate: existsSync, + }, + ]); + jdkPath = jdk.path; + } else { + await fsPromises.mkdir(DEFAULT_JDK_FOLDER); + console.log(`Downloading JDK 8 to ${DEFAULT_JDK_FOLDER}`); + const jdkInstaller = new JdkInstaller(process); + jdkPath = await jdkInstaller.install(DEFAULT_JDK_FOLDER); + } + + const androidSdk = await inquirer.prompt([ { - name: 'jdkPath', - message: 'Path to the JDK. If not installed, enter the desired install location:', - validate: existsSync, - }, { - name: 'androidSdkPath', + name: 'path', message: 'Path to the Android SDK:', validate: existsSync, }, ]); - let jdkPath = result.jdkPath; - if (!result.jdkExists) { - console.log('Downloading JDK 8'); - const jdkInstaller = new JdkInstaller(process); - jdkPath = await jdkInstaller.install(result.jdkPath); - } - - return new Config(jdkPath, result.androidSdkPath); + return new Config(jdkPath, androidSdk.path); } async function renameConfigIfNeeded(log: Log): Promise {