Skip to content

Commit

Permalink
refactor: modularize js-ipfs-api(ipfs-inactive#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunofmn committed Jun 26, 2017
1 parent 3ca9904 commit 4d810a0
Show file tree
Hide file tree
Showing 150 changed files with 2,394 additions and 1,422 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ test/setup/tmp-disposable-nodes-addrs.json
dist
coverage
**/*.swp
examples/sub-module/**/bundle.js
examples/sub-module/**/*-minified.js
examples/sub-module/*-bundle.js
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ipfs-api
- [Install](#install)
- [Running the daemon with the right port](#running-the-daemon-with-the-right-port)
- [Importing the module and usage](#importing-the-module-and-usage)
- [Importing a sub-module and usage](#importing-a-sub-module-and-usage)
- [In a web browser through Browserify](#in-a-web-browser-through-browserify)
- [In a web browser from CDN](#in-a-web-browser-from-cdn)
- [CORS](#cors)
Expand Down Expand Up @@ -74,6 +75,14 @@ var ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/5001')
// or using options
var ipfs = ipfsAPI({host: 'localhost', port: '5001', protocol: 'http'})
```
### Importing a sub-module and usage
```javascript
const bitswap = require('ipfs-api/bitswap')('/ip4/127.0.0.1/tcp/5001')

bitswap.unwant(key, (err) => {
// ...
}
```
### In a web browser through Browserify
Expand Down Expand Up @@ -224,12 +233,15 @@ This means:
- [`ipfs.id([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#id)
- [`ipfs.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#version)
- [`ipfs.ping()`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#ping)
- [`ipfs.log()`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#log)
#### [key](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key)
- log:
- [`ipfs.log.ls([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
- [`ipfs.log.tail([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
- [`ipfs.log.level(subsystem, level, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
- [`ipfs.key.gen(name, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#gen)
- [`ipfs.key.list([options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#list)
- key:
- [`ipfs.key.gen(name, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#gen)
- [`ipfs.key.list([options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#list)
##### [name](https://github.com/ipfs/interface-ipfs-core/tree/master/API/name)
Expand Down
25 changes: 25 additions & 0 deletions examples/sub-module/bundles-size.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name - bundled - minified
IPFS - 1684,11 - 661,26
bitswap - 683,51 - 231,75
block - 723,48 - 249,85
bootstrap - 684,34 - 232,01
commands - 682,59 - 231,38
config - 685,58 - 232,72
dht - 687,22 - 233,03
diag - 683,67 - 231,80
files - 1119,09 - 403,92
id - 683,01 - 231,57
key - 683,29 - 231,65
log - 684,11 - 232,00
ls - 682,71 - 231,42
mount - 682,89 - 231,49
name - 683,33 - 231,68
object - 922,37 - 340,19
pin - 684,22 - 232,01
ping - 683,30 - 231,52
pubsub - 739,11 - 249,16
refs - 683,10 - 231,57
repo - 683,27 - 231,64
swarm - 1322,89 - 526,65
update - 683,16 - 231,58
version - 682,92 - 231,51
3 changes: 3 additions & 0 deletions examples/sub-module/complete-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const ipfs = require('../../src')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/bitswap/bitswap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const bitswap = require('../../../../src/bitswap')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/block/block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const block = require('../../../../src/block')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/bootstrap/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const bootstrap = require('../../../../src/bootstrap')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/commands/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const commands = require('../../../../src/commands')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const config = require('../../../../src/config')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/dht/dht.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const dht = require('../../../../src/dht')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/diag/diag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const diag = require('../../../../src/diag')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/files/files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const files = require('../../../../src/files')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/id/id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const id = require('../../../../src/id')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/key/key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const key = require('../../../../src/key')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/log/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const log = require('../../../../src/log')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/ls/ls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const ls = require('../../../../src/ls')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/mount/mount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const mount = require('../../../../src/mount')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/name/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const name = require('../../../../src/name')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/object/object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const object = require('../../../../src/object')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/pin/pin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const pin = require('../../../../src/pin')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/ping/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const ping = require('../../../../src/ping')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/pubsub/pubsub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const pubsub = require('../../../../src/pubsub')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/refs/refs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const refs = require('../../../../src/refs')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/repo/repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const repo = require('../../../../src/repo')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/swarm/swarm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const swarm = require('../../../../src/swarm')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/update/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const update = require('../../../../src/update')('/ip4/127.0.0.1/tcp/5001')
3 changes: 3 additions & 0 deletions examples/sub-module/modules/version/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const version = require('../../../../src/version')('/ip4/127.0.0.1/tcp/5001')
17 changes: 17 additions & 0 deletions examples/sub-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "sub-module",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Nuno Nogueira",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.0",
"babel-preset-env": "^1.5.2",
"babili": "^0.1.4",
"webpack": "^3.0.0"
}
}
25 changes: 25 additions & 0 deletions examples/sub-module/test-modules-size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

modules=($(ls modules/))

echo "name - bundled - minified"

# Full IPFS module
webpack --display none --config webpack.config.js complete-module.js complete-bundle.js
babili complete-bundle.js -o complete-bundle-minified.js

ipfsBundleSize=($(wc -c < complete-bundle.js | awk '{b=$1/1024; printf "%.2f\n", b}'))
ipfsMinSize=($(wc -c < complete-bundle-minified.js | awk '{b=$1/1024; printf "%.2f\n", b}'))

echo IPFS - $ipfsBundleSize - $ipfsMinSize

for module in "${modules[@]}"
do
moduledir="modules/$module"
webpack --display none --config webpack.config.js $moduledir/$module.js $moduledir/bundle.js
babili $moduledir/bundle.js -o $moduledir/bundle-minified.js

bundlesize=($(wc -c < $moduledir/bundle.js | awk '{b=$1/1024; printf "%.2f\n", b}'))
minsize=($(wc -c < $moduledir/bundle-minified.js | awk '{b=$1/1024; printf "%.2f\n", b}'))
echo $module - $bundlesize - $minsize
done
15 changes: 15 additions & 0 deletions examples/sub-module/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

module.exports = {
module: {
loaders: [{
test: /\.js$/,
loaders: ['babel-loader']
}]
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
}
29 changes: 0 additions & 29 deletions src/api/bitswap.js

This file was deleted.

113 changes: 0 additions & 113 deletions src/api/block.js

This file was deleted.

Loading

0 comments on commit 4d810a0

Please sign in to comment.