/
coreDataShape.ts
264 lines (238 loc) · 7.2 KB
/
coreDataShape.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import { FoundBrowser, Editor, AllowedState, AllModeOptions, TestingType, BrowserStatus, PACKAGE_MANAGERS, AuthStateName, MIGRATION_STEPS, MigrationStep } from '@packages/types'
import type { WizardFrontendFramework, WizardBundler } from '@packages/scaffold-config'
import type { NexusGenObjects } from '@packages/graphql/src/gen/nxs.gen'
import type { App, BrowserWindow } from 'electron'
import type { ChildProcess } from 'child_process'
import type { SocketIONamespace, SocketIOServer } from '@packages/socket'
import type { Server } from 'http'
import type { ErrorWrapperSource } from '@packages/errors'
import type { GitDataSource, LegacyCypressConfigJson } from '../sources'
export type Maybe<T> = T | null | undefined
export interface AuthenticatedUserShape {
name?: string
email?: string
authToken?: string
}
export interface ProjectShape {
projectRoot: string
savedState?: () => Promise<Maybe<SavedStateShape>>
}
export interface DevStateShape {
refreshState: null | string
}
export interface LocalSettingsDataShape {
refreshing: Promise<Editor[]> | null
availableEditors: Editor[]
preferences: AllowedState
}
export interface SavedStateShape {
firstOpened?: number | null
lastOpened?: number | null
promptsShown?: object | null
lastProjectId?: string | null
}
export interface ConfigChildProcessShape {
/**
* Child process executing the config & sourcing plugin events
*/
process: ChildProcess
/**
* Keeps track of which plugins we have executed in the current config process
*/
executedPlugins: null | 'e2e' | 'ct'
/**
* Config from the initial module.exports
*/
resolvedBaseConfig: Promise<Cypress.ConfigOptions>
}
export interface AppDataShape {
isGlobalMode: boolean
browsers: ReadonlyArray<FoundBrowser> | null
projects: ProjectShape[]
nodePath: Maybe<string>
browserStatus: BrowserStatus
relaunchBrowser: boolean
}
export interface WizardDataShape {
chosenBundler: WizardBundler | null
chosenFramework: WizardFrontendFramework | null
chosenManualInstall: boolean
detectedBundler: WizardBundler | null
detectedFramework: WizardFrontendFramework | null
}
export interface MigrationDataShape {
// TODO: have the model of migration here
step: MigrationStep
videoEmbedHtml: string | null
legacyConfigForMigration?: LegacyCypressConfigJson | null
filteredSteps: MigrationStep[]
flags: {
hasCustomIntegrationFolder: boolean
hasCustomIntegrationTestFiles: boolean
hasCustomComponentFolder: boolean
hasCustomComponentTestFiles: boolean
hasCustomSupportFile: boolean
hasComponentTesting: boolean
hasE2ESpec: boolean
hasPluginsFile: boolean
shouldAddCustomE2ESpecPattern: boolean
}
}
export interface ElectronShape {
app: App | null
browserWindow: BrowserWindow | null
}
export interface AuthStateShape {
name?: AuthStateName
message?: string
browserOpened: boolean
}
export interface ForceReconfigureProjectDataShape {
e2e?: boolean | null
component?: boolean | null
}
export interface ActiveAppData {
error: ErrorWrapperSource | null
warnings: ErrorWrapperSource[]
}
export interface CurrentTestingTypeData {
error: ErrorWrapperSource | null
warnings: ErrorWrapperSource[]
activeAppData: ActiveAppData | null
}
export interface CurrentProjectData {
error: ErrorWrapperSource | null
warnings: ErrorWrapperSource[]
testingTypeData: CurrentTestingTypeData | null
}
export interface CoreDataShape {
cliBrowser: string | null
cliTestingType: string | null
activeBrowser: FoundBrowser | null
machineBrowsers: Promise<FoundBrowser[]> | null
servers: {
appServer?: Maybe<Server>
appServerPort?: Maybe<number>
appSocketServer?: Maybe<SocketIOServer>
appSocketNamespace?: Maybe<SocketIONamespace>
gqlServer?: Maybe<Server>
gqlServerPort?: Maybe<number>
gqlSocketServer?: Maybe<SocketIONamespace>
}
hasInitializedMode: 'run' | 'open' | null
baseError: ErrorWrapperSource | null
dashboardGraphQLError: ErrorWrapperSource | null
dev: DevStateShape
localSettings: LocalSettingsDataShape
app: AppDataShape
currentProject: string | null
currentProjectGitInfo: GitDataSource | null
currentTestingType: TestingType | null
// TODO: Move everything under this container, to make it simpler to reset the data when switching
currentProjectData: CurrentProjectData | null
wizard: WizardDataShape
migration: MigrationDataShape
user: AuthenticatedUserShape | null
electron: ElectronShape
authState: AuthStateShape
scaffoldedFiles: NexusGenObjects['ScaffoldedFile'][] | null
warnings: ErrorWrapperSource[]
packageManager: typeof PACKAGE_MANAGERS[number]
forceReconfigureProject: ForceReconfigureProjectDataShape | null
versionData: {
latestVersion: Promise<string>
npmMetadata: Promise<Record<string, string>>
} | null
}
/**
* All state for the app should live here for now
*/
export function makeCoreData (modeOptions: Partial<AllModeOptions> = {}): CoreDataShape {
return {
servers: {},
cliBrowser: modeOptions.browser ?? null,
cliTestingType: modeOptions.testingType ?? null,
machineBrowsers: null,
hasInitializedMode: null,
baseError: null,
dashboardGraphQLError: null,
dev: {
refreshState: null,
},
app: {
isGlobalMode: Boolean(modeOptions.global),
browsers: null,
projects: [],
nodePath: modeOptions.userNodePath,
browserStatus: 'closed',
relaunchBrowser: false,
},
localSettings: {
availableEditors: [],
preferences: {},
refreshing: null,
},
authState: {
browserOpened: false,
},
currentProject: modeOptions.projectRoot ?? null,
currentProjectData: makeCurrentProjectData(modeOptions.projectRoot, modeOptions.testingType),
currentProjectGitInfo: null,
currentTestingType: modeOptions.testingType ?? null,
wizard: {
chosenBundler: null,
chosenFramework: null,
chosenManualInstall: false,
detectedBundler: null,
detectedFramework: null,
},
migration: {
step: 'renameAuto',
videoEmbedHtml: null,
legacyConfigForMigration: null,
filteredSteps: [...MIGRATION_STEPS],
flags: {
hasCustomIntegrationFolder: false,
hasCustomIntegrationTestFiles: false,
hasCustomComponentFolder: false,
hasCustomComponentTestFiles: false,
hasCustomSupportFile: false,
hasComponentTesting: true,
hasE2ESpec: true,
hasPluginsFile: true,
shouldAddCustomE2ESpecPattern: false,
},
},
warnings: [],
activeBrowser: null,
user: null,
electron: {
app: null,
browserWindow: null,
},
scaffoldedFiles: null,
packageManager: 'npm',
forceReconfigureProject: null,
versionData: null,
}
}
export function makeCurrentProjectData (projectRoot: Maybe<string>, testingType: Maybe<TestingType>): CurrentProjectData | null {
if (projectRoot) {
return {
error: null,
warnings: [],
testingTypeData: makeTestingTypeData(testingType),
}
}
return null
}
export function makeTestingTypeData (testingType: Maybe<TestingType>): CurrentTestingTypeData | null {
if (testingType) {
return {
error: null,
warnings: [],
activeAppData: null,
}
}
return null
}