Module

x/ts_morph/mod.ts>Directory

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Very Popular
Go to Latest
class Directory
import { Directory } from "https://dotland.deno.dev/x/ts_morph@18.0.0/mod.ts";

Constructors

new
private
Directory()

Properties

private
__context
private
_emitInternal
private
_path
private
_pathParts

Methods

addDirectoryAtPath(relativeOrAbsoluteDirPath: string, options?: DirectoryAddOptions): Directory

Adds an existing directory from the relative path or directory name, or throws if it doesn't exist.

Will return the directory if it was already added.

addDirectoryAtPathIfExists(relativeOrAbsoluteDirPath: string, options?: DirectoryAddOptions): Directory | undefined

Adds an existing directory from the relative path or directory name, or returns undefined if it doesn't exist.

Will return the directory if it was already added.

addSourceFileAtPath(relativeFilePath: string): SourceFile

Adds an existing source file, relative to this directory, or throws if it doesn't exist.

Will return the source file if it was already added.

addSourceFileAtPathIfExists(relativeFilePath: string): SourceFile | undefined

Adds an existing source file, relative to this directory, or returns undefined.

Will return the source file if it was already added.

addSourceFilesAtPaths(fileGlobs: string | ReadonlyArray<string>): SourceFile[]

Add source files based on file globs.

clear(): void

Recreates the directory.

clearImmediately(): Promise<void>

Asynchronously recreates the directory.

Synchronously recreates the directory.

copy(relativeOrAbsolutePath: string, options?: DirectoryCopyOptions): Directory

Copies the directory to a new directory.

copyImmediately(relativeOrAbsolutePath: string, options?: DirectoryCopyOptions): Promise<Directory>

Immediately copies the directory to the specified path asynchronously.

copyImmediatelySync(relativeOrAbsolutePath: string, options?: DirectoryCopyOptions): Directory

Immediately copies the directory to the specified path synchronously.

copyToDirectory(dirPathOrDirectory: string | Directory, options?: DirectoryCopyOptions): Directory

Copies the directory to a subdirectory of the specified directory.

createDirectory(relativeOrAbsoluteDirPath: string): Directory

Creates a directory if it doesn't exist.

createSourceFile(
relativeFilePath: string,
sourceFileText?: string | OptionalKind<SourceFileStructure> | WriterFunction,
): SourceFile

Creates a source file, relative to this directory.

Note: The file will not be created and saved to the file system until .save() is called on the source file.

delete(): void

Queues a deletion of the directory to the file system.

The directory will be deleted when calling ast.save(). If you wish to delete the file immediately, then use deleteImmediately().

deleteImmediately(): Promise<void>

Asyncronously deletes the directory and all its descendants from the file system.

Synchronously deletes the directory and all its descendants from the file system.

emit(options?: { emitOnlyDtsFiles?: boolean; outDir?: string; declarationDir?: string; }): Promise<DirectoryEmitResult>

Emits the files in the directory.

emitSync(options?: { emitOnlyDtsFiles?: boolean; outDir?: string; declarationDir?: string; }): DirectoryEmitResult

Emits the files in the directory synchronously.

Remarks: This might be very slow compared to the asynchronous version if there are a lot of files.

forget(): void

Forgets the directory and all its descendants from the Project.

Note: Does not delete the directory from the file system.

getBaseName(): string

Gets the directory path's base name.

Gets the descendant directories.

Gets the source files in the current directory and all the descendant directories.

Gets the child directories.

getDirectory(path: string): Directory | undefined

Gets a directory with the specified path or undefined if not found.

getDirectory(condition: (directory: Directory) => boolean): Directory | undefined

Gets a child directory by the specified condition or undefined if not found.

Gets a child directory with the specified path or throws if not found.

getDirectoryOrThrow(condition: (directory: Directory) => boolean): Directory

Gets a child directory by the specified condition or throws if not found.

getParent(): Directory | undefined

Gets the parent directory if it exists and was added to the project.

getParentOrThrow(message?: string | (() => string)): Directory

Gets the parent directory or throws if it doesn't exist or was never added to the project.

Gets the path to the directory.

Gets the project.

getRelativePathAsModuleSpecifierTo(filePath: string): string

Gets the relative path to the specified file path as a module specifier.

Gets the relative path to the specified source file as a module specifier.

Gets the relative path to the specified directory as a module specifier.

getRelativePathTo(fileOrDirPath: string): string

Gets the relative path to the specified path.

getRelativePathTo(sourceFile: SourceFile): string

Gets the relative path to another source file.

getRelativePathTo(directory: Directory): string

Gets the relative path to another directory.

getSourceFile(path: string): SourceFile | undefined

Gets a child source file with the specified path or undefined if not found.

getSourceFile(condition: (sourceFile: SourceFile) => boolean): SourceFile | undefined

Gets a child source file by the specified condition or undefined if not found.

Gets a child source file with the specified path or throws if not found.

getSourceFileOrThrow(condition: (sourceFile: SourceFile) => boolean): SourceFile

Gets a child source file by the specified condition or throws if not found.

Gets the source files within this directory.

getSourceFiles(globPattern: string): SourceFile[]

Gets all the source files added to the project relative to the directory that match a pattern.

getSourceFiles(globPatterns: ReadonlyArray<string>): SourceFile[]

Gets all the source files added to the project relative to the directory that match the provided patterns.

isAncestorOf(possibleDescendant: Directory | SourceFile): boolean

Checks if this directory is an ancestor of the provided directory.

isDescendantOf(possibleAncestor: Directory): boolean

Checks if this directory is a descendant of the provided directory.

move(relativeOrAbsolutePath: string, options?: DirectoryMoveOptions): this

Moves the directory to a new path.

moveImmediately(relativeOrAbsolutePath: string, options?: DirectoryMoveOptions): Promise<this>

Immediately moves the directory to a new path asynchronously.

moveImmediatelySync(relativeOrAbsolutePath: string, options?: DirectoryMoveOptions): this

Immediately moves the directory to a new path synchronously.

moveToDirectory(dirPathOrDirectory: string | Directory, options?: DirectoryMoveOptions): this

Moves the directory to a subdirectory of the specified directory.

save(): Promise<void>

Asynchronously saves the directory and all the unsaved source files to the disk.

saveSync(): void

Synchronously saves the directory and all the unsaved source files to the disk.

wasForgotten(): boolean

Gets if the directory was forgotten.