Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 51ed87c

Browse files
jeffesquivelsstyppo
authored andcommitted
Support for publishing an npm library package (#117)
Closes #27
1 parent 43da856 commit 51ed87c

File tree

7 files changed

+70
-30
lines changed

7 files changed

+70
-30
lines changed

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
clients/
2+
database/
3+
dist/node.js.map
4+
dist/web*
5+
dist/nimiq.js
6+
gulpfile.js
7+
jasmine.json
8+
karma.conf.js
9+
package-lock.json
10+
spec/
11+
src/
12+
index.js.map
13+
.*

clients/nodejs/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Core = require('../../src/main/platform/nodejs/index.js');
1+
const Nimiq = require('nimiq');
22
const argv = require('minimist')(process.argv.slice(2));
33

44
if (!argv.host || !argv.port || !argv.key || !argv.cert) {
@@ -15,15 +15,15 @@ const key = argv.key;
1515
const cert = argv.cert;
1616

1717
if (argv['log']) {
18-
Log.instance.level = argv['log'] === true ? Log.VERBOSE : argv['log'];
18+
Nimiq.Log.instance.level = argv['log'] === true ? Log.VERBOSE : argv['log'];
1919
}
2020
if (argv['log-tag']) {
2121
if (!Array.isArray(argv['log-tag'])) {
2222
argv['log-tag'] = [argv['log-tag']];
2323
}
2424
argv['log-tag'].forEach((lt) => {
2525
let s = lt.split(':');
26-
Log.instance.setLoggable(s[0], s.length == 1 ? 2 : s[1]);
26+
Nimiq.Log.instance.setLoggable(s[0], s.length == 1 ? 2 : s[1]);
2727
});
2828
}
2929

@@ -34,7 +34,7 @@ console.log('Nimiq NodeJS Client starting (host=' + host + ', port=' + port + ',
3434
NetworkConfig.configurePeerAddress(host, port);
3535
NetworkConfig.configureSSL(key, cert);
3636

37-
(new Core()).then($ => {
37+
(new Nimiq.Core()).then($ => {
3838
console.log('Blockchain: height=' + $.blockchain.height + ', totalWork=' + $.blockchain.totalWork + ', headHash=' + $.blockchain.headHash.toBase64());
3939

4040
if (!passive) {

clients/nodejs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"author": "",
1010
"license": "ISC",
1111
"dependencies": {
12-
"minimist": "^1.2.0"
12+
"minimist": "^1.2.0",
13+
"nimiq": "git+ssh://[email protected]/nimiq-network/core.git"
1314
}
1415
}

gulpfile.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ const sources = {
2929
'./src/main/platform/browser/network/websocket/WebSocketConnector.js',
3030
'./src/main/platform/browser/WorkerBuilder.js'
3131
],
32-
node: []
32+
node: [
33+
'./src/main/platform/nodejs/utils/LogNative.js',
34+
'./src/main/generic/utils/Log.js',
35+
'./src/main/generic/utils/Observable.js',
36+
'./src/main/platform/nodejs/database/TypedDB.js',
37+
'./src/main/platform/nodejs/crypto/CryptoLib.js',
38+
'./src/main/platform/nodejs/network/webrtc/WebRtcConnector.js',
39+
'./src/main/platform/nodejs/network/websocket/WebSocketConnector.js',
40+
'./src/main/platform/nodejs/network/NetworkConfig.js',
41+
'./src/main/platform/nodejs/utils/WindowDetector.js'
42+
]
3343
},
3444
generic: [
35-
'./src/main/generic/utils/Observable.js',
3645
'./src/main/generic/utils/Services.js',
3746
'./src/main/generic/utils/Synchronizer.js',
3847
'./src/main/generic/utils/Timers.js',
@@ -216,7 +225,7 @@ gulp.task('build-loader', function () {
216225
});
217226

218227
gulp.task('build-node', function () {
219-
return gulp.src(sources.platform.node.concat(sources.generic))
228+
return gulp.src(['./src/main/platform/nodejs/index.prefix.js'].concat(sources.platform.node).concat(sources.generic).concat(['./src/main/platform/nodejs/index.suffix.js']))
220229
.pipe(sourcemaps.init())
221230
.pipe(concat('node.js'))
222231
.pipe(sourcemaps.write('.'))

package.json

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
11
{
22
"name": "nimiq",
33
"version": "1.0.0",
4-
"description": "Run `./serve`",
5-
"main": "lovicash.js",
4+
"homepage": "https://nimiq.com/",
5+
"description": "",
6+
"main": "dist/node.js",
7+
"private": true,
68
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
9+
"prepare": "gulp build-node"
10+
},
11+
"author": {
12+
"name" : "The Nimiq Core Development Team",
13+
"url" : "https://nimiq.com/"
14+
},
15+
"license": "Apache-2.0",
16+
"bugs": {
17+
"url": "https://github.com/nimiq-network/core/issues"
818
},
919
"repository": {
1020
"type": "git",
11-
"url": "git+https://github.com/styppo/novicash.git"
21+
"url": "https://github.com/nimiq-network/core.git"
22+
},
23+
"engines" : {
24+
"node" : ">=7.9.0"
25+
},
26+
"dependencies": {
27+
"chalk": "^1.1.3",
28+
"elliptic": "^6.4.0",
29+
"fast-sha256": "^1.0.0",
30+
31+
"atob": "^2.0.3",
32+
"btoa": "^1.1.2",
33+
"leveldown": "^1.6.0",
34+
"levelup": "^1.3.5",
35+
"node-webcrypto-ossl": "^1.0.21",
36+
"ws": ""
1237
},
1338
"devDependencies": {
1439
"babel-cli": "^6.24.1",
1540
"babel-plugin-transform-runtime": "^6.23.0",
1641
"babel-preset-env": "^1.5.1",
1742
"babel-preset-es2016": "^6.24.1",
1843
"babel-preset-es2017": "^6.24.1",
44+
"babel-runtime": "^6.23.0",
1945
"browserify": "^14.4.0",
2046
"eslint": "^3.19.0",
2147
"gulp": "^3.9.1",
@@ -44,17 +70,5 @@
4470
"merge2": "^1.0.3",
4571
"vinyl-buffer": "^1.0.0",
4672
"vinyl-source-stream": "^1.1.0"
47-
},
48-
"author": "",
49-
"license": "ISC",
50-
"bugs": {
51-
"url": "https://github.com/styppo/novicash/issues"
52-
},
53-
"homepage": "https://github.com/styppo/novicash#readme",
54-
"dependencies": {
55-
"babel-runtime": "^6.23.0",
56-
"chalk": "^1.1.3",
57-
"elliptic": "^6.4.0",
58-
"fast-sha256": "^1.0.0"
5973
}
6074
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {};
2+
const atob = require('atob');
3+
const btoa = require('btoa');
4+
5+
global.Class = {
6+
register: clazz => {
7+
module.exports[clazz.prototype.constructor.name] = clazz;
8+
}
9+
};

src/main/platform/nodejs/index.js renamed to src/main/platform/nodejs/index.suffix.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,3 @@ process.on('uncaughtException', (err) => {
1717

1818
console.error(`Uncaught exception: ${err.message || err}`);
1919
});
20-
21-
global.atob = require('atob');
22-
global.btoa = require('btoa');
23-
require('./classes.js');
24-
25-
module.exports = Core;

0 commit comments

Comments
 (0)