diff --git a/app/cli.ts b/app/cli.ts index 33472bb2ac0cfea4e2b8eb955bb2fddb82b02a97..e6ae5f105d800b0a16607b3b0017cacf17b8e5ed 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -13,8 +13,7 @@ const Command = require('commander').Command; const pjson = require('../package.json'); -const duniter = require('../index'); - + export const ExecuteCommand = () => { const options:any = []; diff --git a/app/modules/DuniterModule.ts b/app/modules/DuniterModule.ts index 45f4de7d8471a0b5072ef5b56288de7e088bc641..3a65f9b449f6bd706cbf2c5ca2f3d8fa58cb6025 100644 --- a/app/modules/DuniterModule.ts +++ b/app/modules/DuniterModule.ts @@ -19,17 +19,17 @@ export interface DuniterDependency { 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 + 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> + [k: string]: (conf: ConfDTO, program: ProgramOptions, logger:any) => 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 + 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 } } @@ -44,10 +44,10 @@ export interface CliCommand { 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 + onConfiguredExecute?: (server: Server, conf: ConfDTO, program: ProgramOptions, params: string[], wizardTasks: any, stack: Stack) => Promise<any> + onDatabaseExecute?: (server: Server, conf: ConfDTO, program: ProgramOptions, params: string[], + startServices: () => Promise<void>, + stopServices: () => Promise<void>, + stack: Stack ) => Promise<void> } diff --git a/app/modules/keypair/index.ts b/app/modules/keypair/index.ts index 50f8a3d11a8bd2659bf5f2a7c0e29537550e5033..d91d508959dbb74961f0e451336e41b4dd6f62e2 100644 --- a/app/modules/keypair/index.ts +++ b/app/modules/keypair/index.ts @@ -52,14 +52,14 @@ export const KeypairDependency = { name: 'pub', desc: 'Shows the node public key', logs: false, - onConfiguredExecute: (server:Server, conf:ConfDTO) => { + onConfiguredExecute: async (server:Server, conf:ConfDTO) => { console.log(conf.pair.pub) } }, { name: 'sec', desc: 'Shows the node secret key', logs: false, - onConfiguredExecute: (server:Server, conf:ConfDTO) => { + onConfiguredExecute: async (server:Server, conf:ConfDTO) => { console.log(conf.pair.sec) } }], diff --git a/bin/duniter b/bin/duniter index d91cfe530ace9b8cea85db550a72ba92ab9d32be..47f0e6e7b075cd3c30981798d4add6226ae5d03f 100755 --- a/bin/duniter +++ b/bin/duniter @@ -15,8 +15,7 @@ process.on('uncaughtException', (err) => { (async () => { try { - const duniter = require('../index'); - const stack = duniter.statics.autoStack(); + const stack = require('../index').Statics.autoStack(); await stack.executeStack(process.argv); // Everything went well, close Duniter quietly. process.exit(); diff --git a/index.ts b/index.ts index 1f9e45ca6dbf38afde4d167b04e14480bb0ae2f1..c8d5db1a2070630090c305a9dc8eb73aeb29fdf9 100644 --- a/index.ts +++ b/index.ts @@ -53,7 +53,7 @@ process.on('unhandledRejection', (reason) => { logger.error(reason); }); -class Stacks { +export class Stacks { static todoOnRunDone:() => any = () => process.exit() @@ -84,7 +84,7 @@ class Stacks { return Stacks.todoOnRunDone() } - static autoStack(priorityModules:any) { + static autoStack(priorityModules?:DuniterModule[]) { const duniterModules = []; let duniterDeps:any = [] @@ -140,11 +140,11 @@ const DEFAULT_DEPENDENCIES = MINIMAL_DEPENDENCIES.concat([ const PRODUCTION_DEPENDENCIES = DEFAULT_DEPENDENCIES.concat([ ]); -module.exports = function (home:string, memory:boolean, overConf:any) { +export function NewDuniterServer(home:string, memory:boolean, overConf:any) { return new Server(home, memory, overConf); } -module.exports.statics = { +export const Statics = { logger: logger, diff --git a/test/fast/modules/bma/bma-module-test.ts b/test/fast/modules/bma/bma-module-test.ts index 4e85f3973022d4adb69fa9abece2d2946d7001ea..58c20ea81a5824f6a2f6cd3bb8763b962636e08f 100644 --- a/test/fast/modules/bma/bma-module-test.ts +++ b/test/fast/modules/bma/bma-module-test.ts @@ -14,13 +14,13 @@ import {BmaDependency} from "../../../../app/modules/bma/index" import {KeypairDependency} from "../../../../app/modules/keypair/index" import {Network} from "../../../../app/modules/bma/lib/network" +import {Statics} from "../../../../index" const assert = require('assert'); const should = require('should'); -const duniter = require('../../../../index') const rp = require('request-promise'); -const stack = duniter.statics.minimalStack(); +const stack = Statics.minimalStack(); stack.registerDependency(KeypairDependency, 'duniter-keypair'); stack.registerDependency(BmaDependency, 'duniter-bma'); diff --git a/test/fast/modules/crawler/crawler-peers-garbaging.ts b/test/fast/modules/crawler/crawler-peers-garbaging.ts index 5f51ce67e5c1d038b09f82f7e3a59c7220888993..63eefa1129c5941cee52ed23d836ab3ab92f3b23 100644 --- a/test/fast/modules/crawler/crawler-peers-garbaging.ts +++ b/test/fast/modules/crawler/crawler-peers-garbaging.ts @@ -13,9 +13,9 @@ import {cleanLongDownPeers} from "../../../../app/modules/crawler/lib/garbager" import {Server} from "../../../../server" +import {Statics} from "../../../../index" const should = require('should'); -const duniter = require('../../../../index') let stack:any @@ -23,7 +23,7 @@ describe('Peers garbaging', () => { before(() => { - stack = duniter.statics.autoStack([{ + stack = Statics.autoStack([{ name: 'garbager', required: { duniter: { diff --git a/test/fast/modules/keypair/keypair-module-test.ts b/test/fast/modules/keypair/keypair-module-test.ts index 2b5f5db651266070c6591a4ea30e9590f737f737..45998ad1e6b71463fa2f53ed9783c624435b67c5 100644 --- a/test/fast/modules/keypair/keypair-module-test.ts +++ b/test/fast/modules/keypair/keypair-module-test.ts @@ -12,16 +12,16 @@ // GNU Affero General Public License for more details. import {KeypairDependency} from "../../../../app/modules/keypair/index" +import {Statics} from "../../../../index" const should = require('should'); -const duniter = require('../../../../index') describe('Module usage', () => { it('wrong options should throw', async () => { let errMessage; try { - const stack = duniter.statics.minimalStack(); + const stack = Statics.minimalStack(); stack.registerDependency(KeypairDependency, 'duniter-keypair'); await stack.executeStack(['node', 'index.js', 'config', '--memory', '--keyN', '2048']); } catch (e) { @@ -32,7 +32,7 @@ describe('Module usage', () => { }) it('no options on brand new node should generate random key', async () => { - const stack = duniter.statics.minimalStack(); + const stack = Statics.minimalStack(); stack.registerDependency(KeypairDependency, 'duniter-keypair'); const res = await stack.executeStack(['node', 'index.js', 'config', '--memory']); // This is extremely very unlikely to happen diff --git a/test/integration/identity/identity-absorption.ts b/test/integration/identity/identity-absorption.ts index 4ee1051e018870ed5beecdeadabf905a1427465e..ec7ed91ce3d31f0998670e837e86532c0279d3d2 100644 --- a/test/integration/identity/identity-absorption.ts +++ b/test/integration/identity/identity-absorption.ts @@ -11,7 +11,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. -import {TestingServer} from "../tools/toolbox" +import {NewTestingServer, TestingServer} from "../tools/toolbox" import {TestUser} from "../tools/TestUser" import {BmaDependency} from "../../../app/modules/bma/index" import {shouldFail} from "../../unit-tools" @@ -19,7 +19,6 @@ import {Underscore} from "../../../app/lib/common-libs/underscore" import {shutDownEngine} from "../tools/shutdown-engine" import {expectAnswer} from "../tools/http-expect" -const duniter = require('../../../index'); const rp = require('request-promise'); const MEMORY_MODE = true; @@ -39,10 +38,10 @@ describe("Identity absorption", () => { before(async () => { - s1 = duniter( - '/bb12', - MEMORY_MODE, + s1 = NewTestingServer( Underscore.extend({ + name: 'bb12', + memory: MEMORY_MODE, port: '4450', pair: { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', @@ -50,10 +49,10 @@ describe("Identity absorption", () => { } }, commonConf)); - s2 = duniter( - '/bb12', - MEMORY_MODE, + s2 = NewTestingServer( Underscore.extend({ + name: 'bb12', + memory: MEMORY_MODE, port: '4451', pair: { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', diff --git a/test/integration/misc/cli.ts b/test/integration/misc/cli.ts index 7da9a12535569f374ad26630852b4583a6680f38..4a02c6a5e13dcade7564d3b65a67b89680d584a3 100644 --- a/test/integration/misc/cli.ts +++ b/test/integration/misc/cli.ts @@ -14,11 +14,11 @@ import {hashf} from "../../../app/lib/common" import {fakeSyncServer} from "../tools/toolbox" import {Underscore} from "../../../app/lib/common-libs/underscore" +import {Statics} from "../../../index" const spawn = require('child_process').spawn; const path = require('path'); const should = require('should'); -const duniter = require('../../../index'); const DB_NAME = "unit_tests"; @@ -157,7 +157,7 @@ describe("CLI", function() { */ async function execute(args:(string)[]) { const finalArgs = [process.argv[0], __filename].concat(args).concat(['--mdb', DB_NAME]); - const stack = duniter.statics.autoStack(); + const stack = Statics.autoStack(); // Executes the command return stack.executeStack(finalArgs); } diff --git a/test/integration/protocol/v1.0-modules-api.ts b/test/integration/protocol/v1.0-modules-api.ts index 28c2798a45768c4d91af68d462c4650ad996fe5a..76f309372a8b260111c635588239b0068c24342c 100644 --- a/test/integration/protocol/v1.0-modules-api.ts +++ b/test/integration/protocol/v1.0-modules-api.ts @@ -17,27 +17,27 @@ import {Server} from "../../../server" import {ConfDTO} from "../../../app/lib/dto/ConfDTO" import {KeypairDependency} from "../../../app/modules/keypair/index" import {BmaDependency} from "../../../app/modules/bma/index" +import {Statics} from "../../../index" const should = require('should'); const util = require('util'); const path = require('path'); -const duniter = require('../../../index'); const querablep = require('querablep'); describe("v1.0 Module API", () => { it('should be able to execute `hello` command with quickRun', async () => { - duniter.statics.setOnRunDone(() => { /* Do not exit the process */ }) + Statics.setOnRunDone(() => { /* Do not exit the process */ }) const absolutePath = path.join(__dirname, '../scenarios/hello-plugin.js') process.argv = ['', absolutePath, 'hello-world', '--memory'] - const res = await duniter.statics.quickRun(absolutePath) + const res = await Statics.quickRun(absolutePath) res.should.equal('Hello world! from within Duniter.') }) it('should be able to execute `hello` command', async () => { - const sStack = duniter.statics.simpleStack(); - const aStack = duniter.statics.autoStack(); + const sStack = Statics.simpleStack(); + const aStack = Statics.autoStack(); const helloDependency = { duniter: { @@ -77,7 +77,7 @@ describe("v1.0 Module API", () => { before(async () => { - stack = duniter.statics.simpleStack(); + stack = Statics.simpleStack(); const configurationDependency = { duniter: { cliOptions: [ @@ -174,7 +174,7 @@ describe("v1.0 Module API", () => { before(async () => { - stack = duniter.statics.simpleStack(); + stack = Statics.simpleStack(); fakeI = new FakeStream((that:any, data:any) => { // Note: we never pass here if (typeof data == "string") {