diff --git a/packages/packemon/src/commands/Scaffold.tsx b/packages/packemon/src/commands/Scaffold.tsx index e0811f82f..972ab99ce 100644 --- a/packages/packemon/src/commands/Scaffold.tsx +++ b/packages/packemon/src/commands/Scaffold.tsx @@ -181,9 +181,7 @@ export class ScaffoldCommand extends Command { break; default: { - const version = Number.parseFloat((await this.executeCommand('yarn', ['-v'])).stdout); - - args.unshift('add', '--dev', type === 'monorepo' && version < 2 ? '-W' : ''); + args.unshift('add', '--dev', type === 'monorepo' ? '-W' : ''); break; } } @@ -202,7 +200,11 @@ export class ScaffoldCommand extends Command { const pkg = await this.loadJsonConfig<{ infra: string }>(packagePath); - if (pkg.infra !== type) { + if (pkg.infra === undefined) { + throw new Error( + `A package.json already exists, cannot setup ${type} infrastructure. Perhaps you want "${type}-package"?`, + ); + } else if (pkg.infra !== type) { throw new Error( `Cannot scaffold ${type} infrastructure, as destination has already been setup as a ${pkg.infra}.`, ); diff --git a/packages/packemon/src/components/Scaffold/index.tsx b/packages/packemon/src/components/Scaffold/index.tsx index 7dd330b83..48e829b9a 100644 --- a/packages/packemon/src/components/Scaffold/index.tsx +++ b/packages/packemon/src/components/Scaffold/index.tsx @@ -1,5 +1,5 @@ import { useCallback, useEffect, useState } from 'react'; -import { Box } from 'ink'; +import { Box, Text } from 'ink'; import { Input, useProgram } from '@boost/cli/react'; import { isModuleName } from '@boost/common'; import { ScaffoldParams, TemplateType } from '../../types'; @@ -17,6 +17,7 @@ export function Scaffold({ defaultTemplate, onComplete }: ScaffoldProps) { const [projectName, setProjectName] = useState(''); const [repoUrl, setRepoUrl] = useState(''); const [author, setAuthor] = useState(''); + const [running, setRunning] = useState(false); useEffect(() => { // eslint-disable-next-line complexity @@ -39,6 +40,8 @@ export function Scaffold({ defaultTemplate, onComplete }: ScaffoldProps) { } try { + setRunning(true); + await onComplete({ author, template, @@ -50,6 +53,7 @@ export function Scaffold({ defaultTemplate, onComplete }: ScaffoldProps) { } catch (error: unknown) { exit(error as Error); } finally { + setRunning(false); exit(); } } @@ -81,6 +85,14 @@ export function Scaffold({ defaultTemplate, onComplete }: ScaffoldProps) { } }, []); + if (running) { + return ( + + Scaffolding {template}... + + ); + } + const isPackage = template === 'monorepo-package' || template === 'polyrepo-package'; return (