cli: fixes for common package factory

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-11-13 15:26:23 +01:00
parent 069934c627
commit bd3ae04de9
3 changed files with 18 additions and 7 deletions
@@ -29,6 +29,11 @@ describe('pluginCommon factory', () => {
});
});
afterEach(() => {
mockFs.restore();
jest.resetAllMocks();
});
it('should create a common plugin package', async () => {
mockFs({
'/root': {
@@ -72,7 +77,7 @@ describe('pluginCommon factory', () => {
'templating README.md.hbs ✔',
'templating package.json.hbs ✔',
'copying tsconfig.json ✔',
'copying index.ts ✔',
'templating index.ts.hbs ✔',
'copying setupTests.ts ✔',
'Installing:',
'moving plugins/test-common ✔',
@@ -83,7 +88,7 @@ describe('pluginCommon factory', () => {
).resolves.toEqual(
expect.objectContaining({
name: 'plugin-test-common',
description: 'Common functionalities for the test-common plugin',
description: 'Common functionalities for the test plugin',
private: true,
version: '1.0.0',
}),
@@ -36,15 +36,18 @@ export const pluginCommon = createFactory<Options>({
}),
optionsPrompts: [pluginIdPrompt(), ownerPrompt()],
async create(options: Options, ctx: CreateContext) {
const id = `${options.id}-common`;
const name = ctx.scope ? `@${ctx.scope}/plugin-${id}` : `plugin-${id}`;
const { id } = options;
const suffix = `${id}-common`;
const name = ctx.scope
? `@${ctx.scope}/plugin-${suffix}`
: `plugin-${suffix}`;
Task.log();
Task.log(`Creating backend plugin ${chalk.cyan(name)}`);
const targetDir = ctx.isMonoRepo
? paths.resolveTargetRoot('plugins', id)
: paths.resolveTargetRoot(`backstage-plugin-${id}`);
? paths.resolveTargetRoot('plugins', suffix)
: paths.resolveTargetRoot(`backstage-plugin-${suffix}`);
await executePluginPackageTemplate(ctx, {
targetDir,
@@ -59,7 +62,7 @@ export const pluginCommon = createFactory<Options>({
});
if (options.owner) {
await addCodeownersEntry(`/plugins/${id}`, options.owner);
await addCodeownersEntry(`/plugins/${suffix}`, options.owner);
}
await Task.forCommand('yarn install', { cwd: targetDir, optional: true });
@@ -1,5 +1,8 @@
/***/
/**
* Common functionalities for the {{id}} plugin.
*
* @packageDocumentation
*/
/**