Skip to content

Commit

Permalink
feat(lagon): write .lagon/config.json on build (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz authored Feb 28, 2023
1 parent c63e504 commit ddf151b
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/presets/lagon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import type { PackageJson } from "pkg-types";
import { resolve } from "pathe";
import { resolve, relative } from "pathe";
import { defineNitroPreset } from "../preset";
import { writeFile } from "../utils";

/**
* Both function_id and organization_id fields are required but only used when deploying the function
* Ref: https://github.com/lagonapp/lagon/blob/06093d051898d7603f356b9cae5e3f14078d480a/crates/cli/src/utils/deployments.rs#L34
*/
export interface LagonFunctionConfig {
function_id: string;
organization_id: string;
index: string;
client?: string;
assets?: string;
}

export const lagon = defineNitroPreset({
extends: "base-worker",
entry: "#internal/nitro/entries/lagon",
Expand All @@ -19,7 +31,24 @@ export const lagon = defineNitroPreset({

hooks: {
async compiled(nitro) {
// TODO: write lagon config when it's supported
// Write Lagon config
const root = nitro.options.output.dir;
const indexPath = relative(
root,
resolve(nitro.options.output.serverDir, "index.mjs")
);
const assetsDir = relative(root, nitro.options.output.publicDir);

await writeFile(
resolve(root, ".lagon", "config.json"),
JSON.stringify(<LagonFunctionConfig>{
function_id: "",
organization_id: "",
index: indexPath,
client: null,
assets: assetsDir,
})
);

// Write package.json for deployment
await writeFile(
Expand All @@ -28,9 +57,8 @@ export const lagon = defineNitroPreset({
<PackageJson>{
private: true,
scripts: {
dev: "npx -p esbuild -p @lagon/cli lagon dev ./server/index.mjs -p ./public",
deploy:
"npx -p esbuild -p @lagon/cli lagon deploy ./server/index.mjs -p ./public",
dev: "npx -p esbuild -p @lagon/cli lagon dev",
deploy: "npx -p esbuild -p @lagon/cli lagon deploy",
},
},
null,
Expand Down

0 comments on commit ddf151b

Please sign in to comment.