This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { FileType, Uri, workspace } from 'vscode'; | ||
import { actions } from '../data/slice'; | ||
import { doesJobAddNewFile } from '../selectors/comparePersistedJobs'; | ||
import { Store } from '../data'; | ||
import { FileService } from '../components/fileService'; | ||
import { homedir } from 'node:os'; | ||
import { join } from 'node:path'; | ||
|
||
type Dependencies = Readonly<{ | ||
store: Store; | ||
fileService: FileService; | ||
}>; | ||
|
||
export const createClearStateCommand = | ||
({ fileService, store }: Dependencies) => | ||
async () => { | ||
const state = store.getState(); | ||
|
||
store.dispatch(actions.clearState()); | ||
|
||
try { | ||
const uris: Uri[] = []; | ||
|
||
for (const job of Object.values(state.job.entities)) { | ||
if ( | ||
!job || | ||
!doesJobAddNewFile(job.kind) || | ||
job.newContentUri === null || | ||
job.newContentUri.includes('.intuita/cases') | ||
) { | ||
continue; | ||
} | ||
|
||
uris.push(Uri.parse(job.newContentUri)); | ||
} | ||
|
||
await fileService.deleteFiles({ uris }); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
try { | ||
const casesDirectoryUri = Uri.parse( | ||
join(homedir(), '.intuita', 'cases'), | ||
); | ||
|
||
const files = await workspace.fs.readDirectory(casesDirectoryUri); | ||
|
||
const caseDirectoryUris = files | ||
.filter(([, fileType]) => fileType === FileType.Directory) | ||
.map(([name]) => Uri.joinPath(casesDirectoryUri, name)); | ||
|
||
await fileService.deleteDirectories({ uris: caseDirectoryUris }); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
store.dispatch(actions.onStateCleared()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters