Merge pull request #2868 from spotify/feat/fix-backend-cli

chore(cli): backend plugins should have the backend suffix
This commit is contained in:
Ben Lambert
2020-10-13 13:45:55 +02:00
committed by GitHub
2 changed files with 18 additions and 11 deletions
@@ -224,9 +224,11 @@ export default async (cmd: Command) => {
}
const answers: Answers = await inquirer.prompt(questions);
const pluginId = cmd.backend ? `${answers.id}-backend` : answers.id;
const name = cmd.scope
? `@${cmd.scope.replace(/^@/, '')}/plugin-${answers.id}`
: `plugin-${answers.id}`;
? `@${cmd.scope.replace(/^@/, '')}/plugin-${pluginId}`
: `plugin-${pluginId}`;
const npmRegistry = cmd.npmRegistry && cmd.scope ? cmd.npmRegistry : '';
const privatePackage = cmd.private === false ? false : true;
const isMonoRepo = await fs.pathExists(paths.resolveTargetRoot('lerna.json'));
@@ -236,10 +238,10 @@ export default async (cmd: Command) => {
? 'templates/default-backend-plugin'
: 'templates/default-plugin',
);
const tempDir = resolvePath(os.tmpdir(), answers.id);
const tempDir = resolvePath(os.tmpdir(), pluginId);
const pluginDir = isMonoRepo
? paths.resolveTargetRoot('plugins', answers.id)
: paths.resolveTargetRoot(answers.id);
? paths.resolveTargetRoot('plugins', pluginId)
: paths.resolveTargetRoot(pluginId);
const ownerIds = parseOwnerIds(answers.owner);
const { version } = isMonoRepo
? await fs.readJson(paths.resolveTargetRoot('lerna.json'))
@@ -267,7 +269,7 @@ export default async (cmd: Command) => {
});
Task.section('Moving to final location');
await movePlugin(tempDir, pluginDir, answers.id);
await movePlugin(tempDir, pluginDir, pluginId);
Task.section('Building the plugin');
await buildPlugin(pluginDir);
@@ -277,13 +279,13 @@ export default async (cmd: Command) => {
await addPluginDependencyToApp(paths.targetRoot, name, version);
Task.section('Import plugin in app');
await addPluginToApp(paths.targetRoot, answers.id, name);
await addPluginToApp(paths.targetRoot, pluginId, name);
}
if (ownerIds && ownerIds.length) {
await addCodeownersEntry(
codeownersPath!,
`/plugins/${answers.id}`,
`/plugins/${pluginId}`,
ownerIds,
);
}
+8 -3
View File
@@ -56,7 +56,7 @@ export async function run() {
const pluginName = await createPlugin('test-plugin', appDir);
print('Creating a Backstage Backend Plugin');
await createPlugin('test-backend-plugin', appDir, ['--backend']);
await createPlugin('test-plugin', appDir, ['--backend']);
print('Starting the app');
await testAppServe(pluginName, appDir);
@@ -265,13 +265,18 @@ async function createPlugin(
print('Waiting for plugin create script to be done');
await waitForExit(child);
const pluginDir = resolvePath(appDir, 'plugins', pluginName);
const canonicalName = options.includes('--backend')
? `${pluginName}-backend`
: pluginName;
const pluginDir = resolvePath(appDir, 'plugins', canonicalName);
for (const cmd of [['tsc'], ['lint'], ['test', '--no-watch']]) {
print(`Running 'yarn ${cmd.join(' ')}' in newly created plugin`);
await runPlain(['yarn', ...cmd], { cwd: pluginDir });
}
return pluginName;
return canonicalName;
} finally {
child.kill();
}