提交 3f6dd33f 编写于 作者: J Joao Moreno

woo: smoke infrastructure up and running

上级 b1f17c53
......@@ -29,7 +29,8 @@ const options: minimist.Opts = {
'enable-proposed-api',
'export-default-configuration',
'install-source',
'upload-logs'
'upload-logs',
'driver'
],
boolean: [
'help',
......
......@@ -11,6 +11,8 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/tmp": "^0.0.33",
"tmp": "^0.0.33",
"typescript": "^2.8.1"
}
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as fs from 'fs';
import * as path from 'path';
import * as cp from 'child_process';
import { tmpName } from 'tmp';
import { IDriver, connect as connectDriver, IDisposable } from './driver';
const repoPath = path.join(__dirname, '../../..');
function getDevElectronPath(): string {
const buildPath = path.join(repoPath, '.build');
const product = require(path.join(repoPath, 'product.json'));
switch (process.platform) {
case 'darwin':
return path.join(buildPath, 'electron', `${product.nameLong}.app`, 'Contents', 'MacOS', 'Electron');
case 'linux':
return path.join(buildPath, 'electron', `${product.applicationName}`);
case 'win32':
return path.join(buildPath, 'electron', `${product.nameShort}.exe`);
default:
throw new Error('Unsupported platform.');
}
}
function getBuildElectronPath(root: string): string {
switch (process.platform) {
case 'darwin':
return path.join(root, 'Contents', 'MacOS', 'Electron');
case 'linux': {
const product = require(path.join(root, 'resources', 'app', 'product.json'));
return path.join(root, product.applicationName);
}
case 'win32': {
const product = require(path.join(root, 'resources', 'app', 'product.json'));
return path.join(root, `${product.nameShort}.exe`);
}
default:
throw new Error('Unsupported platform.');
}
}
function getDevOutPath(): string {
return path.join(repoPath, 'out');
}
function getBuildOutPath(root: string): string {
switch (process.platform) {
case 'darwin':
return path.join(root, 'Contents', 'Resources', 'app', 'out');
default:
return path.join(root, 'resources', 'app', 'out');
}
}
export class Code {
constructor(
private process: cp.ChildProcess,
private client: IDisposable,
readonly driver: IDriver
) {
}
dispose(): void {
this.client.dispose();
this.process.kill();
}
}
export interface SpawnOptions {
codePath?: string;
userDataDir: string;
extensionsPath: string;
}
export async function connect(child: cp.ChildProcess, outPath: string, handlePath: string): Promise<Code> {
let errCount = 0;
while (true) {
try {
const { client, driver } = await connectDriver(outPath, handlePath);
return new Code(child, client, driver);
} catch (err) {
if (++errCount > 50) {
child.kill();
throw err;
}
// retry
await new Promise(c => setTimeout(c, 100));
}
}
}
export function spawn(options: SpawnOptions): Promise<Code> {
const codePath = options.codePath;
const electronPath = codePath ? getBuildElectronPath(codePath) : getDevElectronPath();
const outPath = codePath ? getBuildOutPath(codePath) : getDevOutPath();
return new Promise((c, e) => {
tmpName((err, handlePath) => {
if (err) { return e(err); }
const args = [
'--skip-getting-started',
'--skip-release-notes',
'--sticky-quickopen',
'--disable-telemetry',
'--disable-updates',
'--disable-crash-reporter',
`--extensions-dir=${options.extensionsPath}`,
`--user-data-dir=${options.userDataDir}`,
'--driver', handlePath
];
if (!codePath) {
args.unshift(repoPath);
}
const child = cp.spawn(electronPath, args);
connect(child, outPath, handlePath).then(c, e);
});
});
}
\ No newline at end of file
......@@ -5,14 +5,27 @@
import * as path from 'path';
import { connect } from './driver';
import { spawn } from './code';
const rootPath = path.dirname(path.dirname(path.dirname(__dirname)));
const outPath = path.join(rootPath, 'out');
const handlePath = path.join(rootPath, 'foo.sock');
// const rootPath = path.dirname(path.dirname(path.dirname(__dirname)));
// const outPath = path.join(rootPath, 'out');
// const handlePath = path.join(rootPath, 'foo.sock');
connect(outPath, handlePath).then(({ client, driver }) => {
return driver.getWindows().then(w => {
// connect(outPath, handlePath).then(({ client, driver }) => {
// return driver.getWindows().then(w => {
// console.log(w);
// client.dispose();
// });
// }, err => console.error('oh no', err));
const opts = {
extensionsPath: '/Users/joao/Desktop/extensions',
userDataDir: '/Users/joao/Desktop/user-data-dir',
};
spawn(opts).then(code => {
return code.driver.getWindows().then(w => {
console.log(w);
client.dispose();
code.dispose();
});
}, err => console.error('oh no', err));
\ No newline at end of file
{
"compilerOptions": {
"module": "commonjs",
"outDir": "out"
"outDir": "out",
"target": "es6",
"strictNullChecks": true
},
"exclude": [
"node_modules"
......
......@@ -2,6 +2,20 @@
# yarn lockfile v1
"@types/tmp@^0.0.33":
version "0.0.33"
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.0.33.tgz#1073c4bc824754ae3d10cfab88ab0237ba964e4d"
os-tmpdir@~1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
dependencies:
os-tmpdir "~1.0.2"
typescript@^2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册