The “file API” is provided by the File class. It effectively binds a file path to the current Context object, so you can pass it around more easily.
While the File class is provided by the jumpgen package, you may want to use the context-specific File class instead, which has the context injected for you. In particular, it's really handy if you prefer to destructure the context object (in which case, you won't have a reference to the entire context anymore).
import { jumpgen, File } from 'jumpgen'
// The “hard” way to create a File object:
const myGenerator = jumpgen('name', context => {
const file = new File('path/to/file.txt', context)
})
// The simpler way to create a File object:
const otherGenerator = jumpgen('other', ({ File }) => {
const file = new File('path/to/file.txt')
})-
Properties
path: The file path, relative to therootdirectory.name: The file's base name.absolutePath: The file path prefixed with therootdirectory.
-
Methods
exists(): Whether the file exists on the filesystem. Read moreisFile(): Whether the file exists and is a regular file. Read moreisDirectory(): Whether the file exists and is a directory. Read moreisSymlink(): Whether the file exists and is a symbolic link. Read moreread(options?): Read the file's contents. Read moretryRead(options?): Read the file's contents, returningnullif the file does not exist. Read morewrite(data): Write data to the file. Read more