Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions packages/@apphosting/build/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@apphosting/build",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to reuse this package for what you want to do here it would probably be a good idea to clean it up a bit too. This was created a long time ago as a part of some prototype James was working on where we could call the adapter from Firebase Hosting classic but I doubt we're gonna go that route now.

I don't think the other code in src/bin is used anywhere afaik (might be good to double check) and we may want to delete it if this is a real package we're relying on now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 planning to delete the old script.
james confirmed it's unused.

"version": "0.1.0",
"version": "0.1.1",
"main": "dist/index.js",
"description": "Experimental addon to the Firebase CLI to add web framework support",
"repository": {
"type": "git",
"url": "git+https://github.com/FirebaseExtended/firebase-framework-tools.git"
},
"bin": {
"build": "dist/bin/build.js"
"build": "dist/bin/build.js",
"apphosting-local-build": "dist/bin/localbuild.js"
},
"author": {
"name": "Firebase",
Expand All @@ -20,7 +21,7 @@
"type": "module",
"sideEffects": false,
"scripts": {
"build": "rm -rf dist && tsc && chmod +x ./dist/bin/*"
"build": "rm -rf dist && tsc && chmod +x ./dist/bin/*"
},
"exports": {
".": {
Expand All @@ -40,6 +41,6 @@
"ts-node": "^10.9.1"
},
"devDependencies": {
"@types/commander": "*"
"@types/commander": "*"
}
}
46 changes: 46 additions & 0 deletions packages/@apphosting/build/src/bin/localbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /usr/bin/env node
import { spawn } from "child_process";
import { program } from "commander";
import { yellow, bgRed, bold } from "colorette";

// TODO(#382): add framework option later or incorporate micro-discovery.
// TODO(#382): parse apphosting.yaml for environment variables / secrets.
// TODO(#382): parse apphosting.yaml for runConfig and include in buildSchema
// TODO(#382): Support custom build and run commands (parse and pass run command to build schema).
program
.argument("<projectRoot>", "path to the project's root directory")
.action(async (projectRoot: string) => {
const framework = "nextjs";
// TODO(#382): We are using the latest framework adapter versions, but in the future
// we should parse the framework version and use the matching adapter version.
const adapterName = `@apphosting/adapter-nextjs`;
const packumentResponse = await fetch(`https://registry.npmjs.org/${adapterName}`);
if (!packumentResponse.ok) throw new Error(`Something went wrong fetching ${adapterName}`);
const packument = await packumentResponse.json();
const adapterVersion = packument?.["dist-tags"]?.["latest"];
if (!adapterVersion) {
throw new Error(`Could not find 'latest' dist-tag for ${adapterName}`);
}
// TODO(#382): should check for existence of adapter in app's package.json and use that version instead.

console.log(" 🔥", bgRed(` ${adapterName}@${yellow(bold(adapterVersion))} `), "\n");

const buildCommand = `apphosting-adapter-${framework}-build`;
await new Promise<void>((resolve, reject) => {
const child = spawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], {
cwd: projectRoot,
shell: true,
stdio: "inherit",
});

child.on("exit", (code) => {
if (code !== 0) {
reject(new Error(`framework adapter build failed with error code ${code}.`));
}
resolve();
});
});
// TODO(#382): parse bundle.yaml and apphosting.yaml and output a buildschema somewhere.
});

program.parse();
9 changes: 7 additions & 2 deletions packages/@apphosting/build/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
"extends": "../../../tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "dist"
"outDir": "dist",
"rootDir": "src"

},
"include": [
"src/index.ts",
"src/bin/*.ts",
]
],
"exclude": [
"src/*.spec.ts"
]
}