Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
timothe
duniter
Commits
c3728e6d
Commit
c3728e6d
authored
Nov 01, 2018
by
Cédric Moreau
Browse files
[enh] Precising Duniter exportable definitions
parent
0ffdf513
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/lib/common-libs/programOptions.ts
View file @
c3728e6d
...
...
@@ -24,6 +24,9 @@ export interface ProgramOptions {
isSync
:
boolean
noSources
:
boolean
slow
?:
boolean
loglevel
?:
string
sqlTraces
?:
boolean
memory
?:
boolean
}
export
const
cliprogram
:
ProgramOptions
=
{
...
...
app/modules/DuniterModule.ts
0 → 100644
View file @
c3728e6d
import
{
Server
}
from
"
../../server
"
import
{
ConfDTO
}
from
"
../lib/dto/ConfDTO
"
import
{
ProgramOptions
}
from
"
../lib/common-libs/programOptions
"
import
{
ConfDAL
}
from
"
../lib/dal/fileDALs/ConfDAL
"
import
{
ReadableDuniterService
,
Stack
,
TransformableDuniterService
}
from
"
../../index
"
export
interface
DuniterModule
{
name
:
string
required
:
{
duniter
:
DuniterDependency
}
}
export
interface
DuniterDependency
{
cliOptions
?:
CliOption
[]
cli
?:
CliCommand
[]
config
?:
{
onLoading
:
(
conf
:
ConfDTO
,
program
:
ProgramOptions
,
logger
:
any
,
confDAL
:
ConfDAL
)
=>
void
beforeSave
:
(
conf
:
ConfDTO
,
program
:
ProgramOptions
,
logger
:
any
,
confDAL
:
ConfDAL
)
=>
void
}
onReset
?:
{
data
:
(
conf
:
ConfDTO
,
program
:
ProgramOptions
,
logger
:
any
,
confDAL
:
ConfDAL
)
=>
void
config
:
(
conf
:
ConfDTO
,
program
:
ProgramOptions
,
logger
:
any
,
confDAL
:
ConfDAL
)
=>
void
}
wizard
?:
{
[
k
:
string
]:
(
conf
:
ConfDTO
,
program
:
ProgramOptions
)
=>
Promise
<
void
>
}
service
?:
{
input
:
(
server
:
Server
,
conf
:
ConfDTO
,
logger
:
any
)
=>
ReadableDuniterService
process
:
(
server
:
Server
,
conf
:
ConfDTO
,
logger
:
any
)
=>
TransformableDuniterService
output
:
(
server
:
Server
,
conf
:
ConfDTO
,
logger
:
any
)
=>
TransformableDuniterService
neutral
:
(
server
:
Server
,
conf
:
ConfDTO
,
logger
:
any
)
=>
TransformableDuniterService
}
}
export
interface
CliOption
{
value
:
string
desc
:
string
parser
?:
(
parameter
:
string
)
=>
any
}
export
interface
CliCommand
{
name
:
string
desc
:
string
logs
?:
boolean
preventIfRunning
?:
boolean
onConfiguredExecute
?:
(
server
:
Server
,
conf
?:
ConfDTO
,
program
?:
ProgramOptions
,
params
?:
string
[],
wizardTasks
?:
any
,
stack
?:
Stack
)
=>
Promise
<
void
>
onDatabaseExecute
?:
(
server
:
Server
,
conf
?:
ConfDTO
,
program
?:
ProgramOptions
,
params
?:
string
[],
startServices
?:
()
=>
Promise
<
void
>
,
stopServices
?:
()
=>
Promise
<
void
>
,
stack
?:
Stack
)
=>
Promise
<
void
>
}
index.ts
View file @
c3728e6d
...
...
@@ -26,6 +26,8 @@ import {RouterDependency} from "./app/modules/router"
import
{
OtherConstants
}
from
"
./app/lib/other_constants
"
import
{
Directory
}
from
"
./app/lib/system/directory
"
import
{
Underscore
}
from
"
./app/lib/common-libs/underscore
"
import
{
CliCommand
,
DuniterDependency
,
DuniterModule
}
from
"
./app/modules/DuniterModule
"
import
{
ProgramOptions
}
from
"
./app/lib/common-libs/programOptions
"
const
path
=
require
(
'
path
'
);
const
constants
=
require
(
'
./app/lib/constants
'
);
...
...
@@ -179,7 +181,7 @@ export interface DuniterService {
export
interface
ReadableDuniterService
extends
DuniterService
,
stream
.
Readable
{}
export
interface
TransformableDuniterService
extends
DuniterService
,
stream
.
Transform
{}
class
Stack
{
export
class
Stack
{
private
injectedServices
=
false
...
...
@@ -192,7 +194,7 @@ class Stack {
private
PROCESS
:
any
private
loaded
:
any
private
wizardTasks
:
any
private
definitions
:
an
y
[]
=
[]
private
definitions
:
DuniterDependenc
y
[]
=
[]
private
streams
:
{
input
:
ReadableDuniterService
[]
process
:
TransformableDuniterService
[]
...
...
@@ -205,7 +207,7 @@ class Stack {
neutral
:
[]
}
constructor
(
private
dependencies
:
any
[])
{
constructor
(
private
dependencies
:
DuniterModule
[])
{
this
.
cli
=
ExecuteCommand
()
this
.
configLoadingCallbacks
=
[]
this
.
configBeforeSaveCallbacks
=
[]
...
...
@@ -227,7 +229,7 @@ class Stack {
return
this
.
loaded
[
name
]
}
registerDependency
(
requiredObject
:
any
,
name
:
string
)
{
registerDependency
(
requiredObject
:
{
duniter
:
DuniterDependency
}
,
name
:
string
)
{
if
(
name
&&
this
.
loaded
[
name
])
{
// Do not try to load it twice
return
;
...
...
@@ -286,8 +288,8 @@ class Stack {
};
async
processCommand
(...
args
:
any
[])
{
const
command
=
args
[
0
];
const
program
=
args
[
1
];
const
command
:
CliCommand
=
args
[
0
];
const
program
:
ProgramOptions
=
args
[
1
];
const
params
=
args
.
slice
(
2
);
params
.
pop
();
// Don't need the command argument
...
...
@@ -393,6 +395,8 @@ class Stack {
if
(
!
command
.
onDatabaseExecute
)
{
return
res
}
}
else
if
(
!
command
.
onDatabaseExecute
)
{
throw
`Command
${
command
.
name
}
does not implement onConfiguredExecute nor onDatabaseExecute.`
}
// Second possible class of commands: post-service
await
server
.
initDAL
(
conf
);
...
...
@@ -602,3 +606,11 @@ class ProcessStream extends stream.Transform {
done
&&
done
();
};
}
export
const
Duniter
=
{
run
(
modules
:
DuniterModule
[]
=
[],
args
?:
string
[])
{
return
Stacks
.
autoStack
(
modules
).
executeStack
(
args
||
process
.
argv
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment