Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoCLI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
UI
DojoCLI
Commits
2acf5849
Commit
2acf5849
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Commander => Add alert and informations about dev version and new versions
parent
d6989ceb
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#28431
passed
1 year ago
Stage: code_quality
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
NodeApp/src/commander/CommanderApp.ts
+50
-1
50 additions, 1 deletion
NodeApp/src/commander/CommanderApp.ts
NodeApp/src/config/Config.ts
+7
-2
7 additions, 2 deletions
NodeApp/src/config/Config.ts
NodeApp/src/managers/HttpManager.ts
+11
-0
11 additions, 0 deletions
NodeApp/src/managers/HttpManager.ts
with
68 additions
and
3 deletions
NodeApp/src/commander/CommanderApp.ts
+
50
−
1
View file @
2acf5849
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
NodeApp/src/config/Config.ts
+
7
−
2
View file @
2acf5849
...
@@ -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
||
''
};
};
...
...
This diff is collapsed.
Click to expand it.
NodeApp/src/managers/HttpManager.ts
+
11
−
0
View file @
2acf5849
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment