import { dirname, ensureDir, join, sprintf } from "./deps.ts";import { ISource, Source } from "./source.ts";
export class SourceFile extends Source implements ISource { 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; }}