Environment Setup
Development Cycle
Testing
• Unit Tests
• NUTs (Non-Unit Tests)
Debugging
Running Commands
Useful Yarn Commands
- Install NodeJS. If you need to work with multiple versions of Node, consider using nvm.
- Suggestion: Use the current LTS version of node.
- Install yarn v1 to manage node dependencies.
- Suggestion: install
yarnglobally usingnpm install --global yarn
- Suggestion: install
- Clone this repository from Github.
- External contributors must fork the
mainbranch of the repo - Internal committers can clone the
mainbranch directly.- Example (ssh):
git clone [email protected]:salesforcecli/plugin-bre-to-cml.git
- Example (ssh):
- External contributors must fork the
- Configure git commit signing.
cdinto theplugin-bre-to-cmldirectory- Checkout the
mainbranch:git checkout main - Get all latest changes:
git pull - Install NPM dependencies:
yarn install.- If it's been a while since you last did this you may want to run
yarn clean-allbefore this step.
- If it's been a while since you last did this you may want to run
- Build and lint the code:
yarn build - Create a branch off
mainfor new work:git checkout -b <branch_name>- Suggestion: Use branch name format of
<initials>/<work-title>.- Example:
mb/refactor-tests
- Example:
- Suggestion: Use branch name format of
- Make code changes and build:
yarn build - Run changed commands: e.g.,
./bin/run.js my-topic my-command - Write tests and run:
yarn test(unit) and/oryarn test:nuts(NUTS) - Show all changed files:
git status - Add all files to staging:
git add . - Commit staged files with helpful commit message:
git commit- Important: We use conventional commits to drive semver versioning. Examples:
chore: my chore message--> No releasefix: my fix message--> Patch releasefeat: my feat message--> Minor release
- Important: We use conventional commits to drive semver versioning. Examples:
- Push commit(s) to remote:
git push -u origin <branch_name> - Create a pull request (PR) using the GitHub UI here.
All changes must have associated tests. This library uses a combination of unit testing and NUTs (non-unit tests).
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/commands/my-topic/my-command/<test-file>.test.ts. Notice that the directory structure is similar to the commands in the src directory. Use existing unit tests as a guide when writing and testing code changes.
Non-unit tests are run with yarn test:nuts and use the cli-plugin-testkit framework. These tests run using the default devhub in your environment. NUTs are a way to test the library code in a real environment versus a unit test environment where many things are stubbed.
If you need to debug plugin code or tests you should refer to the excellent documentation on this topic in the Plugin Developer Guide.
To run your modified plugin commands locally, use ./bin/run.js or ./bin/run.cmd (Windows). Note that you must compile any code changes (yarn build) before seeing those changes with ./bin/run.js. You can also use yarn build --watch to auto-build files when saved.
# Run using local script.
./bin/run.js my-topic my-commandThere should be no differences when running via the Salesforce CLI or using the local bin scripts. However, it can be useful to link the plugin to the CLI to do some additional testing or run your commands from anywhere on your machine.
# Link your plugin to the sf cli
sf plugins link .
# To verify
sf plugins
# To run
sf my-topic my-commandThis downloads all NPM dependencies into the node_modules directory.
This compiles the typescript to javascript.
This watches for file changes and compiles the typescript to javascript.
This lints all the typescript using eslint.
This compiles and lints all the typescript (e.g., yarn compile && yarn lint).
This cleans all generated files and directories. Run yarn clean-all to also clean up the node_modules directories.
This runs unit tests (mocha) for the project using ts-node.
This runs NUTs (non-unit tests) for the project using ts-node.