feature(@embark/embarkjs-ipfs: make embarkjs ipfs plugin a module on its own

This commit is contained in:
Iuri Matias 2019-03-29 17:16:26 -04:00
parent d71352b781
commit c87284f72a
11 changed files with 142 additions and 6 deletions

View File

@ -96,6 +96,7 @@
"embark-utils": "^4.0.0", "embark-utils": "^4.0.0",
"embark-webserver": "^4.0.0", "embark-webserver": "^4.0.0",
"embarkjs": "^4.0.0", "embarkjs": "^4.0.0",
"embarkjs-ipfs": "^4.0.0",
"eth-ens-namehash": "2.0.8", "eth-ens-namehash": "2.0.8",
"ethereumjs-tx": "1.3.7", "ethereumjs-tx": "1.3.7",
"ethereumjs-util": "6.0.0", "ethereumjs-util": "6.0.0",

View File

@ -42,6 +42,8 @@ class VM {
"eth-ens-namehash", "eth-ens-namehash",
"swarm-api", "swarm-api",
"embarkjs-whisper", "embarkjs-whisper",
"ipfs-api",
"embarkjs-ipfs",
"rxjs", "rxjs",
"rxjs/operators", "rxjs/operators",
], ],

View File

@ -1,6 +1,5 @@
const UploadIPFS = require('./upload.js'); const UploadIPFS = require('./upload.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
import {joinPath} from 'embark-utils';
const IpfsApi = require('ipfs-api'); const IpfsApi = require('ipfs-api');
// TODO: not great, breaks module isolation // TODO: not great, breaks module isolation
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher'); const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
@ -105,16 +104,16 @@ class IPFS {
return this.logger.error(err.message || err); return this.logger.error(err.message || err);
} }
this.events.request('code-generator:ready', () => { 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) { if (err) {
this.logger.error(__('Error creating a symlink to IPFS API')); this.logger.error(__('Error creating a symlink to IPFS API'));
return this.logger.error(err.message || err); return this.logger.error(err.message || err);
} }
this.events.emit('runcode:register', 'IpfsApi', require('ipfs-api'), () => { this.events.emit('runcode:register', 'IpfsApi', require('ipfs-api'), () => {
let code = `\nconst IpfsApi = global.IpfsApi || require('${symlinkDest}');`; let code = "";
code += "\n" + this.fs.readFileSync(joinPath(__dirname, 'embarkjs.js')).toString(); code += "\nconst __embarkIPFS = require('embarkjs-ipfs')";
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS);"; code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS.default || __embarkIPFS);";
this.embark.addCodeToEmbarkJS(code); this.embark.addCodeToEmbarkJS(code);
this.embark.addConsoleProviderInit("storage", code, (storageConfig) => storageConfig.enabled); this.embark.addConsoleProviderInit("storage", code, (storageConfig) => storageConfig.enabled);

View File

@ -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;
}
};

1
packages/embarkjs-ipfs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build-test

View File

@ -0,0 +1,4 @@
engine-strict = true
package-lock = false
save-exact = true
scripts-prepend-node-path = true

View File

@ -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).

View File

@ -0,0 +1,73 @@
{
"name": "embarkjs-ipfs",
"version": "4.0.0",
"author": "Iuri Matias <iuri.matias@gmail.com>",
"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"
}
}

View File

@ -0,0 +1 @@
export {default} from './index';

View File

@ -1,4 +1,4 @@
/*global IpfsApi*/ const IpfsApi = require('ipfs-api');
const __embarkIPFS = {}; const __embarkIPFS = {};
@ -146,3 +146,5 @@ __embarkIPFS.register = function(addr, callback) {
callback(addr + " could not be registered"); callback(addr + " could not be registered");
}); });
}; };
export default __embarkIPFS;

View File

@ -0,0 +1 @@
module.exports = require('../embarkjs').default;