Skip to content

Commit e940309

Browse files
authored
chore: migrate to segment (#874)
1 parent 3739549 commit e940309

24 files changed

+394
-391
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
},
6161
"homepage": "https://github.com/apify/apify-cli#readme",
6262
"engines": {
63-
"node": ">=18"
63+
"node": ">=20"
6464
},
6565
"dependencies": {
6666
"@apify/actor-templates": "^0.1.5",
@@ -100,9 +100,7 @@
100100
"js-levenshtein": "^1.1.6",
101101
"lodash.clonedeep": "^4.5.0",
102102
"mime": "~4.0.4",
103-
"mixpanel": "~0.18.0",
104103
"open": "~10.2.0",
105-
"ow": "~2.0.0",
106104
"rimraf": "~6.0.1",
107105
"semver": "~7.7.0",
108106
"string-width": "^7.2.0",

scripts/generate-cli-docs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const categories: Record<string, CommandsInCategory[]> = {
6767
//
6868
{ command: Commands.help },
6969
{ command: Commands.upgrade },
70+
{ command: Commands.telemetry },
71+
{ command: Commands.telemetryEnable },
72+
{ command: Commands.telemetryDisable },
7073
],
7174
'dataset': [
7275
//

src/commands/_register.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { RunCommand } from './run.js';
2828
import { RunsIndexCommand } from './runs/_index.js';
2929
import { SecretsIndexCommand } from './secrets/_index.js';
3030
import { TasksIndexCommand } from './task/_index.js';
31+
import { TelemetryIndexCommand } from './telemetry/_index.js';
3132
import { ValidateInputSchemaCommand } from './validate-schema.js';
3233

3334
export const apifyCommands = [
@@ -41,6 +42,8 @@ export const apifyCommands = [
4142
RunsIndexCommand,
4243
SecretsIndexCommand,
4344
TasksIndexCommand,
45+
TelemetryIndexCommand,
46+
4447
// top-level
4548
TopLevelCallCommand,
4649
UpgradeCommand,
@@ -70,8 +73,12 @@ export const actorCommands = [
7073
ActorGetPublicUrlCommand,
7174
ActorGetInputCommand,
7275
ActorChargeCommand,
76+
7377
// top-level
7478
HelpCommand,
7579
UpgradeCommand,
7680
InstallCommand,
81+
82+
// namespaces
83+
TelemetryIndexCommand,
7784
] as const satisfies (typeof BuiltApifyCommand)[];

src/commands/init.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ import process from 'node:process';
44
import { ApifyCommand } from '../lib/command-framework/apify-command.js';
55
import { Args } from '../lib/command-framework/args.js';
66
import { Flags } from '../lib/command-framework/flags.js';
7-
import {
8-
CommandExitCodes,
9-
DEFAULT_LOCAL_STORAGE_DIR,
10-
EMPTY_LOCAL_CONFIG,
11-
LOCAL_CONFIG_PATH,
12-
PROJECT_TYPES,
13-
} from '../lib/consts.js';
7+
import { CommandExitCodes, DEFAULT_LOCAL_STORAGE_DIR, EMPTY_LOCAL_CONFIG, LOCAL_CONFIG_PATH } from '../lib/consts.js';
148
import { useActorConfig } from '../lib/hooks/useActorConfig.js';
159
import { ProjectLanguage, useCwdProject } from '../lib/hooks/useCwdProject.js';
1610
import { useUserInput } from '../lib/hooks/user-confirmations/useUserInput.js';
@@ -61,7 +55,7 @@ export class InitCommand extends ApifyCommand<typeof InitCommand> {
6155

6256
if (project.type === ProjectLanguage.Scrapy) {
6357
info({ message: 'The current directory looks like a Scrapy project. Using automatic project wrapping.' });
64-
this.telemetryData.actorWrapper = PROJECT_TYPES.SCRAPY;
58+
this.telemetryData.actorWrapper = 'scrapy';
6559

6660
return wrapScrapyProject({ projectPath: cwd });
6761
}

src/commands/login.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { cryptoRandomObjectId } from '@apify/utilities';
1212
import { ApifyCommand } from '../lib/command-framework/apify-command.js';
1313
import { Flags } from '../lib/command-framework/flags.js';
1414
import { AUTH_FILE_PATH } from '../lib/consts.js';
15+
import { updateUserId } from '../lib/hooks/telemetry/useTelemetryState.js';
1516
import { useMaskedInput } from '../lib/hooks/user-confirmations/useMaskedInput.js';
1617
import { useSelectFromList } from '../lib/hooks/user-confirmations/useSelectFromList.js';
1718
import { error, info, success } from '../lib/outputs.js';
18-
import { useApifyIdentity } from '../lib/telemetry.js';
1919
import { getLocalUserInfo, getLoggedClient } from '../lib/utils.js';
2020

2121
const CONSOLE_BASE_URL = 'https://console.apify.com/settings/integrations';
@@ -30,8 +30,10 @@ const API_VERSION = 'v1';
3030
const tryToLogin = async (token: string) => {
3131
const isUserLogged = await getLoggedClient(token, API_BASE_URL);
3232
const userInfo = await getLocalUserInfo();
33+
3334
if (isUserLogged) {
34-
await useApifyIdentity(userInfo.id!);
35+
await updateUserId(userInfo.id!);
36+
3537
success({
3638
message: `You are logged in to Apify as ${userInfo.username || userInfo.id}. ${chalk.gray(`Your token is stored at ${AUTH_FILE_PATH()}.`)}`,
3739
});
@@ -67,6 +69,7 @@ export class LoginCommand extends ApifyCommand<typeof LoginCommand> {
6769

6870
async run() {
6971
const { token, method } = this.flags;
72+
7073
if (token) {
7174
await tryToLogin(token);
7275
return;

src/commands/logout.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ApifyCommand } from '../lib/command-framework/apify-command.js';
22
import { AUTH_FILE_PATH } from '../lib/consts.js';
33
import { rimrafPromised } from '../lib/files.js';
4+
import { updateUserId } from '../lib/hooks/telemetry/useTelemetryState.js';
45
import { success } from '../lib/outputs.js';
5-
import { regenerateLocalDistinctId } from '../lib/telemetry.js';
66

77
export class LogoutCommand extends ApifyCommand<typeof LogoutCommand> {
88
static override name = 'logout' as const;
@@ -13,7 +13,9 @@ export class LogoutCommand extends ApifyCommand<typeof LogoutCommand> {
1313

1414
async run() {
1515
await rimrafPromised(AUTH_FILE_PATH());
16-
regenerateLocalDistinctId();
16+
17+
await updateUserId(null);
18+
1719
success({ message: 'You are logged out from your Apify account.' });
1820
}
1921
}

src/commands/telemetry/_index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
2+
import { TelemetryDisableCommand } from './disable.js';
3+
import { TelemetryEnableCommand } from './enable.js';
4+
5+
export class TelemetryIndexCommand extends ApifyCommand<typeof TelemetryIndexCommand> {
6+
static override name = 'telemetry' as const;
7+
8+
static override description =
9+
'Manages telemetry settings. We use this data to improve the CLI and the Apify platform.\nRead more: https://docs.apify.com/cli/docs/telemetry';
10+
11+
static override subcommands = [TelemetryEnableCommand, TelemetryDisableCommand];
12+
13+
async run() {
14+
this.printHelp();
15+
}
16+
}

src/commands/telemetry/disable.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
2+
import { updateTelemetryEnabled, useTelemetryState } from '../../lib/hooks/telemetry/useTelemetryState.js';
3+
import { info, success } from '../../lib/outputs.js';
4+
5+
export class TelemetryDisableCommand extends ApifyCommand<typeof TelemetryDisableCommand> {
6+
static override name = 'disable' as const;
7+
8+
static override description = 'Disables telemetry.';
9+
10+
async run() {
11+
const currentState = await useTelemetryState();
12+
13+
if (currentState.enabled) {
14+
await updateTelemetryEnabled(false);
15+
16+
success({ message: 'Telemetry disabled.' });
17+
} else {
18+
info({ message: 'Telemetry is already disabled.' });
19+
}
20+
}
21+
}

src/commands/telemetry/enable.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
2+
import { updateTelemetryEnabled, useTelemetryState } from '../../lib/hooks/telemetry/useTelemetryState.js';
3+
import { info, success } from '../../lib/outputs.js';
4+
5+
export class TelemetryEnableCommand extends ApifyCommand<typeof TelemetryEnableCommand> {
6+
static override name = 'enable' as const;
7+
8+
static override description = 'Enables telemetry.';
9+
10+
async run() {
11+
const currentState = await useTelemetryState();
12+
13+
if (currentState.enabled) {
14+
info({ message: 'Telemetry is already enabled.' });
15+
} else {
16+
await updateTelemetryEnabled(true);
17+
18+
success({ message: 'Telemetry enabled.' });
19+
}
20+
}
21+
}

src/entrypoints/_shared.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ export async function runCLI(entrypoint: string) {
190190
cliDebugPrint('RebuiltArgs', rebuiltArgs);
191191
cliDebugPrint('CommandToRun', FinalCommand);
192192

193-
const instance = new FinalCommand(entrypoint);
193+
const instance = new FinalCommand(
194+
entrypoint,
195+
hasSubcommand ? `${baseCommand.name} ${maybeSubcommandName}` : baseCommand.name,
196+
);
194197

195198
// eslint-disable-next-line dot-notation
196199
const parserOptions = instance['_buildParseArgsOption']();

0 commit comments

Comments
 (0)