cli/new: more renames to use portable template
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
+4
-4
@@ -16,7 +16,7 @@
|
||||
|
||||
import inquirer from 'inquirer';
|
||||
import { PortableTemplateConfig } from '../types';
|
||||
import { collectTemplateParams } from './collectTemplateParams';
|
||||
import { collectPortableTemplateParams } from './collectPortableTemplateParams';
|
||||
|
||||
describe('collectTemplateParams', () => {
|
||||
const baseOptions = {
|
||||
@@ -38,7 +38,7 @@ describe('collectTemplateParams', () => {
|
||||
};
|
||||
|
||||
it('should return default values if not provided', async () => {
|
||||
await expect(collectTemplateParams(baseOptions)).resolves.toEqual({
|
||||
await expect(collectPortableTemplateParams(baseOptions)).resolves.toEqual({
|
||||
pluginId: 'test',
|
||||
private: true,
|
||||
baseVersion: '0.1.0',
|
||||
@@ -51,7 +51,7 @@ describe('collectTemplateParams', () => {
|
||||
|
||||
it('should include all non-standard global and prompt values', async () => {
|
||||
await expect(
|
||||
collectTemplateParams({
|
||||
collectPortableTemplateParams({
|
||||
...baseOptions,
|
||||
config: { ...baseOptions.config, globals: { foo: 'bar' } },
|
||||
}),
|
||||
@@ -71,7 +71,7 @@ describe('collectTemplateParams', () => {
|
||||
jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ pluginId: 'other' });
|
||||
|
||||
await expect(
|
||||
collectTemplateParams({
|
||||
collectPortableTemplateParams({
|
||||
...baseOptions,
|
||||
prefilledParams: {},
|
||||
}),
|
||||
+1
-1
@@ -27,7 +27,7 @@ type CollectTemplateParamsOptions = {
|
||||
prefilledParams: Record<string, string | number | boolean>;
|
||||
};
|
||||
|
||||
export async function collectTemplateParams(
|
||||
export async function collectPortableTemplateParams(
|
||||
options: CollectTemplateParamsOptions,
|
||||
): Promise<Record<string, string | number | boolean>> {
|
||||
const { config, template, prefilledParams } = options;
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { collectTemplateParams } from './collection/collectTemplateParams';
|
||||
import { loadConfig } from './preparation/loadConfig';
|
||||
import { executeNewTemplate } from './execution/executeTemplate';
|
||||
import { collectPortableTemplateParams } from './collection/collectPortableTemplateParams';
|
||||
import { loadPortableTemplateConfig } from './preparation/loadPortableTemplateConfig';
|
||||
import { executePortableTemplate } from './execution/executePortableTemplate';
|
||||
import { selectTemplateInteractively } from './preparation/selectTemplateInteractively';
|
||||
import { loadTemplate } from './preparation/loadTemplate';
|
||||
import { loadPortableTemplate } from './preparation/loadPortableTemplate';
|
||||
|
||||
export type CreateNewPackageOptions = {
|
||||
preselectedTemplateId?: string;
|
||||
@@ -33,7 +33,7 @@ export type CreateNewPackageOptions = {
|
||||
};
|
||||
|
||||
export async function createNewPackage(options: CreateNewPackageOptions) {
|
||||
const config = await loadConfig({
|
||||
const config = await loadPortableTemplateConfig({
|
||||
globalOverrides: options.globals,
|
||||
});
|
||||
|
||||
@@ -41,15 +41,15 @@ export async function createNewPackage(options: CreateNewPackageOptions) {
|
||||
config,
|
||||
options.preselectedTemplateId,
|
||||
);
|
||||
const template = await loadTemplate(selectedTemplate);
|
||||
const template = await loadPortableTemplate(selectedTemplate);
|
||||
|
||||
const params = await collectTemplateParams({
|
||||
const params = await collectPortableTemplateParams({
|
||||
config,
|
||||
template,
|
||||
prefilledParams: options.prefilledParams,
|
||||
});
|
||||
|
||||
await executeNewTemplate({
|
||||
await executePortableTemplate({
|
||||
config,
|
||||
template,
|
||||
params,
|
||||
|
||||
+3
-1
@@ -36,7 +36,9 @@ type ExecuteNewTemplateOptions = {
|
||||
params: Record<string, string | number | boolean>;
|
||||
};
|
||||
|
||||
export async function executeNewTemplate(options: ExecuteNewTemplateOptions) {
|
||||
export async function executePortableTemplate(
|
||||
options: ExecuteNewTemplateOptions,
|
||||
) {
|
||||
const { template, params } = options;
|
||||
|
||||
const tmpDirManager = TemporaryDirectoryManager.create();
|
||||
+8
-8
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import { loadTemplate } from './loadTemplate';
|
||||
import { loadPortableTemplate } from './loadPortableTemplate';
|
||||
|
||||
describe('loadTemplate', () => {
|
||||
it('should load a valid template', async () => {
|
||||
@@ -30,7 +30,7 @@ describe('loadTemplate', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const result = await loadTemplate({
|
||||
const result = await loadPortableTemplate({
|
||||
id: 'template1',
|
||||
target: mockDir.resolve('path/to/template1.yaml'),
|
||||
});
|
||||
@@ -47,7 +47,7 @@ describe('loadTemplate', () => {
|
||||
const mockDir = createMockDirectory();
|
||||
|
||||
await expect(
|
||||
loadTemplate({
|
||||
loadPortableTemplate({
|
||||
id: 'template1',
|
||||
target: mockDir.resolve('path/to/template1.yaml'),
|
||||
}),
|
||||
@@ -64,7 +64,7 @@ describe('loadTemplate', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadTemplate({
|
||||
loadPortableTemplate({
|
||||
id: 'template1',
|
||||
target: mockDir.resolve('path/to/template1.yaml'),
|
||||
}),
|
||||
@@ -75,7 +75,7 @@ describe('loadTemplate', () => {
|
||||
|
||||
it('should throw an error if target is a remote URL', async () => {
|
||||
await expect(
|
||||
loadTemplate({
|
||||
loadPortableTemplate({
|
||||
id: 'template1',
|
||||
target: 'http://example.com',
|
||||
}),
|
||||
@@ -84,7 +84,7 @@ describe('loadTemplate', () => {
|
||||
|
||||
it('should throw an error if target directory does not exist', async () => {
|
||||
await expect(
|
||||
loadTemplate({
|
||||
loadPortableTemplate({
|
||||
id: 'template1',
|
||||
target: 'http://example.com',
|
||||
}),
|
||||
@@ -103,7 +103,7 @@ describe('loadTemplate', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadTemplate({
|
||||
loadPortableTemplate({
|
||||
id: 'template1',
|
||||
target: mockDir.resolve('path/to/template1.yaml'),
|
||||
}),
|
||||
@@ -126,7 +126,7 @@ describe('loadTemplate', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadTemplate({
|
||||
loadPortableTemplate({
|
||||
id: 'template1',
|
||||
target: mockDir.resolve('path/to/template1.yaml'),
|
||||
}),
|
||||
+1
-1
@@ -45,7 +45,7 @@ const templateDefinitionSchema = z
|
||||
})
|
||||
.strict();
|
||||
|
||||
export async function loadTemplate({
|
||||
export async function loadPortableTemplate({
|
||||
id,
|
||||
target,
|
||||
}: PortableTemplatePointer): Promise<PortableTemplate> {
|
||||
+8
-8
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { loadConfig } from './loadConfig';
|
||||
import { loadPortableTemplateConfig } from './loadPortableTemplateConfig';
|
||||
import { defaultTemplates } from '../defaultTemplates';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
|
||||
describe('loadConfig', () => {
|
||||
describe('loadPortableTemplateConfig', () => {
|
||||
const mockPkgJson = {
|
||||
backstage: {
|
||||
new: {
|
||||
@@ -61,7 +61,7 @@ describe('loadConfig', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadConfig({
|
||||
loadPortableTemplateConfig({
|
||||
packagePath: mockDir.resolve('package.json'),
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
@@ -75,7 +75,7 @@ describe('loadConfig', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadConfig({
|
||||
loadPortableTemplateConfig({
|
||||
packagePath: mockDir.resolve('package.json'),
|
||||
globalOverrides: {
|
||||
key2: 'override',
|
||||
@@ -110,7 +110,7 @@ describe('loadConfig', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadConfig({
|
||||
loadPortableTemplateConfig({
|
||||
packagePath: mockDir.resolve('package.json'),
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
@@ -136,7 +136,7 @@ describe('loadConfig', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadConfig({
|
||||
loadPortableTemplateConfig({
|
||||
packagePath: mockDir.resolve('package.json'),
|
||||
}),
|
||||
).rejects.toThrow(
|
||||
@@ -150,7 +150,7 @@ describe('loadConfig', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadConfig({
|
||||
loadPortableTemplateConfig({
|
||||
packagePath: mockDir.resolve('package.json'),
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
@@ -160,7 +160,7 @@ describe('loadConfig', () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
loadConfig({
|
||||
loadPortableTemplateConfig({
|
||||
packagePath: mockDir.resolve('package.json'),
|
||||
globalOverrides: {
|
||||
key: 'override',
|
||||
+1
-1
@@ -58,7 +58,7 @@ type LoadConfigOptions = {
|
||||
globalOverrides?: Record<string, string | number | boolean>;
|
||||
};
|
||||
|
||||
export async function loadConfig(
|
||||
export async function loadPortableTemplateConfig(
|
||||
options: LoadConfigOptions = {},
|
||||
): Promise<PortableTemplateConfig> {
|
||||
const pkgPath =
|
||||
Reference in New Issue
Block a user