Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): switch to @janus-idp/cli for new plugins and populate them with the basics #782

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"lint-staged": "lint-staged",
"prettier:check": "prettier --ignore-unknown --check .",
"prettier:fix": "prettier --ignore-unknown --write .",
"new": "backstage-cli new --scope @janus-idp",
"new": "janus-cli new --do-not-edit-packages",
"release": "multi-semantic-release",
"prepare": "husky install",
"versions:bump": "backstage-cli versions:bump && find . -name 'package.json' ! -path '*/node_modules/*' -exec sed -i '' -e '/devDependencies/,/\\}/{ s/\"\\^/\"/; }' {} \\;"
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export function registerCommands(program: Command) {
(opt, arr: string[]) => [...arr, opt],
[],
)
.option('--scope <scope>', 'The scope to use for new packages')
.option(
'--npm-registry <URL>',
'The package registry to use for new packages',
Expand All @@ -148,6 +147,10 @@ export function registerCommands(program: Command) {
'The version to use for any new packages (default: 0.1.0)',
)
.option('--no-private', 'Do not mark new packages as private')
.option(
'--do-not-edit-packages',
'Do not edit packages/app and packages/backend',
)
.action(lazy(() => import('./new/new').then(m => m.default)));

registerScriptCommand(program);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/new/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export default async (opts: OptionValues) => {
await factory.create(options, {
isMonoRepo: await isMonoRepo(),
defaultVersion,
scope: opts.scope?.replace(/^@/, ''),
npmRegistry: opts.npmRegistry,
private: Boolean(opts.private),
createTemporaryDirectory,
markAsModified() {
modified = true;
},
doNotEditPackages: Boolean(opts.doNotEditPackages),
});

Task.log();
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/lib/new/factories/backendModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,22 @@ describe('backendModule factory', () => {

expect(output).toEqual([
'',
'Creating backend module backstage-plugin-test-backend-module-tester-two',
'Creating backend module @janus-idp/backstage-plugin-test-backend-module-tester-two',
'Checking Prerequisites:',
`availability plugins${sep}test-backend-module-tester-two`,
'creating temp dir',
'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',
Expand All @@ -96,7 +102,7 @@ describe('backendModule factory', () => {
fs.readJson('/root/packages/backend/package.json'),
).resolves.toEqual({
dependencies: {
'backstage-plugin-test-backend-module-tester-two': '^1.0.0',
'@janus-idp/backstage-plugin-test-backend-module-tester-two': '^1.0.0',
},
});
const moduleFile = await fs.readFile(
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/lib/new/factories/backendModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export const backendModule = createFactory<Options>({
async create(options: Options, ctx: CreateContext) {
const { id: pluginId, moduleId } = options;
const dirName = `${pluginId}-backend-module-${moduleId}`;
const name = ctx.scope
? `@${ctx.scope}/plugin-${dirName}`
: `backstage-plugin-${dirName}`;
const name = `@janus-idp/backstage-plugin-${dirName}`;

Task.log();
Task.log(`Creating backend module ${chalk.cyan(name)}`);
Expand All @@ -75,7 +73,10 @@ export const backendModule = createFactory<Options>({
},
});

if (await fs.pathExists(paths.resolveTargetRoot('packages/backend'))) {
if (
!ctx.doNotEditPackages &&
(await fs.pathExists(paths.resolveTargetRoot('packages/backend')))
) {
await Task.forItem('backend', 'adding dependency', async () => {
await addPackageDependency(
paths.resolveTargetRoot('packages/backend/package.json'),
Expand Down
14 changes: 10 additions & 4 deletions packages/cli/src/lib/new/factories/backendPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,25 @@ describe('backendPlugin factory', () => {

expect(output).toEqual([
'',
'Creating backend plugin backstage-plugin-test-backend',
'Creating backend plugin @janus-idp/backstage-plugin-test-backend',
'Checking Prerequisites:',
`availability plugins${sep}test-backend`,
'creating temp dir',
'Executing Template:',
'copying .eslintrc.js',
'templating README.md.hbs',
'copying app-config.janus-idp.yaml',
'copying config.d.ts',
'templating package.json.hbs',
'copying index.ts',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'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`,
Expand All @@ -99,7 +105,7 @@ describe('backendPlugin factory', () => {
fs.readJson('/root/packages/backend/package.json'),
).resolves.toEqual({
dependencies: {
'backstage-plugin-test-backend': '^1.0.0',
'@janus-idp/backstage-plugin-test-backend': '^1.0.0',
},
});
const standaloneServerFile = await fs.readFile(
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/lib/new/factories/backendPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export const backendPlugin = createFactory<Options>({
async create(options: Options, ctx: CreateContext) {
const { id } = options;
const pluginId = `${id}-backend`;
const name = ctx.scope
? `@${ctx.scope}/plugin-${pluginId}`
: `backstage-plugin-${pluginId}`;
const name = `@janus-idp/backstage-plugin-${pluginId}`;

Task.log();
Task.log(`Creating backend plugin ${chalk.cyan(name)}`);
Expand All @@ -65,7 +63,10 @@ export const backendPlugin = createFactory<Options>({
},
});

if (await fs.pathExists(paths.resolveTargetRoot('packages/backend'))) {
if (
!ctx.doNotEditPackages &&
(await fs.pathExists(paths.resolveTargetRoot('packages/backend')))
) {
await Task.forItem('backend', 'adding dependency', async () => {
await addPackageDependency(
paths.resolveTargetRoot('packages/backend/package.json'),
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/new/factories/common/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ some-package@^1.1.0:
{{/if}}
"description": "testing",
"dependencies": {
"some-package": "{{ versionQuery 'some-package' '1.3.0' }}",
"other-package": "{{ versionQuery 'other-package' '2.3.0' }}"
"some-package": "^{{ versionQuery 'some-package' '1.3.0' }}",
"other-package": "^{{ versionQuery 'other-package' '2.3.0' }}"
}
}
`,
Expand Down
15 changes: 9 additions & 6 deletions packages/cli/src/lib/new/factories/frontendPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ describe('frontendPlugin factory', () => {

expect(output).toEqual([
'',
'Creating frontend plugin backstage-plugin-test',
'Creating frontend plugin @janus-idp/backstage-plugin-test',
'Checking Prerequisites:',
`availability plugins${sep}test`,
'creating temp dir',
'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',
'templating index.tsx.hbs',
'templating index.ts.hbs',
'templating plugin.test.ts.hbs',
Expand All @@ -119,14 +123,14 @@ describe('frontendPlugin factory', () => {
fs.readJson('/root/packages/app/package.json'),
).resolves.toEqual({
dependencies: {
'backstage-plugin-test': '^1.0.0',
'@janus-idp/backstage-plugin-test': '^1.0.0',
},
});

await expect(fs.readFile('/root/packages/app/src/App.tsx', 'utf8')).resolves
.toBe(`
import { createApp } from '@backstage/app-defaults';
import { TestPage } from 'backstage-plugin-test';
import { TestPage } from '@janus-idp/backstage-plugin-test';

const router = (
<FlatRoutes>
Expand Down Expand Up @@ -176,7 +180,6 @@ const router = (
jest.spyOn(Task, 'forCommand').mockResolvedValue();

await frontendPlugin.create(options, {
scope: 'internal',
private: true,
isMonoRepo: true,
defaultVersion: '1.0.0',
Expand All @@ -188,14 +191,14 @@ const router = (
fs.readJson('/root/packages/app/package.json'),
).resolves.toEqual({
dependencies: {
'@internal/plugin-test': '^1.0.0',
'@janus-idp/backstage-plugin-test': '^1.0.0',
},
});

await expect(fs.readFile('/root/packages/app/src/App.tsx', 'utf8')).resolves
.toBe(`
import { createApp } from '@backstage/app-defaults';
import { TestPage } from '@internal/plugin-test';
import { TestPage } from '@janus-idp/backstage-plugin-test';

const router = (
<FlatRoutes>
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/lib/new/factories/frontendPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export const frontendPlugin = createFactory<Options>({
async create(options: Options, ctx: CreateContext) {
const { id } = options;

const name = ctx.scope
? `@${ctx.scope}/plugin-${id}`
: `backstage-plugin-${id}`;
const name = `@janus-idp/backstage-plugin-${id}`;
const extensionName = `${upperFirst(camelCase(id))}Page`;

Task.log();
Expand All @@ -68,7 +66,10 @@ export const frontendPlugin = createFactory<Options>({
},
});

if (await fs.pathExists(paths.resolveTargetRoot('packages/app'))) {
if (
!ctx.doNotEditPackages &&
(await fs.pathExists(paths.resolveTargetRoot('packages/app')))
) {
await Task.forItem('app', 'adding dependency', async () => {
await addPackageDependency(
paths.resolveTargetRoot('packages/app/package.json'),
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/lib/new/factories/pluginCommon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ describe('pluginCommon factory', () => {

expect(output).toEqual([
'',
'Creating backend plugin backstage-plugin-test-common',
'Creating backend plugin @janus-idp/backstage-plugin-test-common',
'Checking Prerequisites:',
`availability plugins${sep}test-common`,
'creating temp dir',
'Executing Template:',
'copying .eslintrc.js',
'templating README.md.hbs',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating index.ts.hbs',
'copying setupTests.ts',
'Installing:',
Expand All @@ -89,7 +91,7 @@ describe('pluginCommon factory', () => {
fs.readJson('/root/plugins/test-common/package.json'),
).resolves.toEqual(
expect.objectContaining({
name: 'backstage-plugin-test-common',
name: '@janus-idp/backstage-plugin-test-common',
description: 'Common functionalities for the test plugin',
private: true,
version: '1.0.0',
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/lib/new/factories/pluginCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export const pluginCommon = createFactory<Options>({
async create(options: Options, ctx: CreateContext) {
const { id } = options;
const suffix = `${id}-common`;
const name = ctx.scope
? `@${ctx.scope}/plugin-${suffix}`
: `backstage-plugin-${suffix}`;
const name = `@janus-idp/backstage-plugin-${suffix}`;

Task.log();
Task.log(`Creating backend plugin ${chalk.cyan(name)}`);
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/lib/new/factories/pluginNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ describe('pluginNode factory', () => {

expect(output).toEqual([
'',
'Creating Node.js plugin library backstage-plugin-test-node',
'Creating Node.js plugin library @janus-idp/backstage-plugin-test-node',
'Checking Prerequisites:',
`availability plugins${sep}test-node`,
'creating temp dir',
'Executing Template:',
'copying .eslintrc.js',
'templating README.md.hbs',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating index.ts.hbs',
'copying setupTests.ts',
'Installing:',
Expand All @@ -89,7 +91,7 @@ describe('pluginNode factory', () => {
fs.readJson('/root/plugins/test-node/package.json'),
).resolves.toEqual(
expect.objectContaining({
name: 'backstage-plugin-test-node',
name: '@janus-idp/backstage-plugin-test-node',
description: 'Node.js library for the test plugin',
private: true,
version: '1.0.0',
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/lib/new/factories/pluginNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export const pluginNode = createFactory<Options>({
async create(options: Options, ctx: CreateContext) {
const { id } = options;
const suffix = `${id}-node`;
const name = ctx.scope
? `@${ctx.scope}/plugin-${suffix}`
: `backstage-plugin-${suffix}`;
const name = `@janus-idp/backstage-plugin-${suffix}`;

Task.log();
Task.log(`Creating Node.js plugin library ${chalk.cyan(name)}`);
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/lib/new/factories/pluginWeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ describe('pluginWeb factory', () => {

expect(output).toEqual([
'',
'Creating web plugin library backstage-plugin-test-react',
'Creating web plugin library @janus-idp/backstage-plugin-test-react',
'Checking Prerequisites:',
`availability plugins${sep}test-react`,
'creating temp dir',
'Executing Template:',
'copying .eslintrc.js',
'templating README.md.hbs',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating index.ts.hbs',
'copying setupTests.ts',
'copying index.ts',
Expand All @@ -96,7 +98,7 @@ describe('pluginWeb factory', () => {
fs.readJson('/root/plugins/test-react/package.json'),
).resolves.toEqual(
expect.objectContaining({
name: 'backstage-plugin-test-react',
name: '@janus-idp/backstage-plugin-test-react',
description: 'Web library for the test plugin',
private: true,
version: '1.0.0',
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/lib/new/factories/pluginWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export const pluginWeb = createFactory<Options>({
async create(options: Options, ctx: CreateContext) {
const { id } = options;
const suffix = `${id}-react`;
const name = ctx.scope
? `@${ctx.scope}/plugin-${suffix}`
: `backstage-plugin-${suffix}`;
const name = `@janus-idp/backstage-plugin-${suffix}`;

Task.log();
Task.log(`Creating web plugin library ${chalk.cyan(name)}`);
Expand Down
Loading
Loading