Skip to content

Commit

Permalink
CLI WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyanziano committed Dec 12, 2018
1 parent ac0e3b9 commit 098cfc3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
9 changes: 7 additions & 2 deletions packages/app/main/package.json
Expand Up @@ -6,6 +6,9 @@
"description": "Development tool for the Microsoft Bot Framework. Allows developers to test and debug bots on localhost.",
"main": "./app/server/cli.js",
"homepage": "https://github.com/Microsoft/BotFramework-Emulator",
"config": {
"running_from_source": true
},
"scripts": {
"build": "run-s lint build:electron",
"build:electron": "babel ./src --out-dir app/server --extensions \".ts,.tsx\" --ignore \"**/*.spec.ts\" && npm run copy:extension:stubs",
Expand All @@ -17,7 +20,8 @@
"start:electron": "./node_modules/.bin/electron --inspect=7777 --remote-debugging-port=7778 .",
"start:electron:dev": "cross-env ELECTRON_TARGET_URL=http://localhost:3000/ npm run start:electron",
"start:react-app": "cd ../client && npm start",
"test": "jest"
"test": "jest",
"meow": "node ./app/server/cli.js"
},
"keywords": [
"microsoft",
Expand Down Expand Up @@ -170,7 +174,8 @@
],
"asarUnpack": [
"app/extensions/**",
"node_modules/@bfemulator/extension-*/**"
"node_modules/@bfemulator/extension-*/**",
"app/server/**"
],
"directories": {
"buildResources": "./scripts/config/resources"
Expand Down
101 changes: 94 additions & 7 deletions packages/app/main/src/cli.ts
Expand Up @@ -35,9 +35,98 @@ import { spawn } from 'child_process';
import { join } from 'path';
import { openSync } from 'fs-extra';

const startEmulator = () => {
const launchDetachedEmulator = () => {
const args = process.argv || [];
// console.log('got args: ', args);
// path to electron exe
const electronPath = args[0];
// path to spawn script
const spawner = join(__dirname, 'spawnMain.js');

// pass along args
const argsToPass = args.slice(1);
console.log('args to pass: ', argsToPass);

console.log('spawning spawner');
spawn(
spawner,
argsToPass,
{
detached: false,
stdio: 'inherit',
env: {
ELECTRON_RUN_AS_NODE: true
}
}
);
};

launchDetachedEmulator();

/*
const launchDetachedEmulator = () => {
console.log('process exec path: ', process.execPath);
// console.log(process);
const runningFromSource = process.env.npm_package_config_running_from_source;
if (runningFromSource) {
console.log('Running from source.');
launchDetachedFromSource();
} else {
console.log('Running from packaged version.');
launchDetachedFromPackage();
}
};
const launchDetachedFromPackage = () => {
const args = process.argv || [];
// path to electron exe
const electronPath = args[0];
console.log('ELECTRON PATH: ', electronPath);
// path to app entry point
const main = join(__dirname, 'main.js');
console.log('MAIN PATH: ', main);
// pass args to app (prune '.' from end; will be replaced with path to entry point)
const argsToPass = args.slice(1);
console.log('args to pass: ', argsToPass);
console.log('DIRNAME: ', __dirname);
console.log('CWD: ', process.cwd());
// console.log('spawning child');
// const child = spawn(
// electronPath,
// [main],
// {
// detached: false,
// stdio: 'inherit',
// env: {
// launch_detached: '1'
// }
// }
// );
// child.unref();
// const out = openSync(join(process.cwd(), './out.log'), 'a');
// const err = openSync(join(process.cwd(), './err.log'), 'a');
// console.log('spawning sub process');
// const child = spawn(
// electronPath,
// [
// ...argsToPass,
// main
// ],
// {
// detached: true,
// stdio: 'ignore' // ['ignore', out, err]
// }
// );
// child.unref();
// console.log('should now be running in detached mode');
};
const launchDetachedFromSource = () => {
const args = process.argv || [];
console.log('got args: ', args);
if (!args[0]) {
console.log('no args');
Expand All @@ -56,9 +145,6 @@ const startEmulator = () => {
console.log('DIRNAME: ', __dirname);
console.log('CWD: ', process.cwd());

// const out = openSync(join(process.cwd(), './out.log'), 'a');
// const err = openSync(join(process.cwd(), './err.log'), 'a');
console.log('spawning sub process');
const child = spawn(
Expand All @@ -69,11 +155,12 @@ const startEmulator = () => {
],
{
detached: true,
stdio: 'ignore' // ['ignore', out, err]
stdio: 'ignore'
}
);
child.unref();
console.log('should now be running in detached mode');
};
startEmulator();
launchDetachedEmulator();
*/
2 changes: 2 additions & 0 deletions packages/app/main/src/spawnMain.ts
@@ -0,0 +1,2 @@
const electron = require('electron');
console.log('Electron path from spawner: ', electron);

0 comments on commit 098cfc3

Please sign in to comment.