growthbook
Version:
The GrowthBook command-line interface (CLI) for working with the GrowthBook A/B testing, feature flagging, and experimentation platform
68 lines (67 loc) • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const Fs = require("node:fs");
const toml = require("@iarna/toml");
const file_1 = require("../../utils/file");
const config_1 = require("../../utils/config");
const cli_1 = require("../../utils/cli");
class Logout extends core_1.Command {
async run() {
const { flags: { profile, } } = await this.parse(Logout);
if (profile) {
// Log out of only one specific profile
this.logOutOfProfile(profile);
}
else {
// Log out of all profiles
this.writeBlankFileToGrowthBookConfig();
}
}
/**
* Removes all profiles
* @return void
*/
writeBlankFileToGrowthBookConfig() {
core_1.ux.action.start('Removing all GrowthBook profiles from ~/.growthbook/config.toml');
const configFilePath = (0, file_1.getGrowthBookConfigFilePath)();
try {
Fs.writeFileSync(configFilePath, '');
core_1.ux.action.stop(cli_1.Icons.checkmark);
}
catch (error) {
this.error(`💥 Cannot write to file at ${configFilePath}. It may not exist or there may be insufficient permissions. \n` + error);
}
}
/**
* Removes only specified profile
* @param profile Named profile
* @return void
*/
logOutOfProfile(profile) {
core_1.ux.action.start(`Removing config for profile '${profile}' from ~/.growthbook/config.toml'`);
const configText = (0, config_1.getGrowthBookConfigToml)();
const config = toml.parse(configText);
delete config[profile];
const configFilePath = (0, file_1.getGrowthBookConfigFilePath)();
const stringified = toml.stringify(config);
try {
Fs.writeFileSync(configFilePath, stringified);
core_1.ux.action.stop(cli_1.Icons.checkmark);
}
catch (error) {
this.error(`💥 Cannot write to file at ${configFilePath}. It may not exist or there may be insufficient permissions. \n` + error);
}
}
}
exports.default = Logout;
Logout.description = 'Removes GrowthBook API key configurations';
Logout.examples = [];
Logout.flags = {
profile: core_1.Flags.string({
char: 'p',
description: 'Optional profile (for projects that use multiple GrowthBook instances or organizations) (default: all profiles)',
required: false,
}),
};
Logout.args = {};