cli: refactor to use isMonoRepo helper
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -301,6 +301,7 @@ export default async (opts: OptionValues) => {
|
||||
npmRegistry,
|
||||
},
|
||||
createPackageVersionProvider(lockfile),
|
||||
isMonoRepo,
|
||||
);
|
||||
|
||||
Task.section('Moving to final location');
|
||||
|
||||
@@ -22,6 +22,7 @@ import { FactoryRegistry } from '../../lib/new/FactoryRegistry';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import { Task } from '../../lib/tasks';
|
||||
import { isMonoRepo } from '../../lib/monorepo/isMonoRepo';
|
||||
|
||||
function parseOptions(optionStrings: string[]): Record<string, string> {
|
||||
const options: Record<string, string> = {};
|
||||
@@ -49,21 +50,6 @@ export default async (opts: OptionValues) => {
|
||||
providedOptions,
|
||||
);
|
||||
|
||||
let isMonoRepo = false;
|
||||
try {
|
||||
const rootPackageJson = await fs.readJson(
|
||||
paths.resolveTargetRoot('package.json'),
|
||||
);
|
||||
if (rootPackageJson.workspaces) {
|
||||
isMonoRepo = true;
|
||||
}
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
let defaultVersion = '0.1.0';
|
||||
try {
|
||||
const rootLernaJson = await fs.readJson(
|
||||
@@ -89,7 +75,7 @@ export default async (opts: OptionValues) => {
|
||||
let modified = false;
|
||||
try {
|
||||
await factory.create(options, {
|
||||
isMonoRepo,
|
||||
isMonoRepo: await isMonoRepo(),
|
||||
defaultVersion,
|
||||
scope: opts.scope?.replace(/^@/, ''),
|
||||
npmRegistry: opts.npmRegistry,
|
||||
|
||||
@@ -62,6 +62,7 @@ export async function executePluginPackageTemplate(
|
||||
tempDir,
|
||||
options.values,
|
||||
createPackageVersionProvider(lockfile),
|
||||
ctx.isMonoRepo,
|
||||
);
|
||||
|
||||
// Format package.json if it exists
|
||||
|
||||
@@ -53,6 +53,7 @@ describe('templatingTask', () => {
|
||||
pluginVersion: '0.0.0',
|
||||
},
|
||||
() => '^0.1.2',
|
||||
true,
|
||||
);
|
||||
|
||||
await expect(
|
||||
|
||||
@@ -22,7 +22,6 @@ import { promisify } from 'util';
|
||||
import { basename, dirname } from 'path';
|
||||
import recursive from 'recursive-readdir';
|
||||
import { exec as execCb } from 'child_process';
|
||||
import { paths } from './paths';
|
||||
import { assertError } from '@backstage/errors';
|
||||
|
||||
const exec = promisify(execCb);
|
||||
@@ -102,11 +101,11 @@ export async function templatingTask(
|
||||
destinationDir: string,
|
||||
context: any,
|
||||
versionProvider: (name: string, versionHint?: string) => string,
|
||||
isMonoRepo: boolean,
|
||||
) {
|
||||
const files = await recursive(templateDir).catch(error => {
|
||||
throw new Error(`Failed to read template directory: ${error.message}`);
|
||||
});
|
||||
const isMonoRepo = await fs.pathExists(paths.resolveTargetRoot('lerna.json'));
|
||||
|
||||
for (const file of files) {
|
||||
const destinationFile = file.replace(templateDir, destinationDir);
|
||||
|
||||
Reference in New Issue
Block a user