11import type { MutationAddProjectArgs , MutationAppCreateConfigFileArgs , SpecType } from '@packages/graphql/src/gen/nxs.gen'
22import type { FindSpecs , FoundBrowser , FoundSpec , FullConfig , LaunchArgs , LaunchOpts , OpenProjectLaunchOptions } from '@packages/types'
33import path from 'path'
4- import type { Maybe } from '../data/coreDataShape'
4+ import type { Maybe , ProjectShape } from '../data/coreDataShape'
55
66import type { DataContext } from '..'
77
@@ -16,6 +16,7 @@ export interface ProjectApiShape {
1616 initializeProject ( args : LaunchArgs , options : OpenProjectLaunchOptions , browsers : FoundBrowser [ ] ) : Promise < unknown >
1717 launchProject ( browser : FoundBrowser , spec : Cypress . Spec , options : LaunchOpts ) : void
1818 insertProjectToCache ( projectRoot : string ) : void
19+ removeProjectFromCache ( projectRoot : string ) : void
1920 getProjectRootsFromCache ( ) : Promise < string [ ] >
2021 clearLatestProjectsCache ( ) : Promise < unknown >
2122}
@@ -33,6 +34,14 @@ export class ProjectActions {
3334 return
3435 }
3536
37+ private get projects ( ) {
38+ return this . ctx . coreData . app . projects
39+ }
40+
41+ private set projects ( projects : ProjectShape [ ] ) {
42+ this . ctx . coreData . app . projects = projects
43+ }
44+
3645 async setActiveProject ( projectRoot : string ) {
3746 this . ctx . coreData . app . activeProject = {
3847 projectRoot,
@@ -66,14 +75,14 @@ export class ProjectActions {
6675 }
6776
6877 async loadProjects ( ) {
69- const projectRoots = await this . ctx . _apis . projectApi . getProjectRootsFromCache ( )
78+ const projectRoots = await this . api . getProjectRootsFromCache ( )
7079
71- this . ctx . coreData . app . projects = [
72- ...this . ctx ?. coreData ?. app ?. projects ,
80+ this . projects = [
81+ ...this . projects ,
7382 ...projectRoots . map ( ( projectRoot ) => ( { projectRoot } ) ) ,
7483 ]
7584
76- return this . ctx . coreData . app . projects
85+ return this . projects
7786 }
7887
7988 async initializeActiveProject ( ) {
@@ -107,10 +116,10 @@ export class ProjectActions {
107116 throw new Error ( `Cannot add ${ args . path } as a project, it is not a directory` )
108117 }
109118
110- const found = this . ctx . projectsList . find ( ( x ) => x . projectRoot === args . path )
119+ const found = this . projects . find ( ( x ) => x . projectRoot === args . path )
111120
112121 if ( ! found ) {
113- this . ctx . coreData . app . projects . push ( { projectRoot : args . path } )
122+ this . projects . push ( { projectRoot : args . path } )
114123 this . api . insertProjectToCache ( args . path )
115124 }
116125
@@ -136,8 +145,15 @@ export class ProjectActions {
136145 return this . api . launchProject ( browser , spec , { } )
137146 }
138147
139- removeProject ( ) {
140- //
148+ removeProject ( projectRoot : string ) {
149+ const found = this . ctx . projectsList . find ( ( x ) => x . projectRoot === projectRoot )
150+
151+ if ( ! found ) {
152+ throw new Error ( `Cannot remove ${ projectRoot } , it is not a known project` )
153+ }
154+
155+ this . projects = this . projects . filter ( ( project ) => project . projectRoot !== projectRoot )
156+ this . api . removeProjectFromCache ( projectRoot )
141157 }
142158
143159 syncProjects ( ) {
0 commit comments