More renaming and reorganizing
Signed-off-by: Min Kim <minkimcello@gmail.com>
This commit is contained in:
@@ -28,18 +28,20 @@ import {
|
||||
addCodeownersEntry,
|
||||
getCodeownersFilePath,
|
||||
} from '../../lib/codeowners';
|
||||
import { resolvePackageName } from '../../lib/new/util';
|
||||
import { promptOptions } from '../../lib/new/prompts';
|
||||
import { runAdditionalActions } from '../../lib/new/additionalActions';
|
||||
|
||||
import { executePluginPackageTemplate } from '../../lib/new/executePluginPackageTemplate';
|
||||
import {
|
||||
readCliConfig,
|
||||
templateSelector,
|
||||
verifyTemplate,
|
||||
} from '../../lib/new/templateSelector';
|
||||
import { promptOptions } from '../../lib/new/prompts';
|
||||
import {
|
||||
populateOptions,
|
||||
createDirName,
|
||||
resolvePackageName,
|
||||
} from '../../lib/new/utils';
|
||||
import { runAdditionalActions } from '../../lib/new/additionalActions';
|
||||
import { executePluginPackageTemplate } from '../../lib/new/executeTemplate';
|
||||
|
||||
export default async () => {
|
||||
const pkgJson = await fs.readJson(paths.resolveTargetRoot('package.json'));
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import {
|
||||
mockPaths,
|
||||
} from './testUtils';
|
||||
import { CreateContext } from './types';
|
||||
import { executePluginPackageTemplate } from './executePluginPackageTemplate';
|
||||
import { executePluginPackageTemplate } from './executeTemplate';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
|
||||
const mockDir = createMockDirectory();
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import inquirer from 'inquirer';
|
||||
import { dirname } from 'path';
|
||||
import { parse } from 'yaml';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import { paths } from '../paths';
|
||||
import { Template, TemplateLocation } from './types';
|
||||
|
||||
import defaultTemplates from '../../../templates/all-default-templates';
|
||||
|
||||
export async function readCliConfig(
|
||||
cliConfig:
|
||||
| {
|
||||
defaults?: boolean;
|
||||
templates?: TemplateLocation[];
|
||||
globals?: Record<string, string>;
|
||||
}
|
||||
| undefined,
|
||||
) {
|
||||
let templates: TemplateLocation[] = [];
|
||||
|
||||
if (!cliConfig || cliConfig?.defaults) {
|
||||
templates = defaultTemplates;
|
||||
}
|
||||
|
||||
const cliTemplates = cliConfig?.templates;
|
||||
if (cliTemplates?.length) {
|
||||
cliTemplates.forEach((template: TemplateLocation) => {
|
||||
templates.push({
|
||||
id: template.id,
|
||||
target: template.target,
|
||||
});
|
||||
});
|
||||
}
|
||||
return {
|
||||
templates,
|
||||
globals: { ...cliConfig?.globals },
|
||||
};
|
||||
}
|
||||
|
||||
export async function templateSelector(
|
||||
templates: TemplateLocation[],
|
||||
): Promise<TemplateLocation> {
|
||||
const answer = await inquirer.prompt<{ name: TemplateLocation }>([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'name',
|
||||
message: 'What do you want to create?',
|
||||
choices: templates.map(template => {
|
||||
return {
|
||||
name: template.id,
|
||||
value: template,
|
||||
};
|
||||
}),
|
||||
},
|
||||
]);
|
||||
return answer.name;
|
||||
}
|
||||
|
||||
export async function verifyTemplate({
|
||||
id,
|
||||
target,
|
||||
}: TemplateLocation): Promise<Template> {
|
||||
if (target.startsWith('http')) {
|
||||
throw new Error('Remote templates are not supported yet');
|
||||
}
|
||||
const template = parse(fs.readFileSync(target, 'utf-8'));
|
||||
const templatePath = paths.resolveTargetRoot(
|
||||
dirname(target),
|
||||
template.template,
|
||||
);
|
||||
if (!fs.existsSync(templatePath)) {
|
||||
throw new Error(
|
||||
`Your CLI template skeleton does not exist: ${templatePath}`,
|
||||
);
|
||||
}
|
||||
if (!template.targetPath) {
|
||||
throw new Error(`Your template, ${id}, is missing a targetPath`);
|
||||
}
|
||||
return { id, templatePath, ...template };
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const resolvePackageName = (options: {
|
||||
baseName: string;
|
||||
scope?: string;
|
||||
plugin: boolean;
|
||||
}) => {
|
||||
const { baseName, scope: _scope, plugin } = options;
|
||||
if (_scope) {
|
||||
const scope = _scope.replace(/@/g, '');
|
||||
if (plugin) {
|
||||
const pluginName = scope.startsWith('backstage')
|
||||
? 'plugin'
|
||||
: 'backstage-plugin';
|
||||
return scope.includes('/')
|
||||
? `@${scope}${pluginName}-${baseName}`
|
||||
: `@${scope}/${pluginName}-${baseName}`;
|
||||
}
|
||||
return scope.includes('/')
|
||||
? `@${scope}${baseName}`
|
||||
: `@${scope}/${baseName}`;
|
||||
}
|
||||
|
||||
return plugin ? `backstage-plugin-${baseName}` : baseName;
|
||||
};
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { resolvePackageName } from './util';
|
||||
import { resolvePackageName } from './utils';
|
||||
|
||||
describe('resolvePackageName', () => {
|
||||
it('should generate correct name without scope', () => {
|
||||
@@ -13,88 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import inquirer from 'inquirer';
|
||||
import { dirname } from 'path';
|
||||
import { parse } from 'yaml';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import { paths } from '../paths';
|
||||
|
||||
import defaultTemplates from '../../../templates/all-default-templates';
|
||||
|
||||
import { Template, TemplateLocation } from './types';
|
||||
|
||||
export async function readCliConfig(
|
||||
cliConfig:
|
||||
| {
|
||||
defaults?: boolean;
|
||||
templates?: TemplateLocation[];
|
||||
globals?: Record<string, string>;
|
||||
}
|
||||
| undefined,
|
||||
) {
|
||||
let templates: TemplateLocation[] = [];
|
||||
|
||||
if (!cliConfig || cliConfig?.defaults) {
|
||||
templates = defaultTemplates;
|
||||
}
|
||||
|
||||
const cliTemplates = cliConfig?.templates;
|
||||
if (cliTemplates?.length) {
|
||||
cliTemplates.forEach((template: TemplateLocation) => {
|
||||
templates.push({
|
||||
id: template.id,
|
||||
target: template.target,
|
||||
});
|
||||
});
|
||||
}
|
||||
return {
|
||||
templates,
|
||||
globals: { ...cliConfig?.globals },
|
||||
};
|
||||
}
|
||||
|
||||
export async function templateSelector(
|
||||
templates: TemplateLocation[],
|
||||
): Promise<TemplateLocation> {
|
||||
const answer = await inquirer.prompt<{ name: TemplateLocation }>([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'name',
|
||||
message: 'What do you want to create?',
|
||||
choices: templates.map(template => {
|
||||
return {
|
||||
name: template.id,
|
||||
value: template,
|
||||
};
|
||||
}),
|
||||
},
|
||||
]);
|
||||
return answer.name;
|
||||
}
|
||||
|
||||
export async function verifyTemplate({
|
||||
id,
|
||||
target,
|
||||
}: TemplateLocation): Promise<Template> {
|
||||
if (target.startsWith('http')) {
|
||||
throw new Error('Remote templates are not supported yet');
|
||||
}
|
||||
const template = parse(fs.readFileSync(target, 'utf-8'));
|
||||
const templatePath = paths.resolveTargetRoot(
|
||||
dirname(target),
|
||||
template.template,
|
||||
);
|
||||
if (!fs.existsSync(templatePath)) {
|
||||
throw new Error(
|
||||
`Your CLI template skeleton does not exist: ${templatePath}`,
|
||||
);
|
||||
}
|
||||
if (!template.targetPath) {
|
||||
throw new Error(`Your template, ${id}, is missing a targetPath`);
|
||||
}
|
||||
return { id, templatePath, ...template };
|
||||
}
|
||||
import { Template } from './types';
|
||||
|
||||
interface Options extends Record<string, string | boolean> {
|
||||
id: string;
|
||||
@@ -107,6 +28,30 @@ interface Options extends Record<string, string | boolean> {
|
||||
moduleId: string;
|
||||
}
|
||||
|
||||
export const resolvePackageName = (options: {
|
||||
baseName: string;
|
||||
scope?: string;
|
||||
plugin: boolean;
|
||||
}) => {
|
||||
const { baseName, scope: _scope, plugin } = options;
|
||||
if (_scope) {
|
||||
const scope = _scope.replace(/@/g, '');
|
||||
if (plugin) {
|
||||
const pluginName = scope.startsWith('backstage')
|
||||
? 'plugin'
|
||||
: 'backstage-plugin';
|
||||
return scope.includes('/')
|
||||
? `@${scope}${pluginName}-${baseName}`
|
||||
: `@${scope}/${pluginName}-${baseName}`;
|
||||
}
|
||||
return scope.includes('/')
|
||||
? `@${scope}${baseName}`
|
||||
: `@${scope}/${baseName}`;
|
||||
}
|
||||
|
||||
return plugin ? `backstage-plugin-${baseName}` : baseName;
|
||||
};
|
||||
|
||||
async function calculateBaseVersion(baseVersion: string) {
|
||||
if (!baseVersion) {
|
||||
const lernaVersion = await fs
|
||||
|
||||
Reference in New Issue
Block a user