Skip to content

Commit

Permalink
feat: Added Firefox for Android support and --android and --android-d…
Browse files Browse the repository at this point in the history
…evice CLI options (#868)
  • Loading branch information
rpl authored and kumar303 committed Dec 20, 2017
1 parent 284d4c6 commit 1b22d60
Show file tree
Hide file tree
Showing 12 changed files with 2,895 additions and 24 deletions.
6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -48,6 +48,7 @@
"opera"
],
"dependencies": {
"adbkit": "2.11.0",
"addons-linter": "0.31.0",
"babel-polyfill": "6.20.0",
"babel-runtime": "6.25.0",
Expand All @@ -65,17 +66,17 @@
"mkdirp": "0.5.1",
"mz": "2.6.0",
"node-firefox-connect": "1.2.0",
"open": "0.0.5",
"node-notifier": "5.1.2",
"open": "0.0.5",
"parse-json": "2.2.0",
"regenerator-runtime": "0.11.1",
"require-uncached": "1.0.3",
"sign-addon": "0.2.2",
"source-map-support": "0.5.0",
"stream-to-promise": "2.2.0",
"tmp": "0.0.30",
"watchpack": "1.3.0",
"update-notifier": "2.3.0",
"watchpack": "1.3.0",
"yargs": "6.6.0",
"zip-dir": "1.0.2"
},
Expand All @@ -92,6 +93,7 @@
"babel-preset-es2015": "6.24.1",
"babel-preset-stage-2": "6.24.1",
"chai": "3.5.0",
"chai-as-promised": "7.1.1",
"conventional-changelog-cli": "1.3.1",
"conventional-changelog-lint": "1.1.9",
"copy-dir": "0.3.0",
Expand Down
113 changes: 96 additions & 17 deletions src/cmd/run.js
@@ -1,5 +1,6 @@
/* @flow */

import defaultBuildExtension from './build';
import DefaultADBUtils from '../util/adb';
import {
showDesktopNotification as defaultDesktopNotifications,
} from '../util/desktop-notifier';
Expand All @@ -12,13 +13,19 @@ import defaultGetValidatedManifest from '../util/manifest';
import {
defaultReloadStrategy,
MultiExtensionRunner as DefaultMultiExtensionRunner,
FirefoxDesktopExtensionRunner as DefaultFirefoxDesktopExtensionRunner,
} from '../extension-runners';
import {
FirefoxDesktopExtensionRunner as DefaultFirefoxDesktopExtensionRunner,
} from '../extension-runners/firefox-desktop';
import {
FirefoxAndroidExtensionRunner as defaultFirefoxAndroidExtensionRunner,
} from '../extension-runners/firefox-android';
// Import objects that are only used as Flow types.
import type {FirefoxPreferences} from '../firefox/preferences';

const log = createLogger(__filename);


// Run command types and implementation.

export type CmdRunParams = {|
Expand All @@ -34,14 +41,24 @@ export type CmdRunParams = {|
preInstall: boolean,
sourceDir: string,
startUrl?: string | Array<string>,
target?: string | Array<string>,

// Android CLI options.
adbBin?: string,
adbHost?: string,
adbPort?: string,
adbDevice?: string,
firefoxApk?: string,
|};

export type CmdRunOptions = {|
buildExtension: typeof defaultBuildExtension,
desktopNotifications: typeof defaultDesktopNotifications,
firefoxApp: typeof defaultFirefoxApp,
firefoxClient: typeof defaultFirefoxClient,
reloadStrategy: typeof defaultReloadStrategy,
shouldExitProgram?: boolean,
FirefoxAndroidExtensionRunner?: typeof defaultFirefoxAndroidExtensionRunner,
FirefoxDesktopExtensionRunner?: typeof DefaultFirefoxDesktopExtensionRunner,
MultiExtensionRunner?: typeof DefaultMultiExtensionRunner,
getValidatedManifest?: typeof defaultGetValidatedManifest,
Expand All @@ -61,12 +78,21 @@ export default async function run(
preInstall = false,
sourceDir,
startUrl,
target,
// Android CLI options.
adbBin,
adbHost,
adbPort,
adbDevice,
firefoxApk,
}: CmdRunParams,
{
buildExtension = defaultBuildExtension,
desktopNotifications = defaultDesktopNotifications,
firefoxApp = defaultFirefoxApp,
firefoxClient = defaultFirefoxClient,
reloadStrategy = defaultReloadStrategy,
FirefoxAndroidExtensionRunner = defaultFirefoxAndroidExtensionRunner,
FirefoxDesktopExtensionRunner = DefaultFirefoxDesktopExtensionRunner,
MultiExtensionRunner = DefaultMultiExtensionRunner,
getValidatedManifest = defaultGetValidatedManifest,
Expand All @@ -84,32 +110,85 @@ export default async function run(
const customPrefs = pref;
const manifestData = await getValidatedManifest(sourceDir);

const firefoxDesktopRunnerParams = {
const runners = [];

const commonRunnerParams = {
// Common options.
extensions: [{sourceDir, manifestData}],
keepProfileChanges,
startUrl,
desktopNotifications,
};

// Firefox specific CLI options.
firefoxBinary: firefox,
profilePath: firefoxProfile,
customPrefs,
browserConsole,
preInstall,
if (!target || target.length === 0 || target.includes('firefox-desktop')) {
const firefoxDesktopRunnerParams = {
...commonRunnerParams,

// Firefox runner injected dependencies.
firefoxApp,
firefoxClient,
};
// Firefox specific CLI options.
firefoxBinary: firefox,
profilePath: firefoxProfile,
customPrefs,
browserConsole,
preInstall,

// Firefox runner injected dependencies.
firefoxApp,
firefoxClient,
};

const firefoxDesktopRunner = new FirefoxDesktopExtensionRunner(
firefoxDesktopRunnerParams
);

runners.push(firefoxDesktopRunner);
}

if (target && target.includes('firefox-android')) {
const firefoxAndroidRunnerParams = {
...commonRunnerParams,

// Firefox specific CLI options.
profilePath: firefoxProfile,
customPrefs,
browserConsole,
preInstall,
firefoxApk,
adbDevice,
adbHost,
adbPort,
adbBin,

// Injected dependencies.
firefoxApp,
firefoxClient,
ADBUtils: DefaultADBUtils,
desktopNotifications: defaultDesktopNotifications,
buildSourceDir: (extensionSourceDir: string, tmpArtifactsDir: string) => {
return buildExtension({
sourceDir: extensionSourceDir,
ignoreFiles,
asNeeded: false,
// Use a separate temporary directory for building the extension zip file
// that we are going to upload on the android device.
artifactsDir: tmpArtifactsDir,
}, {
// Suppress the message usually logged by web-ext build.
showReadyMessage: false,
});
},
};

const firefoxAndroidRunner = new FirefoxAndroidExtensionRunner({
...commonRunnerParams,
...firefoxAndroidRunnerParams,
});

const firefoxDesktopRunner = new FirefoxDesktopExtensionRunner(
firefoxDesktopRunnerParams
);
runners.push(firefoxAndroidRunner);
}

const extensionRunner = new MultiExtensionRunner({
runners: [firefoxDesktopRunner],
desktopNotifications,
runners,
});

await extensionRunner.run();
Expand Down

0 comments on commit 1b22d60

Please sign in to comment.