Skip to main content

Setup your development environment

Setting up your local copy of the project for development and testing is essential. Follow the steps below to configure your environment.

Install prerequisites

Before you start contributing to this project, you will need node@20 and npm@10 installed.

tip

To avoid having to install all dependencies by hand you can use Github Codespaces or our dev container. More information can be found under GitHub Codespaces & Visual Studio Remote Development Container.

Getting your local version of the CLI

Setting up your GitHub fork

  1. Navigate to the CLI for Microsoft 365 repository.
  2. Fork this repository. On the GitHub repository page, click the "Fork" button to create your own copy of the repository.
    • Make sure the option 'Copy the main branch only' is selected.
  3. Clone the forked repository to your local machine using Git. Navigate to a folder where you want to store your local copy of the CLI. Then execute the following command in your terminal: git clone [repository URL of your fork].
tip

For more insights about forking a repository, refer to the GitHub Docs - Fork a repo guide.

Setting up your local project

After you've cloned your fork onto your device, navigate to the project directory and execute the following commands to get the project running.

note

If you have installed the CLI globally using the npm i -g @pnp/cli-microsoft365 command, we recommend that you uninstall it, using npm un -g @pnp/cli-microsoft365, before running npm link.

  1. Run npm i to restore all project dependencies.
  2. Run npm run build to build the entire project.
  3. Run npm link to create a link/reference to your local project. This allows you to reference your locally installed CLI instead of the npm-hosted package.

That's it! If you run m365 version now, you will see that you are using the beta version of CLI for Microsoft 365 in your shell!

Visual Studio Code extensions

Although you can use any IDE, we recommend using Visual Studio Code. When using VS Code, the following extensions will come in handy:

ExtensionWhy is it useful?
Mocha Test ExplorerThis extension helps you when writing tests. It can run individual tests and facilitate debugging. You also get a nice overview of all tests within the project.
ESLintWe use ESLint to ensure code consistency within the project. By installing this extension, you will be notified of problems while writing code.
MDXWe use MDX to write our documentation. This extension provides syntax highlighting and other useful features when writing MDX files.

Npm scripts

During your development, you will need a set of commands to test, run, and validate your code. The CLI for Microsoft 365 comes with a set of commands that you can use for each occasion.

CommandDescription
npm run watchBuilds the entire project first. After this, a watcher will trigger an incremental build every time a file is saved. This means that only the changed files are rebuilt, not the entire project. You typically use this command while developing.
npm run buildBuilds the entire project.
npm run cleanCleans the output directory by deleting all built files.
npm run testRuns all tests and checks all ESLint rules. This is a combination of npm run test:cov and npm run lint. Our GitHub workflows execute this command to validate every new PR.
npm run test:covRuns all tests and creates a coverage report.

With these commands at your disposal, you're ready to contribute to the CLI for Microsoft 365 repository!

Next steps

Now that your local environment is ready to go, you can take the following steps to start contributing to the CLI for Microsoft 365:

Adding a new command

Learn how to add a new command to the CLI for Microsoft 365 by following these steps:

  1. New Command Sample
  2. Command Logic
  3. Unit Tests
  4. Help Page
  5. Submitting the Pull Request (PR)

Adding a new script sample

Explore the process of adding a new script sample to the CLI for Microsoft 365 with the following steps:

  1. Adding a Script Sample
  2. Submitting the Pull Request (PR)
CTRL + M