Skip to content
Snippets Groups Projects
Commit 2acf5849 authored by michael.minelli's avatar michael.minelli
Browse files

Commander => Add alert and informations about dev version and new versions

parent d6989ceb
Branches
No related tags found
No related merge requests found
Pipeline #28431 passed
...@@ -3,6 +3,12 @@ import SessionCommand from './session/SessionCommand'; ...@@ -3,6 +3,12 @@ import SessionCommand from './session/SessionCommand';
import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig';
import AssignmentCommand from './assignment/AssignmentCommand'; import AssignmentCommand from './assignment/AssignmentCommand';
import ExerciseCommand from './exercise/ExerciseCommand'; import ExerciseCommand from './exercise/ExerciseCommand';
import SharedConfig from '../shared/config/SharedConfig';
import boxen from 'boxen';
import { stateConfigFile } from '../config/ConfigFiles';
import semver from 'semver/preload';
import { version } from '../config/Version';
import Config from '../config/Config';
class CommanderApp { class CommanderApp {
...@@ -19,7 +25,12 @@ class CommanderApp { ...@@ -19,7 +25,12 @@ class CommanderApp {
sortOptions : true, sortOptions : true,
sortSubcommands : true sortSubcommands : true
}) })
.option('-H, --host <string>', 'override the Dojo API endpoint', ClientsSharedConfig.apiURL); .option('-H, --host <string>', 'override the Dojo API endpoint', ClientsSharedConfig.apiURL)
.hook('preAction', () => {
this.warnDevelopmentVersion();
}).hook('postAction', () => {
this.informNewVersion();
});
this.program.on('option:host', () => { this.program.on('option:host', () => {
ClientsSharedConfig.apiURL = this.program.opts().host; ClientsSharedConfig.apiURL = this.program.opts().host;
...@@ -30,6 +41,44 @@ class CommanderApp { ...@@ -30,6 +41,44 @@ class CommanderApp {
this.program.parse(); this.program.parse();
} }
private warnDevelopmentVersion() {
if ( !SharedConfig.production ) {
console.log(boxen(`This is a development (unstable) version of the DojoCLI.
If you want to use the stable version, please install the package from the following url:
https://gitedu.hesge.ch/dojo_project/projects/ui/dojocli/-/releases/latest`, {
title : 'Warning',
titleAlignment: 'center',
borderColor : 'red',
borderStyle : 'bold',
margin : 1,
padding : 1,
textAlignment : 'left'
}));
}
}
private informNewVersion() {
if ( SharedConfig.production ) {
const latestDojoCliVersion = stateConfigFile.getParam('latestDojoCliVersion') as string | null || '0.0.0';
const latestDojoCliVersionNotification = stateConfigFile.getParam('latestDojoCliVersionNotification') as number | null || 0;
if ( semver.lt(version, latestDojoCliVersion) ) {
if ( (new Date()).getTime() - latestDojoCliVersionNotification >= Config.versionUpdateInformationPeriodHours * 60 * 60 * 1000 ) {
console.log(boxen(`The ${ latestDojoCliVersion } version of the DojoCLI is available:
https://gitedu.hesge.ch/dojo_project/projects/ui/dojocli/-/releases/latest`, {
title : 'Information',
titleAlignment: 'center',
borderColor : 'blue',
borderStyle : 'bold',
margin : 1,
padding : 1,
textAlignment : 'left'
}));
stateConfigFile.setParam('latestDojoCliVersionNotification', (new Date()).getTime());
}
}
}
}
private registerCommands() { private registerCommands() {
SessionCommand.registerOnCommand(this.program); SessionCommand.registerOnCommand(this.program);
AssignmentCommand.registerOnCommand(this.program); AssignmentCommand.registerOnCommand(this.program);
......
...@@ -3,9 +3,11 @@ import getAppDataPath from 'appdata-path'; ...@@ -3,9 +3,11 @@ import getAppDataPath from 'appdata-path';
class Config { class Config {
public readonly localConfig: { public readonly localConfig: {
folder: string; sessionFile: string; folder: string; sessionFile: string; stateFile: string;
}; };
public readonly versionUpdateInformationPeriodHours: number;
public readonly gitlab: { public readonly gitlab: {
cliReleasePage: string cliReleasePage: string
}; };
...@@ -31,9 +33,12 @@ class Config { ...@@ -31,9 +33,12 @@ class Config {
constructor() { constructor() {
this.localConfig = { this.localConfig = {
folder : getAppDataPath('DojoCLI'), folder : getAppDataPath('DojoCLI'),
sessionFile: process.env.LOCAL_CONFIG_FILE_SESSION || '' sessionFile: process.env.LOCAL_CONFIG_FILE_SESSION || '',
stateFile : process.env.LOCAL_CONFIG_STATE || ''
}; };
this.versionUpdateInformationPeriodHours = Number(process.env.VERSION_UPDATE_INFORMATION_PERIOD_HOURS || 24);
this.gitlab = { this.gitlab = {
cliReleasePage: process.env.GITLAB_CLI_RELEASE_PAGE || '' cliReleasePage: process.env.GITLAB_CLI_RELEASE_PAGE || ''
}; };
......
...@@ -9,6 +9,7 @@ import DojoStatusCode from '../shared/types/Dojo/Doj ...@@ -9,6 +9,7 @@ import DojoStatusCode from '../shared/types/Dojo/Doj
import boxen from 'boxen'; import boxen from 'boxen';
import Config from '../config/Config'; import Config from '../config/Config';
import SharedConfig from '../shared/config/SharedConfig'; import SharedConfig from '../shared/config/SharedConfig';
import { stateConfigFile } from '../config/ConfigFiles';
class HttpManager { class HttpManager {
...@@ -68,6 +69,16 @@ class HttpManager { ...@@ -68,6 +69,16 @@ class HttpManager {
SessionManager.apiToken = response.data.sessionToken; SessionManager.apiToken = response.data.sessionToken;
} }
if ( response.headers['dojocli-latest-version'] ) {
const latestDojoCliVersion = response.headers['dojocli-latest-version'];
const storedLatestDojoCliVersion = stateConfigFile.getParam('latestDojoCliVersion') as string | null || '0.0.0';
if ( latestDojoCliVersion !== storedLatestDojoCliVersion ) {
stateConfigFile.setParam('latestDojoCliVersion', latestDojoCliVersion);
stateConfigFile.setParam('latestDojoCliVersionNotification', 0);
}
}
return response; return response;
}, async (error) => { }, async (error) => {
if ( error.response ) { if ( error.response ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment