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
16 changes: 16 additions & 0 deletions src/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import {red} from 'kleur';
import {logHelpVersion} from '../help/version.help';
import {enableDisableVersionCheck} from '../services/version/version.check.services';
import {printVersion} from '../services/version/version.print.services';

export const logVersion = async () => {
await printVersion();
};

export const version = async (args?: string[]) => {
const [subCommand] = args ?? [];

switch (subCommand) {
case 'check':
await enableDisableVersionCheck();
break;
default:
console.log(red('Unknown subcommand.'));
logHelpVersion(args);
}
};
16 changes: 15 additions & 1 deletion src/configs/cli.versions.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ const getVersionConfig = (): Conf<CachedVersions> =>

export const getCachedVersions = (): Conf<CachedVersions> => getVersionConfig();

export const updateLastCheckToNow = ({key}: {key: keyof CachedVersions}) => {
export const isWeeklyCheckEnabled = (): boolean =>
getCachedVersions().get('weeklyCheckEnabled') !== false;

export const isWeeklyCheckDisabled = (): boolean => !isWeeklyCheckEnabled();

export const toggleWeeklyCheck = (enabled: boolean) => {
const config = getVersionConfig();
config.set('weeklyCheckEnabled', enabled);
};

export const updateLastCheckToNow = ({
key
}: {
key: keyof Omit<CachedVersions, 'weeklyCheckEnabled'>;
}) => {
const config = getVersionConfig();

const currentVersions = config.get(key);
Expand Down
2 changes: 1 addition & 1 deletion src/constants/help.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const SNAPSHOT_DESCRIPTION = 'Handle snapshot-related tasks.';
export const START_DESCRIPTION = 'Start a module.';
export const STOP_DESCRIPTION = 'Stop a module.';
export const UPGRADE_DESCRIPTION = 'Upgrade a module to a new version.';
export const VERSION_DESCRIPTION = 'Check the version of the CLI.';
export const VERSION_DESCRIPTION = 'Manage version related tasks.';
export const STATUS_DESCRIPTION = 'Check the status of the modules.';
export const WHOAMI_DESCRIPTION =
'Display your current profile, access key, and links to your satellite.';
Expand Down
7 changes: 5 additions & 2 deletions src/help/version.help.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {cyan, green, yellow} from 'kleur';
import {cyan, green, magenta} from 'kleur';
import {OPTION_HELP, VERSION_DESCRIPTION} from '../constants/help.constants';
import {helpOutput} from './common.help';
import {TITLE} from './help';

const usage = `Usage: ${green('juno')} ${cyan('version')} ${yellow('[options]')}
const usage = `Usage: ${green('juno')} ${cyan('version')} ${magenta('<subcommand>')}

Subcommands:
${magenta('check')} Configure the weekly version check.

Options:
${OPTION_HELP}`;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {helpSnapshot, snapshot} from './commands/snapshot';
import {startStop} from './commands/start-stop';
import {status} from './commands/status';
import {upgrade} from './commands/upgrade';
import {logVersion} from './commands/version';
import {logVersion, version as versionCommand} from './commands/version';
import {whoami} from './commands/whoami';
import {help} from './help/help';
import {logHelpLogin} from './help/login.help';
Expand Down Expand Up @@ -149,7 +149,7 @@ export const run = async () => {
await clear();
break;
case 'version':
await logVersion();
await versionCommand(args);
break;
case 'status':
await status();
Expand Down
24 changes: 24 additions & 0 deletions src/services/version/version.check.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {isNullish} from '@dfinity/utils';
import prompts from 'prompts';
import {isWeeklyCheckEnabled, toggleWeeklyCheck} from '../../configs/cli.versions.config';

export const enableDisableVersionCheck = async () => {
const current = isWeeklyCheckEnabled();

const {enabled}: {enabled: boolean | undefined} = await prompts([
{
type: 'toggle',
name: 'enabled',
message: 'Enable weekly version check?',
initial: current,
active: 'yes',
inactive: 'no'
}
]);

if (isNullish(enabled)) {
return;
}

toggleWeeklyCheck(enabled);
};
2 changes: 1 addition & 1 deletion src/services/version/version.check.weekly.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const check = async ({
releaseFn,
checkVersionFn
}: {
key: keyof CachedVersions;
key: keyof Omit<CachedVersions, 'weeklyCheckEnabled'>;
currentVersion: string;
releaseFn: () => Promise<GithubLastReleaseResult>;
checkVersionFn: (params: {latestVersion: string}) => void;
Expand Down
1 change: 1 addition & 0 deletions src/types/cli/cli.versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CachedVersionSchema = j.strictObject({
});

export const CachedVersionsSchema = j.strictObject({
weeklyCheckEnabled: j.boolean().optional(),
cli: CachedVersionSchema.optional(),
emulator: CachedVersionSchema.optional()
});
Expand Down
9 changes: 9 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {isWeeklyCheckDisabled} from './configs/cli.versions.config';
import {
checkCliVersion,
checkEmulatorVersion
Expand All @@ -10,6 +11,14 @@ export const checkWeeklyVersions = async ({cmd, args}: {cmd: string; args?: stri
return;
}

if (isWeeklyCheckDisabled()) {
return;
}

if (cmd === 'version') {
return;
}

const [subCommand] = args ?? [];

if (cmd === 'emulator' && ['start', 'wait'].includes(subCommand)) {
Expand Down
Loading