1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 11:43:46 +00:00

Feature/put serve behind feature flag (#455)

* Add build-time feature flag capabilities

* Toggle `bw serve` command with `serve` flag

* Run linter and prettier
This commit is contained in:
Matt Gibson
2022-01-28 09:29:04 -05:00
committed by GitHub
parent 1b409653a2
commit 210e0502ca
9 changed files with 117 additions and 18 deletions

5
src/flags.ts Normal file
View File

@@ -0,0 +1,5 @@
export type Flags = {
serve?: boolean;
};
export type FlagName = keyof Flags;

View File

@@ -468,22 +468,24 @@ export class Program extends BaseProgram {
this.processResponse(response);
});
program
.command("serve")
.description("Start a RESTful API webserver.")
.option("--port <port>", "The port to run your API webserver on. Default port is 8087.")
.on("--help", () => {
writeLn("\n Examples:");
writeLn("");
writeLn(" bw serve");
writeLn(" bw serve --port 8080");
writeLn("", true);
})
.action(async (cmd) => {
await this.exitIfNotAuthed();
const command = new ServeCommand(this.main);
await command.run(cmd);
});
if (CliUtils.flagEnabled("serve")) {
program
.command("serve")
.description("Start a RESTful API webserver.")
.option("--port <port>", "The port to run your API webserver on. Default port is 8087.")
.on("--help", () => {
writeLn("\n Examples:");
writeLn("");
writeLn(" bw serve");
writeLn(" bw serve --port 8080");
writeLn("", true);
})
.action(async (cmd) => {
await this.exitIfNotAuthed();
const command = new ServeCommand(this.main);
await command.run(cmd);
});
}
}
protected processResponse(response: Response, exitImmediately = false) {

View File

@@ -9,6 +9,7 @@ import { CollectionView } from "jslib-common/models/view/collectionView";
import { FolderView } from "jslib-common/models/view/folderView";
import { NodeUtils } from "jslib-common/misc/nodeUtils";
import { FlagName, Flags } from "./flags";
export class CliUtils {
static writeLn(s: string, finalLine: boolean = false, error: boolean = false) {
@@ -174,4 +175,18 @@ export class CliUtils {
static convertBooleanOption(optionValue: any) {
return optionValue || optionValue === "" ? true : false;
}
static flagEnabled(flag: FlagName) {
return this.flags[flag] == null || this.flags[flag];
}
private static get flags(): Flags {
const envFlags = process.env.FLAGS;
if (typeof envFlags === "string") {
return JSON.parse(envFlags) as Flags;
} else {
return envFlags as Flags;
}
}
}