Skip to content

Commit 54bc78a

Browse files
committed
WIP webpack full build
1 parent 0e0367f commit 54bc78a

11 files changed

+801
-128
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ language: node_js
33
node_js:
44
- "8"
55

6-
script: npm run test
6+
script:
7+
- npm run lint
8+
- npm run build
9+
- npm run test
710

811
before_script:
912
- export DISPLAY=:99.0

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ If you are in development mode, you can pass an option `mock: true` when initial
1414

1515
### In the Browser
1616

17-
You can require/import this module from the browser through Webpack. Check out [this example](https://github.com/ipfs/js-ipfs/tree/master/examples/browser-webpack) for the additional configuration needed by js-ipfs.
17+
You can require/import this module from the browser through Webpack, look at the Webpack configuration of this project to figure out what you need.
18+
By default webpack will load the prebuilt minified library to avoid issues in front-end projects.
1819

19-
If you don't have webpack, we also have a prebuilt minified version of the library that you can include in a `<script>` tag. Check out the [examples](https://github.com/ChluNetwork/chlu-ipfs-support/blob/master/examples).
20+
If you don't have webpack and want to load this in another way, we also have a prebuilt minified version of the library that you can include in a `<script>` tag.
21+
Check out the [examples](https://github.com/ChluNetwork/chlu-ipfs-support/blob/master/examples).
22+
23+
Keep in mind that the prebuilt minified library includes every dependency, and also works as a commonjs or amd module.
2024

2125
### In Electron
2226

bin/chlu-service-node.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#!/usr/bin/env node
2-
const ChluIPFS = require('../src/index.js');
2+
const ChluIPFS = require('../dist/ChluIPFS.min.js');
33

44
let serviceNode = null;
55

6-
async function main(){
6+
function main(){
77
console.log('Starting Chlu IPFS Service Node');
88
serviceNode = new ChluIPFS({ type: ChluIPFS.types.service });
9-
await serviceNode.start();
9+
return serviceNode.start();
1010
}
1111

1212
main().then(() => console.log('Service Node Started'));
1313

14-
process.on('SIGINT', async function() {
14+
process.on('SIGINT', function() {
1515
console.log('Stopping gracefully');
16-
try {
17-
if (serviceNode) {
18-
await serviceNode.stop();
19-
}
20-
process.exit(0);
21-
} catch(exception) {
22-
process.exit(1);
23-
}
16+
serviceNode.stop()
17+
.then(() => process.exit(0))
18+
.catch(exception => {
19+
console.log(exception.message);
20+
process.exit(1);
21+
});
2422
});

dist/ChluIPFS.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/customer.html

-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
<title>ChluIPFS Customer Example</title>
44
</head>
55
<body>
6-
7-
<!-- ChluIPFS requires ipfs-js and orbit-db but does not include them in the prebuilt browser script -->
8-
<!-- we can easily include them before loading ChluIPFS thanks to the unpkg CDN -->
9-
10-
<!-- Currently using non minified version of IPFS due to this issue https://github.com/ipfs/js-ipfs/issues/1136 -->
11-
<!-- IPFS -->
12-
<script src="https://unpkg.com/[email protected]/dist/index.js"></script>
13-
<!-- OrbitDB -->
14-
<script src="https://unpkg.com/[email protected]/dist/orbitdb.min.js"></script>
156
<script src="../dist/ChluIPFS.min.js"></script>
167
<script>
178
// Utility function to output strings to the web page

examples/serviceNode.html

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
<title>ChluIPFS Service Node Example</title>
44
</head>
55
<body>
6-
<!-- Currently using non minified version of IPFS due to https://github.com/ipfs/js-ipfs/issues/1136 -->
7-
<script src="https://unpkg.com/[email protected]/dist/index.js"></script>
8-
<script src="https://unpkg.com/[email protected]/dist/orbitdb.min.js"></script>
96
<script src="../dist/ChluIPFS.min.js"></script>
107
<script>
118

lib/ChluIPFS.js

+19-31
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class ChluIPFS {
8989
}
9090
// Broadcast my review updates DB
9191
//this.broadcastReviewUpdates();
92-
} else if (this.type === constants.types.service) {
93-
this.startServiceNode();
9492
}
9593

9694
return true;
@@ -126,9 +124,6 @@ class ChluIPFS {
126124
this.dbs = {};
127125
}
128126
this.type = newType;
129-
if (newType === constants.types.service && !this.serviceNodeRoomMessageListener) {
130-
this.startServiceNode();
131-
}
132127
await this.loadPersistedData();
133128
}
134129
}
@@ -228,24 +223,25 @@ class ChluIPFS {
228223
this.events.emit(constants.eventTypes.replicated + '_' + obj.address);
229224
}
230225

231-
// Service node stuff
232-
233-
const isOrbitDb = obj.type === constants.eventTypes.customerReviews || obj.type === constants.eventTypes.updatedReview;
234-
// handle ReviewRecord: pin hash
235-
if (obj.type === constants.eventTypes.wroteReviewRecord && typeof obj.multihash === 'string') {
236-
this.logger.info('Pinning ReviewRecord ' + obj.multihash);
237-
try {
238-
await this.pin(obj.multihash);
239-
this.logger.info('Pinned ReviewRecord ' + obj.multihash);
240-
} catch (exception) {
241-
this.logger.error('Pin Error: ' + exception.message);
242-
}
243-
} else if (isOrbitDb && typeof obj.address === 'string') {
244-
// handle OrbitDB: replicate
245-
try {
246-
this.replicate(obj.address);
247-
} catch (exception) {
248-
this.logger.error('OrbitDB Replication Error: ' + exception.message);
226+
if (this.type === constants.types.service) {
227+
// Service node stuff
228+
const isOrbitDb = obj.type === constants.eventTypes.customerReviews || obj.type === constants.eventTypes.updatedReview;
229+
// handle ReviewRecord: pin hash
230+
if (obj.type === constants.eventTypes.wroteReviewRecord && typeof obj.multihash === 'string') {
231+
this.logger.info('Pinning ReviewRecord ' + obj.multihash);
232+
try {
233+
await this.pin(obj.multihash);
234+
this.logger.info('Pinned ReviewRecord ' + obj.multihash);
235+
} catch (exception) {
236+
this.logger.error('Pin Error: ' + exception.message);
237+
}
238+
} else if (isOrbitDb && typeof obj.address === 'string') {
239+
// handle OrbitDB: replicate
240+
try {
241+
this.replicate(obj.address);
242+
} catch (exception) {
243+
this.logger.error('OrbitDB Replication Error: ' + exception.message);
244+
}
249245
}
250246
}
251247
} catch (exception) {
@@ -327,14 +323,6 @@ class ChluIPFS {
327323
}
328324
}
329325

330-
startServiceNode() {
331-
this.serviceNodeRoomMessageListener = async message => {
332-
// parse messages
333-
const obj = this.utils.decodeMessage(message);
334-
};
335-
this.room.on('message', this.serviceNodeRoomMessageListener);
336-
}
337-
338326
listenToDBEvents(db) {
339327
db.events.on('replicated', address => {
340328
this.logger.debug('OrbitDB Event: Replicated ' + address);

0 commit comments

Comments
 (0)