Merge pull request #33393 from backstage/rugvip/move-cli-new-templates
cli-module-new: move yarn new templates from @backstage/cli
This commit is contained in:
@@ -1 +1,3 @@
|
||||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
|
||||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname, {
|
||||
ignorePatterns: ['templates/**'],
|
||||
});
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
"license": "Apache-2.0",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"bin": "bin/backstage-cli-module-new",
|
||||
"files": [
|
||||
"dist",
|
||||
"bin"
|
||||
"bin",
|
||||
"templates"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "backstage-cli package build",
|
||||
@@ -57,6 +59,5 @@
|
||||
"@types/inquirer": "^8.1.3",
|
||||
"@types/lodash": "^4.14.151",
|
||||
"@types/recursive-readdir": "^2.2.0"
|
||||
},
|
||||
"bin": "bin/backstage-cli-module-new"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
|
||||
export const defaultTemplates = [
|
||||
'@backstage/cli/templates/frontend-plugin',
|
||||
'@backstage/cli/templates/backend-plugin',
|
||||
'@backstage/cli/templates/backend-plugin-module',
|
||||
'@backstage/cli/templates/plugin-web-library',
|
||||
'@backstage/cli/templates/plugin-node-library',
|
||||
'@backstage/cli/templates/plugin-common-library',
|
||||
'@backstage/cli/templates/web-library',
|
||||
'@backstage/cli/templates/node-library',
|
||||
'@backstage/cli/templates/cli-module',
|
||||
'@backstage/cli/templates/catalog-provider-module',
|
||||
'@backstage/cli/templates/scaffolder-backend-module',
|
||||
'@backstage/cli-module-new/templates/frontend-plugin',
|
||||
'@backstage/cli-module-new/templates/backend-plugin',
|
||||
'@backstage/cli-module-new/templates/backend-plugin-module',
|
||||
'@backstage/cli-module-new/templates/plugin-web-library',
|
||||
'@backstage/cli-module-new/templates/plugin-node-library',
|
||||
'@backstage/cli-module-new/templates/plugin-common-library',
|
||||
'@backstage/cli-module-new/templates/web-library',
|
||||
'@backstage/cli-module-new/templates/node-library',
|
||||
'@backstage/cli-module-new/templates/cli-module',
|
||||
'@backstage/cli-module-new/templates/catalog-provider-module',
|
||||
'@backstage/cli-module-new/templates/scaffolder-backend-module',
|
||||
];
|
||||
|
||||
@@ -200,6 +200,72 @@ describe('loadPortableTemplateConfig', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should rewrite legacy @backstage/cli/templates paths', async () => {
|
||||
mockDir.setContent({
|
||||
'package.json': JSON.stringify({
|
||||
backstage: {
|
||||
cli: {
|
||||
new: {
|
||||
templates: [
|
||||
'@backstage/cli/templates/backend-plugin',
|
||||
'@backstage/cli/templates/frontend-plugin',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
node_modules: {
|
||||
'@backstage': {
|
||||
'cli-module-new': {
|
||||
templates: {
|
||||
'backend-plugin': {
|
||||
[TEMPLATE_FILE_NAME]:
|
||||
'name: backend-plugin\nrole: backend-plugin\n',
|
||||
},
|
||||
'frontend-plugin': {
|
||||
[TEMPLATE_FILE_NAME]:
|
||||
'name: frontend-plugin\nrole: frontend-plugin\n',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadPortableTemplateConfig({
|
||||
packagePath: mockDir.resolve('package.json'),
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
isUsingDefaultTemplates: false,
|
||||
templatePointers: [
|
||||
{
|
||||
name: 'backend-plugin',
|
||||
target: realpathSync(
|
||||
mockDir.resolve(
|
||||
'node_modules/@backstage/cli-module-new/templates/backend-plugin',
|
||||
TEMPLATE_FILE_NAME,
|
||||
),
|
||||
),
|
||||
},
|
||||
{
|
||||
name: 'frontend-plugin',
|
||||
target: realpathSync(
|
||||
mockDir.resolve(
|
||||
'node_modules/@backstage/cli-module-new/templates/frontend-plugin',
|
||||
TEMPLATE_FILE_NAME,
|
||||
),
|
||||
),
|
||||
},
|
||||
],
|
||||
license: 'Apache-2.0',
|
||||
private: true,
|
||||
version: '0.1.0',
|
||||
packageNamePrefix: '@internal/',
|
||||
packageNamePluginInfix: 'backstage-plugin-',
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject templates with conflicting names', async () => {
|
||||
mockDir.setContent({
|
||||
'package.json': JSON.stringify({
|
||||
|
||||
@@ -157,6 +157,9 @@ export async function loadPortableTemplateConfig(
|
||||
};
|
||||
}
|
||||
|
||||
const CLI_TEMPLATE_PREFIX = '@backstage/cli/templates/';
|
||||
const CLI_MODULE_NEW_TEMPLATE_PREFIX = '@backstage/cli-module-new/templates/';
|
||||
|
||||
function resolveLocalTemplatePath(pointer: string, basePath: string): string {
|
||||
if (isAbsolute(pointer)) {
|
||||
throw new Error(`Template target may not be an absolute path`);
|
||||
@@ -166,7 +169,14 @@ function resolveLocalTemplatePath(pointer: string, basePath: string): string {
|
||||
return resolvePath(basePath, pointer, TEMPLATE_FILE_NAME);
|
||||
}
|
||||
|
||||
return require.resolve(`${pointer}/${TEMPLATE_FILE_NAME}`, {
|
||||
// Rewrite legacy @backstage/cli/templates/* paths to @backstage/cli-module-new/templates/*
|
||||
const resolvedPointer = pointer.startsWith(CLI_TEMPLATE_PREFIX)
|
||||
? `${CLI_MODULE_NEW_TEMPLATE_PREFIX}${pointer.slice(
|
||||
CLI_TEMPLATE_PREFIX.length,
|
||||
)}`
|
||||
: pointer;
|
||||
|
||||
return require.resolve(`${resolvedPointer}/${TEMPLATE_FILE_NAME}`, {
|
||||
paths: [basePath],
|
||||
});
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user