import { dirname, ensureDir, join, sprintf } from "../deps.ts";import { File, IFile } from "./file.ts";
export class SourceFile extends File implements IFile { constructor(filePath: string, rootPath: string) { super(filePath, rootPath); }
async copyTo( to: string, filepath = this.relativePath(), ): Promise<SourceFile> { const destination = join(to, filepath);
if (destination === this.path()) { throw new Error(sprintf("cannot copy a file to itself: %s", this.path())); }
await ensureDir(dirname(destination)); await Deno.copyFile(this.path(), destination);
const sourceFile = new SourceFile(destination, to);
sourceFile.unlock();
return sourceFile; }
clone(): SourceFile { return new SourceFile(this.path(), this.root()); }}