Sage-Bionetworks / sage-monorepo

Where OpenChallenges, Schematic, and other Sage open source apps are built
https://sage-bionetworks.github.io/sage-monorepo/
Apache License 2.0
21 stars 12 forks source link

[Feature] Explore Nx executors to standardize tasks across projects #2652

Open tschaffter opened 2 months ago

tschaffter commented 2 months ago

What product(s) is this feature for?

Sage Monorepo

Description

A simple executor could be to print information about a project using NX CLI.

Anything else?

No response

Code of Conduct

tschaffter commented 2 months ago

Creating an Nx executor

Create a TS project in the monorepo that will contains multiple executors:

nx g @nx/js:lib sage-monorepo --bundler=tsc --directory=libs/sage-monorepo --unitTestRunner=jest \
  --projectNameAndRootFormat=as-provided --dry-run

Generate an executor:

nx generate @nx/plugin:executor about --directory=libs/sage-monorepo/src/executors/about \
  --nameAndDirectoryFormat=as-provided

Update tsconfig.base.json so that we import the executor as @sagebionetworks/sage-monorepo:about (standard format suggested by Nx) instead of sage-monorepo:about:

      "@sagebionetworks/sage-monorepo": [
        "libs/sage-monorepo/src/index.ts"
      ]

Add the task about to a openchallenges-api-description project by updating its project.json:

    "about": {
      "executor": "@sagebionetworks/sage-monorepo:about"
    }

Run the task:

$ nx about openchallenges-api-description

> nx run openchallenges-api-description:about

Executor ran for About {}

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Successfully ran target about for project openchallenges-api-description (1s)