| 
2 | 2 | import { spawn } from "child_process";  | 
3 | 3 | import { program } from "commander";  | 
4 | 4 | import { yellow, bgRed, bold } from "colorette";  | 
 | 5 | +import { SupportedFrameworks } from "@apphosting/common";  | 
 | 6 | +import { adapterBuild } from "../adapter-builds.js";  | 
5 | 7 | 
 
  | 
6 |  | -// TODO(#382): add framework option later or incorporate micro-discovery.  | 
7 |  | -// TODO(#382): parse apphosting.yaml for environment variables / secrets.  | 
8 |  | -// TODO(#382): parse apphosting.yaml for runConfig and include in buildSchema  | 
 | 8 | +// TODO(#382): parse apphosting.yaml for environment variables / secrets needed during build time.  | 
9 | 9 | // TODO(#382): Support custom build and run commands (parse and pass run command to build schema).  | 
10 |  | -program  | 
11 |  | -  .argument("<projectRoot>", "path to the project's root directory")  | 
12 |  | -  .action(async (projectRoot: string) => {  | 
13 |  | -    const framework = "nextjs";  | 
14 |  | -    // TODO(#382): We are using the latest framework adapter versions, but in the future  | 
15 |  | -    // we should parse the framework version and use the matching adapter version.  | 
16 |  | -    const adapterName = `@apphosting/adapter-nextjs`;  | 
17 |  | -    const packumentResponse = await fetch(`https://registry.npmjs.org/${adapterName}`);  | 
18 |  | -    if (!packumentResponse.ok) throw new Error(`Something went wrong fetching ${adapterName}`);  | 
19 |  | -    const packument = await packumentResponse.json();  | 
20 |  | -    const adapterVersion = packument?.["dist-tags"]?.["latest"];  | 
21 |  | -    if (!adapterVersion) {  | 
22 |  | -      throw new Error(`Could not find 'latest' dist-tag for ${adapterName}`);  | 
23 |  | -    }  | 
24 |  | -    // TODO(#382): should check for existence of adapter in app's package.json and use that version instead.  | 
25 | 10 | 
 
  | 
26 |  | -    console.log(" 🔥", bgRed(` ${adapterName}@${yellow(bold(adapterVersion))} `), "\n");  | 
 | 11 | +// TODO(#382): parse apphosting.yaml for environment variables / secrets needed during runtime to include in the bunde.yaml  | 
 | 12 | +// TODO(#382): parse apphosting.yaml for runConfig to include in bundle.yaml  | 
27 | 13 | 
 
  | 
28 |  | -    const buildCommand = `apphosting-adapter-${framework}-build`;  | 
29 |  | -    await new Promise<void>((resolve, reject) => {  | 
30 |  | -      const child = spawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], {  | 
31 |  | -        cwd: projectRoot,  | 
32 |  | -        shell: true,  | 
33 |  | -        stdio: "inherit",  | 
34 |  | -      });  | 
 | 14 | +program  | 
 | 15 | +  .argument("<projectRoot>", "path to the project's root directory")  | 
 | 16 | +  .argument("<framework>", "the framework to build for")  | 
 | 17 | +  .action(async (projectRoot: string, framework: string) => {  | 
35 | 18 | 
 
  | 
36 |  | -      child.on("exit", (code) => {  | 
37 |  | -        if (code !== 0) {  | 
38 |  | -          reject(new Error(`framework adapter build failed with error code ${code}.`));  | 
39 |  | -        }  | 
40 |  | -        resolve();  | 
41 |  | -      });  | 
42 |  | -    });  | 
43 |  | -    //  TODO(#382): parse bundle.yaml and apphosting.yaml and output a buildschema somewhere.  | 
 | 19 | +    if (SupportedFrameworks.includes(framework)) {  | 
 | 20 | +      adapterBuild(framework, projectRoot)  | 
 | 21 | +    }  | 
44 | 22 |   });  | 
45 | 23 | 
 
  | 
46 | 24 | program.parse();  | 
0 commit comments