Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Experiments feature (#4994)
Add experiments to the Firebase CLI. New commands: ``` firebase experiments:enable <experiment> firebase experiments:disable <experiment> firebase experiments:describe <experiment> firebase experiments:list ```
- Loading branch information
Showing
27 changed files
with
424 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
- Add the "experiments" family of commands (#4994) |
This file contains 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 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,32 @@ | ||
import { bold } from "colorette"; | ||
|
||
import { Command } from "../command"; | ||
import { FirebaseError } from "../error"; | ||
import * as experiments from "../experiments"; | ||
import { logger } from "../logger"; | ||
import { last } from "../utils"; | ||
|
||
export const command = new Command("experiments:describe <experiment>") | ||
.description("enable an experiment on this machine") | ||
.action((experiment: string) => { | ||
if (!experiments.isValidExperiment(experiment)) { | ||
let message = `Cannot find experiment ${bold(experiment)}`; | ||
const potentials = experiments.experimentNameAutocorrect(experiment); | ||
if (potentials.length === 1) { | ||
message = `${message}\nDid you mean ${potentials[0]}?`; | ||
} else if (potentials.length) { | ||
message = `${message}\nDid you mean ${potentials.slice(0, -1).join(",")} or ${last( | ||
potentials | ||
)}?`; | ||
} | ||
throw new FirebaseError(message); | ||
} | ||
|
||
const spec = experiments.ALL_EXPERIMENTS[experiment]; | ||
logger.info(`${bold("Name")}: ${experiment}`); | ||
logger.info(`${bold("Enabled")}: ${experiments.isEnabled(experiment) ? "yes" : "no"}`); | ||
if (spec.docsUri) { | ||
logger.info(`${bold("Documentation")}: ${spec.docsUri}`); | ||
} | ||
logger.info(`${bold("Description")}: ${spec.fullDescription || spec.shortDescription}`); | ||
}); |
This file contains 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,29 @@ | ||
import { bold } from "colorette"; | ||
|
||
import { Command } from "../command"; | ||
import { FirebaseError } from "../error"; | ||
import * as experiments from "../experiments"; | ||
import { logger } from "../logger"; | ||
import { last } from "../utils"; | ||
|
||
export const command = new Command("experiments:disable <experiment>") | ||
.description("disable an experiment on this machine") | ||
.action((experiment: string) => { | ||
if (experiments.isValidExperiment(experiment)) { | ||
experiments.setEnabled(experiment, false); | ||
experiments.flushToDisk(); | ||
logger.info(`Disabled experiment ${bold(experiment)}`); | ||
return; | ||
} | ||
|
||
let message = `Cannot find experiment ${bold(experiment)}`; | ||
const potentials = experiments.experimentNameAutocorrect(experiment); | ||
if (potentials.length === 1) { | ||
message = `${message}\nDid you mean ${potentials[0]}?`; | ||
} else if (potentials.length) { | ||
message = `${message}\nDid you mean ${potentials.slice(0, -1).join(",")} or ${last( | ||
potentials | ||
)}?`; | ||
} | ||
throw new FirebaseError(message); | ||
}); |
This file contains 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,29 @@ | ||
import { bold } from "colorette"; | ||
|
||
import { Command } from "../command"; | ||
import { FirebaseError } from "../error"; | ||
import * as experiments from "../experiments"; | ||
import { logger } from "../logger"; | ||
import { last } from "../utils"; | ||
|
||
export const command = new Command("experiments:enable <experiment>") | ||
.description("enable an experiment on this machine") | ||
.action((experiment: string) => { | ||
if (experiments.isValidExperiment(experiment)) { | ||
experiments.setEnabled(experiment, true); | ||
experiments.flushToDisk(); | ||
logger.info(`Enabled experiment ${bold(experiment)}`); | ||
return; | ||
} | ||
|
||
let message = `Cannot find experiment ${bold(experiment)}`; | ||
const potentials = experiments.experimentNameAutocorrect(experiment); | ||
if (potentials.length === 1) { | ||
message = `${message}\nDid you mean ${potentials[0]}?`; | ||
} else if (potentials.length) { | ||
message = `${message}\nDid you mean ${potentials.slice(0, -1).join(",")} or ${last( | ||
potentials | ||
)}?`; | ||
} | ||
throw new FirebaseError(message); | ||
}); |
This file contains 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,25 @@ | ||
import { Command } from "../command"; | ||
import Table = require("cli-table"); | ||
import * as experiments from "../experiments"; | ||
import { partition } from "../functional"; | ||
import { logger } from "../logger"; | ||
|
||
export const command = new Command("experiments:list").action(() => { | ||
const table = new Table({ | ||
head: ["Enabled", "Name", "Description"], | ||
style: { head: ["yellow"] }, | ||
}); | ||
const [enabled, disabled] = partition(Object.entries(experiments.ALL_EXPERIMENTS), ([name]) => { | ||
return experiments.isEnabled(name as experiments.ExperimentName); | ||
}); | ||
for (const [name, exp] of enabled) { | ||
table.push(["y", name, exp.shortDescription]); | ||
} | ||
for (const [name, exp] of disabled) { | ||
if (!exp.public) { | ||
continue; | ||
} | ||
table.push(["n", name, exp.shortDescription]); | ||
} | ||
logger.info(table.toString()); | ||
}); |
This file contains 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 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 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 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 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 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 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 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
Oops, something went wrong.