Rename CliPlugin to CliModule and cli-plugin role to cli-module
Rename createCliPlugin to createCliModule, CliPlugin to CliModule, and the cli-plugin package role to cli-module to better distinguish CLI modules from other plugin types. Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com> Made-with: Cursor
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
'@backstage/cli-node': patch
|
||||
---
|
||||
|
||||
Added a new `cli-plugin` package role for packages that provide CLI plugin extensions.
|
||||
Added a new `cli-module` package role for packages that provide CLI plugin extensions.
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
'@backstage/cli-node': minor
|
||||
---
|
||||
|
||||
Added `createCliPlugin` API and related types for building Backstage CLI plugins.
|
||||
Added `createCliModule` API and related types for building Backstage CLI plugins.
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Added support for the new `cli-plugin` package role in the build system, ESLint configuration, Jest configuration, and maintenance commands.
|
||||
Added support for the new `cli-module` package role in the build system, ESLint configuration, Jest configuration, and maintenance commands.
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Migrated CLI plugin modules to use `createCliPlugin` from `@backstage/cli-node`.
|
||||
Migrated CLI plugin modules to use `createCliModule` from `@backstage/cli-node`.
|
||||
|
||||
+4
-4
@@ -14,17 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CliCommand, CliPlugin } from '@backstage/cli-node';
|
||||
import { CliCommand, CliModule } from '@backstage/cli-node';
|
||||
import { OpaqueType } from '@internal/opaque';
|
||||
|
||||
export const OpaqueCliPlugin = OpaqueType.create<{
|
||||
public: CliPlugin;
|
||||
export const OpaqueCliModule = OpaqueType.create<{
|
||||
public: CliModule;
|
||||
versions: {
|
||||
readonly version: 'v1';
|
||||
readonly packageName: string;
|
||||
readonly commands: Promise<ReadonlyArray<CliCommand>>;
|
||||
};
|
||||
}>({
|
||||
type: '@backstage/CliPlugin',
|
||||
type: '@backstage/CliModule',
|
||||
versions: ['v1'],
|
||||
});
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { OpaqueCliPlugin } from './InternalCliPlugin';
|
||||
export { OpaqueCliModule } from './InternalCliModule';
|
||||
export type {
|
||||
CommandNode,
|
||||
CommandTreeNode,
|
||||
|
||||
@@ -111,9 +111,9 @@ export interface CliCommandContext {
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface CliPlugin {
|
||||
export interface CliModule {
|
||||
// (undocumented)
|
||||
readonly $$type: '@backstage/CliPlugin';
|
||||
readonly $$type: '@backstage/CliModule';
|
||||
}
|
||||
|
||||
// @public
|
||||
@@ -124,14 +124,14 @@ export type ConcurrentTasksOptions<TItem> = {
|
||||
};
|
||||
|
||||
// @public
|
||||
export function createCliPlugin(options: {
|
||||
export function createCliModule(options: {
|
||||
packageJson: {
|
||||
name: string;
|
||||
};
|
||||
init: (registry: {
|
||||
addCommand: (command: CliCommand) => void;
|
||||
}) => Promise<void>;
|
||||
}): CliPlugin;
|
||||
}): CliModule;
|
||||
|
||||
// @public
|
||||
export class GitUtils {
|
||||
@@ -227,7 +227,7 @@ export type PackageRole =
|
||||
| 'frontend'
|
||||
| 'backend'
|
||||
| 'cli'
|
||||
| 'cli-plugin'
|
||||
| 'cli-module'
|
||||
| 'web-library'
|
||||
| 'node-library'
|
||||
| 'common-library'
|
||||
|
||||
+7
-7
@@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { OpaqueCliPlugin } from '@internal/cli';
|
||||
import { CliCommand, CliPlugin } from './types';
|
||||
import { OpaqueCliModule } from '@internal/cli';
|
||||
import { CliCommand, CliModule } from './types';
|
||||
|
||||
/**
|
||||
* Creates a new CLI plugin that provides commands to the Backstage CLI.
|
||||
@@ -26,10 +26,10 @@ import { CliCommand, CliPlugin } from './types';
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* import { createCliPlugin } from '@backstage/cli-node';
|
||||
* import { createCliModule } from '@backstage/cli-node';
|
||||
* import packageJson from '../package.json';
|
||||
*
|
||||
* export default createCliPlugin({
|
||||
* export default createCliModule({
|
||||
* packageJson,
|
||||
* init: async reg => {
|
||||
* reg.addCommand({
|
||||
@@ -43,7 +43,7 @@ import { CliCommand, CliPlugin } from './types';
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function createCliPlugin(options: {
|
||||
export function createCliModule(options: {
|
||||
/** The `package.json` contents of the plugin package, used to identify the plugin. */
|
||||
packageJson: { name: string };
|
||||
/**
|
||||
@@ -54,13 +54,13 @@ export function createCliPlugin(options: {
|
||||
/** Registers a new command with the CLI. */
|
||||
addCommand: (command: CliCommand) => void;
|
||||
}) => Promise<void>;
|
||||
}): CliPlugin {
|
||||
}): CliModule {
|
||||
const commands: CliCommand[] = [];
|
||||
const commandsPromise = options
|
||||
.init({ addCommand: command => commands.push(command) })
|
||||
.then(() => commands);
|
||||
|
||||
return OpaqueCliPlugin.createInstance('v1', {
|
||||
return OpaqueCliModule.createInstance('v1', {
|
||||
packageName: options.packageJson.name,
|
||||
commands: commandsPromise,
|
||||
});
|
||||
+2
-2
@@ -14,5 +14,5 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { createCliPlugin } from './createCliPlugin';
|
||||
export type { CliCommand, CliCommandContext, CliPlugin } from './types';
|
||||
export { createCliModule } from './createCliModule';
|
||||
export type { CliCommand, CliCommandContext, CliModule } from './types';
|
||||
+3
-3
@@ -109,10 +109,10 @@ export interface CliCommand {
|
||||
|
||||
/**
|
||||
* An opaque representation of a Backstage CLI plugin, created
|
||||
* using {@link createCliPlugin}.
|
||||
* using {@link createCliModule}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface CliPlugin {
|
||||
readonly $$type: '@backstage/CliPlugin';
|
||||
export interface CliModule {
|
||||
readonly $$type: '@backstage/CliModule';
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
export * from './cache';
|
||||
export * from './cli-plugin';
|
||||
export * from './cli-module';
|
||||
export * from './concurrency';
|
||||
export * from './git';
|
||||
export * from './monorepo';
|
||||
|
||||
@@ -34,7 +34,7 @@ const packageRoleInfos: PackageRoleInfo[] = [
|
||||
output: ['cjs'],
|
||||
},
|
||||
{
|
||||
role: 'cli-plugin',
|
||||
role: 'cli-module',
|
||||
platform: 'node',
|
||||
output: ['types', 'cjs'],
|
||||
},
|
||||
|
||||
@@ -23,7 +23,7 @@ export type PackageRole =
|
||||
| 'frontend'
|
||||
| 'backend'
|
||||
| 'cli'
|
||||
| 'cli-plugin'
|
||||
| 'cli-module'
|
||||
| 'web-library'
|
||||
| 'node-library'
|
||||
| 'common-library'
|
||||
|
||||
@@ -269,7 +269,7 @@ function createConfigForRole(dir, role, extraConfig = {}) {
|
||||
});
|
||||
|
||||
case 'cli':
|
||||
case 'cli-plugin':
|
||||
case 'cli-module':
|
||||
case 'node-library':
|
||||
case 'backend':
|
||||
case 'backend-plugin':
|
||||
|
||||
@@ -38,7 +38,7 @@ const FRONTEND_ROLES = [
|
||||
const NODE_ROLES = [
|
||||
'backend',
|
||||
'cli',
|
||||
'cli-plugin',
|
||||
'cli-module',
|
||||
'node-library',
|
||||
'backend-plugin',
|
||||
'backend-plugin-module',
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createCliPlugin } from '../../wiring/factory';
|
||||
import { createCliModule } from '../../wiring/factory';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export const buildPlugin = createCliPlugin({
|
||||
export const buildPlugin = createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -33,7 +33,7 @@ describe('typeDistProject', () => {
|
||||
frontend: false,
|
||||
backend: false,
|
||||
cli: false,
|
||||
'cli-plugin': false,
|
||||
'cli-module': false,
|
||||
'common-library': false,
|
||||
};
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export const configOption = [
|
||||
@@ -23,7 +23,7 @@ export const configOption = [
|
||||
Array<string>(),
|
||||
] as const;
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -298,7 +298,7 @@ export function fixPluginId(pkg: FixablePackage) {
|
||||
role === 'backend' ||
|
||||
role === 'frontend' ||
|
||||
role === 'cli' ||
|
||||
role === 'cli-plugin'
|
||||
role === 'cli-module'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -385,7 +385,7 @@ export function fixPluginPackages(
|
||||
role === 'backend' ||
|
||||
role === 'frontend' ||
|
||||
role === 'cli' ||
|
||||
role === 'cli-plugin'
|
||||
role === 'cli-module'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -22,7 +22,7 @@ import type { CliCommandContext } from '../../../wiring/types';
|
||||
|
||||
const configArgPattern = /--config[=\s][^\s$]+/;
|
||||
|
||||
const noStartRoles: PackageRole[] = ['cli', 'cli-plugin', 'common-library'];
|
||||
const noStartRoles: PackageRole[] = ['cli', 'cli-module', 'common-library'];
|
||||
|
||||
export default async ({ args, info }: CliCommandContext) => {
|
||||
cli({ help: info, booleanFlagNegation: true }, undefined, args);
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import { NotImplementedError } from '@backstage/errors';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '@backstage/cli-node';
|
||||
import { createCliModule } from '@backstage/cli-node';
|
||||
import packageJson from '../../../package.json';
|
||||
|
||||
export default createCliPlugin({
|
||||
export default createCliModule({
|
||||
packageJson,
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import { CliInitializer } from './CliInitializer';
|
||||
import { createCliPlugin } from './factory';
|
||||
import { createCliModule } from './factory';
|
||||
|
||||
process.exit = jest.fn() as any;
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('CliInitializer', () => {
|
||||
process.argv = ['node', 'cli', 'test'];
|
||||
const initializer = new CliInitializer();
|
||||
initializer.add(
|
||||
createCliPlugin({
|
||||
createCliModule({
|
||||
packageJson: { name: '@backstage/test' },
|
||||
init: async reg =>
|
||||
reg.addCommand({
|
||||
@@ -50,7 +50,7 @@ describe('CliInitializer', () => {
|
||||
process.argv = ['node', 'cli', 'test', '[positional]', '<arg>'];
|
||||
const initializer = new CliInitializer();
|
||||
initializer.add(
|
||||
createCliPlugin({
|
||||
createCliModule({
|
||||
packageJson: { name: '@backstage/test' },
|
||||
init: async reg =>
|
||||
reg.addCommand({
|
||||
@@ -72,7 +72,7 @@ describe('CliInitializer', () => {
|
||||
process.argv = ['node', 'cli', 'test', '--verbose'];
|
||||
const initializer = new CliInitializer();
|
||||
initializer.add(
|
||||
createCliPlugin({
|
||||
createCliModule({
|
||||
packageJson: { name: '@backstage/test' },
|
||||
init: async reg =>
|
||||
reg.addCommand({
|
||||
@@ -97,7 +97,7 @@ describe('CliInitializer', () => {
|
||||
process.argv = ['node', 'cli', 'secret'];
|
||||
const initializer = new CliInitializer();
|
||||
initializer.add(
|
||||
createCliPlugin({
|
||||
createCliModule({
|
||||
packageJson: { name: '@backstage/test' },
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
@@ -124,7 +124,7 @@ describe('CliInitializer', () => {
|
||||
const writeSpy = jest.spyOn(process.stdout, 'write');
|
||||
const initializer2 = new CliInitializer();
|
||||
initializer2.add(
|
||||
createCliPlugin({
|
||||
createCliModule({
|
||||
packageJson: { name: '@backstage/test' },
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
@@ -152,7 +152,7 @@ describe('CliInitializer', () => {
|
||||
const writeSpy = jest.spyOn(process.stdout, 'write');
|
||||
const initializer = new CliInitializer();
|
||||
initializer.add(
|
||||
createCliPlugin({
|
||||
createCliModule({
|
||||
packageJson: { name: '@backstage/test' },
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
@@ -187,7 +187,7 @@ describe('CliInitializer', () => {
|
||||
const writeSpy = jest.spyOn(process.stdout, 'write');
|
||||
const initializer = new CliInitializer();
|
||||
initializer.add(
|
||||
createCliPlugin({
|
||||
createCliModule({
|
||||
packageJson: { name: '@backstage/test' },
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
@@ -223,7 +223,7 @@ describe('CliInitializer', () => {
|
||||
];
|
||||
const initializer = new CliInitializer();
|
||||
initializer.add(
|
||||
createCliPlugin({
|
||||
createCliModule({
|
||||
packageJson: { name: '@backstage/test' },
|
||||
init: async reg =>
|
||||
reg.addCommand({
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
import { CommandGraph } from './CommandGraph';
|
||||
import {
|
||||
OpaqueCliPlugin,
|
||||
OpaqueCliModule,
|
||||
OpaqueCommandTreeNode,
|
||||
OpaqueCommandLeafNode,
|
||||
} from '@internal/cli';
|
||||
import type { CommandNode } from '@internal/cli';
|
||||
import type { CliPlugin } from '@backstage/cli-node';
|
||||
import type { CliModule } from '@backstage/cli-node';
|
||||
import { CommandRegistry } from './CommandRegistry';
|
||||
import { Command } from 'commander';
|
||||
import { version } from './version';
|
||||
@@ -39,12 +39,12 @@ function isNodeHidden(node: CommandNode): boolean {
|
||||
return children.every(child => isNodeHidden(child));
|
||||
}
|
||||
|
||||
type UninitializedFeature = CliPlugin | Promise<{ default: CliPlugin }>;
|
||||
type UninitializedFeature = CliModule | Promise<{ default: CliModule }>;
|
||||
|
||||
export class CliInitializer {
|
||||
private graph = new CommandGraph();
|
||||
private commandRegistry = new CommandRegistry(this.graph);
|
||||
#uninitiazedFeatures: Promise<CliPlugin>[] = [];
|
||||
#uninitiazedFeatures: Promise<CliModule>[] = [];
|
||||
|
||||
add(feature: UninitializedFeature) {
|
||||
if (isPromise(feature)) {
|
||||
@@ -56,9 +56,9 @@ export class CliInitializer {
|
||||
}
|
||||
}
|
||||
|
||||
async #register(feature: CliPlugin) {
|
||||
if (OpaqueCliPlugin.isType(feature)) {
|
||||
const internal = OpaqueCliPlugin.toInternal(feature);
|
||||
async #register(feature: CliModule) {
|
||||
if (OpaqueCliModule.isType(feature)) {
|
||||
const internal = OpaqueCliModule.toInternal(feature);
|
||||
for (const command of await internal.commands) {
|
||||
this.commandRegistry.addCommand(command);
|
||||
}
|
||||
@@ -186,8 +186,8 @@ export class CliInitializer {
|
||||
|
||||
/** @internal */
|
||||
export function unwrapFeature(
|
||||
feature: CliPlugin | { default: CliPlugin },
|
||||
): CliPlugin {
|
||||
feature: CliModule | { default: CliModule },
|
||||
): CliModule {
|
||||
if ('$$type' in feature) {
|
||||
return feature;
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { createCliPlugin } from '@backstage/cli-node';
|
||||
export { createCliModule } from '@backstage/cli-node';
|
||||
|
||||
@@ -17,5 +17,5 @@
|
||||
export type {
|
||||
CliCommandContext,
|
||||
CliCommand,
|
||||
CliPlugin,
|
||||
CliModule,
|
||||
} from '@backstage/cli-node';
|
||||
|
||||
Reference in New Issue
Block a user