import { error , isExist } from '../utils' ; import { ArticleItem } from '../treeViews/articleTreeView/hexoArticleProvider' ; import { Command , ICommandParsed , Commands , command } from './common' ; import path from 'path' ; import { configs } from '../configs' ; import { Uri , workspace } from 'vscode' ; @ command ( ) export class DeleteFile extends Command { constructor ( ) { super ( Commands . delete ) ; } async execute ( _ , _file , list = [ ] ) { if ( list . length === 0 ) { list . push ( _file ) ; } const p = list . map ( async ( item ) => { const fileUri = item . resourceUri ! ; const filename = path . parse ( fileUri . fsPath ) . name ; if ( await isExist ( fileUri ) ) { await workspace . fs . delete ( fileUri ) ; await this . deleteAssetFolder ( filename ) ; } else { error ( `${ fileUri } is not exist` ) ; } } ) ; await Promise . all ( p ) ; } async deleteAssetFolder ( filename ) { const assetsFolder = Uri . joinPath ( configs . paths . post , filename ) ; if ( ( await isExist ( assetsFolder ) ) && ( await workspace . fs . readDirectory ( assetsFolder ) ) . length === 0 ) { await workspace . fs . delete ( assetsFolder ) ; } } }