diff --git a/packages/cli/src/commands/create-plugin/createPlugin.ts b/packages/cli/src/commands/create-plugin/createPlugin.ts index 5e6882a4a0..8f75728544 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.ts @@ -175,7 +175,7 @@ export async function movePlugin( }); } -export default async () => { +export default async ({ backend }: { backend: boolean }) => { const codeownersPath = await getCodeownersFilePath(paths.targetRoot); const questions: Question[] = [ @@ -223,7 +223,9 @@ export default async () => { const answers: Answers = await inquirer.prompt(questions); const appPackage = paths.resolveTargetRoot('packages/app'); - const templateDir = paths.resolveOwn('templates/default-plugin'); + const templateDir = paths.resolveOwn( + backend ? 'templates/default-backend-plugin' : 'templates/default-plugin', + ); const tempDir = resolvePath(os.tmpdir(), answers.id); const pluginDir = paths.resolveTargetRoot('plugins', answers.id); const ownerIds = parseOwnerIds(answers.owner); @@ -240,6 +242,7 @@ export default async () => { await createTemporaryPluginFolder(tempDir); Task.section('Preparing files'); + await templatingTask(templateDir, tempDir, { ...answers, version, @@ -252,7 +255,7 @@ export default async () => { Task.section('Building the plugin'); await buildPlugin(pluginDir); - if (await fs.pathExists(appPackage)) { + if ((await fs.pathExists(appPackage)) && !backend) { Task.section('Adding plugin as dependency in app'); await addPluginDependencyToApp(paths.targetRoot, answers.id, version); diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 4e031cdbc1..a0b898db75 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -61,6 +61,10 @@ export function registerCommands(program: CommanderStatic) { program .command('create-plugin') + .option( + '--backend', + 'Create plugin with the backend dependencies as default', + ) .description('Creates a new plugin in the current repository') .action( lazy(() => import('./create-plugin/createPlugin').then(m => m.default)), diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 1cf9ab1c5b..8a1d5a9522 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -17,16 +17,16 @@ "test": "backstage-cli test", "prepack": "backstage-cli prepack", "postpack": "backstage-cli postpack", - "clean": "backstage-cli clean", - "mock-data": "./scripts/mock-data.sh" + "clean": "backstage-cli clean" }, "dependencies": { "@backstage/backend-common": "^{{version}}", + "@backstage/config": "^{{version}}", "@types/express": "^4.17.6", "express": "^4.17.1", "express-promise-router": "^3.0.3", - "whatwg-fetch": "^2.0.0", "winston": "^3.2.1", + "node-fetch": "^2.6.0", "yn": "^4.0.0" }, "devDependencies": { diff --git a/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh b/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh deleted file mode 100755 index ff30921715..0000000000 --- a/packages/cli/templates/default-backend-plugin/scripts/mock-data.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -echo "use this script to load your service with some mock data if needed!" diff --git a/packages/cli/templates/default-backend-plugin/src/index.ts b/packages/cli/templates/default-backend-plugin/src/index.ts index 7332f92d68..7612c392a2 100644 --- a/packages/cli/templates/default-backend-plugin/src/index.ts +++ b/packages/cli/templates/default-backend-plugin/src/index.ts @@ -14,5 +14,4 @@ * limitations under the License. */ -require('whatwg-fetch'); export * from './service/router'; diff --git a/packages/cli/templates/default-backend-plugin/src/setupTests.ts b/packages/cli/templates/default-backend-plugin/src/setupTests.ts index ac41ef995a..ba33cf996b 100644 --- a/packages/cli/templates/default-backend-plugin/src/setupTests.ts +++ b/packages/cli/templates/default-backend-plugin/src/setupTests.ts @@ -13,6 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require('whatwg-fetch'); export {};