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

modularize js-ipfs-api #561

Merged
merged 7 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 additions & 0 deletions examples/sub-module/bundles-size-KBs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name, bundled (KBs), minified (KBs)
IPFS, 1685.41, 661.64
add, 968.11, 344.13
bitswap, 684.80, 232.13
block, 724.77, 250.23
bootstrap, 685.64, 232.39
cat, 725.05, 250.33
commands, 683.89, 231.76
config, 686.87, 233.10
dht, 688.51, 233.41
diag, 684.97, 232.18
files, 1120.38, 404.30
get, 907.74, 318.35
id, 684.31, 231.95
key, 684.59, 232.03
log, 685.40, 232.38
ls, 684.00, 231.80
mount, 684.18, 231.86
name, 684.63, 232.06
object, 923.66, 340.57
pin, 685.51, 232.39
ping, 684.59, 231.90
pubsub, 740.40, 249.54
refs, 684.39, 231.94
repo, 684.56, 232.02
swarm, 1324.18, 527.03
update, 684.45, 231.96
version, 684.21, 231.88
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/add/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const add = require('../../../../src/add')('/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/cat/cat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const cat = require('../../../../src/cat')('/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/get/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

const get = require('../../../../src/get')('/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"
}
}
26 changes: 26 additions & 0 deletions examples/sub-module/test-modules-size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
set -e

Copy link
Contributor

@victorb victorb Jun 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have at least set -e so it exits the entire script if there is a error

modules=($(ls modules/))

echo "name, bundled (KBs), minified (KBs)"

# Full IPFS module
webpack --display none --config webpack.confg.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}' | sed 's/,/./g'))
ipfsMinSize=($(wc -c < complete-bundle-minified.js | awk '{b=$1/1024; printf "%.2f\n", b}' | sed 's/,/./g'))

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}' | sed 's/,/./g'))
minsize=($(wc -c < $moduledir/bundle-minified.js | awk '{b=$1/1024; printf "%.2f\n", b}' | sed 's/,/./g'))
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'
}
}
9 changes: 9 additions & 0 deletions src/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

const moduleConfig = require('./utils/module-config')

module.exports = (arg) => {
const send = moduleConfig(arg)

return require('./files/add')(send)
}
29 changes: 0 additions & 29 deletions src/api/bitswap.js

This file was deleted.

Loading