Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { info } from "./scripts/info.js";
import { removeModules } from "./scripts/remove.js";
import { commitModules } from "./scripts/commit-module.js";
import { upgradeScaffold } from "./scripts/upgrade.js";
import { valid, invalid, section, isUserEnvironment } from "./utils.js";
import { valid, invalid, section, isUserEnvironment, isLoginNotReqCommand } from "./utils.js";
import { createModule } from "./scripts/create.js";
import { login } from "./scripts/login.js";
import { configFile } from "./scripts/utils/configFile.js";
Expand All @@ -49,6 +49,7 @@ import { EVENT } from "./scripts/analytics/constants.js";
import { configureInitialLogin } from "./scripts/analytics/scripts.js";
import { sentryMonitoring } from "./scripts/utils/sentry.js";
import { setModuleDetails } from "./scripts/setModuleDetails.js";
import { isUserLoggedIn } from "./scripts/utils/auth.js";
import { logger, prettyPrintShellOutput } from "./scripts/utils/logger.js";

const GLOBAL_ARGS = {
Expand All @@ -69,7 +70,7 @@ Visit our official documentation for more information and try again: https://doc
async function dispatcher() {
const useDefaults = process.env.npm_config_yes;

// check config if they have been asked opted in or out of amplitude
// check config if the inital login has been done
const isInitialLogin = configFile.get(HAS_ASKED_OPT_IN_NAME) || false;
if (!isInitialLogin && isUserEnvironment && !useDefaults) {
await configureInitialLogin();
Expand All @@ -94,6 +95,13 @@ async function dispatcher() {

sentryMonitoring.registerCommandName(command);

const isLoggedIn = isUserLoggedIn();

if (!isLoggedIn && !isLoginNotReqCommand(command)) {
section("We see you are not logged in. Please log in to run Crowdbotics commands");
await login();
}

await commands[command]();

if (!analytics.event.name && !useDefaults) {
Expand Down Expand Up @@ -449,6 +457,7 @@ demo`;
return;
}
configFile.set(OPT_IN_NAME, false);
configFile.save();
valid("Successfully opted out of analytics");
},
optin: () => {
Expand All @@ -457,6 +466,7 @@ demo`;
return;
}
configFile.set(OPT_IN_NAME, true);
configFile.save();
valid("Successfully opted in of analytics");
},
help: () => {
Expand Down
4 changes: 0 additions & 4 deletions scripts/analytics/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ export const configureInitialLogin = async () => {
configFile.set(HAS_ASKED_OPT_IN_NAME, true);
configFile.save();
};

// when log in we will always have
// check OPT_IN_NAME instances
// make command for opting in again
4 changes: 4 additions & 0 deletions scripts/utils/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ export const performLogout = async () => {
return false;
}
};

export const isUserLoggedIn = () => {
return !!configFile.get(TOKEN_CONFIG_NAME);
};
6 changes: 6 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const generateCommand = (str) => str.join(" ");
const VALID_MARK = "\u2705";
const INVALID_MARK = "\u274C";
const WARNING_MARK = "\u26A0";
const LOGIN_REQUIRED_COMMANDS = ["help", "logout", "login"];

export const valid = (...args) => {
console.log(VALID_MARK, ...args);
Expand All @@ -23,3 +24,8 @@ export const section = (...args) => {
};

export const isUserEnvironment = !process?.env?.CI && !process?.env?.CIRCLE_JOB;

export const isLoginNotReqCommand = (command) => {
const allowedCommands = LOGIN_REQUIRED_COMMANDS;
return allowedCommands.includes(command);
};