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.

resolve 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");

resolveOwn returns the built URL for one of your plugin’s own files.

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

It’s the same as calling resolve with your plugin’s name in front of the path.

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

getPluginName returns your plugin’s name, from its plugin.json.

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

getProjectSettings 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. Inkweaver stores the files in the browser’s IndexedDB.

readFile reads a file from the reader’s device.

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

writeFile writes a file to the reader’s device.

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