From 13b438f8d83d02e8ff57f50530c072687c718c92 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Wed, 24 Aug 2022 07:39:01 +0200 Subject: [PATCH] refactor: Decouple the module from @appium/gulp-plugins (#70) --- .eslintignore | 1 + .eslintrc | 3 -- .eslintrc.json | 11 +++++++ .github/workflows/node.js.yml | 9 +++--- .github/workflows/publish.js.yml | 4 +-- .mocharc.js | 4 +++ README.md | 11 ++----- babel.config.json | 25 +++++++++++++++ gulpfile.js | 14 --------- lib/xcode.js | 9 ++++-- package.json | 54 ++++++++++++++++++++++---------- test/.eslintrc | 5 --- test/{ => e2e}/xcode-specs.js | 4 +-- test/{ => unit}/index-specs.js | 4 +-- 14 files changed, 95 insertions(+), 63 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.json create mode 100644 .mocharc.js create mode 100644 babel.config.json delete mode 100644 gulpfile.js delete mode 100644 test/.eslintrc rename test/{ => e2e}/xcode-specs.js (98%) rename test/{ => unit}/index-specs.js (75%) diff --git a/.eslintignore b/.eslintignore index 4ebc8ae..fb7020d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ coverage +build diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 47415a5..0000000 --- a/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "@appium/eslint-config-appium" -} diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..69a602c --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,11 @@ +{ + "extends": "@appium/eslint-config-appium", + "overrides": [ + { + "files": "test/**/*.js", + "rules": { + "func-names": "off" + } + } + ] +} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 028df2c..6cefcd3 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,17 +1,16 @@ name: Node.js CI on: [push, pull_request] env: - NODE_VERSION: 14.x + NODE_VERSION: 16.x jobs: build: - # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md - runs-on: macos-10.15 + runs-on: macos-11 strategy: matrix: - xcode-version: ["10.3", "11.7", "12.4"] + xcode-version: ["11.7", "12.4", "13.2"] steps: - uses: actions/checkout@v2 @@ -21,5 +20,5 @@ jobs: node-version: ${{ env.NODE_VERSION }} - name: Select Xcode ${{ matrix.xcode-version }} run: sudo xcode-select --switch /Applications/Xcode_${{ matrix.xcode-version }}.app - - run: npm run clean + - run: npm install - run: _FORCE_LOGS=1 npm run test diff --git a/.github/workflows/publish.js.yml b/.github/workflows/publish.js.yml index c31062f..367590c 100644 --- a/.github/workflows/publish.js.yml +++ b/.github/workflows/publish.js.yml @@ -10,10 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Use Node.js 14.x + - name: Use Node.js 18.x uses: actions/setup-node@v1 with: - node-version: 14.x + node-version: 18.x - run: npm install --no-package-lock name: Install dev dependencies - run: npm test diff --git a/.mocharc.js b/.mocharc.js new file mode 100644 index 0000000..66d4a97 --- /dev/null +++ b/.mocharc.js @@ -0,0 +1,4 @@ +module.exports = { + require: ['@babel/register'], + forbidOnly: Boolean(process.env.CI) +}; diff --git a/README.md b/README.md index 5bcb4fa..14552af 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ appium-xcode ES7 module for interacting with Xcode and Xcode-related functions. Used by [Appium](github.com/appium/appium) -*Note*: Issue tracking for this repo has been disabled. Please use the [main Appium issue tracker](https://github.com/appium/appium/issues) instead. - API === @@ -66,16 +64,11 @@ clears the internal cache used for memoizing functions. Develop ======= -## Watch - -``` -npm run watch -``` - ## Test ``` npm test +npm e2e-test ``` Debug @@ -83,4 +76,4 @@ Debug After cloning appium-xcode, execute `npm link` in the appium-xcode directory. Next run `npm link appium-xcode` from the appium directory. This will symlink appium-xcode to node_modules/appium-xcode. If the clone becomes out of date remember to unlink or delete node_modules and reinstall. -For quick debugging you could cd into the node_modules/appium-xcode folder and run `npm install` followed by `gulp transpile`. +For quick debugging you could cd into the node_modules/appium-xcode folder and run `npm install` followed by `npm run build`. diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 0000000..048e9cf --- /dev/null +++ b/babel.config.json @@ -0,0 +1,25 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "14" + }, + "shippedProposals": true + } + ] + ], + "plugins": [ + "source-map-support", + "@babel/plugin-transform-runtime" + ], + "comments": false, + "sourceMaps": "both", + "env": { + "test": { + "retainLines": true, + "comments": true + } + } +} diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index ec3f613..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -const gulp = require('gulp'); -const boilerplate = require('@appium/gulp-plugins').boilerplate.use(gulp); -const DEFAULTS = require('@appium/gulp-plugins').boilerplate.DEFAULTS; - -boilerplate({ - build: 'Appium Xcode', - files: DEFAULTS.files.concat('index.js'), - coverage: { - files: ['./build/test/**/*-specs.js', '!./build/test/**/*-e2e-specs.js'], - verbose: true, - }, -}); diff --git a/lib/xcode.js b/lib/xcode.js index 01571ba..e40018f 100644 --- a/lib/xcode.js +++ b/lib/xcode.js @@ -105,11 +105,16 @@ async function getPathFromXcodeSelect (timeout = XCRUN_TIMEOUT) { const getPath = _.memoize(function getPath (timeout = XCRUN_TIMEOUT) { // first we try using xcode-select to find the path // then we try using the symlinks that Apple has by default - return getPathFromXcodeSelect(timeout).catch(getPathFromSymlink); + return (async () => { + try { + return await getPathFromXcodeSelect(timeout); + } catch (e) { + return await getPathFromSymlink(e.message); + } + })(); }); - async function getVersionWithoutRetry (timeout = XCRUN_TIMEOUT) { const xcodePath = await getPath(timeout); diff --git a/package.json b/package.json index 629e9b2..7e8dee9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "xcode" ], "version": "4.0.0", - "author": "appium", + "author": "Appium Contributors", "license": "Apache-2.0", "repository": { "type": "git", @@ -16,9 +16,10 @@ "bugs": { "url": "https://github.com/appium/appium-xcode/issues" }, - "engines": [ - "node" - ], + "engines": { + "node": ">=14", + "npm": ">=8" + }, "main": "./build/index.js", "bin": {}, "directories": { @@ -41,32 +42,51 @@ "teen_process": "^2.0.0" }, "scripts": { - "clean": "rm -rf node_modules && rm -f package-lock.json && npm install", - "prepare": "gulp prepublish", - "test": "gulp once", - "watch": "gulp watch", - "mocha": "mocha", - "build": "gulp transpile", - "e2e-test": "gulp e2e-test", - "coverage": "gulp coveralls", + "build": "rm -rf build && babel --out-dir=build/lib lib && babel --out-dir=build index.js", + "dev": "npm run build -- --watch", + "lint": "eslint .", + "lint:fix": "npm run lint -- --fix", + "precommit-lint": "lint-staged", "precommit-msg": "echo 'Pre-commit checks...' && exit 0", - "lint": "gulp lint", - "lint:fix": "gulp eslint --fix" + "prepare": "npm run build", + "test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"", + "e2e-test": "mocha --exit --timeout 5m \"./test/e2e/**/*-specs.js\"" }, "pre-commit": [ "precommit-msg", - "test" + "precommit-lint" ], + "lint-staged": { + "*.js": [ + "eslint --fix" + ] + }, + "prettier": { + "bracketSpacing": false, + "printWidth": 100, + "singleQuote": true + }, "devDependencies": { - "@appium/gulp-plugins": "^7.0.0", "@appium/eslint-config-appium": "^6.0.0", + "@babel/cli": "^7.18.10", + "@babel/core": "^7.18.10", + "@babel/eslint-parser": "^7.18.9", + "@babel/plugin-transform-runtime": "^7.18.10", + "@babel/preset-env": "^7.18.10", + "@babel/register": "^7.18.9", "@semantic-release/git": "^10.0.1", + "babel-plugin-source-map-support": "^2.2.0", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", + "eslint": "^7.32.0", "eslint-config-prettier": "^8.5.0", - "gulp": "^4.0.0", + "eslint-plugin-import": "^2.26.0", + "eslint-plugin-mocha": "^9.0.0", + "eslint-plugin-promise": "^6.0.0", + "lint-staged": "^13.0.3", "mocha": "^10.0.0", "pre-commit": "^1.1.3", + "prettier": "^2.7.1", "semantic-release": "^19.0.2" } } diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 6c8f75a..0000000 --- a/test/.eslintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "func-names": 0 - } -} diff --git a/test/xcode-specs.js b/test/e2e/xcode-specs.js similarity index 98% rename from test/xcode-specs.js rename to test/e2e/xcode-specs.js index 0347948..d1df7f7 100644 --- a/test/xcode-specs.js +++ b/test/e2e/xcode-specs.js @@ -1,6 +1,4 @@ -// transpile:mocha - -import xcode from '../index'; +import xcode from '../../index'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { fs, util } from '@appium/support'; diff --git a/test/index-specs.js b/test/unit/index-specs.js similarity index 75% rename from test/index-specs.js rename to test/unit/index-specs.js index fab8135..8869c19 100644 --- a/test/index-specs.js +++ b/test/unit/index-specs.js @@ -1,6 +1,4 @@ -// transpile:mocha - -import xcode from '../index.js'; +import xcode from '../../index.js'; import chai from 'chai'; chai.should();