Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
f6032d72
Commit
f6032d72
authored
8 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#989
Add a `duniter.statics.quickRun()` facility for module development
parent
e2cc4264
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.js
+35
-7
35 additions, 7 deletions
index.js
test/integration/scenarios/hello-plugin.js
+18
-0
18 additions, 0 deletions
test/integration/scenarios/hello-plugin.js
test/integration/v1.0-modules-api.js
+9
-0
9 additions, 0 deletions
test/integration/v1.0-modules-api.js
with
62 additions
and
7 deletions
index.js
+
35
−
7
View file @
f6032d72
...
...
@@ -65,13 +65,15 @@ module.exports.statics = {
* Creates a new stack pre-registered with compliant modules found in package.json
*/
autoStack
:
(
priorityModules
)
=>
{
const
pjson
=
require
(
path
.
resolve
(
'
./package.json
'
))
const
duniterModules
=
[];
let
duniterDeps
=
[]
try
{
const
pjson
=
require
(
path
.
resolve
(
'
./package.json
'
))
// Look for compliant packages
const
prodDeps
=
Object
.
keys
(
pjson
.
dependencies
);
const
devDeps
=
Object
.
keys
(
pjson
.
devDependencies
);
const
duniterDeps
=
prodDeps
.
concat
(
devDeps
)
duniterDeps
=
prodDeps
.
concat
(
devDeps
)
}
catch
(
e
)
{
/* duniter as a dependency might not be run from an NPM project */
}
for
(
const
dep
of
duniterDeps
)
{
try
{
const
required
=
require
(
dep
);
...
...
@@ -86,7 +88,33 @@ module.exports.statics = {
// The final stack
return
new
Stack
((
priorityModules
||
[]).
concat
(
PRODUCTION_DEPENDENCIES
).
concat
(
duniterModules
));
},
quickRun
:
function
()
{
const
deps
=
Array
.
from
(
arguments
).
map
((
f
,
index
)
=>
{
const
canonicalPath
=
path
.
resolve
(
f
)
console
.
log
(
canonicalPath
)
return
{
name
:
'
duniter-quick-module-
'
+
index
,
required
:
require
(
canonicalPath
)
}
})
const
that
=
this
const
stack
=
this
.
autoStack
(
deps
)
return
co
(
function
*
()
{
let
res
try
{
res
=
yield
stack
.
executeStack
(
that
.
quickRunGetArgs
())
}
catch
(
e
)
{
console
.
error
(
e
)
}
that
.
onRunDone
()
return
res
})
},
quickRunGetArgs
:
()
=>
process
.
argv
.
slice
(),
onRunDone
:
()
=>
process
.
exit
()
};
function
Stack
(
dependencies
)
{
...
...
This diff is collapsed.
Click to expand it.
test/integration/scenarios/hello-plugin.js
0 → 100644
+
18
−
0
View file @
f6032d72
"
use strict
"
const
co
=
require
(
'
co
'
)
module
.
exports
=
{
duniter
:
{
cli
:
[{
name
:
'
hello-world
'
,
desc
:
'
Says hello from
\
`duniter
\
` command.
'
,
logs
:
false
,
onDatabaseExecute
:
(
server
,
conf
,
program
,
params
)
=>
co
(
function
*
()
{
const
msg
=
'
Hello world! from within Duniter.
'
console
.
log
(
msg
)
return
msg
})
}]
}
}
This diff is collapsed.
Click to expand it.
test/integration/v1.0-modules-api.js
+
9
−
0
View file @
f6032d72
...
...
@@ -4,6 +4,7 @@ const co = require('co');
const
_
=
require
(
'
underscore
'
);
const
should
=
require
(
'
should
'
);
const
util
=
require
(
'
util
'
);
const
path
=
require
(
'
path
'
);
const
stream
=
require
(
'
stream
'
);
const
duniter
=
require
(
'
../../index
'
);
const
parsers
=
require
(
'
duniter-common
'
).
parsers
;
...
...
@@ -11,6 +12,14 @@ const querablep = require('querablep');
describe
(
"
v1.0 Module API
"
,
()
=>
{
it
(
'
should be able to execute `hello` command with quickRun
'
,
()
=>
co
(
function
*
()
{
duniter
.
statics
.
quickRunGetArgs
=
()
=>
[
''
,
''
,
'
hello-world
'
]
duniter
.
statics
.
onRunDone
=
()
=>
{
/* Do not exit the process */
}
const
absolutePath
=
path
.
join
(
__dirname
,
'
./scenarios/hello-plugin.js
'
)
const
res
=
yield
duniter
.
statics
.
quickRun
(
absolutePath
)
res
.
should
.
equal
(
'
Hello world! from within Duniter.
'
)
}))
it
(
'
should be able to execute `hello` command
'
,
()
=>
co
(
function
*
()
{
const
sStack
=
duniter
.
statics
.
simpleStack
();
...
...
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