@constructor-io/constructorio-connect-cli
Version:
CLI tool to enable users to interface with the Constructor Connect Ecosystem
36 lines (35 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RefreshConnectionsCommand = void 0;
const core_1 = require("@oclif/core");
const refresh_connections_list_1 = require("../helpers/refresh-connections-list");
const prepend_file_sync_1 = require("../helpers/prepend-file-sync");
class RefreshConnectionsCommand extends core_1.Command {
async run() {
if (this.shouldAutoRefreshConnections()) {
await (0, refresh_connections_list_1.refreshConnectionsList)();
}
return await this.runCommand();
}
/**
* Checks if the connections list should be automatically refreshed if
* 1) IS_CI environment variable is not true; and
* 2) AUTO_REFRESH_CONNECTIONS environment variable set to "true", true,
* or if it is undefined (in which case it will be set to true).
*
* @returns {boolean} - true if the connections list should be refreshed, false otherwise.
*/
shouldAutoRefreshConnections() {
if (process.env.IS_CI === "true") {
return false;
}
if (process.env.AUTO_REFRESH_CONNECTIONS === undefined) {
(0, prepend_file_sync_1.prependFileSync)(".env", `AUTO_REFRESH_CONNECTIONS=true\n`);
// Manually set it to true otherwise any access to it within
// the same process will be outdated (will still return undefined)
process.env.AUTO_REFRESH_CONNECTIONS = "true";
}
return process.env.AUTO_REFRESH_CONNECTIONS === "true";
}
}
exports.RefreshConnectionsCommand = RefreshConnectionsCommand;