Skip to content

Commit a7a56e8

Browse files
feat: package.json entries cleanup
1 parent 7e2dfb7 commit a7a56e8

2 files changed

Lines changed: 183 additions & 143 deletions

File tree

source/import/components/steps/FileCleanup.tsx

Lines changed: 183 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { readFileSync, writeFileSync } from 'node:fs'
2+
import { join } from 'node:path'
13
import { Box, Text } from 'ink'
24
import { Script, Spawn } from 'ink-spawn'
35
import React, { type FC, useMemo } from 'react'
4-
import { homeFolder } from '../../constants/config.js'
56
import type { InstallationType, MultiSelectItem } from '../../types/types.js'
67
import { featureSelected, getProjectFolder } from '../../utils/utils.js'
78
import Divider from '../Divider.js'
@@ -15,6 +16,31 @@ interface Props {
1516
}
1617
}
1718

19+
const packageJSONCleanup = (projectFolder: string, selectedFeatures?: Array<MultiSelectItem>) => {
20+
const packageJSONPath = join(projectFolder, 'package.json')
21+
const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'))
22+
23+
if (!featureSelected('subgraph', selectedFeatures)) {
24+
packageJSON.scripts['subgraph-codegen'] = undefined
25+
}
26+
27+
if (!featureSelected('typedoc', selectedFeatures)) {
28+
packageJSON.scripts['typedoc:build'] = undefined
29+
}
30+
31+
if (!featureSelected('vocs', selectedFeatures)) {
32+
packageJSON.scripts['docs:build'] = undefined
33+
packageJSON.scripts['docs:dev'] = undefined
34+
packageJSON.scripts['docs:preview'] = undefined
35+
}
36+
37+
if (!featureSelected('husky', selectedFeatures)) {
38+
packageJSON.scripts.prepare = undefined
39+
}
40+
41+
writeFileSync(packageJSONPath, `${JSON.stringify(packageJSON, null, 2)}\n`)
42+
}
43+
1844
/**
1945
* Performs file cleanup after the installation process
2046
* @param onCompletion
@@ -34,66 +60,29 @@ const FileCleanup: FC<Props> = ({ onCompletion, installationConfig, projectName
3460
gap={0}
3561
>
3662
<Script>
37-
{/* Component demos files and folders */}
38-
{!featureSelected('demo', selectedFeatures) && (
39-
<Script>
40-
<Text color={'whiteBright'}>Component demos</Text>
41-
<Spawn
42-
shell
43-
cwd={projectFolder}
44-
silent
45-
command="rm"
46-
args={['-rf', currentHomeFolder]}
47-
runningText={'Removing home files...'}
48-
successText={'Done!'}
49-
failureText={'Error...'}
50-
/>
51-
<Spawn
52-
shell
53-
cwd={projectFolder}
54-
silent
55-
command="mkdir"
56-
args={['-p', currentHomeFolder]}
57-
runningText={'Creating home folder...'}
58-
successText={'Done!'}
59-
failureText={'Error...'}
60-
/>
61-
<Spawn
62-
shell
63-
cwd={projectFolder}
64-
silent
65-
command="cp"
66-
args={['.install-files/home/index.tsx', currentHomeFolder]}
67-
runningText={'Creating new home page file...'}
68-
successText={'Done!'}
69-
failureText={'Error...'}
70-
/>
71-
</Script>
72-
)}
73-
{/* Subgraph files and folders */}
74-
{!featureSelected('subgraph', selectedFeatures) && (
75-
<Script>
76-
<Text color={'whiteBright'}>Subgraph</Text>
77-
<Spawn
78-
shell
79-
cwd={projectFolder}
80-
silent
81-
command="rm"
82-
args={['-rf', 'src/subgraphs']}
83-
runningText={'Removing subgraphs folder...'}
84-
successText={'Done!'}
85-
failureText={'Error...'}
86-
/>
87-
{/* The user chose to keep the component demos but opted out of subgraph support */}
88-
{featureSelected('demo', selectedFeatures) && (
63+
{installationType === 'custom' && (
64+
<Script onCompletion={() => packageJSONCleanup(projectFolder, selectedFeatures)}>
65+
{/* Component demos files and folders */}
66+
{!featureSelected('demo', selectedFeatures) && (
8967
<Script>
68+
<Text color={'whiteBright'}>Component demos</Text>
9069
<Spawn
9170
shell
9271
cwd={projectFolder}
9372
silent
9473
command="rm"
95-
args={['-rf', `${currentHomeFolder}/Examples/demos/subgraphs`]}
96-
runningText={'Removing subgraphs demos folder...'}
74+
args={['-rf', currentHomeFolder]}
75+
runningText={'Removing home files...'}
76+
successText={'Done!'}
77+
failureText={'Error...'}
78+
/>
79+
<Spawn
80+
shell
81+
cwd={projectFolder}
82+
silent
83+
command="mkdir"
84+
args={['-p', currentHomeFolder]}
85+
runningText={'Creating home folder...'}
9786
successText={'Done!'}
9887
failureText={'Error...'}
9988
/>
@@ -102,98 +91,149 @@ const FileCleanup: FC<Props> = ({ onCompletion, installationConfig, projectName
10291
cwd={projectFolder}
10392
silent
10493
command="cp"
105-
args={[
106-
'.install-files/home/Examples/index.tsx',
107-
`${currentHomeFolder}/index.tsx`,
108-
]}
94+
args={['./.install-files/home/index.tsx', currentHomeFolder]}
10995
runningText={'Creating new home page file...'}
11096
successText={'Done!'}
11197
failureText={'Error...'}
11298
/>
11399
</Script>
114100
)}
115-
</Script>
116-
)}
117-
{/* Typedoc files and folders */}
118-
{!featureSelected('typedoc', selectedFeatures) && (
119-
<Script>
120-
<Text color={'whiteBright'}>Typedoc</Text>
121-
<Spawn
122-
shell
123-
cwd={projectFolder}
124-
silent
125-
command="rm"
126-
args={['typedoc.json']}
127-
runningText={'Removing config...'}
128-
successText={'Done!'}
129-
failureText={'Error...'}
130-
/>
131-
</Script>
132-
)}
133-
{/* Vocs files and folders */}
134-
{!featureSelected('vocs', selectedFeatures) && (
135-
<Script>
136-
<Text color={'whiteBright'}>Vocs</Text>
137-
<Spawn
138-
shell
139-
cwd={projectFolder}
140-
silent
141-
command="rm"
142-
args={['vocs.config.ts']}
143-
runningText={'Removing config...'}
144-
successText={'Done!'}
145-
failureText={'Error...'}
146-
/>
147-
<Spawn
148-
shell
149-
cwd={projectFolder}
150-
silent
151-
command="rm"
152-
args={['-rf', 'docs']}
153-
runningText={'Removing docs folder...'}
154-
successText={'Done!'}
155-
failureText={'Error...'}
156-
/>
157-
</Script>
158-
)}
159-
{/* Husky files and folders */}
160-
{/* Also removes files from tasks executed by Husky:
161-
- lint-staged
162-
- commitlint
163-
*/}
164-
{!featureSelected('husky', selectedFeatures) && (
165-
<Script>
166-
<Text color={'whiteBright'}>Husky</Text>
167-
<Spawn
168-
shell
169-
cwd={projectFolder}
170-
silent
171-
command="rm"
172-
args={['-rf', '.husky']}
173-
runningText={'Removing Husky folder...'}
174-
successText={'Done!'}
175-
failureText={'Error...'}
176-
/>
177-
<Spawn
178-
shell
179-
cwd={projectFolder}
180-
silent
181-
command="rm"
182-
args={['.lintstagedrc.mjs']}
183-
runningText={'Removing lint-staged config...'}
184-
successText={'Done!'}
185-
failureText={'Error...'}
186-
/>
187-
<Spawn
188-
shell
189-
cwd={projectFolder}
190-
silent
191-
command="rm"
192-
args={['commitlint.config.js']}
193-
runningText={'Removing commitlint config...'}
194-
successText={'Done!'}
195-
failureText={'Error...'}
196-
/>
101+
{/* Subgraph files and folders */}
102+
{!featureSelected('subgraph', selectedFeatures) && (
103+
<Script>
104+
<Text color={'whiteBright'}>Subgraph</Text>
105+
<Spawn
106+
shell
107+
cwd={projectFolder}
108+
silent
109+
command="rm"
110+
args={['-rf', './src/subgraphs']}
111+
runningText={'Removing subgraphs folder...'}
112+
successText={'Done!'}
113+
failureText={'Error...'}
114+
/>
115+
{/* The user chose to keep the component demos but opted out of subgraph support */}
116+
{featureSelected('demo', selectedFeatures) && (
117+
<Script>
118+
<Spawn
119+
shell
120+
cwd={projectFolder}
121+
silent
122+
command="rm"
123+
args={['-rf', `${currentHomeFolder}/Examples/demos/subgraphs`]}
124+
runningText={'Removing subgraphs demos folder...'}
125+
successText={'Done!'}
126+
failureText={'Error...'}
127+
/>
128+
<Spawn
129+
shell
130+
cwd={projectFolder}
131+
silent
132+
command="rm"
133+
args={[`${currentHomeFolder}/index.tsx`]}
134+
runningText={'Removing home page file...'}
135+
successText={'Done!'}
136+
failureText={'Error...'}
137+
/>
138+
<Spawn
139+
shell
140+
cwd={projectFolder}
141+
silent
142+
command="cp"
143+
args={[
144+
'./.install-files/home/Examples/index.tsx',
145+
`${currentHomeFolder}/index.tsx`,
146+
]}
147+
runningText={'Creating new home page file...'}
148+
successText={'Done!'}
149+
failureText={'Error...'}
150+
/>
151+
</Script>
152+
)}
153+
</Script>
154+
)}
155+
{/* Typedoc files and folders */}
156+
{!featureSelected('typedoc', selectedFeatures) && (
157+
<Script>
158+
<Text color={'whiteBright'}>Typedoc</Text>
159+
<Spawn
160+
shell
161+
cwd={projectFolder}
162+
silent
163+
command="rm"
164+
args={['./typedoc.json']}
165+
runningText={'Removing config...'}
166+
successText={'Done!'}
167+
failureText={'Error...'}
168+
/>
169+
</Script>
170+
)}
171+
{/* Vocs files and folders */}
172+
{!featureSelected('vocs', selectedFeatures) && (
173+
<Script>
174+
<Text color={'whiteBright'}>Vocs</Text>
175+
<Spawn
176+
shell
177+
cwd={projectFolder}
178+
silent
179+
command="rm"
180+
args={['./vocs.config.ts']}
181+
runningText={'Removing config...'}
182+
successText={'Done!'}
183+
failureText={'Error...'}
184+
/>
185+
<Spawn
186+
shell
187+
cwd={projectFolder}
188+
silent
189+
command="rm"
190+
args={['-rf', './docs']}
191+
runningText={'Removing docs folder...'}
192+
successText={'Done!'}
193+
failureText={'Error...'}
194+
/>
195+
</Script>
196+
)}
197+
{/* Husky files and folders */}
198+
{/* Also removes files from tasks executed by Husky:
199+
- lint-staged
200+
- commitlint
201+
*/}
202+
{!featureSelected('husky', selectedFeatures) && (
203+
<Script>
204+
<Text color={'whiteBright'}>Husky</Text>
205+
<Spawn
206+
shell
207+
cwd={projectFolder}
208+
silent
209+
command="rm"
210+
args={['-rf', './.husky']}
211+
runningText={'Removing Husky folder...'}
212+
successText={'Done!'}
213+
failureText={'Error...'}
214+
/>
215+
<Spawn
216+
shell
217+
cwd={projectFolder}
218+
silent
219+
command="rm"
220+
args={['./.lintstagedrc.mjs']}
221+
runningText={'Removing lint-staged config...'}
222+
successText={'Done!'}
223+
failureText={'Error...'}
224+
/>
225+
<Spawn
226+
shell
227+
cwd={projectFolder}
228+
silent
229+
command="rm"
230+
args={['./commitlint.config.js']}
231+
runningText={'Removing commitlint config...'}
232+
successText={'Done!'}
233+
failureText={'Error...'}
234+
/>
235+
</Script>
236+
)}
197237
</Script>
198238
)}
199239
{/* Install script files and folders */}
@@ -203,10 +243,11 @@ const FileCleanup: FC<Props> = ({ onCompletion, installationConfig, projectName
203243
cwd={projectFolder}
204244
silent
205245
command="rm"
206-
args={['-rf', '.install-files']}
246+
args={['-rf', './.install-files']}
207247
runningText={'Removing folder...'}
208248
successText={'Done!'}
209249
failureText={'Error...'}
250+
onCompletion={onCompletion}
210251
/>
211252
</Script>
212253
</Box>

source/import/constants/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const repoUrl = 'https://github.com/BootNodeDev/dAppBooster.git'
2-
export const homeFolder = '/src/components/pageComponents/home'
32

43
export const featurePackages: {
54
[key: string]: string[]

0 commit comments

Comments
 (0)