From 0bdafc273fceec02437be49ab017b71b436b14ac Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Fri, 21 Sep 2018 16:52:28 -0400 Subject: [PATCH] Fetch IPFS dir hash deterministically --- lib/modules/ipfs/upload.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/modules/ipfs/upload.js b/lib/modules/ipfs/upload.js index 23b410f55..b53cde3d0 100644 --- a/lib/modules/ipfs/upload.js +++ b/lib/modules/ipfs/upload.js @@ -2,8 +2,9 @@ require('colors'); let async = require('async'); let shelljs = require('shelljs'); -class IPFS { +const path = require('path'); +class IPFS { constructor(options) { this.options = options; this.buildDir = options.buildDir || 'dist/'; @@ -35,11 +36,11 @@ class IPFS { }); }, function getHashFromOutput(result, callback) { - let rows = result.split("\n"); - let dir_row = rows[rows.length - 2]; - let dir_hash = dir_row.split(" ")[1]; + const pattern = `added ([a-zA-Z1-9]{46}) ${path.basename(self.buildDir)}\n`; + const regex = RegExp(pattern, 'm'); + const dirHash = result.match(regex)[1]; - callback(null, dir_hash); + callback(null, dirHash); }, function printUrls(dir_hash, callback) { console.log(("=== " + __("DApp available at") + " http://localhost:8080/ipfs/" + dir_hash + "/").green);