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
fd5ab6eb
Commit
fd5ab6eb
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
LocalConfig => Move for singleton to a generic class for local config files
parent
11c4e397
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
NodeApp/src/config/LocalConfigFile.ts
+24
-30
24 additions, 30 deletions
NodeApp/src/config/LocalConfigFile.ts
with
24 additions
and
30 deletions
NodeApp/src/config/LocalConfigFile.ts
+
24
−
30
View file @
fd5ab6eb
import
*
as
fs
from
'
fs
'
;
import
*
as
fs
from
'
fs
'
;
import
SessionManager
from
'
../managers/SessionManager
'
;
import
Config
from
'
./Config
'
;
import
Config
from
'
./Config
'
;
import
LocalConfigKeys
from
'
../types/LocalConfigKeys
'
;
import
GitlabManager
from
'
../managers/GitlabManager
'
;
import
JSON5
from
'
json5
'
;
import
JSON5
from
'
json5
'
;
import
ClientsSharedConfig
from
'
../sharedByClients/config/ClientsSharedConfig
'
;
class
LocalConfigFile
{
class
LocalConfigFile
{
constructor
(
private
filename
:
string
)
{}
constructor
(
private
filename
:
string
)
{}
private
get
configPath
():
string
{
private
get
configPath
():
string
{
return
`
${
Config
.
localConfig
.
folder
}
/
${
Config
.
localConfig
.
fil
e
}
`
;
return
`
${
Config
.
localConfig
.
folder
}
/
${
this
.
filenam
e
}
`
;
}
}
private
_config
:
{
[
key
in
LocalConfigKeys
]?
:
any
}
=
{};
private
_config
:
{
[
key
:
string
]
:
any
}
=
{};
loadConfig
()
{
loadConfig
()
{
if
(
!
fs
.
existsSync
(
this
.
configPath
)
)
{
if
(
!
fs
.
existsSync
(
this
.
configPath
)
)
{
...
@@ -26,38 +21,37 @@ class LocalConfigFile {
...
@@ -26,38 +21,37 @@ class LocalConfigFile {
try
{
try
{
this
.
_config
=
JSON5
.
parse
(
fs
.
readFileSync
(
this
.
configPath
).
toString
());
this
.
_config
=
JSON5
.
parse
(
fs
.
readFileSync
(
this
.
configPath
).
toString
());
if
(
LocalConfigKeys
.
API_TOKEN
in
this
.
_config
&&
ClientsSharedConfig
.
apiURL
in
this
.
_config
[
LocalConfigKeys
.
API_TOKEN
]
)
{
SessionManager
.
token
=
this
.
_config
[
LocalConfigKeys
.
API_TOKEN
][
ClientsSharedConfig
.
apiURL
];
}
GitlabManager
.
config
=
this
.
_config
[
LocalConfigKeys
.
GITLAB
];
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
}
}
}
}
updateConfig
(
key
:
LocalConfigKeys
,
value
:
any
)
{
getParam
(
key
:
string
):
any
|
null
{
let
previousValue
=
(
this
.
_config
as
any
)[
key
];
const
value
=
key
in
this
.
_config
?
this
.
_config
[
key
]
:
null
;
if
(
previousValue
===
value
)
{
if
(
value
===
null
)
{
return
;
return
null
;
}
else
if
(
typeof
value
===
'
object
'
)
{
return
{
...
value
};
}
else
{
return
value
;
}
}
if
(
key
===
LocalConfigKeys
.
API_TOKEN
)
{
if
(
!
(
LocalConfigKeys
.
API_TOKEN
in
this
.
_config
)
)
{
(
this
.
_config
as
any
)[
LocalConfigKeys
.
API_TOKEN
]
=
{};
}
}
(
this
.
_config
as
any
)[
LocalConfigKeys
.
API_TOKEN
][
ClientsSharedConfig
.
apiURL
]
=
value
;
setParam
(
key
:
string
,
value
:
any
):
void
{
}
else
{
let
previousValue
=
this
.
getParam
(
key
);
(
this
.
_config
as
any
)[
key
]
=
value
;
if
(
JSON5
.
stringify
(
previousValue
)
===
JSON5
.
stringify
(
value
)
)
{
return
;
}
}
this
.
_config
[
key
]
=
value
;
try
{
try
{
fs
.
writeFileSync
(
this
.
configPath
,
JSON5
.
stringify
(
this
.
_config
,
null
,
4
));
fs
.
writeFileSync
(
this
.
configPath
,
JSON5
.
stringify
(
this
.
_config
,
null
,
4
));
}
catch
(
error
)
{
}
}
catch
(
error
)
{
console
.
log
(
error
);
}
}
}
}
}
export
default
new
LocalConfig
();
export
default
LocalConfigFile
;
\ No newline at end of file
\ No newline at end of file
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