diff --git a/.changeset/cli-node-add-cli-plugin.md b/.changeset/cli-node-add-cli-plugin.md new file mode 100644 index 0000000000..b5a26979a9 --- /dev/null +++ b/.changeset/cli-node-add-cli-plugin.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli-node': minor +--- + +Added `createCliPlugin` API and related types for building Backstage CLI plugins. diff --git a/.changeset/cli-use-cli-plugin-api.md b/.changeset/cli-use-cli-plugin-api.md index b55858ba62..cf7f7f12b5 100644 --- a/.changeset/cli-use-cli-plugin-api.md +++ b/.changeset/cli-use-cli-plugin-api.md @@ -2,4 +2,4 @@ '@backstage/cli': patch --- -Migrated CLI plugin modules to use `createCliPlugin` from the new `@backstage/cli-plugin-api` package. +Migrated CLI plugin modules to use `createCliPlugin` from `@backstage/cli-node`. diff --git a/.changeset/create-cli-plugin-api.md b/.changeset/create-cli-plugin-api.md deleted file mode 100644 index d740fe7897..0000000000 --- a/.changeset/create-cli-plugin-api.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@backstage/cli-plugin-api': minor ---- - -Added a new `@backstage/cli-plugin-api` package that provides the `createCliPlugin` API for building Backstage CLI plugins. diff --git a/packages/cli-internal/package.json b/packages/cli-internal/package.json index 80c68c74d3..068735bac3 100644 --- a/packages/cli-internal/package.json +++ b/packages/cli-internal/package.json @@ -22,7 +22,7 @@ "test": "backstage-cli package test" }, "dependencies": { - "@backstage/cli-plugin-api": "workspace:^" + "@backstage/cli-node": "workspace:^" }, "devDependencies": { "@backstage/cli": "workspace:^" diff --git a/packages/cli-internal/src/InternalCliPlugin.ts b/packages/cli-internal/src/InternalCliPlugin.ts index 426f3d23e6..e51b2e3f0e 100644 --- a/packages/cli-internal/src/InternalCliPlugin.ts +++ b/packages/cli-internal/src/InternalCliPlugin.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { BackstageCommand, CliPlugin } from '@backstage/cli-plugin-api'; +import { BackstageCommand, CliPlugin } from '@backstage/cli-node'; import { OpaqueType } from '@internal/opaque'; export const OpaqueCliPlugin = OpaqueType.create<{ diff --git a/packages/cli-internal/src/InternalCommandNode.ts b/packages/cli-internal/src/InternalCommandNode.ts index fec79ffb8e..11147c3373 100644 --- a/packages/cli-internal/src/InternalCommandNode.ts +++ b/packages/cli-internal/src/InternalCommandNode.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { BackstageCommand } from '@backstage/cli-plugin-api'; +import { BackstageCommand } from '@backstage/cli-node'; import { OpaqueType } from '@internal/opaque'; /** @internal */ diff --git a/packages/cli-node/report.api.md b/packages/cli-node/report.api.md index 05d1545ae4..0ce66e7cb5 100644 --- a/packages/cli-node/report.api.md +++ b/packages/cli-node/report.api.md @@ -6,6 +6,21 @@ import { JsonValue } from '@backstage/types'; import { Package } from '@manypkg/get-packages'; +// @public +export interface BackstageCommand { + deprecated?: boolean; + description: string; + execute: + | ((context: CommandContext) => Promise) + | { + loader: () => Promise<{ + default: (context: CommandContext) => Promise; + }>; + }; + experimental?: boolean; + path: string[]; +} + // @public export type BackstagePackage = { dir: string; @@ -86,6 +101,21 @@ export interface BackstagePackageJson { version: string; } +// @public +export interface CliPlugin { + // (undocumented) + readonly $$type: '@backstage/CliPlugin'; +} + +// @public +export interface CommandContext { + args: string[]; + info: { + usage: string; + name: string; + }; +} + // @public export type ConcurrentTasksOptions = { concurrencyFactor?: number; @@ -93,6 +123,16 @@ export type ConcurrentTasksOptions = { worker: (item: TItem) => Promise; }; +// @public +export function createCliPlugin(options: { + packageJson: { + name: string; + }; + init: (registry: { + addCommand: (command: BackstageCommand) => void; + }) => Promise; +}): CliPlugin; + // @public export class GitUtils { static listChangedFiles(ref: string): Promise; diff --git a/packages/cli-plugin-api/src/createCliPlugin.ts b/packages/cli-node/src/cli-plugin/createCliPlugin.ts similarity index 97% rename from packages/cli-plugin-api/src/createCliPlugin.ts rename to packages/cli-node/src/cli-plugin/createCliPlugin.ts index 17ddd8ebb9..f007f74eb4 100644 --- a/packages/cli-plugin-api/src/createCliPlugin.ts +++ b/packages/cli-node/src/cli-plugin/createCliPlugin.ts @@ -26,7 +26,7 @@ import { BackstageCommand, CliPlugin } from './types'; * * @example * ``` - * import { createCliPlugin } from '@backstage/cli-plugin-api'; + * import { createCliPlugin } from '@backstage/cli-node'; * import packageJson from '../package.json'; * * export default createCliPlugin({ diff --git a/packages/cli-plugin-api/src/index.ts b/packages/cli-node/src/cli-plugin/index.ts similarity index 100% rename from packages/cli-plugin-api/src/index.ts rename to packages/cli-node/src/cli-plugin/index.ts diff --git a/packages/cli-plugin-api/src/types.ts b/packages/cli-node/src/cli-plugin/types.ts similarity index 100% rename from packages/cli-plugin-api/src/types.ts rename to packages/cli-node/src/cli-plugin/types.ts diff --git a/packages/cli-node/src/index.ts b/packages/cli-node/src/index.ts index 35074507c4..7c18070bbe 100644 --- a/packages/cli-node/src/index.ts +++ b/packages/cli-node/src/index.ts @@ -21,6 +21,7 @@ */ export * from './cache'; +export * from './cli-plugin'; export * from './concurrency'; export * from './git'; export * from './monorepo'; diff --git a/packages/cli-plugin-api/.eslintrc.js b/packages/cli-plugin-api/.eslintrc.js deleted file mode 100644 index e2a53a6ad2..0000000000 --- a/packages/cli-plugin-api/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/packages/cli-plugin-api/catalog-info.yaml b/packages/cli-plugin-api/catalog-info.yaml deleted file mode 100644 index 3a0aca14b9..0000000000 --- a/packages/cli-plugin-api/catalog-info.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: backstage.io/v1alpha1 -kind: Component -metadata: - name: backstage-cli-plugin-api - title: '@backstage/cli-plugin-api' - description: API for building Backstage CLI plugins -spec: - lifecycle: experimental - type: backstage-cli-plugin - owner: tooling-maintainers diff --git a/packages/cli-plugin-api/package.json b/packages/cli-plugin-api/package.json deleted file mode 100644 index 4d256f3c96..0000000000 --- a/packages/cli-plugin-api/package.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "name": "@backstage/cli-plugin-api", - "version": "0.1.0", - "description": "API for building Backstage CLI plugins", - "backstage": { - "role": "cli-plugin" - }, - "publishConfig": { - "access": "public", - "main": "dist/index.cjs.js", - "types": "dist/index.d.ts" - }, - "homepage": "https://backstage.io", - "repository": { - "type": "git", - "url": "https://github.com/backstage/backstage", - "directory": "packages/cli-plugin-api" - }, - "license": "Apache-2.0", - "main": "src/index.ts", - "types": "src/index.ts", - "files": [ - "dist" - ], - "scripts": { - "build": "backstage-cli package build", - "clean": "backstage-cli package clean", - "lint": "backstage-cli package lint", - "prepack": "backstage-cli package prepack", - "postpack": "backstage-cli package postpack", - "test": "backstage-cli package test" - }, - "dependencies": { - "@backstage/errors": "workspace:^" - }, - "devDependencies": { - "@backstage/cli": "workspace:^" - } -} diff --git a/packages/cli-plugin-api/report.api.md b/packages/cli-plugin-api/report.api.md deleted file mode 100644 index 0821e01085..0000000000 --- a/packages/cli-plugin-api/report.api.md +++ /dev/null @@ -1,50 +0,0 @@ -## API Report File for "@backstage/cli-plugin-api" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts -// @public -export interface BackstageCommand { - deprecated?: boolean; - description: string; - execute: - | ((context: CommandContext) => Promise) - | { - loader: () => Promise<{ - default: (context: CommandContext) => Promise; - }>; - }; - experimental?: boolean; - path: string[]; -} - -// @public -export type CliFeature = CliPlugin; - -// @public -export interface CliPlugin { - // (undocumented) - readonly $$type: '@backstage/CliPlugin'; -} - -// @public -export interface CommandContext { - args: string[]; - info: { - usage: string; - name: string; - }; -} - -// @public -export function createCliPlugin(options: { - packageJson: { - name: string; - }; - init: (registry: { - addCommand: (command: BackstageCommand) => void; - }) => Promise; -}): CliPlugin; - -// (No @packageDocumentation comment for this package) -``` diff --git a/packages/cli/package.json b/packages/cli/package.json index d309e0453c..8e03c60d0f 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -50,7 +50,6 @@ "@backstage/catalog-model": "workspace:^", "@backstage/cli-common": "workspace:^", "@backstage/cli-node": "workspace:^", - "@backstage/cli-plugin-api": "workspace:^", "@backstage/config": "workspace:^", "@backstage/config-loader": "workspace:^", "@backstage/errors": "workspace:^", diff --git a/packages/cli/src/modules/build/index.ts b/packages/cli/src/modules/build/index.ts index 1c8d2217ed..e3c04e6325 100644 --- a/packages/cli/src/modules/build/index.ts +++ b/packages/cli/src/modules/build/index.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export const buildPlugin = createCliPlugin({ diff --git a/packages/cli/src/modules/config/index.ts b/packages/cli/src/modules/config/index.ts index 3c59f96948..e2ddec3678 100644 --- a/packages/cli/src/modules/config/index.ts +++ b/packages/cli/src/modules/config/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export const configOption = [ diff --git a/packages/cli/src/modules/create-github-app/index.ts b/packages/cli/src/modules/create-github-app/index.ts index 69fe5869d4..2171f2ca2e 100644 --- a/packages/cli/src/modules/create-github-app/index.ts +++ b/packages/cli/src/modules/create-github-app/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export default createCliPlugin({ diff --git a/packages/cli/src/modules/info/index.ts b/packages/cli/src/modules/info/index.ts index df8a848f11..b1fa885f03 100644 --- a/packages/cli/src/modules/info/index.ts +++ b/packages/cli/src/modules/info/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export default createCliPlugin({ diff --git a/packages/cli/src/modules/lint/index.ts b/packages/cli/src/modules/lint/index.ts index 51e5b981a4..7da72679d4 100644 --- a/packages/cli/src/modules/lint/index.ts +++ b/packages/cli/src/modules/lint/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export default createCliPlugin({ diff --git a/packages/cli/src/modules/maintenance/index.ts b/packages/cli/src/modules/maintenance/index.ts index 142bd543f2..cf6cf00b2c 100644 --- a/packages/cli/src/modules/maintenance/index.ts +++ b/packages/cli/src/modules/maintenance/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export default createCliPlugin({ diff --git a/packages/cli/src/modules/migrate/index.ts b/packages/cli/src/modules/migrate/index.ts index 603712f8e2..16cf45d244 100644 --- a/packages/cli/src/modules/migrate/index.ts +++ b/packages/cli/src/modules/migrate/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export default createCliPlugin({ diff --git a/packages/cli/src/modules/new/index.ts b/packages/cli/src/modules/new/index.ts index 076a49f9be..9ceb50e272 100644 --- a/packages/cli/src/modules/new/index.ts +++ b/packages/cli/src/modules/new/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import { NotImplementedError } from '@backstage/errors'; import packageJson from '../../../package.json'; diff --git a/packages/cli/src/modules/test/index.ts b/packages/cli/src/modules/test/index.ts index 596572cb9a..07eabbf3f7 100644 --- a/packages/cli/src/modules/test/index.ts +++ b/packages/cli/src/modules/test/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export default createCliPlugin({ diff --git a/packages/cli/src/modules/translations/index.ts b/packages/cli/src/modules/translations/index.ts index 16c19d9345..1903d87684 100644 --- a/packages/cli/src/modules/translations/index.ts +++ b/packages/cli/src/modules/translations/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createCliPlugin } from '@backstage/cli-plugin-api'; +import { createCliPlugin } from '@backstage/cli-node'; import packageJson from '../../../package.json'; export default createCliPlugin({ diff --git a/packages/cli/src/wiring/CliInitializer.ts b/packages/cli/src/wiring/CliInitializer.ts index ad9c483d33..37156641ee 100644 --- a/packages/cli/src/wiring/CliInitializer.ts +++ b/packages/cli/src/wiring/CliInitializer.ts @@ -21,7 +21,7 @@ import { OpaqueCommandLeafNode, } from '@internal/cli'; import type { CommandNode } from '@internal/cli'; -import type { CliPlugin } from '@backstage/cli-plugin-api'; +import type { CliPlugin } from '@backstage/cli-node'; import { CommandRegistry } from './CommandRegistry'; import { Command } from 'commander'; import { version } from './version'; diff --git a/packages/cli/src/wiring/factory.ts b/packages/cli/src/wiring/factory.ts index 19c68e805f..e840e694c6 100644 --- a/packages/cli/src/wiring/factory.ts +++ b/packages/cli/src/wiring/factory.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { createCliPlugin } from '@backstage/cli-plugin-api'; +export { createCliPlugin } from '@backstage/cli-node'; diff --git a/packages/cli/src/wiring/types.ts b/packages/cli/src/wiring/types.ts index 98a20427b3..04eedfbd0d 100644 --- a/packages/cli/src/wiring/types.ts +++ b/packages/cli/src/wiring/types.ts @@ -18,4 +18,4 @@ export type { CommandContext, BackstageCommand, CliPlugin, -} from '@backstage/cli-plugin-api'; +} from '@backstage/cli-node'; diff --git a/yarn.lock b/yarn.lock index 2ef9ed9764..7465a75f4d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2822,15 +2822,6 @@ __metadata: languageName: unknown linkType: soft -"@backstage/cli-plugin-api@workspace:^, @backstage/cli-plugin-api@workspace:packages/cli-plugin-api": - version: 0.0.0-use.local - resolution: "@backstage/cli-plugin-api@workspace:packages/cli-plugin-api" - dependencies: - "@backstage/cli": "workspace:^" - "@backstage/errors": "workspace:^" - languageName: unknown - linkType: soft - "@backstage/cli@workspace:*, @backstage/cli@workspace:^, @backstage/cli@workspace:packages/cli": version: 0.0.0-use.local resolution: "@backstage/cli@workspace:packages/cli" @@ -2841,7 +2832,6 @@ __metadata: "@backstage/catalog-model": "workspace:^" "@backstage/cli-common": "workspace:^" "@backstage/cli-node": "workspace:^" - "@backstage/cli-plugin-api": "workspace:^" "@backstage/config": "workspace:^" "@backstage/config-loader": "workspace:^" "@backstage/core-app-api": "workspace:^" @@ -9685,7 +9675,7 @@ __metadata: resolution: "@internal/cli@workspace:packages/cli-internal" dependencies: "@backstage/cli": "workspace:^" - "@backstage/cli-plugin-api": "workspace:^" + "@backstage/cli-node": "workspace:^" languageName: unknown linkType: soft