feat: add auto-install params --drivers and --plugins
MODIFY
lib/cli/extension.js
lib/cli/extension.js
@@ -22,7 +22,10 @@ async function runExtensionCommand (args, type) {
if (!extCmd) {
throw new TypeError(`Cannot call ${type} command without a subcommand like 'install'`);
}
- const {json, appiumHome} = args;
+ let {json, suppressOutput, appiumHome} = args;
+ if (suppressOutput) {
+ json = true;
+ }
const logFn = (msg) => log(json, msg);
const ConfigClass = type === DRIVER_TYPE ? DriverConfig : PluginConfig;
const CommandClass = type === DRIVER_TYPE ? DriverCommand : PluginCommand;
@@ -35,7 +38,7 @@ async function runExtensionCommand (args, type) {
errAndQuit(json, err);
}
- if (json) {
+ if (json && !suppressOutput) {
console.log(JSON.stringify(jsonResult, null, JSON_SPACES));
}

MODIFY
package.json
package.json
"bin",
"lib",
"build/lib",
- "npm-shrinkwrap.json"
+ "npm-shrinkwrap.json",
+ "postinstall.js"
],
"dependencies": {
"@appium/base-plugin": "^1.0.0",
"restore-shrinkwrap": "!(test -e npm-shrinkwrap.json) || (mv npm-shrinkwrap-backup.json npm-shrinkwrap.json)",
"backup-shrinkwrap": "mv npm-shrinkwrap.json npm-shrinkwrap-backup.json",
"check-pruned-shrinkwrap": "node check-pruned-shrinkwrap.js",
+ "postinstall": "node ./postinstall.js",
"test": "gulp once",
"e2e-test": "gulp e2e-test",
"watch": "gulp watch",

ADD
postinstall.js
+#!/usr/bin/env node
+/* eslint-disable no-console, promise/prefer-await-to-then */
+
+async function main () {
+ const driverEnv = process.env.npm_config_drivers;
+ const pluginEnv = process.env.npm_config_plugins;
+
+ if (!driverEnv && !pluginEnv) {
+ console.log('Not auto-installing any drivers or plugins');
+ return;
+ }
+
+ let extension;
+ try {
+ extension = require('./build/lib/cli/extension');
+ } catch (e) {
+ throw new Error(`Could not load extension CLI file; has the project been transpiled? (${e})`);
+ }
+
+ const {DEFAULT_APPIUM_HOME, DRIVER_TYPE, PLUGIN_TYPE} = require('./build/lib/extension-config');
+ const {runExtensionCommand} = extension;
+ const appiumHome = process.env.npm_config_appium_home || DEFAULT_APPIUM_HOME;
+ const specs = [[DRIVER_TYPE, driverEnv], [PLUGIN_TYPE, pluginEnv]];
+
+ for (const [type, extEnv] of specs) {
+ if (extEnv) {
+ for (const ext of extEnv.split(',')) {
+ const extList = await runExtensionCommand({
+ appiumHome,
+ [`${type}Command`]: 'list',
+ showInstalled: true,
+ suppressOutput: true,
+ }, type);
+ if (extList[ext]) {
+ console.log(`The ${type} ${ext} was already installed, skipping...`);
+ continue;
+ }
+ console.log(`Installing the ${type} ${ext}...`);
+ await runExtensionCommand({
+ appiumHome,
+ [`${type}Command`]: 'install',
+ [type]: ext,
+ suppressOutput: true,
+ }, type);
+ }
+ }
+ }
+}
+
+if (require.main === module) {
+ main().then(() => {
+ process.exit(0);
+ }).catch((e) => {
+ console.error(e);
+ process.exit(1);
+ });
+}

feat: add auto-install params --drivers and --plugins