|
| 1 | +# Developing |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | +[One-time Setup](#one-time-setup)</br> |
| 6 | +[Quick Start](#quick-start)</br> |
| 7 | +[Testing](#testing)</br> |
| 8 | +[Debugging](#debugging)</br> |
| 9 | +[Linking the Packaging Library](#linking-the-packaging-library)</br> |
| 10 | +[Running Commands](#running-commands)</br> |
| 11 | +[Useful Yarn Commands](#useful-yarn-commands)</br> |
| 12 | + |
| 13 | +<hr> |
| 14 | + |
| 15 | +## One-time Setup |
| 16 | + |
| 17 | +1. Install NodeJS. If you need to work with multiple versions of Node, you |
| 18 | + might consider using [nvm](https://github.com/creationix/nvm). </br>_Suggestion: use the current [LTS version of node](https://github.com/nodejs/release#release-schedule)._ |
| 19 | +1. Install [yarn](https://yarnpkg.com/) to manage node dependencies. </br>_Suggestion: install yarn globally using `npm install --global yarn`_ |
| 20 | +1. Clone this repository from git. E.g., (ssh): </ br> `git clone [email protected]:salesforcecli/plugin-packaging.git` |
| 21 | +1. Configure [git commit signing](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits). |
| 22 | + |
| 23 | +## Quick Start |
| 24 | + |
| 25 | +1. `cd` into the `plugin-packaging` directory |
| 26 | +1. Checkout the main branch: `git checkout main` |
| 27 | +1. Get all latest changes: `git pull` |
| 28 | +1. Download NPM dependencies: `yarn install`. If it's been a while since you last did this you may want to run `yarn clean-all` before this step. |
| 29 | +1. Build and lint the code: `yarn build` |
| 30 | +1. Create a branch off main for new work: `git checkout -b <branch_name>` _Suggestion: use branch_name format of initials/work-title_. For external contributors, please fork the main branch of the repo instead and PR the fork to the main branch. |
| 31 | +1. Make code changes and build: `yarn build` |
| 32 | +1. Run changed commands: `./bin/dev force:package:beta:create -h` |
| 33 | +1. Write tests and run: `yarn test` (unit) and/or `yarn test:nuts` (NUTs) |
| 34 | +1. Show all changed files: `git status` |
| 35 | +1. Add all files to staging: `git add .` |
| 36 | +1. Commit staged files with helpful commit message: `git commit` |
| 37 | +1. Push commit(s) to remote: `git push -u origin <branch_name>` |
| 38 | +1. Create a pull request (PR) using the GitHub UI [here](https://github.com/salesforcecli/plugin-packaging). |
| 39 | + |
| 40 | +## Testing |
| 41 | + |
| 42 | +All changes must have associated tests. This library uses a combination of unit testing and NUTs (non-unit tests). |
| 43 | + |
| 44 | +### Unit tests |
| 45 | + |
| 46 | +Unit tests are run with `yarn test` and use the mocha test framework. Tests are located in the test directory and are named with the pattern, `<test-file>.test.ts`. E.g., [install.test.ts](test/commands/force/package/install.test.ts). Reference the existing unit tests when writing and testing code changes. |
| 47 | + |
| 48 | +### NUTs (non-unit tests) |
| 49 | + |
| 50 | +Non-unit tests are run with `yarn test:nuts` and use the [cli-plugin-testkit](https://github.com/salesforcecli/cli-plugins-testkit) framework. These tests run using the default devhub in your environment. If you're running the 1GP package NUTs you will need to set the `ONEGP_TESTKIT_AUTH_URL` environment variable as a target org. NUTs are a way to test the library code in a real environment versus a unit test environment where many things are stubbed. |
| 51 | + |
| 52 | +## Debugging |
| 53 | + |
| 54 | +If you need to debug plugin code or tests you should refer to the excellent documentation on this topic in the [Plugin Developer Guide](https://github.com/salesforcecli/cli/wiki/Debug-Your-Plugin). |
| 55 | + |
| 56 | +## Linking the packaging library |
| 57 | + |
| 58 | +When you want to use a branch of the packaging library in this plugin to test changes, reference [this doc](https://github.com/forcedotcom/packaging/blob/main/DEVELOPING.md#linking-to-the-packaging-plugin) in the packaging library. |
| 59 | + |
| 60 | +## Running Commands |
| 61 | + |
| 62 | +To run your modified plugin commands locally, use `./bin/dev` or `./bin/dev.cmd` file, which uses ts-node to execute the plugin's TypeScript commands. |
| 63 | + |
| 64 | +```bash |
| 65 | +# Run using local dev file. |
| 66 | +./bin/dev force:package:create --help |
| 67 | +``` |
| 68 | + |
| 69 | +There should be no differences when running via the Salesforce CLI or using the local scripts. However, it can be useful to link the plugin to do some additional testing or run your commands from anywhere on your machine. |
| 70 | + |
| 71 | +```bash |
| 72 | +# Link your plugin to the sfdx cli |
| 73 | +sfdx plugins:link . |
| 74 | +# To verify |
| 75 | +sfdx plugins |
| 76 | +# To run |
| 77 | +sfdx force:package:create --help |
| 78 | +``` |
| 79 | + |
| 80 | +## Useful yarn commands |
| 81 | + |
| 82 | +#### `yarn install` |
| 83 | + |
| 84 | +This downloads all NPM dependencies into the node_modules directory. |
| 85 | + |
| 86 | +#### `yarn compile` |
| 87 | + |
| 88 | +This compiles the typescript to javascript. |
| 89 | + |
| 90 | +#### `yarn lint` |
| 91 | + |
| 92 | +This lints all the typescript using eslint. |
| 93 | + |
| 94 | +#### `yarn build` |
| 95 | + |
| 96 | +This compiles and lints all the typescript (e.g., `yarn compile && yarn lint`). |
| 97 | + |
| 98 | +#### `yarn clean` |
| 99 | + |
| 100 | +This cleans all generated files and directories. Run `yarn clean-all` to also clean up the node_module directories. |
| 101 | + |
| 102 | +#### `yarn test` |
| 103 | + |
| 104 | +This runs unit tests (mocha) for the project using ts-node. |
| 105 | + |
| 106 | +#### `yarn test:nuts` |
| 107 | + |
| 108 | +This runs NUTs (non-unit tests) for the project using ts-node. |
0 commit comments