You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

43 lines
1023 B

import * as fs from 'fs-extra';
import * as path from 'path';
import { workspace } from 'vscode';
// tslint:disable-next-line
const trash = require('trash');
export class FileItem {
private SourcePath: string;
private TargetPath: string;
constructor(sourcePath: string, targetPath?: string) {
this.SourcePath = sourcePath;
this.TargetPath = targetPath;
}
get path(): string {
return this.SourcePath;
}
get targetPath(): string {
return this.TargetPath;
}
get exists(): boolean {
return fs.existsSync(this.targetPath);
}
public create(isDir: boolean = false): Promise<FileItem> {
const fn = isDir ? fs.ensureDir : fs.createFile;
return Promise.resolve(fs.remove(this.targetPath))
.then(() => fn(this.targetPath))
.then(() => new FileItem(this.targetPath));
}
private ensureDir(): Promise<any> {
return Promise.resolve(fs.ensureDir(path.dirname(this.targetPath)));
}
}