Skip to content
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
18 changes: 17 additions & 1 deletion bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import chalk from 'chalk';

const NODE_VERSION_RANGE = '>=18.17.0';

Expand All @@ -20,8 +21,23 @@
import type { CloudRegion, WizardOptions } from './src/utils/types';
import { runWizard } from './src/run';
import { runEventSetupWizard } from './src/nextjs/event-setup';
import { readEnvironment } from './src/utils/environment';
import {
readEnvironment,
isNonInteractiveEnvironment,
} from './src/utils/environment';
import path from 'path';
import clack from './src/utils/clack';

if (isNonInteractiveEnvironment()) {
clack.intro(chalk.inverse(`PostHog Wizard`));
Comment thread
jonathanlab marked this conversation as resolved.

clack.log.error(
'This installer requires an interactive terminal (TTY) to run.\n' +
'It appears you are running in a non-interactive environment.\n' +
'Please run the wizard in an interactive terminal.',
);
process.exit(1);
}

if (process.env.NODE_ENV === 'test') {
void (async () => {
Expand Down Expand Up @@ -104,24 +120,24 @@
});
},
(argv) => {
const finalArgs = {

Check warning on line 123 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an `any` value
...argv,
...readEnvironment(),
} as any;

Check warning on line 126 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

let resolvedInstallDir: string;
if (finalArgs.installDir) {

Check warning on line 129 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe member access .installDir on an `any` value
if (path.isAbsolute(finalArgs.installDir)) {

Check warning on line 130 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe member access .installDir on an `any` value

Check warning on line 130 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe argument of type `any` assigned to a parameter of type `string`
resolvedInstallDir = finalArgs.installDir;

Check warning on line 131 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe member access .installDir on an `any` value

Check warning on line 131 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an `any` value
} else {
resolvedInstallDir = path.join(process.cwd(), finalArgs.installDir);

Check warning on line 133 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe member access .installDir on an `any` value

Check warning on line 133 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe argument of type `any` assigned to a parameter of type `string`
}
} else {
resolvedInstallDir = process.cwd();
}

const wizardOptions: WizardOptions = {
debug: finalArgs.debug ?? false,

Check warning on line 140 in bin.ts

View workflow job for this annotation

GitHub Actions / Lint

Unsafe assignment of an `any` value
installDir: resolvedInstallDir,
cloudRegion: finalArgs.region as CloudRegion | undefined,
default: finalArgs.default ?? false,
Expand Down
13 changes: 13 additions & 0 deletions src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import readEnv from 'read-env';
import { getPackageDotJson } from './clack-utils';
import type { WizardOptions } from './types';
import fg from 'fast-glob';
import { IS_DEV } from '../lib/constants';

export function isNonInteractiveEnvironment(): boolean {
if (IS_DEV) {
return false;
}

if (!process.stdout.isTTY || !process.stderr.isTTY) {
return true;
}

return false;
}

export function readEnvironment(): Record<string, unknown> {
const result = readEnv('POSTHOG_WIZARD');
Expand Down