Type export only
Only the type is exported, to create an instance of AkteApp, see defineAkteApp.
Exhaustive but simplified Akte API references.
AkteAppOnly the type is exported, to create an instance of AkteApp, see defineAkteApp.
An Akte app, ready to be interacted with.
filesReadonly array of Akte files registered within the app.
AkteFiles[];
lookupLooks up the Akte file responsible for rendering the path.
(path: string) => Match;
Throws NotFoundError when path could not be looked up.
renderRenders a match from lookup.
(match: Match) => Promise<string>;
Throws NotFoundError when match could not be rendered.
renderAllRenders all Akte files.
() => Promise<Record<string, string>>; // Record<path, content>
writeAllWrites a map of rendered Akte files.
(args: {
outDir?: string; // Defaults to the app configured one, or `"dist"`
files: Record<string, string>;
}) => Promise<void>;
buildAllBuilds (renders and writes) all Akte files.
(args: {
outDir?: string; // Defaults to the app configured one, or `"dist"`
}) => Promise<string[]>; // Built files
clearCacheAkte caches all globalData, bulkData, data calls for performance. The clearCache method allows you to clear these caches.
// Only clears global data cache unless `true`
(alsoClearFileCache?: boolean) => void;
globalDataCacheReadonly cache of the app's definition globalData method.
Awaitable<TGlobalData> | undefined;
getGlobalDataRetrieves data from the app's definition globalData method.
() => Awaitable<TGlobalData>;
AkteFilesOnly the type is exported, to create an instance of AkteFiles, see defineAkteFile and defineAkteFiles.
An Akte files, managing its data cascade and rendering process.
Methods and properties from the AkteFiles class are not documented for now and to be considered internal. They are the ones that are the most likely to evolve.
If you're looking to render a single file, don't be afraid to spin up and AkteApp, even if it's just for it.
import { defineAkteApp } from "akte";
import { foo } from "./foo"; // An `AkteFiles` instance
const app = defineAkteApp({ files: [foo] });
const file = await app.render(app.lookup("/foo"));
NotFoundErrorCreates a 404 error. To be used within Akte files definition data function.
import { NotFoundError } from "akte";
new NotFoundError(path); // Pure 404
new NotFoundError(path, { cause }); // Maybe 500
defineAkteAppCreates an Akte app from given configuration.
import { defineAkteApp } from "akte";
defineAkteApp(config);
defineAkteApp<GlobalDataType>(config);
type Config<TGlobalData> = {
// Akte files this config is responsible for.
files: AkteFiles[];
// Required when global data type is defined or inferred.
globalData?: () => Awaitable<TGlobalData>;
// Configuration related to Akte build process.
build?: {
// Only used by the CLI build command, defaults to `"dist"`
outDir?: string;
};
};
defineAkteFileCreates an Akte files instance for a single file from a definition.
import { defineAkteFile } from "akte";
defineAkteFile().from(definition);
defineAkteFile<GlobalDataType>().from(definition);
defineAkteFile<GlobalDataType, DataType>().from(definition);
type Definition<TGlobalData, TData> = {
// Path for the Akte file, e.g. `/about` or `/sitemap.xml`
path: string;
// Required when data type is defined.
data?: (context: {
path: string;
globalData: TGlobalData;
}) => Awaitable<TData>;
// Function to render the file.
render: (context: {
path: string;
globalData: TGlobalData;
data: TData;
}) => Awaitable<string>;
};
defineAkteFilesCreates an Akte files instance from a definition.
import { defineAkteFiles } from "akte";
defineAkteFiles().from(definition);
defineAkteFiles<GlobalDataType>().from(definition);
defineAkteFiles<GlobalDataType, ParamsTuple>().from(definition);
defineAkteFiles<GlobalDataType, ParamsTuple, DataType>().from(definition);
type Definition<TGlobalData, TParams, TData> = {
// Path pattern for the Akte files, e.g. `/posts/:slug` or `/**`
path: string;
// Inferred from `bulkData` when not provided. Used for
// optimization when rendering only one file (e.g. for serverless)
data?: (context: {
path: string;
params: Record<TParams[number], string>;
globalData: TGlobalData;
}) => Awaitable<TData>;
// Required when data type is defined.
bulkData?: (context: {
globalData: TGlobalData;
}) => Awaitable<Record<string, TData>>;
// Function to render each file.
render: (context: {
path: string;
globalData: TGlobalData;
data: TData;
}) => Awaitable<string>;
};
akte (plugin)Akte Vite plugin factory.
import { defineConfig } from "vite";
import akte from "akte/vite";
import { app } from "./akte.app";
export default defineConfig({
plugins: [akte({ app, ...options })],
});
type Options<TGlobalData> = {
app: AkteApp<TGlobalData>;
// Has to be a children of Vite `root` directory.
// Defaults to `".akte"`
cacheDir?: string;
// On by defaults, requires `html-minifier-terser` to be installed.
minifyHTML?: boolean : MinifyHTMLOptions;
}
See html-minifier-terser documentation for available options.
Akte integrates a small CLI for minimal use cases allowing you to build a given app without processing it through Vite. The CLI can be run by executing your Akte app configuration.
node akte.app.js <command>
npx tsx akte.app.ts <command>
| Command | Description |
|---|---|
build | Build the current Akte app |
| Flag | Description |
|---|---|
--silent, -s | Silence output |
--help, -h | Display help |
--version, -v | Display version |