feat: add postinstall functionality for auto installing drivers and plugins
MODIFY
lib/cli/extension.js
lib/cli/extension.js
@@ -35,6 +35,11 @@ async function runExtensionCommand (args, type) {
await config.read();
jsonResult = await cmd.execute(args);
} catch (err) {
+ // in the suppress output case, we are calling this function internally and should
+ // just throw instead of printing an error and ending the process
+ if (suppressOutput) {
+ throw err;
+ }
errAndQuit(json, err);
}

MODIFY
postinstall.js
postinstall.js
@@ -14,7 +14,8 @@ async function main () {
try {
extension = require('./build/lib/cli/extension');
} catch (e) {
- throw new Error(`Could not load extension CLI file; has the project been transpiled? (${e})`);
+ throw new Error(`Could not load extension CLI file; has the project been transpiled? ` +
+ `(${e.message})`);
}
const {DEFAULT_APPIUM_HOME, DRIVER_TYPE, PLUGIN_TYPE} = require('./build/lib/extension-config');
@@ -25,6 +26,22 @@ async function main () {
for (const [type, extEnv] of specs) {
if (extEnv) {
for (const ext of extEnv.split(',')) {
+ try {
+ await checkAndInstallExtension({runExtensionCommand, appiumHome, type, ext});
+ } catch (e) {
+ console.log(`There was an error checking and installing ${type} ${ext}: ${e.message}`);
+ }
+ }
+ }
+ }
+}
+
+async function checkAndInstallExtension ({
+ runExtensionCommand,
+ appiumHome,
+ type,
+ ext,
+}) {
const extList = await runExtensionCommand({
appiumHome,
[`${type}Command`]: 'list',
@@ -33,7 +50,7 @@ async function main () {
}, type);
if (extList[ext]) {
console.log(`The ${type} ${ext} was already installed, skipping...`);
- continue;
+ return;
}
console.log(`Installing the ${type} ${ext}...`);
await runExtensionCommand({
@@ -43,9 +60,6 @@ async function main () {
suppressOutput: true,
}, type);
}
- }
- }
-}
if (require.main === module) {
main().then(() => {

feat: add postinstall functionality for auto installing drivers and plugins