Skip to content

Commit

Permalink
feat: add jams support
Browse files Browse the repository at this point in the history
  • Loading branch information
lonerapier committed May 20, 2022
1 parent 16a68b5 commit 4fd2ab3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
};
exports.__esModule = true;
exports.putIpfsJson = exports.getIpfsJson = exports.Dapp = exports.PackBuilder = exports.builder = exports.load = void 0;
var fs_1 = require("fs");
var jams_js_1 = require("jams.js");
var builder_1 = require("./src/builder");
exports.PackBuilder = builder_1.PackBuilder;
var dapp_1 = require("./src/dapp");
Expand All @@ -60,7 +62,7 @@ var load = function (arg, _ethers, _signer) {
_a = _b.sent();
return [3 /*break*/, 3];
case 2:
_a = require(arg);
_a = (arg.split('.').pop() === 'jams') ? (0, jams_js_1.jams)((0, fs_1.readFileSync)(arg)) : require(arg);
_b.label = 3;
case 3:
arg = _a;
Expand Down
10 changes: 8 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { readFileSync } from 'fs'
import { jams } from 'jams.js'
import { PackBuilder } from './src/builder'
import { Dapp } from './src/dapp'
import { getIpfsJson, putIpfsJson, isCid } from './src/ipfs-util'
import { need } from './src/util'

export const load = async (arg, _ethers = undefined, _signer = undefined) => {
if (typeof arg === 'string') {
arg = (isCid(arg)) ? await getIpfsJson(arg) : require(arg)
if (typeof arg === "string") {
arg = isCid(arg)
? await getIpfsJson(arg)
: arg.split(".").pop() === "jams"
? jams(readFileSync(arg))
: require(arg);
}
need(typeof arg === 'object' && Object.keys(arg).length, 'Could not find a pack from provided source.')
return await Dapp.loadFromPack(arg, _ethers, _signer)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"debug": "^4.3.2",
"ethers": "^5.4.5",
"ipfs-http-client": "^55.0.0",
"jams.js": "^0.0.7",
"multiformats": "^9.6.4"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "jams.js"

0 comments on commit 4fd2ab3

Please sign in to comment.