diff --git a/packages/embark/package.json b/packages/embark/package.json index 8eceb0c69..f7bfb96c4 100644 --- a/packages/embark/package.json +++ b/packages/embark/package.json @@ -96,6 +96,7 @@ "embark-utils": "^4.0.0", "embark-webserver": "^4.0.0", "embarkjs": "^4.0.0", + "embarkjs-ipfs": "^4.0.0", "eth-ens-namehash": "2.0.8", "ethereumjs-tx": "1.3.7", "ethereumjs-util": "6.0.0", diff --git a/packages/embark/src/lib/modules/codeRunner/vm.ts b/packages/embark/src/lib/modules/codeRunner/vm.ts index 0aef94a88..e26820873 100644 --- a/packages/embark/src/lib/modules/codeRunner/vm.ts +++ b/packages/embark/src/lib/modules/codeRunner/vm.ts @@ -42,6 +42,8 @@ class VM { "eth-ens-namehash", "swarm-api", "embarkjs-whisper", + "ipfs-api", + "embarkjs-ipfs", "rxjs", "rxjs/operators", ], diff --git a/packages/embark/src/lib/modules/ipfs/index.js b/packages/embark/src/lib/modules/ipfs/index.js index 5ecc32a4b..9c09f59bd 100644 --- a/packages/embark/src/lib/modules/ipfs/index.js +++ b/packages/embark/src/lib/modules/ipfs/index.js @@ -1,6 +1,5 @@ const UploadIPFS = require('./upload.js'); const utils = require('../../utils/utils.js'); -import {joinPath} from 'embark-utils'; const IpfsApi = require('ipfs-api'); // TODO: not great, breaks module isolation const StorageProcessesLauncher = require('../storage/storageProcessesLauncher'); @@ -105,16 +104,16 @@ class IPFS { return this.logger.error(err.message || err); } this.events.request('code-generator:ready', () => { - this.events.request('code-generator:symlink:generate', location, 'ipfs-api', (err, symlinkDest) => { + this.events.request('code-generator:symlink:generate', location, 'ipfs-api', (err, _symlinkDest) => { if (err) { this.logger.error(__('Error creating a symlink to IPFS API')); return this.logger.error(err.message || err); } this.events.emit('runcode:register', 'IpfsApi', require('ipfs-api'), () => { - let code = `\nconst IpfsApi = global.IpfsApi || require('${symlinkDest}');`; - code += "\n" + this.fs.readFileSync(joinPath(__dirname, 'embarkjs.js')).toString(); - code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS);"; + let code = ""; + code += "\nconst __embarkIPFS = require('embarkjs-ipfs')"; + code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);"; this.embark.addCodeToEmbarkJS(code); this.embark.addConsoleProviderInit("storage", code, (storageConfig) => storageConfig.enabled); diff --git a/packages/embarkjs-ipfs/.babelrc.js b/packages/embarkjs-ipfs/.babelrc.js new file mode 100644 index 000000000..787135151 --- /dev/null +++ b/packages/embarkjs-ipfs/.babelrc.js @@ -0,0 +1,46 @@ +/* global module require */ + +const cloneDeep = require('lodash.clonedeep'); + +module.exports = (api) => { + const env = api.env(); + + const base = {}; + + const browser = cloneDeep(base); + Object.assign(browser, { + ignore: [ + 'src/embarkjs.js', + 'src/node/index.js' + ] + }); + + const node = cloneDeep(base); + Object.assign(node, { + ignore: [ + 'src/browser.js' + ] + }); + + const nodeAsync = cloneDeep(base); + Object.assign(nodeAsync, { + ignore: [ + 'src/node/index.js' + ] + }); + + const nodeTest = cloneDeep(base); + + switch (env) { + case 'browser': + return browser; + case 'node': + return node; + case 'node:async': + return nodeAsync; + case 'node:test': + return nodeTest; + default: + return base; + } +}; diff --git a/packages/embarkjs-ipfs/.gitignore b/packages/embarkjs-ipfs/.gitignore new file mode 100644 index 000000000..b6420126f --- /dev/null +++ b/packages/embarkjs-ipfs/.gitignore @@ -0,0 +1 @@ +build-test diff --git a/packages/embarkjs-ipfs/.npmrc b/packages/embarkjs-ipfs/.npmrc new file mode 100644 index 000000000..e031d3432 --- /dev/null +++ b/packages/embarkjs-ipfs/.npmrc @@ -0,0 +1,4 @@ +engine-strict = true +package-lock = false +save-exact = true +scripts-prepend-node-path = true diff --git a/packages/embarkjs-ipfs/README.md b/packages/embarkjs-ipfs/README.md new file mode 100644 index 000000000..1bd3dccf5 --- /dev/null +++ b/packages/embarkjs-ipfs/README.md @@ -0,0 +1,6 @@ +# `embarkjs-ipfs` + +embarkjs plugin to interact with ipfs + +Visit [embark.status.im](https://embark.status.im/) to get started with +[Embark](https://github.com/embark-framework/embark). diff --git a/packages/embarkjs-ipfs/package.json b/packages/embarkjs-ipfs/package.json new file mode 100644 index 000000000..0a24c7679 --- /dev/null +++ b/packages/embarkjs-ipfs/package.json @@ -0,0 +1,73 @@ +{ + "name": "embarkjs-ipfs", + "version": "4.0.0", + "author": "Iuri Matias ", + "contributors": [], + "description": "Ipfs plugin for embarkjs", + "homepage": "https://github.com/embark-framework/embark/tree/master/packages/embarkjs-ipfs#readme", + "bugs": "https://github.com/embark-framework/embark/issues", + "keywords": [ + "blockchain", + "dapps", + "ethereum", + "ipfs", + "serverless", + "solc", + "solidity" + ], + "license": "MIT", + "repository": { + "directory": "packages/embarkjs-ipfs", + "type": "git", + "url": "https://github.com/embark-framework/embark.git" + }, + "main": "dist/node/index.js", + "browser": { + "./dist/node/index.js": "./dist/browser/index.js" + }, + "browserslist": [ + "last 1 version", + "not dead", + "> 0.2%" + ], + "files": [ + "dist" + ], + "scripts": { + "build": "npm-run-all build:**", + "build:browser": "cross-env BABEL_ENV=browser babel src --out-dir dist/browser --root-mode upward", + "build:node": "cross-env BABEL_ENV=node babel src --out-dir dist --root-mode upward --source-maps", + "build:node:async": "cross-env BABEL_ENV=node:async babel src/node --out-dir dist --root-mode upward --source-maps", + "// build:node:test": "cross-env BABEL_ENV=node:test babel test --out-dir build-test --root-mode upward --source-maps", + "ci": "npm run qa", + "clean": "npm run reset", + "package": "npm pack", + "// qa": "npm-run-all build test package", + "qa": "npm-run-all build package", + "reset": "npx rimraf build-test dist embarkjs-*.tgz package", + "start": "npm run watch", + "test": "mocha \"build-test/**/*.js\" --exit --no-timeouts --require source-map-support/register", + "watch": "run-p \"build:** -- --verbose --watch\"" + }, + "dependencies": { + "@babel/runtime-corejs2": "7.3.1", + "ipfs-api": "17.2.4" + }, + "devDependencies": { + "@babel/cli": "7.2.3", + "@babel/core": "7.2.2", + "ajv": "6.5.2", + "chai": "4.2.0", + "cross-env": "5.2.0", + "lodash.clonedeep": "4.5.0", + "mocha": "5.2.0", + "npm-run-all": "4.1.5", + "rimraf": "2.6.3", + "source-map-support": "0.5.9" + }, + "engines": { + "node": ">=8.12.0", + "npm": ">=6.4.1", + "yarn": ">=1.12.3" + } +} diff --git a/packages/embarkjs-ipfs/src/embarkjs.js b/packages/embarkjs-ipfs/src/embarkjs.js new file mode 100644 index 000000000..eb6ba4c77 --- /dev/null +++ b/packages/embarkjs-ipfs/src/embarkjs.js @@ -0,0 +1 @@ +export {default} from './index'; diff --git a/packages/embark/src/lib/modules/ipfs/embarkjs.js b/packages/embarkjs-ipfs/src/index.js similarity index 98% rename from packages/embark/src/lib/modules/ipfs/embarkjs.js rename to packages/embarkjs-ipfs/src/index.js index 7a4b30cd9..5a545c260 100644 --- a/packages/embark/src/lib/modules/ipfs/embarkjs.js +++ b/packages/embarkjs-ipfs/src/index.js @@ -1,4 +1,4 @@ -/*global IpfsApi*/ +const IpfsApi = require('ipfs-api'); const __embarkIPFS = {}; @@ -146,3 +146,5 @@ __embarkIPFS.register = function(addr, callback) { callback(addr + " could not be registered"); }); }; + +export default __embarkIPFS; diff --git a/packages/embarkjs-ipfs/src/node/index.js b/packages/embarkjs-ipfs/src/node/index.js new file mode 100644 index 000000000..a61b612f1 --- /dev/null +++ b/packages/embarkjs-ipfs/src/node/index.js @@ -0,0 +1 @@ +module.exports = require('../embarkjs').default;