File tree Expand file tree Collapse file tree 5 files changed +41
-26
lines changed
frontend-shared/src/locales Expand file tree Collapse file tree 5 files changed +41
-26
lines changed Original file line number Diff line number Diff line change @@ -110,21 +110,33 @@ export class ProjectActions {
110110 }
111111
112112 async addProject ( args : MutationAddProjectArgs ) {
113- const dirStat = await this . ctx . fs . stat ( args . path )
113+ const projectRoot = await this . getDirectoryPath ( args . path )
114114
115- if ( ! dirStat . isDirectory ( ) ) {
116- throw new Error ( `Cannot add ${ args . path } as a project, it is not a directory` )
117- }
118-
119- const found = this . projects . find ( ( x ) => x . projectRoot === args . path )
115+ const found = this . projects . find ( ( x ) => x . projectRoot === projectRoot )
120116
121117 if ( ! found ) {
122- this . projects . push ( { projectRoot : args . path } )
123- this . api . insertProjectToCache ( args . path )
118+ this . projects . push ( { projectRoot } )
119+ this . api . insertProjectToCache ( projectRoot )
124120 }
125121
126122 if ( args . open ) {
127- await this . setActiveProject ( args . path )
123+ await this . setActiveProject ( projectRoot )
124+ }
125+ }
126+
127+ private async getDirectoryPath ( projectRoot : string ) {
128+ try {
129+ const { dir, base } = path . parse ( projectRoot )
130+ const fullPath = path . join ( dir , base )
131+ const dirStat = await this . ctx . fs . stat ( fullPath )
132+
133+ if ( dirStat . isDirectory ( ) ) {
134+ return fullPath
135+ }
136+
137+ return dir
138+ } catch ( exception ) {
139+ throw Error ( `Cannot add ${ projectRoot } to projects as it does not exist in the file system` )
128140 }
129141 }
130142
Original file line number Diff line number Diff line change 8686 "empty" : {
8787 "title" : " Welcome to Cypress!" ,
8888 "helper" : " Add your first project below to start testing with Cypress." ,
89- "dropText" : " Drag your project here or {0}" ,
89+ "dropText" : " Drag your project directory here or {0}" ,
9090 "browseManually" : " browse manually."
9191 },
9292 "searchPlaceholder" : " Search Projects" ,
Original file line number Diff line number Diff line change 4747</template >
4848
4949<script lang="ts" setup>
50- import { getDirectoryPath } from ' ../utils/getDirectoryPath'
5150import { useI18n } from ' @cy/i18n'
5251import IconPlaceholder from ' ~icons/icons8/circle-thin'
5352import { FileSelector , Dropzone } from ' vue3-file-selector'
@@ -62,9 +61,12 @@ const emits = defineEmits<{
6261 (e : ' addProject' , value : string ): void
6362}>()
6463
64+ type WebkitFile = File & { path: string }
6565watch (files , (newVal ) => {
6666 if (newVal.length) {
67- emits (' addProject' , getDirectoryPath (newVal as FileList ))
67+ const file = newVal [0 ] as WebkitFile
68+
69+ emits (' addProject' , file .path )
6870 }
6971})
7072
Original file line number Diff line number Diff line change 2727
2828<script lang="ts" setup>
2929import { ref } from ' vue'
30- import { getDirectoryPath } from ' ../utils/getDirectoryPath'
3130import Button from ' @cy/components/Button.vue'
3231import Input from ' @cy/components/Input.vue'
3332import IconPlus from ' ~icons/mdi/plus'
@@ -52,9 +51,22 @@ function handleButtonClick () {
5251
5352function handleFileSelection (e : Event ) {
5453 const target = e .target as HTMLInputElement
55- const dirPath = getDirectoryPath (target .files )
54+ const files = target .files
55+ const path = getFilePath (files )
5656
57- emits (' addProject' , dirPath )
57+ emits (' addProject' , path )
58+ }
59+
60+ type WebkitFile = File & { path: string }
61+ function getFilePath (files : FileList | null ) {
62+ if (files ) {
63+ const file = files [0 ] as WebkitFile
64+ const path = file ?.path ?? ' '
65+
66+ return path
67+ }
68+
69+ return ' '
5870}
5971
6072const localValue = useModelWrapper (props , emits , ' modelValue' )
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments