Skip to content
Snippets Groups Projects
Commit f2818a68 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] index.ts must not use "module.exports"

parent 258f5f15
Branches
Tags
No related merge requests found
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
const Command = require('commander').Command; const Command = require('commander').Command;
const pjson = require('../package.json'); const pjson = require('../package.json');
const duniter = require('../index');
export const ExecuteCommand = () => { export const ExecuteCommand = () => {
......
...@@ -19,17 +19,17 @@ export interface DuniterDependency { ...@@ -19,17 +19,17 @@ export interface DuniterDependency {
beforeSave: (conf: ConfDTO, program: ProgramOptions, logger:any, confDAL: ConfDAL) => void beforeSave: (conf: ConfDTO, program: ProgramOptions, logger:any, confDAL: ConfDAL) => void
} }
onReset?: { onReset?: {
data: (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 config?: (conf: ConfDTO, program: ProgramOptions, logger:any, confDAL: ConfDAL) => void
} }
wizard?: { wizard?: {
[k: string]: (conf: ConfDTO, program: ProgramOptions) => Promise<void> [k: string]: (conf: ConfDTO, program: ProgramOptions, logger:any) => Promise<void>
} }
service?: { service?: {
input: (server: Server, conf: ConfDTO, logger:any) => ReadableDuniterService input?: (server: Server, conf: ConfDTO, logger:any) => ReadableDuniterService
process: (server: Server, conf: ConfDTO, logger:any) => TransformableDuniterService process?: (server: Server, conf: ConfDTO, logger:any) => TransformableDuniterService
output: (server: Server, conf: ConfDTO, logger:any) => TransformableDuniterService output?: (server: Server, conf: ConfDTO, logger:any) => TransformableDuniterService
neutral: (server: Server, conf: ConfDTO, logger:any) => TransformableDuniterService neutral?: (server: Server, conf: ConfDTO, logger:any) => TransformableDuniterService
} }
} }
...@@ -44,10 +44,10 @@ export interface CliCommand { ...@@ -44,10 +44,10 @@ export interface CliCommand {
desc: string desc: string
logs?: boolean logs?: boolean
preventIfRunning?: boolean preventIfRunning?: boolean
onConfiguredExecute?: (server: Server, conf?: ConfDTO, program?: ProgramOptions, params?: string[], wizardTasks?: any, stack?: Stack) => Promise<void> onConfiguredExecute?: (server: Server, conf: ConfDTO, program: ProgramOptions, params: string[], wizardTasks: any, stack: Stack) => Promise<any>
onDatabaseExecute?: (server: Server, conf?: ConfDTO, program?: ProgramOptions, params?: string[], onDatabaseExecute?: (server: Server, conf: ConfDTO, program: ProgramOptions, params: string[],
startServices?: () => Promise<void>, startServices: () => Promise<void>,
stopServices?: () => Promise<void>, stopServices: () => Promise<void>,
stack?: Stack stack: Stack
) => Promise<void> ) => Promise<void>
} }
...@@ -52,14 +52,14 @@ export const KeypairDependency = { ...@@ -52,14 +52,14 @@ export const KeypairDependency = {
name: 'pub', name: 'pub',
desc: 'Shows the node public key', desc: 'Shows the node public key',
logs: false, logs: false,
onConfiguredExecute: (server:Server, conf:ConfDTO) => { onConfiguredExecute: async (server:Server, conf:ConfDTO) => {
console.log(conf.pair.pub) console.log(conf.pair.pub)
} }
}, { }, {
name: 'sec', name: 'sec',
desc: 'Shows the node secret key', desc: 'Shows the node secret key',
logs: false, logs: false,
onConfiguredExecute: (server:Server, conf:ConfDTO) => { onConfiguredExecute: async (server:Server, conf:ConfDTO) => {
console.log(conf.pair.sec) console.log(conf.pair.sec)
} }
}], }],
......
...@@ -15,8 +15,7 @@ process.on('uncaughtException', (err) => { ...@@ -15,8 +15,7 @@ process.on('uncaughtException', (err) => {
(async () => { (async () => {
try { try {
const duniter = require('../index'); const stack = require('../index').Statics.autoStack();
const stack = duniter.statics.autoStack();
await stack.executeStack(process.argv); await stack.executeStack(process.argv);
// Everything went well, close Duniter quietly. // Everything went well, close Duniter quietly.
process.exit(); process.exit();
......
...@@ -53,7 +53,7 @@ process.on('unhandledRejection', (reason) => { ...@@ -53,7 +53,7 @@ process.on('unhandledRejection', (reason) => {
logger.error(reason); logger.error(reason);
}); });
class Stacks { export class Stacks {
static todoOnRunDone:() => any = () => process.exit() static todoOnRunDone:() => any = () => process.exit()
...@@ -84,7 +84,7 @@ class Stacks { ...@@ -84,7 +84,7 @@ class Stacks {
return Stacks.todoOnRunDone() return Stacks.todoOnRunDone()
} }
static autoStack(priorityModules:any) { static autoStack(priorityModules?:DuniterModule[]) {
const duniterModules = []; const duniterModules = [];
let duniterDeps:any = [] let duniterDeps:any = []
...@@ -140,11 +140,11 @@ const DEFAULT_DEPENDENCIES = MINIMAL_DEPENDENCIES.concat([ ...@@ -140,11 +140,11 @@ const DEFAULT_DEPENDENCIES = MINIMAL_DEPENDENCIES.concat([
const PRODUCTION_DEPENDENCIES = DEFAULT_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); return new Server(home, memory, overConf);
} }
module.exports.statics = { export const Statics = {
logger: logger, logger: logger,
......
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
import {BmaDependency} from "../../../../app/modules/bma/index" import {BmaDependency} from "../../../../app/modules/bma/index"
import {KeypairDependency} from "../../../../app/modules/keypair/index" import {KeypairDependency} from "../../../../app/modules/keypair/index"
import {Network} from "../../../../app/modules/bma/lib/network" import {Network} from "../../../../app/modules/bma/lib/network"
import {Statics} from "../../../../index"
const assert = require('assert'); const assert = require('assert');
const should = require('should'); const should = require('should');
const duniter = require('../../../../index')
const rp = require('request-promise'); const rp = require('request-promise');
const stack = duniter.statics.minimalStack(); const stack = Statics.minimalStack();
stack.registerDependency(KeypairDependency, 'duniter-keypair'); stack.registerDependency(KeypairDependency, 'duniter-keypair');
stack.registerDependency(BmaDependency, 'duniter-bma'); stack.registerDependency(BmaDependency, 'duniter-bma');
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
import {cleanLongDownPeers} from "../../../../app/modules/crawler/lib/garbager" import {cleanLongDownPeers} from "../../../../app/modules/crawler/lib/garbager"
import {Server} from "../../../../server" import {Server} from "../../../../server"
import {Statics} from "../../../../index"
const should = require('should'); const should = require('should');
const duniter = require('../../../../index')
let stack:any let stack:any
...@@ -23,7 +23,7 @@ describe('Peers garbaging', () => { ...@@ -23,7 +23,7 @@ describe('Peers garbaging', () => {
before(() => { before(() => {
stack = duniter.statics.autoStack([{ stack = Statics.autoStack([{
name: 'garbager', name: 'garbager',
required: { required: {
duniter: { duniter: {
......
...@@ -12,16 +12,16 @@ ...@@ -12,16 +12,16 @@
// GNU Affero General Public License for more details. // GNU Affero General Public License for more details.
import {KeypairDependency} from "../../../../app/modules/keypair/index" import {KeypairDependency} from "../../../../app/modules/keypair/index"
import {Statics} from "../../../../index"
const should = require('should'); const should = require('should');
const duniter = require('../../../../index')
describe('Module usage', () => { describe('Module usage', () => {
it('wrong options should throw', async () => { it('wrong options should throw', async () => {
let errMessage; let errMessage;
try { try {
const stack = duniter.statics.minimalStack(); const stack = Statics.minimalStack();
stack.registerDependency(KeypairDependency, 'duniter-keypair'); stack.registerDependency(KeypairDependency, 'duniter-keypair');
await stack.executeStack(['node', 'index.js', 'config', '--memory', '--keyN', '2048']); await stack.executeStack(['node', 'index.js', 'config', '--memory', '--keyN', '2048']);
} catch (e) { } catch (e) {
...@@ -32,7 +32,7 @@ describe('Module usage', () => { ...@@ -32,7 +32,7 @@ describe('Module usage', () => {
}) })
it('no options on brand new node should generate random key', async () => { 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'); stack.registerDependency(KeypairDependency, 'duniter-keypair');
const res = await stack.executeStack(['node', 'index.js', 'config', '--memory']); const res = await stack.executeStack(['node', 'index.js', 'config', '--memory']);
// This is extremely very unlikely to happen // This is extremely very unlikely to happen
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details. // 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 {TestUser} from "../tools/TestUser"
import {BmaDependency} from "../../../app/modules/bma/index" import {BmaDependency} from "../../../app/modules/bma/index"
import {shouldFail} from "../../unit-tools" import {shouldFail} from "../../unit-tools"
...@@ -19,7 +19,6 @@ import {Underscore} from "../../../app/lib/common-libs/underscore" ...@@ -19,7 +19,6 @@ import {Underscore} from "../../../app/lib/common-libs/underscore"
import {shutDownEngine} from "../tools/shutdown-engine" import {shutDownEngine} from "../tools/shutdown-engine"
import {expectAnswer} from "../tools/http-expect" import {expectAnswer} from "../tools/http-expect"
const duniter = require('../../../index');
const rp = require('request-promise'); const rp = require('request-promise');
const MEMORY_MODE = true; const MEMORY_MODE = true;
...@@ -39,10 +38,10 @@ describe("Identity absorption", () => { ...@@ -39,10 +38,10 @@ describe("Identity absorption", () => {
before(async () => { before(async () => {
s1 = duniter( s1 = NewTestingServer(
'/bb12',
MEMORY_MODE,
Underscore.extend({ Underscore.extend({
name: 'bb12',
memory: MEMORY_MODE,
port: '4450', port: '4450',
pair: { pair: {
pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
...@@ -50,10 +49,10 @@ describe("Identity absorption", () => { ...@@ -50,10 +49,10 @@ describe("Identity absorption", () => {
} }
}, commonConf)); }, commonConf));
s2 = duniter( s2 = NewTestingServer(
'/bb12',
MEMORY_MODE,
Underscore.extend({ Underscore.extend({
name: 'bb12',
memory: MEMORY_MODE,
port: '4451', port: '4451',
pair: { pair: {
pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV',
......
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
import {hashf} from "../../../app/lib/common" import {hashf} from "../../../app/lib/common"
import {fakeSyncServer} from "../tools/toolbox" import {fakeSyncServer} from "../tools/toolbox"
import {Underscore} from "../../../app/lib/common-libs/underscore" import {Underscore} from "../../../app/lib/common-libs/underscore"
import {Statics} from "../../../index"
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
const path = require('path'); const path = require('path');
const should = require('should'); const should = require('should');
const duniter = require('../../../index');
const DB_NAME = "unit_tests"; const DB_NAME = "unit_tests";
...@@ -157,7 +157,7 @@ describe("CLI", function() { ...@@ -157,7 +157,7 @@ describe("CLI", function() {
*/ */
async function execute(args:(string)[]) { async function execute(args:(string)[]) {
const finalArgs = [process.argv[0], __filename].concat(args).concat(['--mdb', DB_NAME]); const finalArgs = [process.argv[0], __filename].concat(args).concat(['--mdb', DB_NAME]);
const stack = duniter.statics.autoStack(); const stack = Statics.autoStack();
// Executes the command // Executes the command
return stack.executeStack(finalArgs); return stack.executeStack(finalArgs);
} }
......
...@@ -17,27 +17,27 @@ import {Server} from "../../../server" ...@@ -17,27 +17,27 @@ import {Server} from "../../../server"
import {ConfDTO} from "../../../app/lib/dto/ConfDTO" import {ConfDTO} from "../../../app/lib/dto/ConfDTO"
import {KeypairDependency} from "../../../app/modules/keypair/index" import {KeypairDependency} from "../../../app/modules/keypair/index"
import {BmaDependency} from "../../../app/modules/bma/index" import {BmaDependency} from "../../../app/modules/bma/index"
import {Statics} from "../../../index"
const should = require('should'); const should = require('should');
const util = require('util'); const util = require('util');
const path = require('path'); const path = require('path');
const duniter = require('../../../index');
const querablep = require('querablep'); const querablep = require('querablep');
describe("v1.0 Module API", () => { describe("v1.0 Module API", () => {
it('should be able to execute `hello` command with quickRun', async () => { 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') const absolutePath = path.join(__dirname, '../scenarios/hello-plugin.js')
process.argv = ['', absolutePath, 'hello-world', '--memory'] 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.') res.should.equal('Hello world! from within Duniter.')
}) })
it('should be able to execute `hello` command', async () => { it('should be able to execute `hello` command', async () => {
const sStack = duniter.statics.simpleStack(); const sStack = Statics.simpleStack();
const aStack = duniter.statics.autoStack(); const aStack = Statics.autoStack();
const helloDependency = { const helloDependency = {
duniter: { duniter: {
...@@ -77,7 +77,7 @@ describe("v1.0 Module API", () => { ...@@ -77,7 +77,7 @@ describe("v1.0 Module API", () => {
before(async () => { before(async () => {
stack = duniter.statics.simpleStack(); stack = Statics.simpleStack();
const configurationDependency = { const configurationDependency = {
duniter: { duniter: {
cliOptions: [ cliOptions: [
...@@ -174,7 +174,7 @@ describe("v1.0 Module API", () => { ...@@ -174,7 +174,7 @@ describe("v1.0 Module API", () => {
before(async () => { before(async () => {
stack = duniter.statics.simpleStack(); stack = Statics.simpleStack();
fakeI = new FakeStream((that:any, data:any) => { fakeI = new FakeStream((that:any, data:any) => {
// Note: we never pass here // Note: we never pass here
if (typeof data == "string") { if (typeof data == "string") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment