From db9fbef140d9383ebb6b9a8e916bf4d6cab540aa Mon Sep 17 00:00:00 2001 From: emizzle Date: Tue, 22 May 2018 15:15:34 +1000 Subject: [PATCH] Add loading placeholder page while embark is building asset files. We could extend this further to launch the webserver with the placeholder page before building the contracts as well. --- lib/core/fs.js | 5 +++++ lib/i18n/locales/en.json | 3 ++- lib/pipeline/pipeline.js | 48 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/core/fs.js b/lib/core/fs.js index 84fb6bdf4..6dbc12285 100644 --- a/lib/core/fs.js +++ b/lib/core/fs.js @@ -19,6 +19,10 @@ function copySync() { return fs.copySync.apply(fs.copySync, arguments); } +function move(){ + return fs.move.apply(fs.move, arguments); +} + function appendFileSync() { return fs.appendFileSync.apply(fs.writeFileSync, arguments); } @@ -87,6 +91,7 @@ module.exports = { mkdirp, copy, copySync, + move, readFile, readFileSync, appendFileSync, diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index 81f2aa879..458d22bdf 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -104,5 +104,6 @@ "Ethereum node (version unknown)": "Ethereum node (version unknown)", "No Blockchain node found": "No Blockchain node found", "Couldn't connect to an Ethereum node are you sure it's on?": "Couldn't connect to an Ethereum node are you sure it's on?", - "make sure you have an Ethereum node or simulator running. e.g '%s'": "make sure you have an Ethereum node or simulator running. e.g '%s'" + "make sure you have an Ethereum node or simulator running. e.g '%s'": "make sure you have an Ethereum node or simulator running. e.g '%s'", + "Embark is building, please wait...": "Embark is building, please wait..." } \ No newline at end of file diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 5bcea392c..4f74a6692 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -4,6 +4,7 @@ const ProcessLauncher = require('../process/processLauncher'); const utils = require('../utils/utils.js'); const constants = require('../constants'); + require("babel-preset-react"); require("babel-preset-es2015"); require("babel-preset-es2016"); @@ -25,8 +26,41 @@ class Pipeline { build(abi, contractsJSON, path, callback) { let self = this; const importsList = {}; + let placeholderPage; async.waterfall([ + function createPlaceholderPage(next){ + let html = ` + + + + ${__('Embark is building, please wait...')} + + + + +
+
+
+
+
+
+ + + + + + + + + +

${__('Embark is building, please wait...')}

+ + `; + fs.writeFile(self.buildDir + 'index.html', html, next); + }, function buildTheContracts(next) { self.buildContracts(next); }, @@ -141,11 +175,25 @@ class Pipeline { }).join("\n"); self.logger.info(__("writing file") + " " + (self.buildDir + targetFile).bold.dim); + if(new RegExp(/^index.html?/i).test(targetFile)){ + targetFile = targetFile.replace('index', 'index-temp'); + placeholderPage = targetFile; + } fs.writeFile(self.buildDir + targetFile, content, cb); } ); }, next); + }, + function removePlaceholderPage(next){ + let placeholderFile = self.buildDir + placeholderPage; + fs.access(self.buildDir + placeholderPage, (err) => { + if (err) return next(); // index-temp doesn't exist, do nothing + + // rename index-temp.htm/l to index.htm/l, effectively replacing our placeholder page + // with the contents of the built index.html page + fs.move(placeholderFile, placeholderFile.replace('index-temp', 'index'), {overwrite: true}, next); + }); } ], callback); }