From 1147b530799db2eebed61af021962cc08a35da81 Mon Sep 17 00:00:00 2001 From: unwriter Date: Tue, 27 Aug 2019 10:00:33 -0400 Subject: [PATCH] support js module import --- index.js | 21 +++++++++++++------- package-lock.json | 50 +++++++++++++++++------------------------------ package.json | 5 +++-- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/index.js b/index.js index f698064..d3ede80 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ const fs = require('fs'); const path = require('path'); const stream = require('stream') const minimist = require('minimist') +const requireStr = require('require-from-string'); // Implement log stream - must define _read() callback or errs const log = new stream.Readable() @@ -38,9 +39,15 @@ const validate = function(config, vmode) { const loadAndValidateConfig = async function(options) { const configs = await new Promise(function(resolve, reject) { - if (options.jsonconfig) { - console.log("EVENTCHAIN", "Using JSON config") - let config = JSON.parse(options.jsonconfig) + if (options.strconfig) { + let config; + if (options.strconfig.startsWith("module.exports")) { + console.log("EVENTCHAIN", "Using JavaScript config") + config = requireStr(options.strconfig) + } else { + console.log("EVENTCHAIN", "Using JSON config") + config = JSON.parse(options.strconfig) + } resolve([config]) } else if (options.config) { console.log("EVENTCHAIN", "Loading config:", options.config) @@ -104,7 +111,7 @@ const start = async function(options) { log.push("ONSTART " + Date.now() + " " + JSON.stringify(e) + "\n") }, }; - if (options && options.tape) gene.tape = options.tape; + if (options && options.dest) gene.tape = options.dest; if (gene.tape) { chaindir = path.resolve(process.cwd(), gene.tape, "eventchain") } else { @@ -117,10 +124,10 @@ if (require.main === module && process.argv.length > 2) { const cmd = process.argv[2].toLowerCase(); const opts = minimist(process.argv.slice(3), { alias: { - config: 'c', - jsonconfig: 'j', + fileconfig: 'f', + strconfig: 's', pipe: 'p', - tape: 't', + dest: 'd', }, boolean: ['pipe'] }); diff --git a/package-lock.json b/package-lock.json index 816c6e1..07e75c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "echain", - "version": "0.0.12", + "version": "0.0.39", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -649,7 +649,7 @@ "requires": { "bitcore-lib-cash": "^0.17.0", "bloom-filter": "^0.2.0", - "buffers": "github:bitpay/node-buffers#v0.1.2-bitpay", + "buffers": "github:bitpay/node-buffers#04f4c4264e0d105db2b99b786843ed64f23230d8", "socks5-client": "^0.3.6" } }, @@ -2433,8 +2433,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -2452,13 +2451,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2471,18 +2468,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -2585,8 +2579,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -2596,7 +2589,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2609,20 +2601,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2639,7 +2628,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2712,8 +2700,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -2723,7 +2710,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -2799,8 +2785,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -2830,7 +2815,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2848,7 +2832,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2887,13 +2870,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -4637,6 +4618,11 @@ "throttleit": "^1.0.0" } }, + "require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" + }, "require-uncached": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", diff --git a/package.json b/package.json index 56bddaf..1397bed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "echain", - "version": "0.0.39", + "version": "0.0.42", "description": "", "main": "index.js", "author": "unwriter@protonmail.com", @@ -11,6 +11,7 @@ "dependencies": { "glob": "^7.1.4", "minimist": "^1.2.0", - "neonplanaria": "0.0.39" + "neonplanaria": "0.0.39", + "require-from-string": "^2.0.2" } }