Skip to content

Commit

Permalink
feat(cli): switch to @janus-idp/cli for new plugins and populate them…
Browse files Browse the repository at this point in the history
… with the basics

Signed-off-by: Tomas Coufal <[email protected]>
  • Loading branch information
tumido committed Oct 25, 2023
1 parent 1071eeb commit 1cef7d9
Show file tree
Hide file tree
Showing 49 changed files with 291 additions and 135 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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
5 changes: 4 additions & 1 deletion packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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 @@ -129,6 +128,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
6 changes: 4 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,14 +77,16 @@ 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',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'templating index.ts.hbs',
'templating module.ts.hbs',
'Installing:',
Expand All @@ -96,7 +98,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
6 changes: 4 additions & 2 deletions packages/cli/src/lib/new/factories/backendPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ 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',
'templating package.json.hbs',
'templating tsconfig.json.hbs',
'templating turbo.json.hbs',
'copying index.ts',
'templating run.ts.hbs',
'copying setupTests.ts',
Expand All @@ -99,7 +101,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
13 changes: 7 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,16 @@ 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 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 +121,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 +178,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 +189,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
6 changes: 4 additions & 2 deletions packages/cli/src/lib/new/factories/scaffolderModule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ describe('scaffolderModule factory', () => {

expect(output).toEqual([
'',
'Creating module backstage-plugin-scaffolder-backend-module-test',
'Creating module @janus-idp/backstage-plugin-scaffolder-backend-module-test',
'Checking Prerequisites:',
`availability plugins${sep}scaffolder-backend-module-test`,
'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 index.ts',
'copying example.test.ts',
Expand All @@ -92,7 +94,7 @@ describe('scaffolderModule factory', () => {
fs.readJson('/root/plugins/scaffolder-backend-module-test/package.json'),
).resolves.toEqual(
expect.objectContaining({
name: 'backstage-plugin-scaffolder-backend-module-test',
name: '@janus-idp/backstage-plugin-scaffolder-backend-module-test',
description: 'The test module for @backstage/plugin-scaffolder-backend',
private: true,
version: '1.0.0',
Expand Down
9 changes: 1 addition & 8 deletions packages/cli/src/lib/new/factories/scaffolderModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,7 @@ export const scaffolderModule = createFactory<Options>({
const { id } = options;
const slug = `scaffolder-backend-module-${id}`;

let name = `backstage-plugin-${slug}`;
if (ctx.scope) {
if (ctx.scope === 'backstage') {
name = `@backstage/plugin-${slug}`;
} else {
name = `@${ctx.scope}/backstage-plugin-${slug}`;
}
}
const name = `@janus-idp/backstage-plugin-${slug}`;

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

0 comments on commit 1cef7d9

Please sign in to comment.