Permalink
Browse files

move utils.ts->shared/utils.ts, address issues raised in review, new …

…file for command line stuff.
  • Loading branch information...
mgbennet committed Aug 25, 2017
1 parent e2e8840 commit d38e3f449cb99b02f74e2483b81cf3c687f5b3df
View
@@ -10,6 +10,7 @@
"request": "launch",
"program": "${workspaceRoot}/app/server/main.js",
"stopOnEntry": false,
"args": [],
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
@@ -35,7 +35,7 @@ import * as React from 'react';
import { getSettings, Settings, addSettingsListener } from '../settings';
import { AddressBarActions } from '../reducers';
import { IUser } from '../../types/userTypes';
import { uniqueId } from '../../utils';
import { uniqueId } from '../../shared/utils';
export class ConversationSettingsDialog extends React.Component<{}, {}> {
View
@@ -37,7 +37,7 @@ import { Subscription, Observable, Subject } from 'rxjs';
import { getSettings, addSettingsListener } from './settings';
import { LogActions, WordWrapAction } from './reducers';
import * as Constants from './constants';
import { safeStringify } from '../utils';
import { safeStringify } from '../shared/utils';
const { remote } = require('electron');
const { Menu } = remote;
@@ -32,7 +32,7 @@
//
import { ICheckoutCreditCard, ICheckoutShippingAddress } from './checkoutTypes';
import { loadSettings, saveSettings } from '../../utils';
import { loadSettings, saveSettings } from '../../shared/utils';
interface ICheckoutSettings {
creditCards: ICheckoutCreditCard[];
@@ -46,7 +46,7 @@ import { ISettings } from '../settings';
import { ConversationActions, ServerSettingsActions } from '../reducers';
import { Button } from './button';
import { CheckoutSettings } from './checkoutSettings';
import { uniqueId } from '../../utils';
import { uniqueId } from '../../shared/utils';
export class CheckoutView extends React.Component<{}, ICheckoutViewState> {
View
@@ -34,7 +34,7 @@
import { Reducer } from 'redux';
import { IBot } from '../types/botTypes';
import { IUser } from '../types/userTypes';
import { uniqueId } from '../utils';
import { uniqueId } from '../shared/utils';
import * as log from './log';
import {
ISettings as IServerSettings,
View
@@ -37,7 +37,7 @@ import { BehaviorSubject } from 'rxjs';
import { ActivityOrID } from '../types/activityTypes';
import { Settings as ServerSettings } from '../types/serverSettingsTypes';
import { InspectorActions, ConversationActions } from './reducers';
import { loadSettings, saveSettings } from '../utils';
import { loadSettings, saveSettings } from '../shared/utils';
import {
layoutReducer,
addressBarReducer,
@@ -43,7 +43,7 @@ import { Settings } from '../types/serverSettingsTypes';
import * as log from './log';
import * as ngrok from './ngrok';
import { Emulator } from './emulator';
import * as utils from '../utils';
import * as utils from '../shared/utils';
/**
* Communicates with the bot.
@@ -0,0 +1,47 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Bot Framework: http://botframework.com
//
// Bot Framework Emulator Github:
// https://github.com/Microsoft/BotFramwork-Emulator
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// 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';
const optionDefinitions = [
{ name: 'localstore', alias: 'l', type: String, defaultValue: path.join(Electron.app.getPath("userData"), "botframework-emulator") },
];
export function parseCommandLineArgs() {
const parsedCommandLineArgs:ICommandLineArgs = commandLineArgs(optionDefinitions, { partial: true });
global['commandlineargs'] = parsedCommandLineArgs;
}
@@ -36,7 +36,7 @@ import * as HttpStatus from "http-status-codes";
import * as ResponseTypes from '../../../types/responseTypes';
import { ErrorCodes, } from '../../../types/responseTypes';
import { IAttachmentData, IAttachmentInfo } from '../../../types/attachmentTypes';
import { uniqueId } from '../../../utils';
import { uniqueId } from '../../../shared/utils';
import { RestServer } from '../../restServer';
import * as log from '../../log';
@@ -40,7 +40,7 @@ import { RestServer } from '../../restServer';
import { BotFrameworkAuthentication } from '../../botFrameworkAuthentication';
import { jsonBodyParser } from '../../jsonBodyParser';
import { getSettings } from '../../settings';
import { approximateObjectSize } from '../../../utils';
import { approximateObjectSize } from '../../../shared/utils';
interface IBotData {
@@ -38,15 +38,15 @@ import { IUser } from '../types/userTypes';
import { IActivity, IConversationUpdateActivity, IMessageActivity, IContactRelationUpdateActivity, IInvokeActivity } from '../types/activityTypes';
import { PaymentEncoder } from '../shared/paymentEncoder';
import { ISpeechTokenInfo } from '../types/speechTypes';
import { uniqueId } from '../utils';
import { uniqueId } from '../shared/utils';
import { dispatch, getSettings, v31AuthenticationSettings, addSettingsListener, speechSettings } from './settings';
import { Settings } from '../types/serverSettingsTypes';
import * as HttpStatus from "http-status-codes";
import * as ResponseTypes from '../types/responseTypes';
import { ErrorCodes, IResourceResponse } from '../types/responseTypes';
import { emulator } from './emulator';
import * as log from './log';
import * as utils from '../utils';
import * as utils from '../shared/utils';
import { usersDefault } from '../types/serverSettingsTypes';
import * as moment from 'moment';
View
@@ -33,7 +33,7 @@
import * as Restify from 'restify';
import { Emulator } from './emulator';
import { safeStringify } from '../utils';
import { safeStringify } from '../shared/utils';
const sendMessage = (method: string, message: any, ...args) => {
View
@@ -38,21 +38,15 @@ import { WindowStateAction } from './reducers/windowStateReducer';
import * as url from 'url';
import * as path from 'path';
import * as log from './log';
import * as commandLineArgs from 'command-line-args';
import { Emulator } from './emulator';
import { WindowManager } from './windowManager';
import { parseCommandLineArgs } from './commandLineManager'
(process as NodeJS.EventEmitter).on('uncaughtException', (error: Error) => {
console.error(error);
log.error('[err-server]', error.message.toString(), JSON.stringify(error.stack));
});
const optionDefinitions = [
{ name: 'localstore', type: String },
];
const options = commandLineArgs(optionDefinitions, { partial: true });
export let mainWindow: Electron.BrowserWindow;
export let windowManager: WindowManager;
@@ -70,6 +64,8 @@ var onOpenUrl = function (event, url) {
}
};
parseCommandLineArgs();
Electron.app.on('will-finish-launching', (event, args) => {
Electron.ipcMain.on('getUrls', (event, arg) => {
openUrls.forEach(url => mainWindow.webContents.send('botemulator', url));
@@ -229,7 +225,6 @@ const createMainWindow = () => {
mainWindow.loadURL(page);
}
global["localstore"] = options.localstore || path.join(Electron.app.getPath("userData"), "botframework-emulator");
Emulator.startup();
Electron.app.on('ready', createMainWindow);
Electron.app.on('window-all-closed', function () {
@@ -32,7 +32,7 @@
//
import { Reducer } from 'redux';
import { uniqueId } from '../../utils';
import { uniqueId } from '../../shared/utils';
import { IBot } from '../../types/botTypes';
import { getSettings } from '../settings';
View
@@ -37,7 +37,7 @@ import { frameworkReducer } from './reducers/frameworkReducer';
import { botsReducer, activeBotReducer } from './reducers/botReducer';
import { windowStateReducer } from './reducers/windowStateReducer';
import { usersReducer } from './reducers/usersReducer';
import { loadSettings, saveSettings } from '../utils';
import { loadSettings, saveSettings } from '../shared/utils';
import { IBot } from '../types/botTypes';
import {
IFrameworkSettings,
@@ -45,9 +45,10 @@ export const uniqueId = (length?: number) => Math.random().toString(24).substr(2
const ensureStoragePath = (): string => {
const app = Electron.app || Electron.remote.app;
const p = global["localstore"] || Electron.remote.getGlobal("localstore") || path.join(app.getPath('userData'), "botframework-emulator");
Mkdirp.sync(p);
return p;
const globals = global['commandlineargs'] || Electron.remote.getGlobal('commandlineargs');
const storagePath = globals.localstore || path.join(app.getPath('userData'), 'botframework-emulator');
Mkdirp.sync(storagePath);
return storagePath;
}
/**
@@ -74,7 +75,7 @@ export const loadSettings = <T>(filename: string, defaultSettings: T): T => {
export const saveSettings = <T>(filename: string, settings: T) => {
try {
filename = `${ensureStoragePath()}/${filename}`;
Fs.writeFileSync(filename, JSON.stringify(settings, null, 2), 'utf8');
Fs.writeFileSync(filename, JSON.stringify(settings, null, 2), {encoding: 'utf8'});
} catch (e) {
console.error(`Failed to write file: ${filename}`, e);
}
View
@@ -31,7 +31,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import { uniqueId } from '../utils';
import { uniqueId } from '../shared/utils';
export interface IBot {
@@ -0,0 +1,37 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Bot Framework: http://botframework.com
//
// Bot Framework Emulator Github:
// https://github.com/Microsoft/BotFramwork-Emulator
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
export interface ICommandLineArgs {
localstore?: string,
}
@@ -62,10 +62,10 @@ describe("App", function(this: any) {
});
after(function() {
testHelpers.cleanUpLocalStore();
if (app && app.isRunning()) {
return app.stop();
}
testHelpers.cleanUpLocalStore();
});
it("opens a window on launch", function() {
View
@@ -15,7 +15,7 @@ export const tempLocalStore = path.join(__dirname, 'testsettings');
export function cleanUpLocalStore() {
if (fs.existsSync(tempLocalStore)) {
fs.readdirSync(tempLocalStore).forEach((f) => {
fs.unlinkSync(tempLocalStore + "/" + f);
fs.unlinkSync(path.join(tempLocalStore, f));
});
fs.rmdirSync(tempLocalStore);
}
View
@@ -33,8 +33,11 @@
import * as chai from 'chai';
import * as Settings from '../../src/server/settings';
import * as testHelpers from '../testHelpers';
global['commandlineargs'] = {}
global['commandlineargs'].localstore = testHelpers.tempLocalStore;
chai.should();
describe("Settings", function() {
View
@@ -32,7 +32,7 @@
//
import * as chai from 'chai';
import * as utils from '../../src/utils';
import * as utils from '../../src/shared/utils';
chai.should();

0 comments on commit d38e3f4

Please sign in to comment.