Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions packages/@apphosting/build/src/bin/localbuild.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
#! /usr/bin/env node
import { SupportedFrameworks } from "@apphosting/common";
import { adapterBuild } from "../index.js";
import { localBuild } from "../index.js";
import { program } from "commander";

program
.argument("<projectRoot>", "path to the project's root directory")
.option("--framework <framework>")
.action(async (projectRoot, opts) => {
// TODO(#382): support other apphosting.*.yaml files.

// TODO(#382): parse apphosting.yaml for environment variables / secrets needed during build time.
if (opts.framework && SupportedFrameworks.includes(opts.framework)) {
// TODO(#382): Skip this if there's a custom build command in apphosting.yaml.
await adapterBuild(projectRoot, opts.framework);
}

// TODO(#382): Parse apphosting.yaml to set custom run command in bundle.yaml
// TODO(#382): parse apphosting.yaml for environment variables / secrets needed during runtime to include in the bunde.yaml
// TODO(#382): parse apphosting.yaml for runConfig to include in bundle.yaml
await localBuild(projectRoot, opts.framework);
});

program.parse();
39 changes: 38 additions & 1 deletion packages/@apphosting/build/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import promiseSpawn from "@npmcli/promise-spawn";
import { readFileSync, existsSync } from "fs";
import { join } from "path";
import { yellow, bgRed, bold } from "colorette";
import { OutputBundleConfig } from "@apphosting/common";
import { SupportedFrameworks, Framework } from "@apphosting/common";
import { parse as parseYaml } from "yaml";

export async function localBuild(
projectRoot: string,
framework?: string,
): Promise<OutputBundleConfig> {
if (framework && SupportedFrameworks.includes(framework as Framework)) {
// TODO(#382): Skip this if there's a custom build command in apphosting.yaml.
await adapterBuild(projectRoot, framework);
const bundleYamlPath = join(projectRoot, ".apphosting", "bundle.yaml");
if (!existsSync(bundleYamlPath)) {
throw new Error(`Cannot load ${bundleYamlPath} from given path, it doesn't exist`);
}
return parseYaml(readFileSync(bundleYamlPath, "utf8")) as OutputBundleConfig;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what is the reason for adding parse bundle.yaml as OutputBundleConfig here, how is it going to be used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI will call it and use it to make the right apphosting createBuild and createRollout calls

}
throw new Error("framework not supported");
}

export async function adapterBuild(
projectRoot: string,
framework: string,
): Promise<OutputBundleConfig> {
// TODO(#382): support other apphosting.*.yaml files.
// TODO(#382): parse apphosting.yaml for environment variables / secrets needed during build time.

export async function adapterBuild(projectRoot: string, framework: string) {
// TODO(#382): We are using the latest framework adapter versions, but in the future
// we should parse the framework version and use the matching adapter version.
const adapterName = `@apphosting/adapter-${framework}`;
Expand Down Expand Up @@ -30,4 +57,14 @@ export async function adapterBuild(projectRoot: string, framework: string) {
shell: true,
stdio: "inherit",
});

const bundleYamlPath = join(projectRoot, ".apphosting", "bundle.yaml");
if (!existsSync(bundleYamlPath)) {
throw new Error(`Cannot load ${bundleYamlPath} from given path, it doesn't exist`);
}
return parseYaml(readFileSync(bundleYamlPath, "utf8")) as OutputBundleConfig;

// TODO(#382): Parse apphosting.yaml to set custom run command in bundle.yaml
// TODO(#382): parse apphosting.yaml for runConfig to include in bundle.yaml
// TODO(#382): parse apphosting.yaml for environment variables / secrets needed during runtime to include in the bundle.yaml
}
1 change: 1 addition & 0 deletions packages/@apphosting/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from "node:path";

// List of apphosting supported frameworks.
export const SupportedFrameworks = ["nextjs", "angular"] as const;
export type Framework = (typeof SupportedFrameworks)[number];

// **** OutputBundleConfig interfaces ****

Expand Down
Loading