Skip to content

Commit

Permalink
feat(config): add support for setting default keystore path (#53)
Browse files Browse the repository at this point in the history
Allows the user to have the keystore path and alias saved in the settings.json.

Fixes #51 

### Verification steps

1. Add settings `titanium.android.keystorePath` and or `titanium.android.keystoreAlias` to the .vscode settings file
2. Package an to an android application using the saved keystore path
  • Loading branch information
longton95 authored and ewanharris committed Mar 7, 2019
1 parent 26357e0 commit a0832ac
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@
"properties": {
"titanium.android.keystoreAlias": {
"type": "string",
"default": "",
"default": null,
"description": "Keystore alias used for packaging Android applications"
},
"titanium.android.keystorePath": {
"type": "string",
"default": "",
"default": null,
"description": "Path to keystore used for packaging Android applications"
},
"titanium.build.liveview": {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/packageApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export async function packageApplication (node: DeviceNode | OSVerNode | Platfor

if (platform === 'android' && !keystoreInfo) {
const lastKeystore = ExtensionContainer.context.workspaceState.get<string>(WorkspaceState.LastKeystorePath);
const savedKeystorePath = ExtensionContainer.config.android.keystorePath;
// TODO: Private key password?
keystoreInfo = await enterAndroidKeystoreInfo(lastKeystore);
keystoreInfo = await enterAndroidKeystoreInfo(lastKeystore, savedKeystorePath);
ExtensionContainer.context.workspaceState.update(WorkspaceState.LastKeystorePath, keystoreInfo.location);
} else if (platform === 'ios' && !iOSCertificate) {
const codesigning = await selectiOSCodeSigning(buildType, target, project.appId());
Expand Down
30 changes: 24 additions & 6 deletions src/quickpicks/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as path from 'path';
import appc from '../appc';
import * as utils from '../utils';

import { InputBoxOptions, OpenDialogOptions, QuickPickOptions, window } from 'vscode';
import { UserCancellation } from '../commands/common';
import { pathExists } from 'fs-extra';
import { InputBoxOptions, OpenDialogOptions, QuickPickOptions, window, workspace } from 'vscode';
import { InteractionError, UserCancellation } from '../commands/common';
import { ExtensionContainer } from '../container';

export async function selectFromFileSystem (options: OpenDialogOptions) {
if (!options.canSelectMany) {
Expand Down Expand Up @@ -111,7 +114,7 @@ export function selectAndroidEmulator () {
return quickPick(options, { placeHolder: 'Select emulator' });
}

export async function selectAndroidKeystore (lastUsed) {
export async function selectAndroidKeystore (lastUsed, savedKeystorePath) {
const items = [{
label: 'Browse for keystore',
id: 'browse'
Expand All @@ -122,18 +125,33 @@ export async function selectAndroidKeystore (lastUsed) {
id: 'last'
});
}
if (savedKeystorePath) {
items.push({
label: `Saved ${savedKeystorePath}`,
id: 'saved'
});
}
const keystoreAction = await quickPick(items, { placeHolder: 'Browse for keystore or use last keystore' });
if (keystoreAction.id === 'browse') {
const uri = await window.showOpenDialog({ canSelectFolders: false, canSelectMany: false });
return uri[0].path;
} else if (keystoreAction.id === 'saved') {
if (!path.isAbsolute(savedKeystorePath)) {
savedKeystorePath = path.resolve(workspace.rootPath, savedKeystorePath);
}
return savedKeystorePath;
} else {
return lastUsed;
}
}

export async function enterAndroidKeystoreInfo (lastUsed) {
const location = await selectAndroidKeystore(lastUsed);
const alias = await inputBox({ placeHolder: 'Enter your keystore alias' });
export async function enterAndroidKeystoreInfo (lastUsed, savedKeystorePath) {
const location = await selectAndroidKeystore(lastUsed, savedKeystorePath);

if (!await pathExists(location)) {
throw new InteractionError(`The Keystore file ${location} does not exist`);
}
const alias = await inputBox({ placeHolder: 'Enter your keystore alias', value: ExtensionContainer.config.android.keystoreAlias });
const password = await enterPassword({ placeHolder: 'Enter your keystore password' });
return {
alias,
Expand Down
4 changes: 2 additions & 2 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { LogLevel } from './common';

export interface Config {
android: {
keystoreAlias: string,
keystorePath: string
keystoreAlias: string | null,
keystorePath: string | null
};
build: {
liveview: boolean
Expand Down

0 comments on commit a0832ac

Please sign in to comment.