Skip to content

Commit fd276b3

Browse files
authored
make local build callable (#402)
* Move adapterBuild to index.ts * update package version
1 parent c969a35 commit fd276b3

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

packages/@apphosting/build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@apphosting/build",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"main": "dist/index.js",
55
"description": "Experimental addon to the Firebase CLI to add web framework support",
66
"repository": {

packages/@apphosting/build/src/adapter-builds.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/@apphosting/build/src/bin/localbuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /usr/bin/env node
22
import { SupportedFrameworks } from "@apphosting/common";
3-
import { adapterBuild } from "../adapter-builds.js";
3+
import { adapterBuild } from "../index.js";
44
import { program } from "commander";
55

66
program
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
export {};
1+
import promiseSpawn from "@npmcli/promise-spawn";
2+
import { yellow, bgRed, bold } from "colorette";
3+
4+
export async function adapterBuild(projectRoot: string, framework: string) {
5+
// TODO(#382): We are using the latest framework adapter versions, but in the future
6+
// we should parse the framework version and use the matching adapter version.
7+
const adapterName = `@apphosting/adapter-${framework}`;
8+
const packumentResponse = await fetch(`https://registry.npmjs.org/${adapterName}`);
9+
if (!packumentResponse.ok)
10+
throw new Error(
11+
`Failed to fetch ${adapterName}: ${packumentResponse.status} ${packumentResponse.statusText}`,
12+
);
13+
let packument;
14+
try {
15+
packument = await packumentResponse.json();
16+
} catch (e) {
17+
throw new Error(`Failed to parse response from NPM registry for ${adapterName}.`);
18+
}
19+
const adapterVersion = packument?.["dist-tags"]?.["latest"];
20+
if (!adapterVersion) {
21+
throw new Error(`Could not find 'latest' dist-tag for ${adapterName}`);
22+
}
23+
// TODO(#382): should check for existence of adapter in app's package.json and use that version instead.
24+
25+
console.log(" 🔥", bgRed(` ${adapterName}@${yellow(bold(adapterVersion))} `), "\n");
26+
27+
const buildCommand = `apphosting-adapter-${framework}-build`;
28+
await promiseSpawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], {
29+
cwd: projectRoot,
30+
shell: true,
31+
stdio: "inherit",
32+
});
33+
}

0 commit comments

Comments
 (0)