Skip to content

Commit 7c8ef1b

Browse files
refactor: move full installation script to single file
1 parent f4dc290 commit 7c8ef1b

4 files changed

Lines changed: 64 additions & 38 deletions

File tree

source/import/components/steps/Install/CustomInstallation.tsx

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@ import process from 'node:process'
33
import { Box, Text } from 'ink'
44
import { Script, Spawn } from 'ink-spawn'
55
import React, { type FC } from 'react'
6-
import { featurePackages } from '../../../constants/config.js'
6+
import { featurePackages, homeFolder } from '../../../constants/config.js'
77
import type { Item as CustomOptionsItem } from '../OptionalPackages.js'
8+
import InstallAllPackages from './InstallAllPackages.js'
89

910
interface Props {
1011
customOptions?: Array<CustomOptionsItem>
1112
onCompletion: () => void
12-
projectName: string
13+
projectDir: string
1314
}
1415

1516
/**
1617
* Performs a custom installation based on the selected features: basically we tell `pnpm` what
1718
* features to remove (everything's included in package.json by default to simplify things)
18-
* @param projectName
1919
* @param onCompletion
2020
* @param customOptions
21+
* @param projectDir
2122
*/
22-
const CustomInstallation: FC<Props> = ({ projectName, onCompletion, customOptions }) => {
23-
const projectDir = join(process.cwd(), projectName)
23+
const CustomInstallation: FC<Props> = ({ onCompletion, customOptions, projectDir }) => {
24+
const demosFolder = join(process.cwd(), homeFolder)
2425

2526
/**
2627
* Selected features won't be removed, unselected features will be.
@@ -61,16 +62,8 @@ const CustomInstallation: FC<Props> = ({ projectName, onCompletion, customOption
6162
{!packagesToRemove ? (
6263
<Script>
6364
{/* If there are no packages to remove simply install everything... */}
64-
<Text color={'whiteBright'}>Installing packages</Text>
65-
<Spawn
66-
shell
67-
cwd={projectDir}
68-
silent
69-
command={'pnpm'}
70-
args={['i']}
71-
runningText={'Working...'}
72-
successText={'Done!'}
73-
failureText={'Error...'}
65+
<InstallAllPackages
66+
projectDir={projectDir}
7467
onCompletion={onCompletion}
7568
/>
7669
</Script>
@@ -99,8 +92,23 @@ const CustomInstallation: FC<Props> = ({ projectName, onCompletion, customOption
9992
runningText={'Working...'}
10093
successText={'Done!'}
10194
failureText={'Error...'}
102-
// onCompletion={onCompletion}
10395
/>
96+
{!featureSelected('demo', customOptions) && (
97+
<>
98+
<Text color={'whiteBright'}>Removing component demos</Text>
99+
<Spawn
100+
shell
101+
cwd={projectDir}
102+
silent
103+
command={'pnpm'}
104+
args={['run', 'postinstall']}
105+
runningText={'Working...'}
106+
successText={'Done!'}
107+
failureText={'Error...'}
108+
// onCompletion={onCompletion}
109+
/>
110+
</>
111+
)}
104112
</Script>
105113
)}
106114
</Box>

source/import/components/steps/Install/FullInstallation.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1-
import { join } from 'node:path'
2-
import process from 'node:process'
3-
import { Box, Text } from 'ink'
4-
import { Script, Spawn } from 'ink-spawn'
1+
import { Box } from 'ink'
2+
import { Script } from 'ink-spawn'
53
import React, { type FC } from 'react'
4+
import InstallAllPackages from './InstallAllPackages.js'
65

76
interface Props {
8-
projectName: string
9-
onCompletion: () => void
7+
projectDir: string
8+
onCompletion?: () => void
109
}
1110

12-
const FullInstallation: FC<Props> = ({ projectName, onCompletion }) => {
13-
const projectDir = join(process.cwd(), projectName)
14-
11+
const FullInstallation: FC<Props> = ({ onCompletion, projectDir }) => {
1512
return (
1613
<Box
1714
flexDirection={'column'}
1815
gap={0}
1916
>
2017
<Script>
21-
<Text color={'whiteBright'}>Installing packages</Text>
22-
<Spawn
23-
shell
24-
cwd={projectDir}
25-
silent
26-
command={'pnpm'}
27-
args={['i']}
28-
runningText={'Working...'}
29-
successText={'Done!'}
30-
failureText={'Error...'}
18+
<InstallAllPackages
19+
projectDir={projectDir}
3120
onCompletion={onCompletion}
3221
/>
3322
</Script>

source/import/components/steps/Install/Install.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ interface Props {
1919
}
2020

2121
const Install: FC<Props> = ({ projectName, onCompletion, installation }) => {
22-
const { installationType, customOptions } = installation
2322
const projectDir = join(process.cwd(), projectName)
23+
const { installationType, customOptions } = installation
2424

2525
return (
2626
<>
@@ -54,15 +54,15 @@ const Install: FC<Props> = ({ projectName, onCompletion, installation }) => {
5454
/>
5555
{installationType === 'full' && (
5656
<FullInstallation
57-
projectName={projectName}
5857
onCompletion={onCompletion}
58+
projectDir={projectDir}
5959
/>
6060
)}
6161
{installationType === 'custom' && (
6262
<CustomInstallation
6363
customOptions={customOptions}
64-
projectName={projectName}
6564
onCompletion={onCompletion}
65+
projectDir={projectDir}
6666
/>
6767
)}
6868
</Script>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Text } from 'ink'
2+
import { Spawn } from 'ink-spawn'
3+
import React, { type FC } from 'react'
4+
5+
interface Props {
6+
onCompletion?: () => void
7+
projectDir: string
8+
}
9+
10+
const InstallAllPackages: FC<Props> = ({ projectDir, onCompletion }) => {
11+
return (
12+
<>
13+
<Text color={'whiteBright'}>Installing packages</Text>
14+
<Spawn
15+
shell
16+
cwd={projectDir}
17+
silent
18+
command={'pnpm'}
19+
args={['i']}
20+
runningText={'Working...'}
21+
successText={'Done!'}
22+
failureText={'Error...'}
23+
onCompletion={onCompletion}
24+
/>
25+
</>
26+
)
27+
}
28+
29+
export default InstallAllPackages

0 commit comments

Comments
 (0)