Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update new plugin templates to include scaffolding for dynamic …
Browse files Browse the repository at this point in the history
…plugins

Signed-off-by: Tomas Coufal <[email protected]>
tumido committed Jan 23, 2024

Verified

This commit was signed with the committer’s verified signature.
tumido Tom Coufal
1 parent b63e7d6 commit 84af3e6
Showing 36 changed files with 288 additions and 76 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -99,6 +99,7 @@
"@backstage/core-plugin-api": "1.7.0",
"@backstage/dev-utils": "1.0.22",
"@backstage/plugin-scaffolder-backend": "1.18.0",
"@backstage/plugin-scaffolder-node": "0.2.6",
"@backstage/test-utils": "1.4.4",
"@backstage/theme": "0.4.3",
"@types/express": "4.17.20",
4 changes: 4 additions & 0 deletions packages/cli/src/lib/new/factories/backendModule.test.ts
Original file line number Diff line number Diff line change
@@ -84,11 +84,15 @@ describe('backendModule factory', () => {
'Executing Template:',
'copying .eslintrc.js',
'templating README.md.hbs',
'copying app-config.janus-idp.yaml',
'copying config.d.ts',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating index.ts.hbs',
'templating module.ts.hbs',
'templating alpha.ts.hbs',
'templating index.ts.hbs',
'Installing:',
`moving plugins${sep}test-backend-module-tester-two`,
'backend adding dependency',
8 changes: 6 additions & 2 deletions packages/cli/src/lib/new/factories/backendPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -83,14 +83,18 @@ describe('backendPlugin factory', () => {
'Executing Template:',
'copying .eslintrc.js',
'templating README.md.hbs',
'copying app-config.janus-idp.yaml',
'copying config.d.ts',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'copying index.ts',
'templating index.ts.hbs',
'templating run.ts.hbs',
'copying setupTests.ts',
'templating alpha.ts.hbs',
'templating index.ts.hbs',
'copying router.test.ts',
'copying router.ts',
'templating router.ts.hbs',
'templating standaloneServer.ts.hbs',
'Installing:',
`moving plugins${sep}test-backend`,
2 changes: 2 additions & 0 deletions packages/cli/src/lib/new/factories/frontendPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -96,6 +96,8 @@ describe('frontendPlugin factory', () => {
'Executing Template:',
'copying .eslintrc.js',
'templating README.md.hbs',
'templating app-config.janus-idp.yaml.hbs',
'copying config.d.ts',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
4 changes: 4 additions & 0 deletions packages/cli/src/lib/new/factories/scaffolderModule.test.ts
Original file line number Diff line number Diff line change
@@ -78,10 +78,14 @@ describe('scaffolderModule factory', () => {
'Executing Template:',
'copying .eslintrc.js',
'templating README.md.hbs',
'copying app-config.janus-idp.yaml',
'copying config.d.ts',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating index.ts.hbs',
'templating alpha.ts.hbs',
'templating index.ts.hbs',
'copying index.ts',
'copying example.test.ts',
'copying example.ts',
15 changes: 8 additions & 7 deletions packages/cli/src/lib/version.ts
Original file line number Diff line number Diff line change
@@ -36,6 +36,13 @@ import Manifest from '../../package.json';
import { paths } from './paths';
import { Lockfile } from './versioning';

export function findVersion() {
const pkgContent = fs.readFileSync(paths.resolveOwn('package.json'), 'utf8');
return JSON.parse(pkgContent).version;
}

export const version = findVersion();

export const packageVersions: Record<string, string> = {
...Object.fromEntries(
Object.entries(Manifest.devDependencies as Record<string, string>).filter(
@@ -47,15 +54,9 @@ export const packageVersions: Record<string, string> = {
([k, _v]) => k.startsWith('@backstage/'),
),
),
'@janus-idp/cli': version,
};

export function findVersion() {
const pkgContent = fs.readFileSync(paths.resolveOwn('package.json'), 'utf8');
return JSON.parse(pkgContent).version;
}

export const version = findVersion();

export function createPackageVersionProvider(lockfile?: Lockfile) {
return (name: string, versionHint?: string): string => {
const packageVersion = packageVersions[name];
Empty file.
1 change: 1 addition & 0 deletions packages/cli/templates/default-backend-module/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface Config {}
40 changes: 33 additions & 7 deletions packages/cli/templates/default-backend-module/package.json.hbs
Original file line number Diff line number Diff line change
@@ -19,26 +19,52 @@
"backstage": {
"role": "backend-plugin-module"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"export-dynamic": "janus-cli package export-dynamic-plugin",
"lint": "backstage-cli package lint",
"postpack": "backstage-cli package postpack",
"postversion": "yarn run export-dynamic",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
"start": "backstage-cli package start",
"test": "backstage-cli package test --passWithNoTests --coverage",
"tsc": "tsc"
},
"dependencies": {
"@backstage/backend-common": "^{{versionQuery '@backstage/backend-common'}}",
"@backstage/backend-plugin-api": "^{{versionQuery '@backstage/backend-plugin-api'}}"
"@backstage/backend-plugin-api": "^{{versionQuery '@backstage/backend-plugin-api'}}",
"@backstage/backend-plugin-manager": "{{versionQuery '@backstage/backend-plugin-manager' 'npm:@janus-idp/[email protected]'}}"
},
"devDependencies": {
"@backstage/backend-test-utils": "{{versionQuery '@backstage/backend-test-utils'}}",
"@backstage/cli": "{{versionQuery '@backstage/cli'}}"
"@backstage/cli": "{{versionQuery '@backstage/cli'}}",
"@janus-idp/cli": "{{versionQuery '@janus-idp/cli'}}"
},
"files": [
"dist"
"dist",
"config.d.ts",
"dist-dynamic/*.*",
"dist-dynamic/dist/**",
"dist-dynamic/alpha/*",
"app-config.janus-idp.yaml"
],
"configSchema": "config.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/janus-idp/backstage-plugins",
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager';

import { {{moduleVar}} } from '../module';

export const dynamicPluginInstaller: BackendDynamicPluginInstaller = {
kind: 'new',
install: {{moduleVar}},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager';

export const dynamicPluginInstaller: BackendDynamicPluginInstaller = {
kind: 'legacy'
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***/
/**
* The {{moduleId}} backend module for the {{pluginId}} plugin.
*
* @packageDocumentation
*/

export { {{moduleVar}} } from './module';
export * from './dynamic/index';
export * from './module';
Empty file.
1 change: 1 addition & 0 deletions packages/cli/templates/default-backend-plugin/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface Config {}
37 changes: 32 additions & 5 deletions packages/cli/templates/default-backend-plugin/package.json.hbs
Original file line number Diff line number Diff line change
@@ -18,17 +18,37 @@
"backstage": {
"role": "backend-plugin"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"export-dynamic": "janus-cli package export-dynamic-plugin",
"lint": "backstage-cli package lint",
"postpack": "backstage-cli package postpack",
"postversion": "yarn run export-dynamic",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
"start": "backstage-cli package start",
"test": "backstage-cli package test --passWithNoTests --coverage",
"tsc": "tsc"
},
"dependencies": {
"@backstage/backend-common": "^{{versionQuery '@backstage/backend-common'}}",
"@backstage/backend-plugin-api": "^{{versionQuery '@backstage/backend-plugin-api'}}",
"@backstage/backend-plugin-manager": "{{versionQuery '@backstage/backend-plugin-manager' 'npm:@janus-idp/[email protected]'}}",
"@backstage/config": "^{{versionQuery '@backstage/config'}}",
"@types/express": "^{{versionQuery '@types/express' '4.17.6'}}",
"express": "^{{versionQuery 'express' '4.17.1'}}",
@@ -39,13 +59,20 @@
},
"devDependencies": {
"@backstage/cli": "{{versionQuery '@backstage/cli'}}",
"@janus-idp/cli": "{{versionQuery '@janus-idp/cli'}}",
"@types/supertest": "{{versionQuery '@types/supertest' '2.0.12'}}",
"supertest": "{{versionQuery 'supertest' '6.2.4'}}",
"msw": "{{versionQuery 'msw' '1.0.0'}}"
},
"files": [
"dist"
"dist",
"config.d.ts",
"dist-dynamic/*.*",
"dist-dynamic/dist/**",
"dist-dynamic/alpha/*",
"app-config.janus-idp.yaml"
],
"configSchema": "config.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/janus-idp/backstage-plugins",
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager';

import { {{id}}Plugin } from '../service/router';

export const dynamicPluginInstaller: BackendDynamicPluginInstaller = {
kind: 'new',
install: () => [{{id}}Plugin()],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager';
import { createRouter } from '../service/router';

export const dynamicPluginInstaller: BackendDynamicPluginInstaller = {
kind: 'legacy',
router: {
pluginID: '{{id}}',
createPlugin: createRouter,
},
};
1 change: 0 additions & 1 deletion packages/cli/templates/default-backend-plugin/src/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* The {{id}} backend plugin.
*
* @packageDocumentation
*/

export * from './dynamic/index';
export * from './service/router';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { errorHandler, loggerToWinstonLogger } from '@backstage/backend-common';
import { coreServices, createBackendPlugin } from '@backstage/backend-plugin-api';
import express from 'express';
import Router from 'express-promise-router';
import { Logger } from 'winston';

export interface RouterOptions {
logger: Logger;
}

export async function createRouter(
options: RouterOptions,
): Promise<express.Router> {
const { logger } = options;

const router = Router();
router.use(express.json());

router.get('/health', (_, response) => {
logger.info('PONG!');
response.json({ status: 'ok' });
});
router.use(errorHandler());
return router;
}
export const {{id}}Plugin = createBackendPlugin({
pluginId: '{{id}}',
register(env) {
env.registerInit({
deps: {
logger: coreServices.logger,
config: coreServices.rootConfig,
http: coreServices.httpRouter,
},
async init({ config, logger, http }) {
http.use(() => createRouter({...config, logger: loggerToWinstonLogger(logger)}));
},
});
},
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@backstage/cli/config/tsconfig.json",
"include": ["src", "dev, "migrations"],
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../dist-types/plugins/{{id}}",
Original file line number Diff line number Diff line change
@@ -23,11 +23,13 @@
"sideEffects": false,
"scripts": {
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"lint": "backstage-cli package lint",
"postpack": "backstage-cli package postpack",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
"start": "backstage-cli package start",
"test": "backstage-cli package test --passWithNoTests --coverage",
"tsc": "tsc"
},
"devDependencies": {
"@backstage/cli": "{{versionQuery '@backstage/cli'}}"
Original file line number Diff line number Diff line change
@@ -21,11 +21,13 @@
},
"scripts": {
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"lint": "backstage-cli package lint",
"postpack": "backstage-cli package postpack",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
"start": "backstage-cli package start",
"test": "backstage-cli package test --passWithNoTests --coverage",
"tsc": "tsc"
},
"devDependencies": {
"@backstage/cli": "{{versionQuery '@backstage/cli'}}"
Loading

0 comments on commit 84af3e6

Please sign in to comment.