├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── appveyor.yml ├── bin └── ipld ├── ci └── Jenkinsfile ├── circle.yml ├── package.json ├── src ├── commands │ ├── add.js │ └── cat.js └── index.js └── test └── index.spec.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | lib 36 | dist 37 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | test 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. 2 | sudo: false 3 | language: node_js 4 | 5 | matrix: 6 | include: 7 | - node_js: 6 8 | env: CXX=g++-4.8 9 | - node_js: 8 10 | env: CXX=g++-4.8 11 | # - node_js: stable 12 | # env: CXX=g++-4.8 13 | 14 | script: 15 | - npm run lint 16 | - npm run test 17 | - npm run coverage 18 | 19 | before_script: 20 | - export DISPLAY=:99.0 21 | - sh -e /etc/init.d/xvfb start 22 | 23 | after_success: 24 | - npm run coverage-publish 25 | 26 | addons: 27 | firefox: 'latest' 28 | apt: 29 | sources: 30 | - ubuntu-toolchain-r-test 31 | packages: 32 | - g++-4.8 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Protocol Labs Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # js-ipld-cli 2 | 3 | [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) 4 | [![](https://img.shields.io/badge/project-IPLD-blue.svg?style=flat-square)](http://github.com/ipld/ipld) 5 | [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) 6 | [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) 7 | [![Dependency Status](https://david-dm.org/ipld/js-ipld-cli.svg?style=flat-square)](https://david-dm.org/ipld/js-ipld-cli) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) 8 | 9 | # `DEPRECATED` - The CLI will present on the https://github.com/ipld/js-ipld-resolver 10 | 11 | ## License 12 | 13 | [MIT](LICENSE) © 2016 Protocol Labs Inc. 14 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. 2 | version: "{build}" 3 | 4 | environment: 5 | matrix: 6 | - nodejs_version: "6" 7 | - nodejs_version: "8" 8 | 9 | matrix: 10 | fast_finish: true 11 | 12 | install: 13 | # Install Node.js 14 | - ps: Install-Product node $env:nodejs_version 15 | 16 | # Upgrade npm 17 | - npm install -g npm 18 | 19 | # Output our current versions for debugging 20 | - node --version 21 | - npm --version 22 | 23 | # Install our package dependencies 24 | - npm install 25 | 26 | test_script: 27 | - npm run test:node 28 | 29 | build: off 30 | -------------------------------------------------------------------------------- /bin/ipld: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict' 3 | 4 | require('../src') 5 | -------------------------------------------------------------------------------- /ci/Jenkinsfile: -------------------------------------------------------------------------------- 1 | // Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. 2 | javascript() 3 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | # Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. 2 | machine: 3 | node: 4 | version: stable 5 | 6 | dependencies: 7 | pre: 8 | - google-chrome --version 9 | - curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 10 | - sudo dpkg -i google-chrome.deb || true 11 | - sudo apt-get update 12 | - sudo apt-get install -f 13 | - sudo apt-get install --only-upgrade lsb-base 14 | - sudo dpkg -i google-chrome.deb 15 | - google-chrome --version 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ipld-cli", 3 | "version": "1.0.0", 4 | "description": "IPLD command line tool", 5 | "main": "src/index.js", 6 | "bin": { 7 | "ipld": "./bin/ipld" 8 | }, 9 | "preferGlobal": true, 10 | "dependencies": { 11 | "argparse": "^1.0.7", 12 | "fs-blob-store": "^5.2.1", 13 | "ipfs-block-service": "^0.4.0", 14 | "ipfs-ipld": "^2.0.0", 15 | "ipfs-repo": "^0.8.0", 16 | "json-colorz": "^0.2.7", 17 | "prettyjson": "^1.1.3" 18 | }, 19 | "devDependencies": { 20 | "aegir": "^4.0.0", 21 | "chai": "^3.5.0", 22 | "pre-commit": "^1.1.3" 23 | }, 24 | "scripts": { 25 | "lint": "aegir-lint", 26 | "test": "aegir-test --env node", 27 | "release": "aegir-release --env no-build", 28 | "coverage": "aegir-coverage", 29 | "coverage-publish": "aegir-coverage publish" 30 | }, 31 | "repository": { 32 | "type": "git", 33 | "url": "git+https://github.com/ipld/js-ipld-cli.git" 34 | }, 35 | "keywords": [ 36 | "ipfs", 37 | "ipld" 38 | ], 39 | "author": "Friedel Ziegelmayer ", 40 | "license": "MIT", 41 | "bugs": { 42 | "url": "https://github.com/ipld/js-ipld-cli/issues" 43 | }, 44 | "homepage": "https://github.com/ipfs/js-ipld-cli#readme", 45 | "jsnext:main": "src/index.js", 46 | "pre-commit": [ 47 | "lint", 48 | "test" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /src/commands/add.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const ipld = require('ipld') 4 | 5 | module.exports = function add (args, ipldService, cb) { 6 | cb = cb || (() => {}) 7 | 8 | let content 9 | try { 10 | content = JSON.parse(args.content) 11 | } catch (err) { 12 | console.error('Invalid JSON') 13 | process.exit(1) 14 | } 15 | 16 | ipldService.add(content, function (err) { 17 | if (err) { 18 | console.error(err) 19 | process.exit(1) 20 | } 21 | 22 | const mh = ipld.multihash(ipld.marshal(content)) 23 | console.log('Added new node with hash %s', mh) 24 | cb(null, mh) 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /src/commands/cat.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const resolve = require('ipfs-ipld/src').resolve 4 | const colorz = require('json-colorz') 5 | const prettyjson = require('prettyjson') 6 | 7 | module.exports = function cat (args, ipldService) { 8 | resolve(ipldService, args.path, function (err, res) { 9 | if (err) { 10 | console.error(err) 11 | process.exit(1) 12 | } 13 | 14 | if (args.noColors) { 15 | console.log(JSON.stringify(res, null, 2)) 16 | } else if (args.yml) { 17 | console.log(prettyjson.render(res, {indent: 2})) 18 | } else if (args.json) { 19 | colorz(res) 20 | } 21 | }) 22 | } 23 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const ArgumentParser = require('argparse').ArgumentParser 4 | const pkg = require('../package.json') 5 | const path = require('path') 6 | const os = require('os') 7 | const fsb = require('fs-blob-store') 8 | const IPFSRepo = require('ipfs-repo') 9 | const BlockService = require('ipfs-block-service') 10 | const IPLDService = require('ipfs-ipld/src').IPLDService 11 | 12 | const addCmd = require('./commands/add') 13 | const catCmd = require('./commands/cat') 14 | 15 | const parser = new ArgumentParser({ 16 | version: pkg.version, 17 | addHelp: true, 18 | description: 'IPLD command line tool' 19 | }) 20 | 21 | const subparsers = parser.addSubparsers({ 22 | title: 'commands', 23 | dest: 'subcommand' 24 | }) 25 | 26 | const add = subparsers.addParser('add', { 27 | addHelp: true, 28 | description: 'Add a new object in JSON format' 29 | }) 30 | add.addArgument('content', { 31 | type: String 32 | }) 33 | 34 | const cat = subparsers.addParser('cat', { 35 | addHelp: true, 36 | description: 'Resolve a given path' 37 | }) 38 | cat.addArgument('path', { 39 | type: String 40 | }) 41 | cat.addArgument('--yml', { 42 | type: Boolean, 43 | defaultValue: false, 44 | nargs: 0, 45 | help: 'Print the result in yaml' 46 | }) 47 | cat.addArgument('--json', { 48 | type: Boolean, 49 | nargs: 0, 50 | defaultValue: true, 51 | help: 'Print the result in json' 52 | }) 53 | cat.addArgument('--no-colors', { 54 | type: Boolean, 55 | nargs: 0, 56 | defaultValue: false, 57 | help: 'Print the result without colors', 58 | dest: 'noColors' 59 | }) 60 | 61 | const args = parser.parseArgs() 62 | const repo = new IPFSRepo(path.join(os.homedir(), '.ipfs-cli'), {stores: fsb}) 63 | const bs = new BlockService(repo) 64 | const ipldService = new IPLDService(bs) 65 | 66 | switch (args.subcommand) { 67 | case 'add': 68 | addCmd(args, ipldService) 69 | break 70 | case 'cat': 71 | catCmd(args, ipldService) 72 | break 73 | default: 74 | throw new Error('Invalid command') 75 | } 76 | -------------------------------------------------------------------------------- /test/index.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | 'use strict' 3 | 4 | const expect = require('chai').expect 5 | const path = require('path') 6 | const os = require('os') 7 | const fsb = require('fs-blob-store') 8 | const IPFSRepo = require('ipfs-repo') 9 | const BlockService = require('ipfs-block-service') 10 | const IPLDService = require('ipfs-ipld/src').IPLDService 11 | 12 | const add = require('../src/commands/add') 13 | 14 | describe('ipld-cli', () => { 15 | describe('commands', () => { 16 | it('add', (done) => { 17 | const repo = new IPFSRepo(path.join(os.tmpdir(), '.ipfs-cli'), {stores: fsb}) 18 | const bs = new BlockService(repo) 19 | const service = new IPLDService(bs) 20 | 21 | add({content: JSON.stringify({hello: 'world'})}, service, (err, mh) => { 22 | expect(err).to.not.exist 23 | expect(mh).to.be.eql('QmWSKnuEtJzn3EjFbSQsbiTPAPMgrL9piq68PaJYRNeqbv') 24 | done() 25 | }) 26 | }) 27 | }) 28 | }) 29 | --------------------------------------------------------------------------------