@inlang/paraglide-js
Version:
[](https://www.npmjs.com/package/@inlang/paraglide-js) [;
/**
* Loads, compiles, and writes the output to disk.
*
* This is the main function to use when you want to compile a project.
* If you want to adjust inlang project loading, or the output, use
* `compileProject()` instead.
*
* @example
* await compile({
* project: 'path/to/project',
* outdir: 'path/to/output',
* })
*/
export async function compile(options) {
const withDefaultOptions = {
...defaultCompilerOptions,
...options,
};
if (compilationInProgress) {
await compilationInProgress;
}
compilationInProgress = (async () => {
try {
const fs = withDefaultOptions.fs ?? (await import("node:fs"));
const absoluteOutdir = path.resolve(process.cwd(), withDefaultOptions.outdir);
// const localAccount = getLocalAccount({ fs });
const project = await loadProjectFromDirectory({
path: withDefaultOptions.project,
fs,
// account: localAccount,
});
const output = await compileProject({
compilerOptions: withDefaultOptions,
project,
projectPath: withDefaultOptions.project,
});
const outputHashes = await writeOutput({
directory: absoluteOutdir,
output,
cleanDirectory: withDefaultOptions.cleanOutdir,
fs: fs.promises,
previousOutputHashes: options.previousCompilation?.outputHashes,
});
// if (!localAccount) {
// const activeAccount = await project.lix.db
// .selectFrom("active_account as aa")
// .innerJoin("account_all as a", "a.id", "aa.account_id")
// .where("a.lixcol_version_id", "=", "global")
// .select(["a.id", "a.name"])
// .executeTakeFirstOrThrow();
// saveLocalAccount({ fs, account: activeAccount });
// }
const warningsAndErrors = await project.errors.get();
for (const warningOrError of warningsAndErrors) {
logger.warn(warningOrError);
}
await project.close();
return { outputHashes };
}
catch (e) {
// release the lock in case of an error
compilationInProgress = null;
throw e;
}
})();
const result = structuredClone(await compilationInProgress);
compilationInProgress = null;
return result;
}
//# sourceMappingURL=compile.js.map