|
1 | 1 | # Contributing
|
2 | 2 |
|
3 |
| -This project has adopted the [Microsoft Open Source Code of Conduct ](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
| 3 | +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). |
| 4 | +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact |
| 5 | +[[email protected]](mailto:[email protected]) with any additional questions or comments. |
| 6 | + |
| 7 | +## Table of contents |
| 8 | + |
| 9 | +* [Prerequisites](#prerequisites) |
| 10 | +* [Build the code](#build-the-code) |
| 11 | + * [Troubleshoot](#troubleshoot) |
| 12 | +* [Run `oad` locally from sources](#run-oad-locally-from-sources) |
| 13 | +* [Install `oad` globally from sources or npm feed](#install-oad-globally-from-sources-or-npm-feed) |
| 14 | + * [Uninstall `oad` globally](#uninstall-oad-globally) |
| 15 | +* [Purge the obsolete `oad` package from your system](#purge-the-obsolete-oad-package-from-your-system) |
| 16 | + |
| 17 | +<!-- <small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'> |
| 18 | +Table of contents generated with markdown-toc</a></i></small> --> |
4 | 19 |
|
5 | 20 | ## Prerequisites
|
6 | 21 |
|
7 |
| -- [Node.js](https://nodejs.org/) (14.x or higher) |
8 |
| -- [.NET runtime and SDK](https://aka.ms/dotnet-download) |
9 |
| -- [.NET CLI tools](https://github.com/dotnet/cli/releases) version 2.0.0 or higher |
| 22 | +To execute any instructions in this file, first ensure you fulfill all the following prerequisites: |
10 | 23 |
|
11 |
| -## Build scripts |
| 24 | +1. Install [Node.js](https://nodejs.org/), version 14.x or higher. |
| 25 | +1. Install [.NET runtime and SDK](https://aka.ms/dotnet-download), version 6 or higher. |
| 26 | +1. Install [.NET CLI tools](https://github.com/dotnet/cli/releases) version 2.0.0 or higher. |
| 27 | +1. Execute all commands in this file from your [`openapi-diff`] git repo local clone root dir. |
| 28 | +1. Run `npm install` to install the required node modules. |
12 | 29 |
|
13 |
| -Run `npm install` to install the required modules. |
| 30 | +## Build the code |
14 | 31 |
|
15 |
| -```sh |
16 |
| -npm install |
17 |
| -``` |
| 32 | +`openapi-diff` is composed both of TypeScript and .NET/C# projects, all of which have to be built |
| 33 | +to be able to run the tool locally from sources. |
18 | 34 |
|
19 |
| -## How to build the C# code |
| 35 | +The core logic for `openapi-diff` is written in C# and compiled to a .NET binary. |
| 36 | +The CLI for `openapi-diff` is written in TypeScript and compiled to a Node.js binary. |
20 | 37 |
|
21 |
| -The core logic for openapi-diff is written in C# and compiled to a .NET binary. |
| 38 | +| Build command | Effect | |
| 39 | +|-|-| |
| 40 | +| `npm run dn.build` | Runs [`dotnet build`] and related commands to build the C# code. | |
| 41 | +| `npm run tsc` | Builds the TypeScript code. | |
22 | 42 |
|
23 |
| -Use `dn.build` npm script to build the C# code. |
| 43 | +For more commands, see the [`package.json`](/package.json) `scripts` element. |
| 44 | +Notably: |
24 | 45 |
|
25 |
| -```sh |
26 |
| -npm run dn.build |
27 |
| -``` |
| 46 | +| Command | Effect | |
| 47 | +|-|-| |
| 48 | +| `npm run dn.restore` | Runs [`dotnet restore`] in preparation to build the C# code. | |
| 49 | +| `npm run dn.test` | Runs [`dotnet test`] and related commands to test the C# code. | |
28 | 50 |
|
29 |
| -## How to test the C# code |
| 51 | +### Troubleshoot |
30 | 52 |
|
31 |
| -To run all tests under the repo |
| 53 | +If the `npm run dn.build` command outputs error like: |
32 | 54 |
|
33 |
| -```sh |
34 |
| -npm run dn.test |
35 |
| -``` |
| 55 | +> C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targe |
| 56 | + ts(266,5): error NETSDK1005: Assets file 'C:\(...)\openapi-diff\src\core\OpenApiDiff\ob |
| 57 | + j\project.assets.json' doesn't have a target for 'netcoreapp6.0'. Ensure that restore has run and that you have |
| 58 | + included 'netcoreapp6.0' in the TargetFrameworks for your project. |
| 59 | + |
| 60 | +Then first run `npm run dn.restore` and then run the `npm run dn.build` command again. |
36 | 61 |
|
37 |
| -## How to build the TypeScript code |
| 62 | +## Run `oad` locally from sources |
38 | 63 |
|
39 |
| -The CLI for openapi-diff is written in TypeScript and compiled to a Node.js binary. |
| 64 | +After you have built the C# and TypeScript code, you can run the `openapi-diff` aka `oad` tool locally. |
40 | 65 |
|
41 |
| -Use `tsc` npm script to build the TypeScript code. |
| 66 | +1. Run [`npm link`] once. |
| 67 | +2. Then you can use `oad` by running `oad -h`. |
| 68 | + |
| 69 | +> [!CAUTION] |
| 70 | +> Following commands have different behavior: `oad`, `oad -h`, `oad --help`. |
| 71 | +> As of 11/2/2023 only `oad -h` appears to work as intended. |
| 72 | +
|
| 73 | +## Install `oad` globally from sources or npm feed |
| 74 | + |
| 75 | +You can also install the `oad` tool globally and run it from anywhere. |
42 | 76 |
|
43 | 77 | ```sh
|
44 |
| -npm run tsc |
| 78 | +npm list -g @azure/oad # verify oad is not installed globally |
| 79 | +npm install -g # Install oad from local repo clone source |
| 80 | +npm list -g @azure/oad # verify oad is installed |
| 81 | +oad --version # verify correct version got installed. |
| 82 | +oad -h |
45 | 83 | ```
|
46 | 84 |
|
47 |
| -## How to run locally |
| 85 | +> [!CAUTION] |
| 86 | +> Be careful to use `@azure/oad` and not `oad` as the latter is an obsolete, deprecated package. |
| 87 | +<!-- markdownlint-disable MD028 --> |
| 88 | +<!-- Disabling warning about empty line inside blockquote --> |
| 89 | +> [!TIP] |
| 90 | +> If you want to install `oad` not from your local sources, but the latest from the npm feed, |
| 91 | +> use this alternative `npm install`: |
| 92 | +> `npm install -g @azure/oad` |
48 | 93 |
|
49 |
| -After you have built the C# and TypeScript code, you can run the openapi-diff tool locally. |
50 |
| -To run the openapi-diff tool locally, use the `npm run start` command. |
| 94 | +### Uninstall `oad` globally |
51 | 95 |
|
52 |
| -```sh |
53 |
| -node dist/cli.js --help |
| 96 | +To uninstall `oad` globally: |
| 97 | + |
| 98 | +``` sh |
| 99 | +# if installed from sources |
| 100 | +npm uninstall -g |
| 101 | +# if installed from npm feed |
| 102 | +npm uninstall -g @azure/oad |
54 | 103 | ```
|
55 | 104 |
|
56 |
| -You can also install the package globally and run it from anywhere. |
| 105 | +## Purge the obsolete `oad` package from your system |
57 | 106 |
|
58 |
| -```sh |
59 |
| -npm install -g |
60 |
| -oad --help |
| 107 | +To purge the obsolete, deprecated `oad` package from your system, including [the cache]. |
| 108 | + |
| 109 | +``` sh |
| 110 | +# To remove oad from the cache |
| 111 | +npm cache ls oad |
| 112 | +npm cache clean <copy paste here entries from "ls oad"> # run once per each entry from "ls oad" |
| 113 | +npm cache verify # to fix the cache after removing oad |
| 114 | + |
| 115 | +# To remove oad from the local node_modules |
| 116 | +npm uninstall oad |
| 117 | +npm list oad # Should denote no packages installed |
| 118 | + |
| 119 | +# To remove oad from the global node_modules |
| 120 | +npm uninstall -g oad |
| 121 | +npm list -g oad # Should denote no packages installed |
61 | 122 | ```
|
| 123 | + |
| 124 | +[`openapi-diff`]: https://github.com/Azure/openapi-diff |
| 125 | +[`dotnet restore`]: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore |
| 126 | +[`dotnet build`]: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build |
| 127 | +[`dotnet test`]: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test |
| 128 | +[`npm link`]: https://docs.npmjs.com/cli/v10/commands/npm-link |
| 129 | +[the cache]: https://docs.npmjs.com/cli/v10/configuring-npm/folders#cache |
0 commit comments