-
Notifications
You must be signed in to change notification settings - Fork 283
Create apphosting-local-build command. #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c9bfb4
Create apphosting-local-build command.
annajowang 19316ca
run lint and add test scripts
annajowang 65804c7
e2e tests i will likely delete
annajowang 580df00
Clean and lint
annajowang e08251d
resolve reject
annajowang ee5c8a0
Update version.
annajowang 4a9083f
Remove test script
annajowang 63cdee0
lint
annajowang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.