diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index 809824a8e9..dae5dbb61b 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -32,6 +32,9 @@ module.exports = { handler (argv) { const path = utils.getRepoPath() + const log = utils.createLogger(true) + log(`initializing ipfs node at ${path}`) + const repo = new IpfsRepo(path, { stores: Store }) @@ -41,7 +44,8 @@ module.exports = { ipfs.init({ bits: argv.bits, force: argv.force, - emptyRepo: argv.emptyRepo + emptyRepo: argv.emptyRepo, + log }, function (err) { if (err) { console.error(err.toString()) diff --git a/src/cli/utils.js b/src/cli/utils.js index c592734897..d4d51a06e7 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -49,3 +49,18 @@ exports.getIPFS = (callback) => { exports.getRepoPath = () => { return process.env.IPFS_PATH || os.homedir() + '/.ipfs' } + +exports.createLogger = (visible) => { + return (msg, newline) => { + if (newline === undefined) { + newline = true + } + if (visible) { + if (msg === undefined) { + msg = '' + } + msg = newline ? msg + '\n' : msg + process.stdout.write(msg) + } + } +} diff --git a/src/core/ipfs/init.js b/src/core/ipfs/init.js index d251800b00..2263b53015 100644 --- a/src/core/ipfs/init.js +++ b/src/core/ipfs/init.js @@ -9,6 +9,7 @@ const fs = require('fs') const importer = require('ipfs-unixfs-engine').importer const pull = require('pull-stream') const file = require('pull-file') +const mh = require('multihashes') module.exports = function init (self) { return (opts, callback) => { @@ -19,6 +20,7 @@ module.exports = function init (self) { opts.emptyRepo = opts.emptyRepo || false opts.bits = opts.bits || 2048 + opts.log = opts.log || function () {} let config // Pre-set config values. @@ -47,6 +49,7 @@ module.exports = function init (self) { // Generate peer identity keypair + transform to desired format + add to config. function generateAndSetKeypair () { + opts.log(`generating ${opts.bits}-bit RSA keypair...`, false) var keys = peerId.create({ bits: opts.bits }) @@ -54,6 +57,8 @@ module.exports = function init (self) { PeerID: keys.toB58String(), PrivKey: keys.privKey.bytes.toString('base64') } + opts.log('done') + opts.log('peer identity: ' + config.Identity.PeerID) writeVersion() } @@ -108,6 +113,15 @@ module.exports = function init (self) { }), pull.filter(Boolean), importer(dag), + pull.through((el) => { + if (el.path === 'files/init-docs/docs') { + const hash = mh.toB58String(el.multihash) + opts.log('to get started, enter:') + opts.log() + opts.log(`\t jsipfs files cat /ipfs/${hash}/readme`) + opts.log() + } + }), pull.onEnd((err) => { if (err) return callback(err)