diff --git a/.gitignore b/.gitignore index ea440ea6c9..254988dc81 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ build # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules + +lib +dist diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000000..59335fda64 --- /dev/null +++ b/.npmignore @@ -0,0 +1,34 @@ +**/node_modules/ +**/*.log +test/repo-tests* + +# Logs +logs +*.log + +coverage + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +build + +# Dependency directory +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git +node_modules + +test diff --git a/.travis.yml b/.travis.yml index bcbe5793d3..e1d6320be4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,24 @@ +sudo: false language: node_js node_js: - - "4" - - "5" + - 4 + - 5 +# Make sure we have new NPM. before_install: - - npm i -g npm - # Workaround for a permissions issue with Travis virtual machine images - -addons: - firefox: 'latest' + - npm install -g npm script: + - npm run lint - npm test + - npm run coverage + +addons: + firefox: 'latest' before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start + +after_success: + - npm run coverage-publish diff --git a/README.md b/README.md index 36a6210af2..b090b34122 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ IPFS JavaScript Implementation ============================== -[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) -[[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) ![Build Status](https://travis-ci.org/ipfs/js-ipfs.svg?style=flat-square&branch=master)](https://travis-ci.org/ipfs/js-ipfs) -![](https://img.shields.io/badge/coverage-75%25-yellow.svg?style=flat-square) -[![Dependency Status](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) +[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) +[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) +[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) +[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-ipfs/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipfs?branch=master) +[![Travis CI](https://travis-ci.org/ipfs/js-ipfs.svg?branch=master)](https://travis-ci.org/ipfs/js-ipfs) +[![Circle CI](https://circleci.com/gh/ipfs/js-ipfs.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs) +[![Dependency Status](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) -> IPFS JavaScript implementation. +> IPFS JavaScript implementation. # Description @@ -37,7 +39,7 @@ $ npm i ipfs --save ## Use in Node.js -```JavaScript +```js var IPFS = require('ipfs') var node = new IPFS() @@ -57,7 +59,7 @@ The cli is availble through `jsipfs` in your terminal The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process. -```JavaScript +```js ``` ## Use in a browser using a script tag @@ -100,40 +102,40 @@ IPFS Core is divided into separate subsystems, each of them exist in their own r ▶ ┌───────────────────────────────────────────────────────────────────────────────┐ │ IPFS Core │ │ └───────────────────────────────────────────────────────────────────────────────┘ - │ - │ │ - │ - │ ┌──────────────┬──────────────┼────────────┬─────────────────┐ - │ │ │ │ │ - │ │ │ │ │ │ - ▼ │ ▼ │ ▼ + │ + │ │ + │ + │ ┌──────────────┬──────────────┼────────────┬─────────────────┐ + │ │ │ │ │ + │ │ │ │ │ │ + ▼ │ ▼ │ ▼ │ ┌──────────────────┐ │ ┌──────────────────┐ │ ┌──────────────────┐ │ │ │ │ │ │ │ │ │ │ Block Service │ │ │ DAG Service │ │ │ IPFS Repo │ │ │ │ │ │ │ │ │ │ └──────────────────┘ │ └──────────────────┘ │ └──────────────────┘ - │ │ │ │ - IPFS Core │ ▼ │ ┌────┴────┐ │ - ┌────────┐ │ ▼ ▼ │ - │ │ Block │ │ ┌────────┐┌────────┐ │ - └────────┘ │ │DAG Node││DAG Link│ │ - │ │ └────────┘└────────┘ │ + │ │ │ │ + IPFS Core │ ▼ │ ┌────┴────┐ │ + ┌────────┐ │ ▼ ▼ │ + │ │ Block │ │ ┌────────┐┌────────┐ │ + └────────┘ │ │DAG Node││DAG Link│ │ + │ │ └────────┘└────────┘ │ ┌──────────────────┐ │ │ ┌──────────────────┐ │ │ │ │ │ │ │ │ Bitswap │◀────┤ ├──────▶│ Importer │ │ │ │ │ │ │ │ └──────────────────┘ │ │ └──────────────────┘ - │ │ │ │ - │ │ ┌────┴────┐ - │ │ │ ▼ ▼ + │ │ │ │ + │ │ ┌────┴────┐ + │ │ │ ▼ ▼ │ │ ┌────────┐┌────────┐ │ ┌──────────────────┐ │ │ │ layout ││chunker │ │ │ │ ┌────────────┘ └────────┘└────────┘ - │ │ Files │◀────┘ │ - │ │ │ - │ └──────────────────┘ │ - ▶ │ - ▼ + │ │ Files │◀────┘ │ + │ │ │ + │ └──────────────────┘ │ + ▶ │ + ▼ ┌───────────────────────────────────────────────────────────────────────────────┐ │ │ │ │ diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index 1348bc2796..0000000000 --- a/karma.conf.js +++ /dev/null @@ -1,58 +0,0 @@ -module.exports = function (config) { - var path = require('path') - var nodeForgePath = path.resolve(__dirname, 'node_modules/peer-id/vendor/forge.bundle.js') - - config.set({ - basePath: '', - frameworks: ['mocha'], - - files: [ - nodeForgePath, - 'test/core-tests/browser.js' - ], - - preprocessors: { - 'test/core-tests/*': ['webpack'] - }, - - webpack: { - resolve: { - extensions: ['', '.js', '.json'] - }, - externals: { - fs: '{}', - 'node-forge': 'forge', - 'ipfs-data-importing': '{ import: {} }', - 'libp2p-ipfs': {} // to be 'libp2p-ipfs-browser' - }, - node: { - Buffer: true - }, - module: { - loaders: [ - { test: /\.json$/, loader: 'json' } - ], - postLoaders: [{ - test: /\.js$/, - loader: 'transform?brfs', - include: /node_modules\/peer-id/ - }] - } - }, - - webpackMiddleware: { - noInfo: true, - stats: { - colors: true - } - }, - reporters: ['spec'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: false, - browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'], - captureTimeout: 60000, - singleRun: true - }) -} diff --git a/package.json b/package.json index 58d6f0743b..4e3d17b084 100644 --- a/package.json +++ b/package.json @@ -5,24 +5,22 @@ "bin": { "jsipfs": "src/cli/bin.js" }, - "main": "src/core/index.js", + "main": "lib/core/index.js", + "jsnext:main": "src/core/index.js", "scripts": { - "lint": "standard --verbose | snazzy", - "coverage": "istanbul cover --print both -- _mocha test/core-tests/index.js", - "coverage:http-api": "istanbul cover --print both -- _mocha test/http-api-tests/index.js", - "test": "npm run test:node && npm run test:browser", - "test:node": "npm run test:node:core && npm run test:node:http-api && npm run test:node:cli", - "test:node:teamcity": "npm run test:node:core:teamcity && npm run test:node:http-api:teamcity && npm run test:node:cli:teamcity", - "test:node:cli:teamcity": "mocha --reporter mocha-teamcity-reporter test/cli-tests/index.js", - "test:node:core:teamcity": "mocha --reporter mocha-teamcity-reporter test/core-tests/index.js", - "test:node:http-api:teamcity": "mocha --reporter mocha-teamcity-reporter test/http-api-tests/index.js", - "test:node:cli": "mocha test/cli-tests/index.js", + "lint": "aegir-lint", + "coverage": "aegir-coverage", + "test": "aegir-test", + "test:node": "aegir-test node", "test:node:core": "mocha test/core-tests/index.js", "test:node:http-api": "mocha test/http-api-tests/index.js", - "test:browser": "karma start karma.conf.js", - "test:browser:teamcity": "karma start --reporters teamcity --colors false karma.conf.js", - "test:core": "mocha test/core-tests/index.js", - "test:cli": "mocha test/cli-tests/index.js" + "test:node:cli": "mocha test/cli-tests/index.js", + "test:browser": "aegir-test browser", + "build": "aegir-build", + "release": "aegir-release", + "release:minor": "aegir-release minor", + "release:major": "aegir-release major", + "coverage-publish": "aegir-coverage publish" }, "pre-commit": [ "lint", @@ -42,38 +40,26 @@ }, "homepage": "https://github.com/ipfs/js-ipfs#readme", "devDependencies": { + "aegir": "^2.1.1", "async": "^1.5.2", - "brfs": "^1.4.3", "buffer-loader": "0.0.1", - "chai": "^3.4.1", + "chai": "^3.5.0", "expose-loader": "^0.7.1", "form-data": "^1.0.0-rc3", "idb-plus-blob-store": "^1.0.0", - "istanbul": "^0.4.1", - "json-loader": "^0.5.4", - "karma": "^0.13.19", - "karma-chrome-launcher": "^0.2.2", - "karma-cli": "^0.1.2", - "karma-firefox-launcher": "^0.1.7", - "karma-mocha": "^0.2.1", - "karma-spec-reporter": "0.0.26", - "karma-teamcity-reporter": "^0.2.2", - "karma-webpack": "^1.7.0", "local-storage-blob-store": "0.0.3", "lodash": "^4.11.1", "mocha": "^2.3.4", - "mocha-teamcity-reporter": "^1.0.0", "ncp": "^2.0.0", "nexpect": "^0.5.0", "pre-commit": "^1.1.2", "rimraf": "^2.4.4", "snazzy": "^3.0.1", - "standard": "^6.0.7", "stream-to-promise": "^1.1.0", - "transform-loader": "^0.2.3", - "webpack": "^2.0.7-beta" + "transform-loader": "^0.2.3" }, "dependencies": { + "babel-runtime": "^6.6.1", "bl": "^1.1.2", "boom": "^3.1.1", "bs58": "^3.0.0", @@ -95,5 +81,20 @@ "peer-info": "^0.6.2", "ronin": "^0.3.11", "temp": "^0.8.3" + }, + "aegir": { + "webpack": { + "resolve": { + "alias": { + "node-forge": "../../../node_modules/peer-id/vendor/forge.bundle.js" + } + }, + "externals": { + "fs": "{}", + "ipfs-data-importing": "{ import: {} }", + "libp2p-ipfs": "{}", + "mkdirp": "{}" + } + } } } diff --git a/src/cli/commands/block/get.js b/src/cli/commands/block/get.js index ec6baedfcf..9d3d2d97ad 100644 --- a/src/cli/commands/block/get.js +++ b/src/cli/commands/block/get.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/block/put.js b/src/cli/commands/block/put.js index 000d043fc3..28be6dfbbc 100644 --- a/src/cli/commands/block/put.js +++ b/src/cli/commands/block/put.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/cat.js b/src/cli/commands/cat.js index 4e829e0c8c..a18480b818 100644 --- a/src/cli/commands/cat.js +++ b/src/cli/commands/cat.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/config.js b/src/cli/commands/config.js index e328fcf14f..68d095f47b 100644 --- a/src/cli/commands/config.js +++ b/src/cli/commands/config.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const debug = require('debug') const get = require('lodash.get') diff --git a/src/cli/commands/config/replace.js b/src/cli/commands/config/replace.js index c9d5672d32..4b156568bb 100644 --- a/src/cli/commands/config/replace.js +++ b/src/cli/commands/config/replace.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const debug = require('debug') const path = require('path') diff --git a/src/cli/commands/config/show.js b/src/cli/commands/config/show.js index 444bd9f71a..5a837bee6f 100644 --- a/src/cli/commands/config/show.js +++ b/src/cli/commands/config/show.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const debug = require('debug') const log = debug('cli:config') diff --git a/src/cli/commands/dns.js b/src/cli/commands/dns.js index 5d59b3e92d..eaa6654b45 100644 --- a/src/cli/commands/dns.js +++ b/src/cli/commands/dns.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/get.js b/src/cli/commands/get.js index 104a4bccc7..a46afd1faa 100644 --- a/src/cli/commands/get.js +++ b/src/cli/commands/get.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/id.js b/src/cli/commands/id.js index 24f32d3d8c..27240aaa91 100644 --- a/src/cli/commands/id.js +++ b/src/cli/commands/id.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const debug = require('debug') const utils = require('../utils') diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index dcde142265..5572bfb623 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const IpfsRepo = require('ipfs-repo') const Ipfs = require('../../core') @@ -30,14 +32,7 @@ module.exports = Command.extend({ const path = utils.getRepoPath() const repo = new IpfsRepo(path, { - stores: { - keys: fsBlobStore, - config: fsBlobStore, - datastore: fsBlobStore, - logs: fsBlobStore, - locks: fsBlobStore, - version: fsBlobStore - } + stores: fsBlobStore }) var ipfs = new Ipfs(repo) diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index 104a4bccc7..a46afd1faa 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/object/data.js b/src/cli/commands/object/data.js index 1591993c42..f6f32b8051 100644 --- a/src/cli/commands/object/data.js +++ b/src/cli/commands/object/data.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/object/get.js b/src/cli/commands/object/get.js index 66ecbefd8e..3b85740ff5 100644 --- a/src/cli/commands/object/get.js +++ b/src/cli/commands/object/get.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/object/links.js b/src/cli/commands/object/links.js index 7cb20a26f8..e0d16ed4df 100644 --- a/src/cli/commands/object/links.js +++ b/src/cli/commands/object/links.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/object/new.js b/src/cli/commands/object/new.js index a6df1069a1..58e183cd45 100644 --- a/src/cli/commands/object/new.js +++ b/src/cli/commands/object/new.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/object/put.js b/src/cli/commands/object/put.js index 792d16fd66..b5aaa1d449 100644 --- a/src/cli/commands/object/put.js +++ b/src/cli/commands/object/put.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const bs58 = require('bs58') diff --git a/src/cli/commands/ping.js b/src/cli/commands/ping.js index 104a4bccc7..a46afd1faa 100644 --- a/src/cli/commands/ping.js +++ b/src/cli/commands/ping.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/repo/gc.js b/src/cli/commands/repo/gc.js index 2228495248..1d7948d62d 100644 --- a/src/cli/commands/repo/gc.js +++ b/src/cli/commands/repo/gc.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/repo/init.js b/src/cli/commands/repo/init.js index 2228495248..1d7948d62d 100644 --- a/src/cli/commands/repo/init.js +++ b/src/cli/commands/repo/init.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/repo/version.js b/src/cli/commands/repo/version.js index 8ce4b4fe8b..7885b99b40 100644 --- a/src/cli/commands/repo/version.js +++ b/src/cli/commands/repo/version.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') diff --git a/src/cli/commands/resolve.js b/src/cli/commands/resolve.js index 104a4bccc7..a46afd1faa 100644 --- a/src/cli/commands/resolve.js +++ b/src/cli/commands/resolve.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command module.exports = Command.extend({ diff --git a/src/cli/commands/swarm/addrs.js b/src/cli/commands/swarm/addrs.js index f61f941d9b..aa6802e69f 100644 --- a/src/cli/commands/swarm/addrs.js +++ b/src/cli/commands/swarm/addrs.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const debug = require('debug') diff --git a/src/cli/commands/swarm/addrs/local.js b/src/cli/commands/swarm/addrs/local.js index 7371267744..2ba6c510a1 100644 --- a/src/cli/commands/swarm/addrs/local.js +++ b/src/cli/commands/swarm/addrs/local.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../../utils') const debug = require('debug') diff --git a/src/cli/commands/swarm/connect.js b/src/cli/commands/swarm/connect.js index 95a63aad27..dfa4a0932f 100644 --- a/src/cli/commands/swarm/connect.js +++ b/src/cli/commands/swarm/connect.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const debug = require('debug') diff --git a/src/cli/commands/swarm/disconnect.js b/src/cli/commands/swarm/disconnect.js index e87f3d54d8..6ce8687868 100644 --- a/src/cli/commands/swarm/disconnect.js +++ b/src/cli/commands/swarm/disconnect.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') // const bs58 = require('bs58') diff --git a/src/cli/commands/swarm/peers.js b/src/cli/commands/swarm/peers.js index 7d18970f08..3e4c890ee7 100644 --- a/src/cli/commands/swarm/peers.js +++ b/src/cli/commands/swarm/peers.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../../utils') const debug = require('debug') diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index a206a12ce8..f2708f54d7 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -1,3 +1,5 @@ +'use strict' + const Command = require('ronin').Command const utils = require('../utils') const debug = require('debug') diff --git a/src/cli/utils.js b/src/cli/utils.js index d714da286b..c592734897 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -1,8 +1,11 @@ +'use strict' + const fs = require('fs') const os = require('os') const APIctl = require('ipfs-api') const multiaddr = require('multiaddr') const IPFS = require('../core') +const path = require('path') const debug = require('debug') const log = debug('cli') log.error = debug('cli:error') @@ -12,7 +15,7 @@ exports = module.exports exports.isDaemonOn = isDaemonOn function isDaemonOn () { try { - fs.readFileSync(exports.getRepoPath() + '/api') + fs.readFileSync(path.join(exports.getRepoPath(), 'api')) log('daemon is on') return true } catch (err) { @@ -26,14 +29,14 @@ function getAPICtl () { if (!isDaemonOn()) { throw new Error('daemon is not on') } - - const apiAddr = multiaddr(fs.readFileSync(exports.getRepoPath() + '/api').toString()) + const apiPath = path.join(exports.getRepoPath(), 'api') + const apiAddr = multiaddr(fs.readFileSync(apiPath).toString()) return APIctl(apiAddr.toString()) } exports.getIPFS = (callback) => { if (!isDaemonOn()) { - const ipfs = new IPFS() + const ipfs = new IPFS(exports.getRepoPath()) ipfs.load(() => { callback(null, ipfs) }) diff --git a/src/core/default-repo/browser.js b/src/core/default-repo/browser.js index 42315855cf..ffbc8e3600 100644 --- a/src/core/default-repo/browser.js +++ b/src/core/default-repo/browser.js @@ -1,20 +1,8 @@ 'use strict' -const localStorage = require('idb-plus-blob-store') +const idb = require('idb-plus-blob-store') const IPFSRepo = require('ipfs-repo') -const options = { - stores: { - keys: localStorage, - config: localStorage, - datastore: localStorage, - // datastoreLegacy: needs https://github.com/ipfs/js-ipfs-repo/issues/6#issuecomment-164650642 - logs: localStorage, - locks: localStorage, - version: localStorage - } -} - module.exports = () => { - return new IPFSRepo('ipfs', options) + return new IPFSRepo('ipfs', {stores: idb}) } diff --git a/src/core/default-repo/index.js b/src/core/default-repo/index.js index 2ad96ecd6c..e4f2aec4cd 100644 --- a/src/core/default-repo/index.js +++ b/src/core/default-repo/index.js @@ -1,3 +1,5 @@ +'use strict' + const isNode = !global.window module.exports = isNode diff --git a/src/core/default-repo/node.js b/src/core/default-repo/node.js index 0c0e22ec50..8d59a1db50 100644 --- a/src/core/default-repo/node.js +++ b/src/core/default-repo/node.js @@ -3,20 +3,9 @@ const os = require('os') const fs = require('fs-blob-store') const IPFSRepo = require('ipfs-repo') +const path = require('path') -const options = { - stores: { - keys: fs, - config: fs, - datastore: fs, - // datastoreLegacy: needs https://github.com/ipfs/js-ipfs-repo/issues/6#issuecomment-164650642 - logs: fs, - locks: fs, - version: fs - } -} - -module.exports = () => { - const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' - return new IPFSRepo(repoPath, options) +module.exports = (dir) => { + const repoPath = dir || path.join(os.homedir(), '.ipfs') + return new IPFSRepo(repoPath, {stores: fs}) } diff --git a/src/core/index.js b/src/core/index.js index 66b3bb2160..8a91870c25 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -13,6 +13,7 @@ const multiaddr = require('multiaddr') const importer = require('ipfs-data-importing').import const libp2p = require('libp2p-ipfs') const init = require('./init') +const IPFSRepo = require('ipfs-repo') exports = module.exports = IPFS @@ -21,8 +22,8 @@ function IPFS (repo) { throw new Error('Must be instantiated with new') } - if (!repo) { - repo = defaultRepo() + if (!(repo instanceof IPFSRepo)) { + repo = defaultRepo(repo) } const blockS = new BlockService(repo) @@ -105,7 +106,9 @@ function IPFS (repo) { }) }, - gc: function () {} + gc: function () {}, + + path: () => repo.path } this.init = (opts, callback) => { init(repo, opts, callback) } diff --git a/src/core/init.js b/src/core/init.js index 9f3ab4416d..363db8c0a3 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -1,3 +1,5 @@ +'use strict' + const peerId = require('peer-id') const IpfsBlocks = require('ipfs-blocks').BlockService const IpfsDagService = require('ipfs-merkle-dag').DAGService @@ -36,6 +38,7 @@ module.exports = (repo, opts, callback) => { function writeVersion () { const version = '3' + repo.version.set(version, (err) => { if (err) { return callback(err) } diff --git a/src/http-api/index.js b/src/http-api/index.js index cdae357ec8..cf3adddc94 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -4,7 +4,7 @@ const Hapi = require('hapi') const IPFS = require('../core') const debug = require('debug') const fs = require('fs') -const os = require('os') +const path = require('path') const log = debug('api') log.error = debug('api:error') @@ -17,14 +17,17 @@ exports.start = (repo, callback) => { } const ipfs = exports.ipfs = new IPFS(repo) + console.log('Starting at %s', ipfs.repo.path()) ipfs.load(() => { - const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' + const repoPath = ipfs.repo.path() + const apiPath = path.join(repoPath, 'api') + console.log('Finished loading') try { - fs.statSync(repoPath + '/api') + fs.statSync(apiPath) console.log('This repo is currently being used by another daemon') process.exit(1) } catch (err) { - fs.writeFileSync(repoPath + '/api', 'api is on by js-ipfs', {flag: 'w+'}) + fs.writeFileSync(apiPath, 'api is on by js-ipfs', {flag: 'w+'}) } ipfs.config.show((err, config) => { @@ -44,7 +47,7 @@ exports.start = (repo, callback) => { const gateway = config.Addresses.Gateway.split('/') // for the CLI to know the where abouts of the API - fs.writeFileSync(repoPath + '/api', config.Addresses.API) + fs.writeFileSync(apiPath, config.Addresses.API) // select which connection with server.select(