Skip to content

Commit 1c9bfb4

Browse files
committed
Create apphosting-local-build command.
1 parent e9e3167 commit 1c9bfb4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

packages/@apphosting/build/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"url": "git+https://github.com/FirebaseExtended/firebase-framework-tools.git"
99
},
1010
"bin": {
11-
"build": "dist/bin/build.js"
11+
"build": "dist/bin/build.js",
12+
"apphosting-local-build": "dist/bin/localbuild.js"
1213
},
1314
"author": {
1415
"name": "Firebase",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#! /usr/bin/env node
2+
import { spawn } from "child_process";
3+
import { program } from "commander";
4+
import { parse as semverParse } from "semver";
5+
import { yellow, bgRed, bold } from "colorette";
6+
// @ts-expect-error TODO add interface
7+
import pickManifest from "npm-pick-manifest";
8+
import { discover } from "@apphosting/discover";
9+
10+
program
11+
// TODO: add framework option later. For now we support nextjs only.
12+
.argument("<directory>", "path to the project's root directory")
13+
.action(async () => {
14+
15+
const projectRoot = program.args[0];
16+
const framework = "nextjs";
17+
// TODO: We are using the latest framework adapter versions, but in the future
18+
// we should parse the framework version and use the matching adapter version.
19+
const adapterName = `@apphosting/adapter-nextjs`;
20+
const packumentResponse = await fetch(`https://registry.npmjs.org/${adapterName}`);
21+
if (!packumentResponse.ok) throw new Error(`Something went wrong fetching ${adapterName}`);
22+
const packument = await packumentResponse.json();
23+
const adapterVersion = packument["dist-tags"]["canary"];
24+
// TODO: should check for existence of adapter in app's package.json and use that version instead.
25+
26+
console.log(" 🔥", bgRed(` ${adapterName}@${yellow(bold(adapterVersion))} `), "\n");
27+
28+
// Call it via NPX
29+
const buildCommand = `apphosting-adapter-${framework}-build`;
30+
spawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], {
31+
cwd: projectRoot,
32+
shell: true,
33+
stdio: "inherit",
34+
});
35+
});
36+
37+
program.parse();

0 commit comments

Comments
 (0)