Skip to content

Assets and files

When Inkweaver builds your novel, it renames each asset based on its contents. For example, act-1.fountain might become 4c76-4803-c0be-a50c.fountain, and the name changes whenever the file does. Use these functions to find an asset’s built file from its original path.

Returns the built URL for an asset path.

resolve<T extends RequestInfo | URL>(url: T, locale?: string): T
ParameterDescription
urlThe asset’s path in your workspace. To find a plugin’s asset, start the path with the plugin’s name, like shop-plugin:assets/inventory.json.
localeThe locale to find. Defaults to the version of the file with no locale.

If the file doesn’t have the requested locale, resolve returns the version with no locale if there is one, and otherwise the first locale it has. See Localization for how to localize files.

Example
const url = resolve("/assets/shop.json");

Returns the built URL for one of the calling plugin’s own files.

resolveOwn(path: string, locale?: string): string

This is the same as calling resolve with the plugin’s name in front of the path.

Example
const url = resolveOwn("assets/inventory.json");
// Same as:
const sameUrl = resolve(`${getPluginName()}:assets/inventory.json`);

Returns the calling plugin’s name, from its plugin.json.

getPluginName(): string
Example
console.log(`${getPluginName()} is ready`);

Returns the settings from your workspace’s project.json.

getProjectSettings(): ProjectSettings
interface ProjectSettings {
exports?: BuildExports;
locales?: Array<string>;
main?: string;
startup: {
bootstrapCommand?: string;
startLabel: string;
};
version: string;
}

locales lists the IETF language tags your novel supports. See declaring supported locales.

Example
const { locales } = getProjectSettings();

These functions read and write files on the reader’s device. Files are stored in the browser’s IndexedDB.

Reads a file.

readFile(input: RequestInfo | URL, init?: RequestInit): Promise<Response>
Example
const response = await readFile("/notes.txt");
const text = await response.text();

Writes a file.

writeFile(input: RequestInfo | URL, data: any, init?: RequestInit): Promise<Response>
Example
await writeFile("/notes.txt", "The butler did it.");