From b45eb4b113470d9ebfbfa33552290dab4fbfb113 Mon Sep 17 00:00:00 2001 From: 0xdef1cafe <88504456+0xdef1cafe@users.noreply.github.com> Date: Tue, 12 Oct 2021 11:58:05 -0600 Subject: [PATCH] chore: yarn link scripts and docs --- .eslintignore | 1 + README.md | 41 ++++++++++++++++++++++++++++++++++++++++- package.json | 2 ++ scripts/linkPackages.js | 19 +++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 scripts/linkPackages.js diff --git a/.eslintignore b/.eslintignore index d3f9eede2..8e3e09169 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,3 +3,4 @@ node_modules config babel.config.js generated +scripts diff --git a/README.md b/README.md index 0907bc3c6..d4abe1d77 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,45 @@ yarn ``` +If you're working in this repo, you're likely also working in [web](https://github.com/shapeshift/web). Run the following command to automatically `yarn link` all the packages in this repo so they can also be linked in `web` + +```bash +➜ yarn link-packages +yarn run v1.22.15 +$ node scripts/linkPackages.js link +success Registered "@shapeshiftoss/asset-service". +info You can now run `yarn link "@shapeshiftoss/asset-service"` in the projects where you want to use this package and it will be used instead. +success Registered "@shapeshiftoss/chain-adapters". +info You can now run `yarn link "@shapeshiftoss/chain-adapters"` in the projects where you want to use this package and it will be used instead. +success Registered "@shapeshiftoss/market-service". +info You can now run `yarn link "@shapeshiftoss/market-service"` in the projects where you want to use this package and it will be used instead. +success Registered "@shapeshiftoss/swapper". +info You can now run `yarn link "@shapeshiftoss/swapper"` in the projects where you want to use this package and it will be used instead. +success Registered "@shapeshiftoss/types". +info You can now run `yarn link "@shapeshiftoss/types"` in the projects where you want to use this package and it will be used instead. + +✨ Done in 0.47s. +``` + +Similary you can unlink packages, which can be useful for debugging failing CI runs +```bash +➜ yarn unlink-packages +yarn run v1.22.15 +$ node scripts/linkPackages.js unlink +success Unregistered "@shapeshiftoss/asset-service". +info You can now run `yarn unlink "@shapeshiftoss/asset-service"` in the projects where you no longer want to use this package. +success Unregistered "@shapeshiftoss/chain-adapters". +info You can now run `yarn unlink "@shapeshiftoss/chain-adapters"` in the projects where you no longer want to use this package. +success Unregistered "@shapeshiftoss/market-service". +info You can now run `yarn unlink "@shapeshiftoss/market-service"` in the projects where you no longer want to use this package. +success Unregistered "@shapeshiftoss/swapper". +info You can now run `yarn unlink "@shapeshiftoss/swapper"` in the projects where you no longer want to use this package. +success Unregistered "@shapeshiftoss/types". +info You can now run `yarn unlink "@shapeshiftoss/types"` in the projects where you no longer want to use this package. + +✨ Done in 0.37s. +``` + ## Testing Bug fixes and features should always come with tests, when applicable. Test files should live next to the file they are testing. Before submitting your changes in a pull request, always run the full test suite. @@ -23,7 +62,7 @@ yarn test:dev **Helpful Testing Process** -One technique that can helpful when writing tests, is to reference the coverage report for the file/function/feature you're testing. To do this, run `yarn test:dev` from your terminal. This will generate a coverage report for the project in the `coverage` directory. To view the report, open the file `coverage/lcov-report/index.html`. +One technique that can helpful when writing tests, is to reference the coverage report for the file/function/feature you're testing. To do this, run `yarn test:dev` from your terminal. This will generate a coverage report for the project in the `coverage` directory. To view the report, open the file `coverage/lcov-report/index.html`. ## Contributing diff --git a/package.json b/package.json index 3384a7595..52855644f 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "clean": "rimraf node_modules dist packages/**/dist", "dev": "lerna run dev --stream --parallel", "lint": "eslint --cache .", + "link-packages": "node scripts/linkPackages.js link", + "unlink-packages": "node scripts/linkPackages.js unlink", "test": "jest", "test:dev": "jest --watch", "type-check": "lerna run type-check", diff --git a/scripts/linkPackages.js b/scripts/linkPackages.js new file mode 100644 index 000000000..f6a90d554 --- /dev/null +++ b/scripts/linkPackages.js @@ -0,0 +1,19 @@ +const { readdirSync } = require('fs') +const util = require('util') +const exec = util.promisify(require('child_process').exec) + +async function main() { + // link or unlink + const args = process.argv.slice(2) + const prefix = args[0] === 'unlink' ? 'un' : '' + // get package names + const lsPackages = readdirSync('packages', { withFileTypes: true }) + const packageDirectories = lsPackages.filter(dir => dir.isDirectory()) + const packageNames = packageDirectories.map(({ name }) => name) + // do linky things + const promises = packageNames.map(async package => (await exec(`cd packages/${package} && yarn ${prefix}link --colors`)).stdout) + const result = (await Promise.all(promises)).join('') + console.log(result) +} + +main()