Fetch IPFS dir hash deterministically

This commit is contained in:
Andre Medeiros 2018-09-21 16:52:28 -04:00
parent 636e5a09ac
commit 0bdafc273f
1 changed files with 6 additions and 5 deletions

View File

@ -2,8 +2,9 @@ require('colors');
let async = require('async'); let async = require('async');
let shelljs = require('shelljs'); let shelljs = require('shelljs');
class IPFS { const path = require('path');
class IPFS {
constructor(options) { constructor(options) {
this.options = options; this.options = options;
this.buildDir = options.buildDir || 'dist/'; this.buildDir = options.buildDir || 'dist/';
@ -35,11 +36,11 @@ class IPFS {
}); });
}, },
function getHashFromOutput(result, callback) { function getHashFromOutput(result, callback) {
let rows = result.split("\n"); const pattern = `added ([a-zA-Z1-9]{46}) ${path.basename(self.buildDir)}\n`;
let dir_row = rows[rows.length - 2]; const regex = RegExp(pattern, 'm');
let dir_hash = dir_row.split(" ")[1]; const dirHash = result.match(regex)[1];
callback(null, dir_hash); callback(null, dirHash);
}, },
function printUrls(dir_hash, callback) { function printUrls(dir_hash, callback) {
console.log(("=== " + __("DApp available at") + " http://localhost:8080/ipfs/" + dir_hash + "/").green); console.log(("=== " + __("DApp available at") + " http://localhost:8080/ipfs/" + dir_hash + "/").green);