Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

[Experiment] Adds "firebase shell" command. #1865

wants to merge 6 commits into from

Conversation

mbleigh
Copy link
Contributor

@mbleigh mbleigh commented Dec 13, 2019

Implements a firebase shell command that is pre-initialized with an Admin SDK to perform scripted administrative tasks easily.

@googlebot googlebot added the cla: yes Manual indication that this has passed CLA. label Dec 13, 2019
@coveralls
Copy link

Coverage Status

Coverage remained the same at 65.827% when pulling 384e724 on mb-shell into 7870528 on master.

@mbleigh
Copy link
Contributor Author

mbleigh commented Dec 17, 2020

@bkendall I put this behind a preview flag because I think it's pretty safe to merge even if it's still fairly experimental.

return Object.assign({ __id__: snap.id }, snap.data());
}

module.exports = new Command("shell [script_path]")
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
}

function runRepl(sandbox: Context) {
Copy link
Contributor

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.

Copy link
Contributor Author

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));
Copy link
Contributor

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.

Suggested change
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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

import { readFileSync, existsSync } from "fs";
import fetch, { Response } from "node-fetch";
import { DocumentSnapshot, Firestore, QuerySnapshot } from "@google-cloud/firestore";
import api = require("../api");
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const replServer = start({
prompt: `${yellow("firebase")}${red(">")} `,
eval: shellEval,
// writer: replWriter,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +67 to +68
replServer.on("exit", resolve);
process.on("SIGINT", resolve);
Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@mbleigh mbleigh requested a review from bkendall December 18, 2020 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants