From de9c270522934f0cbfb73c66245bb7eae1b5eb62 Mon Sep 17 00:00:00 2001 From: David Dias Date: Mon, 22 Feb 2016 13:31:40 +0000 Subject: [PATCH] organize code, add feature to init/start daemon if needed --- README.md | 2 +- package.json | 9 +++-- bin.js => src/cli/bin.js | 6 +-- {commands => src/cli/commands}/browse.js | 0 {commands => src/cli/commands}/init.js | 0 src/cli/commands/ipfs/start.js | 42 ++++++++++++++++++++ {commands => src/cli/commands}/preview.js | 0 {commands => src/cli/commands}/publish.js | 0 {commands => src/cli/commands}/screenshot.js | 0 {commands => src/cli/commands}/versions.js | 0 10 files changed, 52 insertions(+), 7 deletions(-) rename bin.js => src/cli/bin.js (64%) rename {commands => src/cli/commands}/browse.js (100%) rename {commands => src/cli/commands}/init.js (100%) create mode 100644 src/cli/commands/ipfs/start.js rename {commands => src/cli/commands}/preview.js (100%) rename {commands => src/cli/commands}/publish.js (100%) rename {commands => src/cli/commands}/screenshot.js (100%) rename {commands => src/cli/commands}/versions.js (100%) diff --git a/README.md b/README.md index 64f4e56..8153e1b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ipscend [![](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) ![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/ipscend.svg?style=flat-square)](https://david-dm.org/diasdavid/ipscend) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) -> Quick and simple deploy tool to host Native Web Applications and Static Web Pages in IPFS +> Web Application publishing, simple and distributed with IPFS ## Usage diff --git a/package.json b/package.json index ccfed13..47cc4b6 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,10 @@ { "name": "ipscend", "version": "0.1.9", - "description": "Quick and simple deploy tool to host Native Web Applications and Static Web Pages in IPFS", - "bin": "bin.js", + "description": "Web Application publishing, simple and distributed with IPFS ", + "bin": { + "ipscend": "src/cli/bin.js" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -21,7 +23,8 @@ "homepage": "https://github.com/diasdavid/ipscend", "dependencies": { "asking": "^0.1.2", - "ipfs-api": "^2.9.11", + "ipfs-api": "^2.13.1", + "ipfsd-ctl": "^0.8.1", "ndjson-aggregator": "^0.1.2", "node-static": "^0.7.7", "open": "0.0.5", diff --git a/bin.js b/src/cli/bin.js similarity index 64% rename from bin.js rename to src/cli/bin.js index 3dcf9c8..7cd179e 100755 --- a/bin.js +++ b/src/cli/bin.js @@ -4,6 +4,6 @@ var ronin = require('ronin') var cli = ronin(__dirname) -cli.autoupdate(function () { - cli.run() -}) +// cli.autoupdate(() => { +cli.run() +// }) diff --git a/commands/browse.js b/src/cli/commands/browse.js similarity index 100% rename from commands/browse.js rename to src/cli/commands/browse.js diff --git a/commands/init.js b/src/cli/commands/init.js similarity index 100% rename from commands/init.js rename to src/cli/commands/init.js diff --git a/src/cli/commands/ipfs/start.js b/src/cli/commands/ipfs/start.js new file mode 100644 index 0000000..deac9f6 --- /dev/null +++ b/src/cli/commands/ipfs/start.js @@ -0,0 +1,42 @@ +const fs = require('fs') +const ipfsd = require('ipfsd-ctl') +const os = require('os') + +var Command = require('ronin').Command +module.exports = Command.extend({ + desc: 'Start your a local IPFS node', + run: () => { + const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs' + var init = false + try { + fs.statSync(repoPath) + // TODO check if it is right repo version, if not, inform the user + // how to migrate + } catch (err) { + init = true + console.log('no IPFS repo found, going to start a new one') + } + + ipfsd.disposable({ + repoPath: repoPath, + init: init + }, (err, node) => { + if (err) { + return console.log(err) + } + console.log('starting IPFS daemon (this might take some seconds)') + node.startDaemon((err) => { + if (err) { + return console.log('failed to start a daemon') + } + console.log('IPFS daemon has started, you can now publish with ipscend') + process.on('SIGINT', () => { + console.log('Got interrupt signal(SIGINT), shutting down.') + node.stopDaemon(() => { + process.exit(0) + }) + }) + }) + }) + } +}) diff --git a/commands/preview.js b/src/cli/commands/preview.js similarity index 100% rename from commands/preview.js rename to src/cli/commands/preview.js diff --git a/commands/publish.js b/src/cli/commands/publish.js similarity index 100% rename from commands/publish.js rename to src/cli/commands/publish.js diff --git a/commands/screenshot.js b/src/cli/commands/screenshot.js similarity index 100% rename from commands/screenshot.js rename to src/cli/commands/screenshot.js diff --git a/commands/versions.js b/src/cli/commands/versions.js similarity index 100% rename from commands/versions.js rename to src/cli/commands/versions.js