diff --git a/packages/cli/package.json b/packages/cli/package.json index a5561a05a4..80fe0ee789 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/cli/src/lib/new/factories/backendModule.test.ts b/packages/cli/src/lib/new/factories/backendModule.test.ts index f2a27dedf7..ce2fb09e97 100644 --- a/packages/cli/src/lib/new/factories/backendModule.test.ts +++ b/packages/cli/src/lib/new/factories/backendModule.test.ts @@ -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', diff --git a/packages/cli/src/lib/new/factories/backendPlugin.test.ts b/packages/cli/src/lib/new/factories/backendPlugin.test.ts index eb0b2ae1b0..8eec54f216 100644 --- a/packages/cli/src/lib/new/factories/backendPlugin.test.ts +++ b/packages/cli/src/lib/new/factories/backendPlugin.test.ts @@ -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`, diff --git a/packages/cli/src/lib/new/factories/frontendPlugin.test.ts b/packages/cli/src/lib/new/factories/frontendPlugin.test.ts index bd9a465238..9d6fca0a98 100644 --- a/packages/cli/src/lib/new/factories/frontendPlugin.test.ts +++ b/packages/cli/src/lib/new/factories/frontendPlugin.test.ts @@ -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', diff --git a/packages/cli/src/lib/new/factories/scaffolderModule.test.ts b/packages/cli/src/lib/new/factories/scaffolderModule.test.ts index 5d1e1071f9..11af2463a4 100644 --- a/packages/cli/src/lib/new/factories/scaffolderModule.test.ts +++ b/packages/cli/src/lib/new/factories/scaffolderModule.test.ts @@ -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', diff --git a/packages/cli/src/lib/version.ts b/packages/cli/src/lib/version.ts index 48f59ed3ea..81dd8b0562 100644 --- a/packages/cli/src/lib/version.ts +++ b/packages/cli/src/lib/version.ts @@ -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 = { ...Object.fromEntries( Object.entries(Manifest.devDependencies as Record).filter( @@ -47,15 +54,9 @@ export const packageVersions: Record = { ([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]; diff --git a/packages/cli/templates/default-backend-module/app-config.janus-idp.yaml b/packages/cli/templates/default-backend-module/app-config.janus-idp.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/cli/templates/default-backend-module/config.d.ts b/packages/cli/templates/default-backend-module/config.d.ts new file mode 100644 index 0000000000..5728ccd9e1 --- /dev/null +++ b/packages/cli/templates/default-backend-module/config.d.ts @@ -0,0 +1 @@ +export interface Config {} diff --git a/packages/cli/templates/default-backend-module/package.json.hbs b/packages/cli/templates/default-backend-module/package.json.hbs index 1b3fb0dae3..fe2a00f9f2 100644 --- a/packages/cli/templates/default-backend-module/package.json.hbs +++ b/packages/cli/templates/default-backend-module/package.json.hbs @@ -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/backend-plugin-manager@0.0.2-janus.5'}}" }, "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", diff --git a/packages/cli/templates/default-backend-module/src/dynamic/alpha.ts.hbs b/packages/cli/templates/default-backend-module/src/dynamic/alpha.ts.hbs new file mode 100644 index 0000000000..49751f95b8 --- /dev/null +++ b/packages/cli/templates/default-backend-module/src/dynamic/alpha.ts.hbs @@ -0,0 +1,8 @@ +import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager'; + +import { {{moduleVar}} } from '../module'; + +export const dynamicPluginInstaller: BackendDynamicPluginInstaller = { + kind: 'new', + install: {{moduleVar}}, +}; diff --git a/packages/cli/templates/default-backend-module/src/dynamic/index.ts.hbs b/packages/cli/templates/default-backend-module/src/dynamic/index.ts.hbs new file mode 100644 index 0000000000..78e10158fe --- /dev/null +++ b/packages/cli/templates/default-backend-module/src/dynamic/index.ts.hbs @@ -0,0 +1,5 @@ +import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager'; + +export const dynamicPluginInstaller: BackendDynamicPluginInstaller = { + kind: 'legacy' +}; diff --git a/packages/cli/templates/default-backend-module/src/index.ts.hbs b/packages/cli/templates/default-backend-module/src/index.ts.hbs index 0cf1f00d42..ab57d913b6 100644 --- a/packages/cli/templates/default-backend-module/src/index.ts.hbs +++ b/packages/cli/templates/default-backend-module/src/index.ts.hbs @@ -1,8 +1,8 @@ -/***/ /** * The {{moduleId}} backend module for the {{pluginId}} plugin. * * @packageDocumentation */ -export { {{moduleVar}} } from './module'; +export * from './dynamic/index'; +export * from './module'; diff --git a/packages/cli/templates/default-backend-plugin/app-config.janus-idp.yaml b/packages/cli/templates/default-backend-plugin/app-config.janus-idp.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/cli/templates/default-backend-plugin/config.d.ts b/packages/cli/templates/default-backend-plugin/config.d.ts new file mode 100644 index 0000000000..5728ccd9e1 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/config.d.ts @@ -0,0 +1 @@ +export interface Config {} diff --git a/packages/cli/templates/default-backend-plugin/package.json.hbs b/packages/cli/templates/default-backend-plugin/package.json.hbs index 13b8573761..b51b724eb4 100644 --- a/packages/cli/templates/default-backend-plugin/package.json.hbs +++ b/packages/cli/templates/default-backend-plugin/package.json.hbs @@ -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/backend-plugin-manager@0.0.2-janus.5'}}", "@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", diff --git a/packages/cli/templates/default-backend-plugin/src/dynamic/alpha.ts.hbs b/packages/cli/templates/default-backend-plugin/src/dynamic/alpha.ts.hbs new file mode 100644 index 0000000000..6e1ee58f39 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/dynamic/alpha.ts.hbs @@ -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()], +}; diff --git a/packages/cli/templates/default-backend-plugin/src/dynamic/index.ts.hbs b/packages/cli/templates/default-backend-plugin/src/dynamic/index.ts.hbs new file mode 100644 index 0000000000..118e8d0a22 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/dynamic/index.ts.hbs @@ -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, + }, +}; diff --git a/packages/cli/templates/default-backend-plugin/src/index.ts b/packages/cli/templates/default-backend-plugin/src/index.ts deleted file mode 100644 index 47af95cb35..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './service/router'; diff --git a/packages/cli/templates/default-backend-plugin/src/index.ts.hbs b/packages/cli/templates/default-backend-plugin/src/index.ts.hbs new file mode 100644 index 0000000000..b1c735bca6 --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/index.ts.hbs @@ -0,0 +1,8 @@ +/** + * The {{id}} backend plugin. + * + * @packageDocumentation + */ + +export * from './dynamic/index'; +export * from './service/router'; diff --git a/packages/cli/templates/default-backend-plugin/src/service/router.ts b/packages/cli/templates/default-backend-plugin/src/service/router.ts deleted file mode 100644 index c15bac5892..0000000000 --- a/packages/cli/templates/default-backend-plugin/src/service/router.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { errorHandler } from '@backstage/backend-common'; -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 { - 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; -} diff --git a/packages/cli/templates/default-backend-plugin/src/service/router.ts.hbs b/packages/cli/templates/default-backend-plugin/src/service/router.ts.hbs new file mode 100644 index 0000000000..aac2a0049c --- /dev/null +++ b/packages/cli/templates/default-backend-plugin/src/service/router.ts.hbs @@ -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 { + 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)})); + }, + }); + }, +}); diff --git a/packages/cli/templates/default-backend-plugin/tsconfig.json.hbs b/packages/cli/templates/default-backend-plugin/tsconfig.json.hbs index 744f9d165c..a05b388c2b 100644 --- a/packages/cli/templates/default-backend-plugin/tsconfig.json.hbs +++ b/packages/cli/templates/default-backend-plugin/tsconfig.json.hbs @@ -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}}", diff --git a/packages/cli/templates/default-common-plugin-package/package.json.hbs b/packages/cli/templates/default-common-plugin-package/package.json.hbs index cc599a14bb..0555f24f26 100644 --- a/packages/cli/templates/default-common-plugin-package/package.json.hbs +++ b/packages/cli/templates/default-common-plugin-package/package.json.hbs @@ -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'}}" diff --git a/packages/cli/templates/default-node-plugin-package/package.json.hbs b/packages/cli/templates/default-node-plugin-package/package.json.hbs index 5189cfab30..177003768b 100644 --- a/packages/cli/templates/default-node-plugin-package/package.json.hbs +++ b/packages/cli/templates/default-node-plugin-package/package.json.hbs @@ -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'}}" diff --git a/packages/cli/templates/default-plugin/app-config.janus-idp.yaml.hbs b/packages/cli/templates/default-plugin/app-config.janus-idp.yaml.hbs new file mode 100644 index 0000000000..5ff6dcb6b8 --- /dev/null +++ b/packages/cli/templates/default-plugin/app-config.janus-idp.yaml.hbs @@ -0,0 +1,8 @@ +dynamicPlugins: + frontend: + janus-idp.backstage-plugin-{{id}}: + apiFactories: [] + appIcons: [] + dynamicRoutes: [] + mountPoints: [] + routeBindings: [] diff --git a/packages/cli/templates/default-plugin/config.d.ts b/packages/cli/templates/default-plugin/config.d.ts new file mode 100644 index 0000000000..5728ccd9e1 --- /dev/null +++ b/packages/cli/templates/default-plugin/config.d.ts @@ -0,0 +1 @@ +export interface Config {} diff --git a/packages/cli/templates/default-plugin/package.json.hbs b/packages/cli/templates/default-plugin/package.json.hbs index 539d059b15..ca33f0b56a 100644 --- a/packages/cli/templates/default-plugin/package.json.hbs +++ b/packages/cli/templates/default-plugin/package.json.hbs @@ -20,13 +20,16 @@ }, "sideEffects": false, "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/core-components": "^{{versionQuery '@backstage/core-components'}}", @@ -45,14 +48,19 @@ "@backstage/core-app-api": "{{versionQuery '@backstage/core-app-api'}}", "@backstage/dev-utils": "{{versionQuery '@backstage/dev-utils'}}", "@backstage/test-utils": "{{versionQuery '@backstage/test-utils'}}", + "@janus-idp/cli": "{{versionQuery '@janus-idp/cli'}}", "@testing-library/jest-dom": "{{versionQuery '@testing-library/jest-dom' '5.10.1'}}", "@testing-library/react": "{{versionQuery '@testing-library/react' '12.1.3'}}", "@testing-library/user-event": "{{versionQuery '@testing-library/user-event' '14.0.0'}}", "msw": "{{versionQuery 'msw' '1.0.0'}}" }, "files": [ - "dist" + "dist", + "config.d.ts", + "dist-scalprum", + "app-config.janus-idp.yaml" ], + "configSchema": "config.d.ts", "repository": { "type": "git", "url": "https://github.com/janus-idp/backstage-plugins", diff --git a/packages/cli/templates/default-react-plugin-package/package.json.hbs b/packages/cli/templates/default-react-plugin-package/package.json.hbs index 987006ab24..cd2348da76 100644 --- a/packages/cli/templates/default-react-plugin-package/package.json.hbs +++ b/packages/cli/templates/default-react-plugin-package/package.json.hbs @@ -21,13 +21,14 @@ }, "sideEffects": false, "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", + "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" }, "dependencies": { "@backstage/core-plugin-api": "^{{versionQuery '@backstage/core-plugin-api'}}", diff --git a/packages/cli/templates/scaffolder-module/app-config.janus-idp.yaml b/packages/cli/templates/scaffolder-module/app-config.janus-idp.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/cli/templates/scaffolder-module/config.d.ts b/packages/cli/templates/scaffolder-module/config.d.ts new file mode 100644 index 0000000000..5728ccd9e1 --- /dev/null +++ b/packages/cli/templates/scaffolder-module/config.d.ts @@ -0,0 +1 @@ +export interface Config {} diff --git a/packages/cli/templates/scaffolder-module/package.json.hbs b/packages/cli/templates/scaffolder-module/package.json.hbs index c179dfbe23..fcad533e21 100644 --- a/packages/cli/templates/scaffolder-module/package.json.hbs +++ b/packages/cli/templates/scaffolder-module/package.json.hbs @@ -19,25 +19,53 @@ "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/plugin-scaffolder-backend": "^{{versionQuery '@backstage/plugin-scaffolder-backend'}}" + "@backstage/plugin-scaffolder-backend": "^{{versionQuery '@backstage/plugin-scaffolder-backend'}}", + "@backstage/backend-plugin-api": "^{{versionQuery '@backstage/backend-plugin-api'}}", + "@backstage/backend-plugin-manager": "{{versionQuery '@backstage/backend-plugin-manager' 'npm:@janus-idp/backend-plugin-manager@0.0.2-janus.5'}}", + "@backstage/plugin-scaffolder-node": "^{{versionQuery '@backstage/plugin-scaffolder-node'}}" }, "devDependencies": { "@backstage/backend-common": "{{versionQuery '@backstage/backend-common'}}", - "@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", diff --git a/packages/cli/templates/scaffolder-module/src/dynamic/alpha.ts.hbs b/packages/cli/templates/scaffolder-module/src/dynamic/alpha.ts.hbs new file mode 100644 index 0000000000..c9681aa11f --- /dev/null +++ b/packages/cli/templates/scaffolder-module/src/dynamic/alpha.ts.hbs @@ -0,0 +1,27 @@ +import { + coreServices, + createBackendModule, +} from '@backstage/backend-plugin-api'; +import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager'; +import { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha'; + +import { createAcmeExampleAction } from '../actions'; + +export const dynamicPluginInstaller: BackendDynamicPluginInstaller = { + kind: 'new', + install: createBackendModule({ + moduleId: 'scaffolder-backend-{{id}}', + pluginId: 'scaffolder', + register(env) { + env.registerInit({ + deps: { + scaffolder: scaffolderActionsExtensionPoint, + config: coreServices.rootConfig, + }, + async init({ scaffolder }) { + scaffolder.addActions(createAcmeExampleAction()); + }, + }); + }, + }), +}; diff --git a/packages/cli/templates/scaffolder-module/src/dynamic/index.ts.hbs b/packages/cli/templates/scaffolder-module/src/dynamic/index.ts.hbs new file mode 100644 index 0000000000..cf1b6aabd9 --- /dev/null +++ b/packages/cli/templates/scaffolder-module/src/dynamic/index.ts.hbs @@ -0,0 +1,7 @@ +import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager'; +import { createAcmeExampleAction } from '../actions'; + +export const dynamicPluginInstaller: BackendDynamicPluginInstaller = { + kind: 'legacy', + scaffolder: () => [createAcmeExampleAction()], +}; diff --git a/packages/cli/templates/scaffolder-module/src/index.ts.hbs b/packages/cli/templates/scaffolder-module/src/index.ts.hbs index 3690e43b8e..674dd7ade4 100644 --- a/packages/cli/templates/scaffolder-module/src/index.ts.hbs +++ b/packages/cli/templates/scaffolder-module/src/index.ts.hbs @@ -6,3 +6,4 @@ */ export * from './actions'; +export * from './dynamic/index'; diff --git a/packages/cli/templates/web-library-package/package.json.hbs b/packages/cli/templates/web-library-package/package.json.hbs index f199190837..10baa085c6 100644 --- a/packages/cli/templates/web-library-package/package.json.hbs +++ b/packages/cli/templates/web-library-package/package.json.hbs @@ -20,13 +20,14 @@ }, "sideEffects": false, "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", + "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'}}", diff --git a/yarn.lock b/yarn.lock index a43d585d6d..5bfc783a64 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5621,7 +5621,7 @@ "@backstage/plugin-permission-common" "^0.7.12" "@backstage/types" "^1.1.1" -"@backstage/plugin-scaffolder-node@^0.2.6": +"@backstage/plugin-scaffolder-node@0.2.6", "@backstage/plugin-scaffolder-node@^0.2.6": version "0.2.6" resolved "https://registry.yarnpkg.com/@backstage/plugin-scaffolder-node/-/plugin-scaffolder-node-0.2.6.tgz#fca73dfb6548522f9f4c4313e4e3b1470b5c5744" integrity sha512-elFe0NTj/jstFHEma3yZ7Br5SvhMnOjFzRRXilg+qdD0byMlA4QtFgWsTzOsCLfxOC14GDrZA4NZU1vqgXLGug==