import { dirname , extname , join , relative , resolve , sep , basename } from 'path' ; export class File { private path : string ; private relativePath : string ; private ext : string ; constructor ( path ) { this . path = resolve ( path ) ; this . relativePath = relative ( process . cwd ( ) , this . path ) ; this . ext = extname ( this . path ) ; } public getAbsolutePath ( ) { return this . path ; } public getRelativePath ( ) { return this . relativePath ; } public getWithoutExtension ( ) { const directory = dirname ( this . path ) ; const stem = basename ( this . path , this . ext ) ; return new File ( resolve ( directory , stem ) ) ; } public isJs ( ) { return this . ext === '.js' ; } public isTypescript ( ) { return this . ext === '.ts' || this . ext === '.tsx' ; } public isTypescriptAmbient ( ) { return this . path . endsWith ( '.d.ts' ) ; } public isSass ( ) { return this . ext === '.sass' || this . ext === '.scss' ; } public isFixture ( ) { return ( this . relativePath . split ( sep ) . includes ( '__fixtures__' ) || this . path . endsWith ( '.test-d.ts' ) ) ; } public getRelativeParentDirs ( ) { const parents = [ ] ; while ( true ) { const parent = parents . length ? join ( parents [ parents . length - 1 ] , '..' ) : dirname ( this . relativePath ) ; if ( parent === '..' || parent === '.' ) { break ; } else { parents . push ( parent ) ; } } return parents ; } public toString ( ) { return this . relativePath ; } public toJSON ( ) { return this . relativePath ; } }