Commit f2818a68 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

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

parent 258f5f15
......@@ -13,8 +13,7 @@
const Command = require('commander').Command;
const pjson = require('../package.json');
const duniter = require('../index');
export const ExecuteCommand = () => {
const options:any = [];
......
......@@ -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>
}
......@@ -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)
}
}],
......
......@@ -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();
......
......@@ -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,
......
......@@ -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');
......
......@@ -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: {
......
......@@ -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
......
......@@ -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',
......
......@@ -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);
}
......
......@@ -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") {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment