|
1 | 1 | import promiseSpawn from "@npmcli/promise-spawn";
|
| 2 | +import { readFileSync, existsSync } from "fs"; |
| 3 | +import { join } from "path"; |
2 | 4 | import { yellow, bgRed, bold } from "colorette";
|
| 5 | +import { OutputBundleConfig } from "@apphosting/common"; |
| 6 | +import { SupportedFrameworks, Framework } from "@apphosting/common"; |
| 7 | +import { parse as parseYaml } from "yaml"; |
| 8 | + |
| 9 | +export async function localBuild( |
| 10 | + projectRoot: string, |
| 11 | + framework?: string, |
| 12 | +): Promise<OutputBundleConfig> { |
| 13 | + if (framework && SupportedFrameworks.includes(framework as Framework)) { |
| 14 | + // TODO(#382): Skip this if there's a custom build command in apphosting.yaml. |
| 15 | + await adapterBuild(projectRoot, framework); |
| 16 | + const bundleYamlPath = join(projectRoot, ".apphosting", "bundle.yaml"); |
| 17 | + if (!existsSync(bundleYamlPath)) { |
| 18 | + throw new Error(`Cannot load ${bundleYamlPath} from given path, it doesn't exist`); |
| 19 | + } |
| 20 | + return parseYaml(readFileSync(bundleYamlPath, "utf8")) as OutputBundleConfig; |
| 21 | + } |
| 22 | + throw new Error("framework not supported"); |
| 23 | +} |
| 24 | + |
| 25 | +export async function adapterBuild( |
| 26 | + projectRoot: string, |
| 27 | + framework: string, |
| 28 | +): Promise<OutputBundleConfig> { |
| 29 | + // TODO(#382): support other apphosting.*.yaml files. |
| 30 | + // TODO(#382): parse apphosting.yaml for environment variables / secrets needed during build time. |
3 | 31 |
|
4 |
| -export async function adapterBuild(projectRoot: string, framework: string) { |
5 | 32 | // TODO(#382): We are using the latest framework adapter versions, but in the future
|
6 | 33 | // we should parse the framework version and use the matching adapter version.
|
7 | 34 | const adapterName = `@apphosting/adapter-${framework}`;
|
@@ -30,4 +57,14 @@ export async function adapterBuild(projectRoot: string, framework: string) {
|
30 | 57 | shell: true,
|
31 | 58 | stdio: "inherit",
|
32 | 59 | });
|
| 60 | + |
| 61 | + const bundleYamlPath = join(projectRoot, ".apphosting", "bundle.yaml"); |
| 62 | + if (!existsSync(bundleYamlPath)) { |
| 63 | + throw new Error(`Cannot load ${bundleYamlPath} from given path, it doesn't exist`); |
| 64 | + } |
| 65 | + return parseYaml(readFileSync(bundleYamlPath, "utf8")) as OutputBundleConfig; |
| 66 | + |
| 67 | + // TODO(#382): Parse apphosting.yaml to set custom run command in bundle.yaml |
| 68 | + // TODO(#382): parse apphosting.yaml for runConfig to include in bundle.yaml |
| 69 | + // TODO(#382): parse apphosting.yaml for environment variables / secrets needed during runtime to include in the bundle.yaml |
33 | 70 | }
|
0 commit comments