@onboardbase/cli
Version:
[](https://www.npmjs.com/package/@onboardbase/cli) [](https://www.npmjs.com/package/@onboardbase/cli) [ • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigSetService = void 0;
const common_1 = require("../../common");
const chalk = require("chalk");
class ConfigSetService extends common_1.BaseService {
getDirectoriesThatRequiresPassword() {
const scoped = this.configManager.getFromGlobal("scoped");
const directoriesThatNeedsPassword = [];
Object.keys(scoped).map((scopedDirectoryKey) => {
if (scoped[scopedDirectoryKey].requirePassword)
directoriesThatNeedsPassword.push(scopedDirectoryKey);
});
return directoriesThatNeedsPassword;
}
async initialize({ args, flags }) {
var _a, _b;
if (flags["re-authenticate"]) {
this.getDirectoriesThatRequiresPassword().map((directory) => this.configManager.setGlobal(`scoped.${directory}`, {
requirePasswordForCurrentSession: true,
}));
}
/**
* check to see if CLI is only trying to re-authenticate and nothing else
*/
const isAReAuthRequest = Object.keys(flags).length === 1 && flags["re-authenticate"];
if (!isAReAuthRequest) {
if (!flags.scope)
console.log(`${chalk.bold.greenBright("Warning:")} You didn't specify a scope... your config will be scoped to root !.e /`);
const scope = ((_a = flags.scope) === null || _a === void 0 ? void 0 : _a.trim()) === "{cwd}" ? process.cwd() : (_b = flags.scope) !== null && _b !== void 0 ? _b : "/";
const config = {
token: flags.token || this.getConfigForCurrentScope("token"),
"api-host": flags["api-host"] || this.getConfigForCurrentScope("api-host"),
"dashboard-host": flags["dashboard-host"] ||
this.getConfigForCurrentScope("dashboard-host"),
encryptToken: false,
requirePassword: Boolean(flags.password),
password: flags.password,
requirePasswordForCurrentSession: Boolean(flags.password),
};
this.configManager.setGlobal(`scoped.${scope}`, config);
// if this is the first onboardase command to run on a machine
// the config for the current scope is assumed to be merged
// this would create partial record since the global scope does not have enough configuration that can be referenced
// in case a missing scoped config is available in the global space
// so we force this re-merge to ensure data consistency on the next command
// config merge is a side effect that happens before the actual code for
// a command runs.
this.setConfigForCurrentScope("merged", false);
console.log(chalk.green("Onboardbase config updated successfully."));
}
}
}
exports.ConfigSetService = ConfigSetService;