cli: update scaffolder-module template
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -29,10 +29,12 @@
|
||||
"postpack": "backstage-cli package postpack"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-plugin-api": "{{versionQuery '@backstage/backend-plugin-api'}}",
|
||||
"@backstage/plugin-scaffolder-node": "{{versionQuery '@backstage/plugin-scaffolder-node'}}"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "{{versionQuery '@backstage/cli'}}"
|
||||
"@backstage/cli": "{{versionQuery '@backstage/cli'}}",
|
||||
"@backstage/plugin-scaffolder-node-test-utils": "{{versionQuery '@backstage/plugin-scaffolder-node-test-utils'}}"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { createExampleAction } from './example';
|
||||
import {createMockActionContext} from '@backstage/plugin-scaffolder-node-test-utils'
|
||||
|
||||
describe('createExampleAction', () => {
|
||||
it('should call action', async () => {
|
||||
const action = createExampleAction();
|
||||
|
||||
await expect(action.handler(createMockActionContext({
|
||||
input: {
|
||||
myParameter: 'test',
|
||||
},
|
||||
}))).resolves.toBeUndefined()
|
||||
});
|
||||
|
||||
it('should fail when passing foo', async () => {
|
||||
const action = createExampleAction();
|
||||
|
||||
await expect(action.handler(createMockActionContext({
|
||||
input: {
|
||||
myParameter: 'foo',
|
||||
},
|
||||
}))).rejects.toThrow("myParameter cannot be 'foo'")
|
||||
});
|
||||
});
|
||||
+7
-3
@@ -9,14 +9,14 @@ import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export function createAcmeExampleAction() {
|
||||
export function createExampleAction() {
|
||||
// For more information on how to define custom actions, see
|
||||
// https://backstage.io/docs/features/software-templates/writing-custom-actions
|
||||
return createTemplateAction<{
|
||||
myParameter: string;
|
||||
}>({
|
||||
id: 'acme:example',
|
||||
description: 'Runs Yeoman on an installed Yeoman generator',
|
||||
description: 'Runs an example action',
|
||||
schema: {
|
||||
input: {
|
||||
type: 'object',
|
||||
@@ -24,7 +24,7 @@ export function createAcmeExampleAction() {
|
||||
properties: {
|
||||
myParameter: {
|
||||
title: 'An example parameter',
|
||||
description: 'This is the schema for our example parameter',
|
||||
description: "This is an example parameter, don't set it to foo",
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
@@ -35,6 +35,10 @@ export function createAcmeExampleAction() {
|
||||
`Running example template with parameters: ${ctx.input.myParameter}`,
|
||||
);
|
||||
|
||||
if (ctx.input.myParameter === 'foo') {
|
||||
throw new Error(`myParameter cannot be 'foo'`);
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
},
|
||||
});
|
||||
@@ -1,32 +0,0 @@
|
||||
import { PassThrough } from 'stream';
|
||||
import { createAcmeExampleAction } from './example';
|
||||
|
||||
describe('acme:example', () => {
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it('should call action', async () => {
|
||||
const action = createAcmeExampleAction();
|
||||
|
||||
const logger = { info: jest.fn() };
|
||||
|
||||
await action.handler({
|
||||
input: {
|
||||
myParameter: 'test',
|
||||
},
|
||||
workspacePath: '/tmp',
|
||||
logger: logger as any,
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory() {
|
||||
// Usage of createMockDirectory is recommended for testing of filesystem operations
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
});
|
||||
|
||||
expect(logger.info).toHaveBeenCalledWith(
|
||||
'Running example template with parameters: test',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
import { scaffolderModule } from './module';
|
||||
|
||||
/*
|
||||
@deprecated - this way of importing modules will soon be unsupported, and you should use `backend.add(import(...))` instead.
|
||||
*/
|
||||
export { createAcmeExampleAction } from './example';
|
||||
export default scaffolderModule;
|
||||
@@ -1 +0,0 @@
|
||||
export * from './example';
|
||||
@@ -5,4 +5,4 @@
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export * from './actions';
|
||||
export { scaffolderModule as default } from './module';
|
||||
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
import { createBackendModule } from "@backstage/backend-plugin-api";
|
||||
import { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';
|
||||
import { createAcmeExampleAction } from "./example";
|
||||
import { createExampleAction } from "./actions/example";
|
||||
|
||||
/**
|
||||
* A backend module that registers the action into the scaffolder
|
||||
*/
|
||||
export const scaffolderModule = createBackendModule({
|
||||
moduleId: 'acme:example',
|
||||
moduleId: 'example-action',
|
||||
pluginId: 'scaffolder',
|
||||
register({ registerInit }) {
|
||||
registerInit({
|
||||
@@ -14,7 +14,7 @@ export const scaffolderModule = createBackendModule({
|
||||
scaffolderActions: scaffolderActionsExtensionPoint
|
||||
},
|
||||
async init({ scaffolderActions}) {
|
||||
scaffolderActions.addActions(createAcmeExampleAction());
|
||||
scaffolderActions.addActions(createExampleAction());
|
||||
}
|
||||
});
|
||||
},
|
||||
Reference in New Issue
Block a user