cli,create-app: refactor package versions handling + fix tasks test

This commit is contained in:
Patrik Oldsberg
2020-10-27 19:09:08 +01:00
parent 2711b9da42
commit 0efbdfbbb8
7 changed files with 14 additions and 15 deletions
@@ -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');
+4 -4
View File
@@ -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}`);
},
+1 -1
View File
@@ -50,7 +50,7 @@ describe('templatingTask', () => {
tmplDir,
destDir,
{
version: '0.0.0',
pluginVersion: '0.0.0',
},
{ 'mock-pkg': '0.1.2' },
);
+1 -1
View File
@@ -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,
+1 -2
View File
@@ -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);
+4 -4
View File
@@ -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,