Skip to content

Commit 4420af7

Browse files
refactor: moved some types to a single file
1 parent 7c8ef1b commit 4420af7

9 files changed

Lines changed: 107 additions & 67 deletions

File tree

source/import/components/steps/CloneRepo/Commands.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface Props {
1616
* @param onCompletion
1717
*/
1818
const Commands: FC<Props> = ({ projectName, onCompletion }) => {
19-
const projectDir = join(process.cwd(), projectName)
19+
const projectFolder = join(process.cwd(), projectName)
2020

2121
return (
2222
<Box
@@ -40,7 +40,7 @@ const Commands: FC<Props> = ({ projectName, onCompletion }) => {
4040
<Text color={'whiteBright'}>Fetching tags</Text>
4141
<Spawn
4242
shell
43-
cwd={projectDir}
43+
cwd={projectFolder}
4444
silent
4545
command={'git'}
4646
args={['fetch', '--tags']}
@@ -51,7 +51,7 @@ const Commands: FC<Props> = ({ projectName, onCompletion }) => {
5151
<Text color={'whiteBright'}>Checking out latest tag</Text>
5252
<Spawn
5353
shell
54-
cwd={projectDir}
54+
cwd={projectFolder}
5555
command="git"
5656
args={['checkout $(git describe --tags `git rev-list --tags --max-count=1`)']}
5757
successText="Done!"
@@ -60,7 +60,7 @@ const Commands: FC<Props> = ({ projectName, onCompletion }) => {
6060
<Text color={'whiteBright'}>Removing .git folder</Text>
6161
<Spawn
6262
shell
63-
cwd={projectDir}
63+
cwd={projectFolder}
6464
command="rm"
6565
args={['-rf', '.git']}
6666
successText="Done!"
@@ -69,7 +69,7 @@ const Commands: FC<Props> = ({ projectName, onCompletion }) => {
6969
<Text color={'whiteBright'}>Initializing Git repository</Text>
7070
<Spawn
7171
shell
72-
cwd={projectDir}
72+
cwd={projectFolder}
7373
command="git"
7474
args={['init']}
7575
successText="Done!"

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

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
import { join } from 'node:path'
2-
import process from 'node:process'
31
import { Box, Text } from 'ink'
42
import { Script, Spawn } from 'ink-spawn'
53
import React, { type FC } from 'react'
64
import { featurePackages, homeFolder } from '../../../constants/config.js'
7-
import type { Item as CustomOptionsItem } from '../OptionalPackages.js'
5+
import type { MultiSelectItem } from '../../../types/types.js'
86
import InstallAllPackages from './InstallAllPackages.js'
97

108
interface Props {
11-
customOptions?: Array<CustomOptionsItem>
9+
customOptions?: Array<MultiSelectItem>
1210
onCompletion: () => void
13-
projectDir: string
11+
projectFolder: string
1412
}
1513

1614
/**
1715
* Performs a custom installation based on the selected features: basically we tell `pnpm` what
1816
* features to remove (everything's included in package.json by default to simplify things)
1917
* @param onCompletion
2018
* @param customOptions
21-
* @param projectDir
19+
* @param projectFolder
2220
*/
23-
const CustomInstallation: FC<Props> = ({ onCompletion, customOptions, projectDir }) => {
24-
const demosFolder = join(process.cwd(), homeFolder)
21+
const CustomInstallation: FC<Props> = ({ onCompletion, customOptions, projectFolder }) => {
22+
const currentHomeFolder = `${projectFolder}${homeFolder}`
23+
const cleanHomeFile = `${projectFolder}/.install-files/home/index.tsx`
2524

2625
/**
2726
* Selected features won't be removed, unselected features will be.
2827
* @param feature
2928
* @param featuresList
3029
*/
31-
const featureSelected = (feature: string, featuresList: Array<CustomOptionsItem> | undefined) => {
32-
return !!featuresList?.find((item: CustomOptionsItem) => item.value === feature)
30+
const featureSelected = (feature: string, featuresList: Array<MultiSelectItem> | undefined) => {
31+
return !!featuresList?.find((item: MultiSelectItem) => item.value === feature)
3332
}
3433

3534
/**
@@ -63,7 +62,7 @@ const CustomInstallation: FC<Props> = ({ onCompletion, customOptions, projectDir
6362
<Script>
6463
{/* If there are no packages to remove simply install everything... */}
6564
<InstallAllPackages
66-
projectDir={projectDir}
65+
projectFolder={projectFolder}
6766
onCompletion={onCompletion}
6867
/>
6968
</Script>
@@ -73,7 +72,7 @@ const CustomInstallation: FC<Props> = ({ onCompletion, customOptions, projectDir
7372
<Text color={'whiteBright'}>Installing packages</Text>
7473
<Spawn
7574
shell
76-
cwd={projectDir}
75+
cwd={projectFolder}
7776
silent
7877
command={'pnpm'}
7978
args={['remove', packagesToRemove]}
@@ -85,29 +84,51 @@ const CustomInstallation: FC<Props> = ({ onCompletion, customOptions, projectDir
8584
<Text color={'whiteBright'}>Executing post-install scripts</Text>
8685
<Spawn
8786
shell
88-
cwd={projectDir}
87+
cwd={projectFolder}
8988
silent
9089
command={'pnpm'}
9190
args={['run', 'postinstall']}
9291
runningText={'Working...'}
9392
successText={'Done!'}
9493
failureText={'Error...'}
94+
onCompletion={onCompletion}
9595
/>
9696
{!featureSelected('demo', customOptions) && (
97-
<>
97+
<Script>
9898
<Text color={'whiteBright'}>Removing component demos</Text>
9999
<Spawn
100100
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}
101+
cwd={projectFolder}
102+
// silent
103+
command="rm"
104+
args={['-rf', currentHomeFolder]}
105+
// runningText={'Working...'}
106+
// successText={'Done!'}
107+
// failureText={'Error...'}
108+
/>
109+
<Text color={'whiteBright'}>Creating new home folder</Text>
110+
<Spawn
111+
shell
112+
cwd={projectFolder}
113+
// silent
114+
command="mkdir"
115+
args={['-p', currentHomeFolder]}
116+
// runningText={'Working...'}
117+
// successText={'Done!'}
118+
// failureText={'Error...'}
119+
/>
120+
<Text color={'whiteBright'}>Creating new home page</Text>
121+
<Spawn
122+
shell
123+
cwd={projectFolder}
124+
// silent
125+
command="cp"
126+
args={[cleanHomeFile, currentHomeFolder]}
127+
// runningText={'Working...'}
128+
// successText={'Done!'}
129+
// failureText={'Error...'}
109130
/>
110-
</>
131+
</Script>
111132
)}
112133
</Script>
113134
)}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import React, { type FC } from 'react'
44
import InstallAllPackages from './InstallAllPackages.js'
55

66
interface Props {
7-
projectDir: string
7+
projectFolder: string
88
onCompletion?: () => void
99
}
1010

11-
const FullInstallation: FC<Props> = ({ onCompletion, projectDir }) => {
11+
const FullInstallation: FC<Props> = ({ onCompletion, projectFolder }) => {
1212
return (
1313
<Box
1414
flexDirection={'column'}
1515
gap={0}
1616
>
1717
<Script>
1818
<InstallAllPackages
19-
projectDir={projectDir}
19+
projectFolder={projectFolder}
2020
onCompletion={onCompletion}
2121
/>
2222
</Script>

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,27 @@ 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 type { InstallationType, MultiSelectItem } from '../../../types/types.js'
67
import Divider from '../../Divider.js'
7-
import type { Installation } from '../InstallationType.js'
8-
import type { Item as CustomOptionsItem } from '../OptionalPackages.js'
98
import CustomInstallation from './CustomInstallation.js'
109
import FullInstallation from './FullInstallation.js'
1110

1211
interface Props {
1312
installation: {
14-
installationType: Installation | undefined
15-
customOptions?: Array<CustomOptionsItem>
13+
installationType: InstallationType | undefined
14+
customOptions?: Array<MultiSelectItem>
1615
}
1716
projectName: string
1817
onCompletion: () => void
1918
}
2019

2120
const Install: FC<Props> = ({ projectName, onCompletion, installation }) => {
22-
const projectDir = join(process.cwd(), projectName)
21+
const projectFolder = join(process.cwd(), projectName)
2322
const { installationType, customOptions } = installation
2423

2524
return (
2625
<>
27-
<Divider title={`Performing ${installation.installationType ?? 'full'} installation`} />
26+
<Divider title={`Executing ${installation.installationType ?? 'full'} installation`} />
2827
<Box
2928
flexDirection={'column'}
3029
gap={0}
@@ -44,7 +43,7 @@ const Install: FC<Props> = ({ projectName, onCompletion, installation }) => {
4443
</Box>
4544
<Spawn
4645
shell
47-
cwd={projectDir}
46+
cwd={projectFolder}
4847
silent
4948
command={'cp'}
5049
args={['.env.example', '.env.local']}
@@ -55,14 +54,14 @@ const Install: FC<Props> = ({ projectName, onCompletion, installation }) => {
5554
{installationType === 'full' && (
5655
<FullInstallation
5756
onCompletion={onCompletion}
58-
projectDir={projectDir}
57+
projectFolder={projectFolder}
5958
/>
6059
)}
6160
{installationType === 'custom' && (
6261
<CustomInstallation
6362
customOptions={customOptions}
6463
onCompletion={onCompletion}
65-
projectDir={projectDir}
64+
projectFolder={projectFolder}
6665
/>
6766
)}
6867
</Script>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import React, { type FC } from 'react'
44

55
interface Props {
66
onCompletion?: () => void
7-
projectDir: string
7+
projectFolder: string
88
}
99

10-
const InstallAllPackages: FC<Props> = ({ projectDir, onCompletion }) => {
10+
const InstallAllPackages: FC<Props> = ({ projectFolder, onCompletion }) => {
1111
return (
1212
<>
1313
<Text color={'whiteBright'}>Installing packages</Text>
1414
<Spawn
1515
shell
16-
cwd={projectDir}
16+
cwd={projectFolder}
1717
silent
1818
command={'pnpm'}
1919
args={['i']}

source/import/components/steps/InstallationType.tsx renamed to source/import/components/steps/InstallationMode.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,15 @@ import figures from 'figures'
22
import { Text } from 'ink'
33
import SelectInput from 'ink-select-input'
44
import React, { useState, type FC } from 'react'
5+
import type { InstallationSelectItem } from '../../types/types.js'
56
import Divider from '../Divider.js'
67

7-
export type Installation = 'full' | 'custom'
8-
9-
export interface Item {
10-
label: string
11-
value: Installation
12-
}
13-
148
interface Props {
159
onCompletion: () => void
16-
onSelect: (item: Item) => void
10+
onSelect: (item: InstallationSelectItem) => void
1711
}
1812

19-
const installationTypeItems: Array<Item> = [
13+
const installationTypeItems: Array<InstallationSelectItem> = [
2014
{
2115
label: 'Full',
2216
value: 'full',
@@ -27,10 +21,10 @@ const installationTypeItems: Array<Item> = [
2721
},
2822
]
2923

30-
const InstallationType: FC<Props> = ({ onCompletion, onSelect }) => {
24+
const InstallationMode: FC<Props> = ({ onCompletion, onSelect }) => {
3125
const [isFocused, setIsFocused] = useState(true)
3226

33-
const handleSelect = (item: Item) => {
27+
const handleSelect = (item: InstallationSelectItem) => {
3428
onSelect(item)
3529
onCompletion()
3630
setIsFocused(false)
@@ -60,4 +54,4 @@ const InstallationType: FC<Props> = ({ onCompletion, onSelect }) => {
6054
)
6155
}
6256

63-
export default InstallationType
57+
export default InstallationMode

source/import/components/steps/OptionalPackages.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
import { Text } from 'ink'
2-
import MultiSelect from '../Multiselect/index.js'
3-
42
import React, { useState, type FC, useEffect } from 'react'
5-
import type { Installation } from './InstallationType.js'
6-
7-
export interface Item {
8-
label: string
9-
value: string
10-
}
3+
import type { InstallationType, MultiSelectItem } from '../../types/types.js'
4+
import MultiSelect from '../Multiselect/index.js'
115

126
interface Props {
13-
installation: Installation | undefined
7+
installation: InstallationType | undefined
148
onCompletion: () => void
15-
onSubmit: (selectedItems: Array<Item>) => void
9+
onSubmit: (selectedItems: Array<MultiSelectItem>) => void
1610
}
1711

18-
const customPackages: Array<Item> = [
12+
const customPackages: Array<MultiSelectItem> = [
1913
{
2014
label: 'Component Demos',
2115
value: 'demo',
@@ -56,7 +50,7 @@ const OptionalPackages: FC<Props> = ({ onCompletion, onSubmit, installation }) =
5650
}
5751
}, [])
5852

59-
const onHandleSubmit = (selectedItems: Array<Item>) => {
53+
const onHandleSubmit = (selectedItems: Array<MultiSelectItem>) => {
6054
onSubmit(selectedItems)
6155
setIsFocused(false)
6256
onCompletion()

source/import/types/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type SelectItem = { label: string; value: string }
2+
3+
export type MultiSelectItem = SelectItem
4+
5+
export type InstallationType = 'full' | 'custom'
6+
7+
export type InstallationSelectItem = { label: string; value: InstallationType }

0 commit comments

Comments
 (0)