Merge pull request #25855 from drodil/cli_license

feat(cli): allow setting license for new command
This commit is contained in:
Ben Lambert
2024-07-31 09:04:36 +02:00
committed by GitHub
33 changed files with 49 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
New command now supports setting package license
+1
View File
@@ -193,6 +193,7 @@ Options:
--scope <scope>
--npm-registry <URL>
--baseVersion <version>
--license <license>
--no-private
-h, --help
```
@@ -19,16 +19,16 @@ import { promisify } from 'util';
import chalk from 'chalk';
import inquirer, { Answers, Question } from 'inquirer';
import { exec as execCb } from 'child_process';
import { resolve as resolvePath, join as joinPath } from 'path';
import { join as joinPath, resolve as resolvePath } from 'path';
import camelCase from 'lodash/camelCase';
import upperFirst from 'lodash/upperFirst';
import os from 'os';
import { OptionValues } from 'commander';
import { assertError } from '@backstage/errors';
import {
parseOwnerIds,
addCodeownersEntry,
getCodeownersFilePath,
parseOwnerIds,
} from '../../lib/codeowners';
import { paths } from '../../lib/paths';
import { Task, templatingTask } from '../../lib/tasks';
@@ -266,6 +266,7 @@ export default async (opts: OptionValues) => {
const { version: pluginVersion } = isMonoRepo
? await fs.readJson(paths.resolveTargetRoot('lerna.json'))
: { version: '0.1.0' };
const license = opts.license ?? 'Apache-2.0';
let lockfile: Lockfile | undefined;
try {
@@ -299,6 +300,7 @@ export default async (opts: OptionValues) => {
name,
privatePackage,
npmRegistry,
license,
},
createPackageVersionProvider(lockfile),
isMonoRepo,
+4
View File
@@ -254,6 +254,10 @@ export function registerCommands(program: Command) {
'--baseVersion <version>',
'The version to use for any new packages (default: 0.1.0)',
)
.option(
'--license <license>',
'The license to use for any new packages (default: Apache-2.0)',
)
.option('--no-private', 'Do not mark new packages as private')
.action(lazy(() => import('./new/new').then(m => m.default)));
+3
View File
@@ -70,11 +70,14 @@ export default async (opts: OptionValues) => {
return dir;
}
const license = opts.license ?? 'Apache-2.0';
let modified = false;
try {
await factory.create(options, {
isMonoRepo: await isMonoRepo(),
defaultVersion,
license,
scope: opts.scope?.replace(/^@/, ''),
npmRegistry: opts.npmRegistry,
private: Boolean(opts.private),
@@ -79,6 +79,7 @@ describe('backendModule factory', () => {
modified = true;
},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -75,6 +75,7 @@ export const backendModule = createFactory<Options>({
packageVersion: ctx.defaultVersion,
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
license: ctx.license,
},
});
@@ -78,6 +78,7 @@ describe('backendPlugin factory', () => {
modified = true;
},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -64,6 +64,7 @@ export const backendPlugin = createFactory<Options>({
pluginVersion: ctx.defaultVersion,
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
license: ctx.license,
},
});
@@ -80,6 +80,7 @@ describe('frontendPlugin factory', () => {
modified = true;
},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -174,6 +175,7 @@ const router = (
defaultVersion: '1.0.0',
markAsModified: () => {},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
await expect(
@@ -67,6 +67,7 @@ export const frontendPlugin = createFactory<Options>({
pluginVersion: ctx.defaultVersion,
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
license: ctx.license,
},
});
@@ -64,6 +64,7 @@ describe('nodeLibraryPackage factory', () => {
modified = true;
},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -134,6 +135,7 @@ describe('nodeLibraryPackage factory', () => {
defaultVersion: '1.0.0',
markAsModified: () => {},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(Task.forCommand).toHaveBeenCalledTimes(2);
@@ -61,6 +61,7 @@ export const nodeLibraryPackage = createFactory<Options>({
pluginVersion: ctx.defaultVersion,
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
license: ctx.license,
},
});
@@ -62,6 +62,7 @@ describe('pluginCommon factory', () => {
modified = true;
},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -61,6 +61,7 @@ export const pluginCommon = createFactory<Options>({
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
pluginVersion: ctx.defaultVersion,
license: ctx.license,
},
});
@@ -62,6 +62,7 @@ describe('pluginNode factory', () => {
modified = true;
},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -61,6 +61,7 @@ export const pluginNode = createFactory<Options>({
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
pluginVersion: ctx.defaultVersion,
license: ctx.license,
},
});
@@ -62,6 +62,7 @@ describe('pluginWeb factory', () => {
modified = true;
},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -61,6 +61,7 @@ export const pluginWeb = createFactory<Options>({
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
pluginVersion: ctx.defaultVersion,
license: ctx.license,
},
});
@@ -62,6 +62,7 @@ describe('scaffolderModule factory', () => {
modified = true;
},
createTemporaryDirectory: (name: string) => fs.mkdtemp(name),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -78,6 +78,7 @@ export const scaffolderModule = createFactory<Options>({
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
pluginVersion: ctx.defaultVersion,
license: ctx.license,
},
});
@@ -64,6 +64,7 @@ describe('webLibraryPackage factory', () => {
modified = true;
},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(modified).toBe(true);
@@ -134,6 +135,7 @@ describe('webLibraryPackage factory', () => {
defaultVersion: '1.0.0',
markAsModified: () => {},
createTemporaryDirectory: () => fs.mkdtemp('test'),
license: 'Apache-2.0',
});
expect(Task.forCommand).toHaveBeenCalledTimes(2);
@@ -61,6 +61,7 @@ export const webLibraryPackage = createFactory<Options>({
pluginVersion: ctx.defaultVersion,
privatePackage: ctx.private,
npmRegistry: ctx.npmRegistry,
license: ctx.license,
},
});
+2
View File
@@ -27,6 +27,8 @@ export interface CreateContext {
isMonoRepo: boolean;
/** The default version to use for new packages */
defaultVersion: string;
/** License to use for new packages */
license: string;
/** Creates a temporary directory. This will always be deleted after creation is done. */
createTemporaryDirectory(name: string): Promise<string>;
@@ -4,7 +4,7 @@
"version": "{{packageVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}
@@ -3,7 +3,7 @@
"version": "{{pluginVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}
@@ -4,7 +4,7 @@
"version": "{{pluginVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}
@@ -4,7 +4,7 @@
"version": "{{pluginVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}
@@ -3,7 +3,7 @@
"version": "{{pluginVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}
@@ -4,7 +4,7 @@
"version": "{{pluginVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}
@@ -3,7 +3,7 @@
"version": "{{pluginVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}
@@ -4,7 +4,7 @@
"version": "{{pluginVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}
@@ -3,7 +3,7 @@
"version": "{{pluginVersion}}",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"license": "{{license}}",
{{#if privatePackage}}
"private": {{privatePackage}},
{{/if}}