cli,create-app: refactor package versions handling + fix tasks test
This commit is contained in:
@@ -28,7 +28,7 @@ import {
|
||||
getCodeownersFilePath,
|
||||
} from '../../lib/codeowners';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { versions } from '../../lib/version';
|
||||
import { packageVersions } from '../../lib/version';
|
||||
import { Task, templatingTask } from '../../lib/tasks';
|
||||
|
||||
const exec = promisify(execCb);
|
||||
@@ -269,7 +269,7 @@ export default async (cmd: Command) => {
|
||||
privatePackage,
|
||||
npmRegistry,
|
||||
},
|
||||
versions,
|
||||
packageVersions,
|
||||
);
|
||||
|
||||
Task.section('Moving to final location');
|
||||
|
||||
@@ -24,7 +24,7 @@ import handlebars from 'handlebars';
|
||||
import recursiveReadDir from 'recursive-readdir';
|
||||
import { paths } from '../paths';
|
||||
import { FileDiff } from './types';
|
||||
import { versions } from '../../lib/version';
|
||||
import { packageVersions } from '../../lib/version';
|
||||
|
||||
export type TemplatedFile = {
|
||||
path: string;
|
||||
@@ -43,9 +43,9 @@ async function readTemplateFile(
|
||||
|
||||
return handlebars.compile(contents)(templateVars, {
|
||||
helpers: {
|
||||
version(name: string) {
|
||||
if (versions[name]) {
|
||||
return versions[name];
|
||||
version(name: keyof typeof packageVersions) {
|
||||
if (name in packageVersions) {
|
||||
return packageVersions[name];
|
||||
}
|
||||
throw new Error(`No version available for package ${name}`);
|
||||
},
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('templatingTask', () => {
|
||||
tmplDir,
|
||||
destDir,
|
||||
{
|
||||
version: '0.0.0',
|
||||
pluginVersion: '0.0.0',
|
||||
},
|
||||
{ 'mock-pkg': '0.1.2' },
|
||||
);
|
||||
|
||||
@@ -39,7 +39,7 @@ import { version as devUtils } from '@backstage/dev-utils/package.json';
|
||||
import { version as testUtils } from '@backstage/test-utils/package.json';
|
||||
import { version as theme } from '@backstage/theme/package.json';
|
||||
|
||||
export const versions: { [name: string]: string } = {
|
||||
export const packageVersions = {
|
||||
'@backstage/backend-common': backendCommon,
|
||||
'@backstage/cli': cli,
|
||||
'@backstage/config': config,
|
||||
|
||||
@@ -22,7 +22,6 @@ import inquirer, { Answers, Question } from 'inquirer';
|
||||
import { exec as execCb } from 'child_process';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { findPaths } from '@backstage/cli-common';
|
||||
import { versions } from './versions';
|
||||
import os from 'os';
|
||||
import { Task, templatingTask } from './lib/tasks';
|
||||
|
||||
@@ -133,7 +132,7 @@ export default async (cmd: Command): Promise<void> => {
|
||||
await createTemporaryAppFolder(tempDir);
|
||||
|
||||
Task.section('Preparing files');
|
||||
await templatingTask(templateDir, tempDir, answers, versions);
|
||||
await templatingTask(templateDir, tempDir, answers);
|
||||
|
||||
Task.section('Moving to final location');
|
||||
await moveApp(tempDir, appDir, answers.name);
|
||||
|
||||
@@ -20,6 +20,7 @@ import handlebars from 'handlebars';
|
||||
import ora from 'ora';
|
||||
import { basename, dirname } from 'path';
|
||||
import recursive from 'recursive-readdir';
|
||||
import { packageVersions } from './versions';
|
||||
|
||||
const TASK_NAME_MAX_LENGTH = 14;
|
||||
|
||||
@@ -68,7 +69,6 @@ export async function templatingTask(
|
||||
templateDir: string,
|
||||
destinationDir: string,
|
||||
context: any,
|
||||
versions: { [name: string]: string },
|
||||
) {
|
||||
const files = await recursive(templateDir).catch(error => {
|
||||
throw new Error(`Failed to read template directory: ${error.message}`);
|
||||
@@ -88,9 +88,9 @@ export async function templatingTask(
|
||||
{ name: basename(destination), ...context },
|
||||
{
|
||||
helpers: {
|
||||
version(name: string) {
|
||||
if (versions[name]) {
|
||||
return versions[name];
|
||||
version(name: keyof typeof packageVersions) {
|
||||
if (name in packageVersions) {
|
||||
return packageVersions[name];
|
||||
}
|
||||
throw new Error(`No version available for package ${name}`);
|
||||
},
|
||||
|
||||
@@ -54,7 +54,7 @@ import { version as pluginUserSettings } from '@backstage/plugin-user-settings/p
|
||||
import { version as testUtils } from '@backstage/test-utils/package.json';
|
||||
import { version as theme } from '@backstage/theme/package.json';
|
||||
|
||||
export const versions = {
|
||||
export const packageVersions = {
|
||||
'@backstage/backend-common': backendCommon,
|
||||
'@backstage/catalog-model': catalogModel,
|
||||
'@backstage/cli': cli,
|
||||
Reference in New Issue
Block a user