Skip to content

Commit

Permalink
docs(nx-dev): creating conformance rules docs adjustments (#30038)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj authored and jaysoo committed Feb 18, 2025
1 parent f15ed12 commit fd07af5
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ nx generate @nx/js:library cloud-conformance-rules
The Nx Cloud distribution mechanism expects each rule to be created in a named subdirectory in the `src/` directory of our new project, and each rule directory to contain an `index.ts` and a `schema.json` file. You can read more about [creating a conformance rule](/nx-api/powerpack-conformance/documents/create-conformance-rule) in the dedicated guide. For this recipe, we'll generate a default rule to use in the publishing process.

```shell
nx g @nx/powerpack-conformance:create-rule --name=test-cloud-rule --directory=cloud-conformance-rules/src/test-cloud-rule --category=reliability --description="A test cloud rule" --reporter=non-project-files-reporter
nx g @nx/powerpack-conformance:create-rule --name=test-cloud-rule --directory=cloud-conformance-rules/src --category=reliability --description="A test cloud rule" --reporter=non-project-files-reporter
```

We now have a valid implementation of a rule and we are ready to build it and publish it to Nx Cloud. The [`@nx/powerpack-conformance` plugin](/nx-api/powerpack-conformance) provides a [dedicated executor called `bundle-rules`](/nx-api/powerpack-conformance/executors/bundle-rules) for creating appropriate build artifacts for this purpose, so we will wire that executor up to a new build target in our `cloud-conformance-rules` project's `project.json` file:
{% callout type="warning" title="Adding the @nx/powerpack-conformance plugin" %}
If you get an error resolving the `@nx/powerpack-conformance` plugin, you may need to add it. You can do this by running `nx add @nx/powerpack-conformance` in your workspace.
{% /callout %}

We now have a valid implementation of a rule and we are ready to build it and publish it to Nx Cloud. The [`@nx/powerpack-conformance` plugin](/nx-api/powerpack-conformance) provides a [dedicated executor called `bundle-rules`](/nx-api/powerpack-conformance/executors/bundle-rules) for creating appropriate build artifacts for this purpose. We will replace the existing build target and wire up that executor in our `cloud-conformance-rules` project's `project.json` file:

```jsonc {% fileName="cloud-conformance-rules/project.json" %}
{
// ...any existing project.json content
"targets": {
// ...any existing targets
// ...any other existing targets
// new build target:
"build": {
"executor": "@nx/powerpack-conformance:bundle-rules",
"outputs": ["{options.outputPath}"],
Expand All @@ -32,6 +37,10 @@ We now have a valid implementation of a rule and we are ready to build it and pu
}
```

{% callout type="note" %}
Remove the existing `lib` directory within the `cloud-conformance-rules` project, as it is no longer needed. Each rule will have its own directory, which is generated by the `create-rule` generator, and will need to always have `index.ts` and `schema.json` files.
{% /callout %}

We can now run `nx build cloud-conformance-rules` to build our rule and create the build artifacts in the `cloud-conformance-rules/dist` directory (or wherever you prefer to configure that `outputPath` location). If we take a look at the output path location we will see the same structure of one named subdirectory per rule, now containing the (bundled) `index.js` and `schema.json` files.

Our final step is to publish the rule artifacts to Nx Cloud. We achieve this by running the `publish-conformance-rules` command on the `nx-cloud` CLI, passing the output path location as the first positional argument:
Expand Down

0 comments on commit fd07af5

Please sign in to comment.