Skip to content

Commit

Permalink
fix: Show a progress indicator when templates are being scaffolded.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed May 27, 2022
1 parent 6360d54 commit a3fd4c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/packemon/src/commands/Scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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}.`,
);
Expand Down
14 changes: 13 additions & 1 deletion packages/packemon/src/components/Scaffold/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,6 +17,7 @@ export function Scaffold({ defaultTemplate, onComplete }: ScaffoldProps) {
const [projectName, setProjectName] = useState<string>('');
const [repoUrl, setRepoUrl] = useState<string>('');
const [author, setAuthor] = useState<string>('');
const [running, setRunning] = useState(false);

useEffect(() => {
// eslint-disable-next-line complexity
Expand All @@ -39,6 +40,8 @@ export function Scaffold({ defaultTemplate, onComplete }: ScaffoldProps) {
}

try {
setRunning(true);

await onComplete({
author,
template,
Expand All @@ -50,6 +53,7 @@ export function Scaffold({ defaultTemplate, onComplete }: ScaffoldProps) {
} catch (error: unknown) {
exit(error as Error);
} finally {
setRunning(false);
exit();
}
}
Expand Down Expand Up @@ -81,6 +85,14 @@ export function Scaffold({ defaultTemplate, onComplete }: ScaffoldProps) {
}
}, []);

if (running) {
return (
<Box flexDirection="column">
<Text>Scaffolding {template}...</Text>
</Box>
);
}

const isPackage = template === 'monorepo-package' || template === 'polyrepo-package';

return (
Expand Down

0 comments on commit a3fd4c4

Please sign in to comment.