Permalink
Browse files

Addressed more CR feedback. Moved where we calculate default storagep…

…ath.
  • Loading branch information...
mgbennet committed Sep 1, 2017
1 parent 61d0824 commit 5d6b7fa812a7544ec53afee5b0bb1aa22cc1521a
@@ -31,18 +31,16 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import * as Electron from 'electron';
import * as path from 'path';
import * as commandLineArgs from 'command-line-args';
import {ICommandLineArgs} from '../types/commandLineArgsTypes';
import * as globals from '../shared/globals';
const optionDefinitions = [
{ name: 'storagepath', alias: 'p', type: String, defaultValue: path.join(Electron.app.getPath("userData"), "botframework-emulator") },
{ name: 'storagepath', alias: 'p', type: String },
];
export function parseArgs() {
export function parseArgs(): void {
const parsedCommandLineArgs:ICommandLineArgs = commandLineArgs(optionDefinitions, { partial: true });
globals.setGlobal('commandlineargs', parsedCommandLineArgs);
}
View
@@ -34,10 +34,16 @@
import * as Electron from 'electron';
export function getGlobal(attributeName: string) {
return global[attributeName] || Electron.remote.getGlobal(attributeName);
export function getGlobal(attributeName: string, defaultValue?: any): any {
if (global[attributeName]) {
return global[attributeName];
} else if (Electron.remote && Electron.remote.getGlobal(attributeName)) {
return Electron.remote.getGlobal(attributeName)
} else {
return defaultValue;
}
}
export function setGlobal(attributeName: string, value) {
export function setGlobal(attributeName: string, value: any): void {
global[attributeName] = value;
}
}
View
@@ -31,9 +31,11 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import * as Electron from 'electron';
import * as Fs from 'fs';
import * as Mkdirp from 'mkdirp';
import * as url from 'url';
import * as path from 'path';
import * as globals from './globals';
@@ -43,7 +45,8 @@ import * as globals from './globals';
export const uniqueId = (length?: number) => Math.random().toString(24).substr(2, length);
const ensureStoragePath = (): string => {
const storagePath = globals.getGlobal('commandlineargs').storagepath;
const commandLineArgs = globals.getGlobal('commandlineargs');
const storagePath = commandLineArgs.storagepath || path.join(Electron.app.getPath("userData"), "botframework-emulator");
Mkdirp.sync(storagePath);
return storagePath;
}
@@ -33,5 +33,5 @@
export interface ICommandLineArgs {
localstore?: string,
storagepath?: string,
}
View
@@ -52,7 +52,7 @@ server.post('/api/messages', connector.listen());
//
// Main methods
//
function getCounter(session) {
function getCounter(session): string {
if (!session.dialogData.hasOwnProperty('counter')) {
session.dialogData.counter = 0;
}
View
@@ -35,6 +35,7 @@ import * as chai from 'chai';
import * as Settings from '../../src/server/settings';
import * as testHelpers from '../testHelpers';
import * as globals from '../../src/shared/globals';
import {ICommandLineArgs} from '../../src/types/commandLineArgsTypes';
import { settingsDefault } from '../../src/types/serverSettingsTypes';
@@ -44,9 +45,10 @@ describe("Server/Settings", function() {
let settings: Settings.PersistentSettings;
before(function() {
globals.setGlobal('commandlineargs', {
const commandLineArgs: ICommandLineArgs = {
storagepath: testHelpers.tempLocalStore
});
};
globals.setGlobal('commandlineargs', commandLineArgs);
return;
});

0 comments on commit 5d6b7fa

Please sign in to comment.