-
Notifications
You must be signed in to change notification settings - Fork 983
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
[Experiment] Adds "firebase shell" command. #1865
base: master
Are you sure you want to change the base?
Conversation
@bkendall I put this behind a preview flag because I think it's pretty safe to merge even if it's still fairly experimental. |
src/commands/shell.ts
Outdated
return Object.assign({ __id__: snap.id }, snap.data()); | ||
} | ||
|
||
module.exports = new Command("shell [script_path]") |
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.
export default new Command
should be okay here
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.
Done.
src/commands/shell.ts
Outdated
} | ||
} | ||
|
||
function runRepl(sandbox: Context) { |
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.
Can return types be added where necessary? any
warnings can be ignored, but return types are useful.
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.
Done.
const script = new Script(readFileSync(scriptPath, { encoding: "utf8" }), { | ||
filename: scriptPath, | ||
}); | ||
return await Promise.resolve(script.runInContext(sandbox)); |
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.
Why the additional wrapping? Also, does it return something worthwhile? Maybe just await
the script and remove the return.
return await Promise.resolve(script.runInContext(sandbox)); | |
return await script.runInContext(sandbox); |
(I'm seeing a comment regarding the wrapping below - if it's the same condition, let's add the same comment here)
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.
Done.
src/commands/shell.ts
Outdated
import { readFileSync, existsSync } from "fs"; | ||
import fetch, { Response } from "node-fetch"; | ||
import { DocumentSnapshot, Firestore, QuerySnapshot } from "@google-cloud/firestore"; | ||
import api = require("../api"); |
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.
Can you import the other 2 values needed in line 6 above where api
is being import
'd?
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.
Done.
src/commands/shell.ts
Outdated
const replServer = start({ | ||
prompt: `${yellow("firebase")}${red(">")} `, | ||
eval: shellEval, | ||
// writer: replWriter, |
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.
Remove?
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.
Done.
replServer.on("exit", resolve); | ||
process.on("SIGINT", resolve); |
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.
Does SIGINT
cause exit
to fire too?
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.
I...don't remember why I have this here but I remember it's necessary. I think it catches a weird state where you had to hit Ctrl+C multiple times or something.
client_id: api.clientId, | ||
client_secret: api.clientSecret, | ||
refresh_token: getRefreshToken(), | ||
} as any, |
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.
The Firestore library doesn't have a type for this? I thought that one carried its own types. It'd be nice to not cast something as any
if we can help it.
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.
It's a hack to allow user credentials, which is an undocumented but technically supported feature. See this issue which I will add in a comment.
Implements a
firebase shell
command that is pre-initialized with an Admin SDK to perform scripted administrative tasks easily.