Skip to content

Commit 62ec239

Browse files
authored
Create apphosting-local-build command. (#383)
1 parent e9e3167 commit 62ec239

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed

package-lock.json

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@apphosting/build/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "@apphosting/build",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"main": "dist/index.js",
55
"description": "Experimental addon to the Firebase CLI to add web framework support",
66
"repository": {
77
"type": "git",
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",
@@ -20,7 +21,7 @@
2021
"type": "module",
2122
"sideEffects": false,
2223
"scripts": {
23-
"build": "rm -rf dist && tsc && chmod +x ./dist/bin/*"
24+
"build": "rm -rf dist && tsc && chmod +x ./dist/bin/*"
2425
},
2526
"exports": {
2627
".": {
@@ -40,6 +41,6 @@
4041
"ts-node": "^10.9.1"
4142
},
4243
"devDependencies": {
43-
"@types/commander": "*"
44+
"@types/commander": "*"
4445
}
4546
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /usr/bin/env node
2+
import { spawn } from "child_process";
3+
import { program } from "commander";
4+
import { yellow, bgRed, bold } from "colorette";
5+
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
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+
26+
console.log(" 🔥", bgRed(` ${adapterName}@${yellow(bold(adapterVersion))} `), "\n");
27+
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+
});
35+
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.
44+
});
45+
46+
program.parse();

packages/@apphosting/build/tsconfig.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
"extends": "../../../tsconfig.json",
33
"compilerOptions": {
44
"noEmit": false,
5-
"outDir": "dist"
5+
"outDir": "dist",
6+
"rootDir": "src"
7+
68
},
79
"include": [
810
"src/index.ts",
911
"src/bin/*.ts",
10-
]
12+
],
13+
"exclude": [
14+
"src/*.spec.ts"
15+
]
1116
}

0 commit comments

Comments
 (0)