Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 4d810a0

Browse files
committed
refactor: modularize js-ipfs-api(#544)
1 parent 3ca9904 commit 4d810a0

File tree

150 files changed

+2394
-1422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+2394
-1422
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ test/setup/tmp-disposable-nodes-addrs.json
44
dist
55
coverage
66
**/*.swp
7+
examples/sub-module/**/bundle.js
8+
examples/sub-module/**/*-minified.js
9+
examples/sub-module/*-bundle.js

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ipfs-api
2525
- [Install](#install)
2626
- [Running the daemon with the right port](#running-the-daemon-with-the-right-port)
2727
- [Importing the module and usage](#importing-the-module-and-usage)
28+
- [Importing a sub-module and usage](#importing-a-sub-module-and-usage)
2829
- [In a web browser through Browserify](#in-a-web-browser-through-browserify)
2930
- [In a web browser from CDN](#in-a-web-browser-from-cdn)
3031
- [CORS](#cors)
@@ -74,6 +75,14 @@ var ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/5001')
7475
// or using options
7576
var ipfs = ipfsAPI({host: 'localhost', port: '5001', protocol: 'http'})
7677
```
78+
### Importing a sub-module and usage
79+
```javascript
80+
const bitswap = require('ipfs-api/bitswap')('/ip4/127.0.0.1/tcp/5001')
81+
82+
bitswap.unwant(key, (err) => {
83+
// ...
84+
}
85+
```
7786
7887
### In a web browser through Browserify
7988
@@ -224,12 +233,15 @@ This means:
224233
- [`ipfs.id([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#id)
225234
- [`ipfs.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#version)
226235
- [`ipfs.ping()`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#ping)
227-
- [`ipfs.log()`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#log)
228236
229-
#### [key](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key)
237+
- log:
238+
- [`ipfs.log.ls([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
239+
- [`ipfs.log.tail([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
240+
- [`ipfs.log.level(subsystem, level, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
230241
231-
- [`ipfs.key.gen(name, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#gen)
232-
- [`ipfs.key.list([options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#list)
242+
- key:
243+
- [`ipfs.key.gen(name, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#gen)
244+
- [`ipfs.key.list([options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/key#list)
233245
234246
##### [name](https://github.com/ipfs/interface-ipfs-core/tree/master/API/name)
235247

examples/sub-module/bundles-size.csv

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name - bundled - minified
2+
IPFS - 1684,11 - 661,26
3+
bitswap - 683,51 - 231,75
4+
block - 723,48 - 249,85
5+
bootstrap - 684,34 - 232,01
6+
commands - 682,59 - 231,38
7+
config - 685,58 - 232,72
8+
dht - 687,22 - 233,03
9+
diag - 683,67 - 231,80
10+
files - 1119,09 - 403,92
11+
id - 683,01 - 231,57
12+
key - 683,29 - 231,65
13+
log - 684,11 - 232,00
14+
ls - 682,71 - 231,42
15+
mount - 682,89 - 231,49
16+
name - 683,33 - 231,68
17+
object - 922,37 - 340,19
18+
pin - 684,22 - 232,01
19+
ping - 683,30 - 231,52
20+
pubsub - 739,11 - 249,16
21+
refs - 683,10 - 231,57
22+
repo - 683,27 - 231,64
23+
swarm - 1322,89 - 526,65
24+
update - 683,16 - 231,58
25+
version - 682,92 - 231,51
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const ipfs = require('../../src')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const bitswap = require('../../../../src/bitswap')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const block = require('../../../../src/block')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const bootstrap = require('../../../../src/bootstrap')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const commands = require('../../../../src/commands')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const config = require('../../../../src/config')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const dht = require('../../../../src/dht')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const diag = require('../../../../src/diag')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const files = require('../../../../src/files')('/ip4/127.0.0.1/tcp/5001')

examples/sub-module/modules/id/id.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const id = require('../../../../src/id')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const key = require('../../../../src/key')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const log = require('../../../../src/log')('/ip4/127.0.0.1/tcp/5001')

examples/sub-module/modules/ls/ls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const ls = require('../../../../src/ls')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const mount = require('../../../../src/mount')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const name = require('../../../../src/name')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const object = require('../../../../src/object')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const pin = require('../../../../src/pin')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const ping = require('../../../../src/ping')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const pubsub = require('../../../../src/pubsub')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const refs = require('../../../../src/refs')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const repo = require('../../../../src/repo')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const swarm = require('../../../../src/swarm')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const update = require('../../../../src/update')('/ip4/127.0.0.1/tcp/5001')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
const version = require('../../../../src/version')('/ip4/127.0.0.1/tcp/5001')

examples/sub-module/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "sub-module",
3+
"version": "1.0.0",
4+
"description": "",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"author": "Nuno Nogueira",
9+
"license": "MIT",
10+
"devDependencies": {
11+
"babel-core": "^6.25.0",
12+
"babel-loader": "^7.1.0",
13+
"babel-preset-env": "^1.5.2",
14+
"babili": "^0.1.4",
15+
"webpack": "^3.0.0"
16+
}
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
modules=($(ls modules/))
4+
5+
echo "name - bundled - minified"
6+
7+
# Full IPFS module
8+
webpack --display none --config webpack.config.js complete-module.js complete-bundle.js
9+
babili complete-bundle.js -o complete-bundle-minified.js
10+
11+
ipfsBundleSize=($(wc -c < complete-bundle.js | awk '{b=$1/1024; printf "%.2f\n", b}'))
12+
ipfsMinSize=($(wc -c < complete-bundle-minified.js | awk '{b=$1/1024; printf "%.2f\n", b}'))
13+
14+
echo IPFS - $ipfsBundleSize - $ipfsMinSize
15+
16+
for module in "${modules[@]}"
17+
do
18+
moduledir="modules/$module"
19+
webpack --display none --config webpack.config.js $moduledir/$module.js $moduledir/bundle.js
20+
babili $moduledir/bundle.js -o $moduledir/bundle-minified.js
21+
22+
bundlesize=($(wc -c < $moduledir/bundle.js | awk '{b=$1/1024; printf "%.2f\n", b}'))
23+
minsize=($(wc -c < $moduledir/bundle-minified.js | awk '{b=$1/1024; printf "%.2f\n", b}'))
24+
echo $module - $bundlesize - $minsize
25+
done

examples/sub-module/webpack.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
module.exports = {
4+
module: {
5+
loaders: [{
6+
test: /\.js$/,
7+
loaders: ['babel-loader']
8+
}]
9+
},
10+
node: {
11+
fs: 'empty',
12+
net: 'empty',
13+
tls: 'empty'
14+
}
15+
}

src/api/bitswap.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/api/block.js

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)