Skip to content

Instantly share code, notes, and snippets.

@dpgraham
Last active January 18, 2019 22:36
Show Gist options
  • Save dpgraham/fc2f899573dc981a1b689f12fa6313eb to your computer and use it in GitHub Desktop.
Save dpgraham/fc2f899573dc981a1b689f12fa6313eb to your computer and use it in GitHub Desktop.
## Summary
The [proof of concept](https://github.com/dpgraham/appium/tree/dpgraham-monorepo) is a monorepo with [Lerna](https://lernajs.io), where the repo has scoped NPM packages that export drivers (`@appium/xcuitest-driver`, `@appium/espresso-driver`, etc...). The package `appium` is a CLI that installs and manages these drivers.
## Description
* Appium 1.x imports and bundles together all drivers. The PoC breaks Appium into different packages.
* One package is `@appium/builder`, which does almost exactly what `appium/appium@1` does, except instead of running the Appium server, it exposes an API that is used to build and run an Appium server.
```
//example usage
new AppiumBuilder()
.withAutomation('appium-xcuitest-driver', XCUITestDriver)
.withAutomation('appium-espresso-driver', EspressoDriver)
.run()
```
* The package `appium` is a CLI that installs drivers, uninstalls drivers, etc... (all the things discussed in the proposal). It uses `@appium/builder` to take the installed drivers and run them. The drivers are installed to a directory that is kept on the user's filesystem.
```
// appium/lib/index.js
#!/usr/bin/env node
// transpile:main
module.exports = require('@oclif/command');
import { asyncify } from 'asyncbox';
import path from 'path';
import AppiumBuilder from '@appium/builder';
import _ from 'lodash';
async function main (args = null) {
const drivers = require(path.resolve('appium-drivers', 'drivers.json'));
const builder = new AppiumBuilder();
for (let [name, packageInfo] of _.toPairs(drivers)) {
const packageName = packageInfo.package;
const driver = require(path.resolve('appium-drivers', 'node_modules', packageName)).default;
builder.withAutomation(name, driver);
}
return await builder.run(args);
}
if (require.main === module) {
asyncify(main);
}
export { main };
```
## Versioning and publishing
* The monorepo approach with Lerna allows one-stop versioning and publishing. The drivers can all be published with one command `lerna publish` which publishes the packages in the repo, and only publishes packages that have changed since the last time they were published.
* We can keep doing Appium versioning via Git tags (2.0.0, 2.1.0, 2.1.1, ...) and use the semver-esque versioning schema that we're currently using
* The packages will be published to NPM and use strict semver versioning
## Packages
* `appium`: The CLI that installs and manages the drivers. Uses `@appium/builder` as a dependency to run the drivers.
* `@appium/builder`: A package that is used to build Appium servers
* `@appium/xcuitest`: A package that exports `appium-xcuitest-driver`
* `@appium/uiautomator2`: A package that exports `appium-uiautomator2-driver`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment