mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-02 17:03:36 +00:00
make pipeline js in a different process (still doesnt work)
This commit is contained in:
parent
204684ef07
commit
148a74f3d6
@ -15,5 +15,12 @@
|
|||||||
"events": {
|
"events": {
|
||||||
"contractFilesChanged": "contractFilesChanged",
|
"contractFilesChanged": "contractFilesChanged",
|
||||||
"contractConfigChanged": "contractConfigChanged"
|
"contractConfigChanged": "contractConfigChanged"
|
||||||
|
},
|
||||||
|
"pipeline": {
|
||||||
|
"init": "init",
|
||||||
|
"build": "build",
|
||||||
|
"initiated": "initiated",
|
||||||
|
"built": "built",
|
||||||
|
"log": "log"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
let Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
let Events = require('./events.js');
|
const Events = require('./events.js');
|
||||||
let Logger = require('./logger.js');
|
const Logger = require('./logger.js');
|
||||||
let Config = require('./config.js');
|
const Config = require('./config.js');
|
||||||
let ContractsManager = require('../contracts/contracts.js');
|
const ContractsManager = require('../contracts/contracts.js');
|
||||||
let DeployManager = require('../contracts/deploy_manager.js');
|
const DeployManager = require('../contracts/deploy_manager.js');
|
||||||
let CodeGenerator = require('../contracts/code_generator.js');
|
const CodeGenerator = require('../contracts/code_generator.js');
|
||||||
let ServicesMonitor = require('./services_monitor.js');
|
const ServicesMonitor = require('./services_monitor.js');
|
||||||
let Pipeline = require('../pipeline/pipeline.js');
|
const Watch = require('../pipeline/watch.js');
|
||||||
let Watch = require('../pipeline/watch.js');
|
const LibraryManager = require('../versions/library_manager.js');
|
||||||
let LibraryManager = require('../versions/library_manager.js');
|
const utils = require('../utils/utils');
|
||||||
|
const constants = require('../constants');
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -41,46 +42,46 @@ class Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
normalizeInput(input) {
|
||||||
|
let args = Object.values(input);
|
||||||
|
if (args.length === 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (args.length === 1) {
|
||||||
|
if (Array.isArray(args[0])) { return args[0].join(','); }
|
||||||
|
return args[0] || "";
|
||||||
|
}
|
||||||
|
return ('[' + args.map((x) => {
|
||||||
|
if (x === null) { return "null"; }
|
||||||
|
if (x === undefined) { return "undefined"; }
|
||||||
|
if (Array.isArray(x)) { return x.join(','); }
|
||||||
|
return x;
|
||||||
|
}).toString() + ']');
|
||||||
|
}
|
||||||
|
|
||||||
doInterceptLogs() {
|
doInterceptLogs() {
|
||||||
var self = this;
|
var self = this;
|
||||||
let context = {};
|
let context = {};
|
||||||
context.console = console;
|
context.console = console;
|
||||||
|
|
||||||
let normalizeInput = function(input) {
|
|
||||||
let args = Object.values(input);
|
|
||||||
if (args.length === 0) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
if (args.length === 1) {
|
|
||||||
if (Array.isArray(args[0])) { return args[0].join(','); }
|
|
||||||
return args[0] || "";
|
|
||||||
}
|
|
||||||
return ('[' + args.map((x) => {
|
|
||||||
if (x === null) { return "null"; }
|
|
||||||
if (x === undefined) { return "undefined"; }
|
|
||||||
if (Array.isArray(x)) { return x.join(','); }
|
|
||||||
return x;
|
|
||||||
}).toString() + ']');
|
|
||||||
};
|
|
||||||
|
|
||||||
context.console.log = function() {
|
context.console.log = function() {
|
||||||
self.logger.info(normalizeInput(arguments));
|
self.logger.info(self.normalizeInput(arguments));
|
||||||
};
|
};
|
||||||
context.console.warn = function() {
|
context.console.warn = function() {
|
||||||
self.logger.warn(normalizeInput(arguments));
|
self.logger.warn(self.normalizeInput(arguments));
|
||||||
};
|
};
|
||||||
context.console.info = function() {
|
context.console.info = function() {
|
||||||
self.logger.info(normalizeInput(arguments));
|
self.logger.info(self.normalizeInput(arguments));
|
||||||
};
|
};
|
||||||
context.console.debug = function() {
|
context.console.debug = function() {
|
||||||
// TODO: ue JSON.stringify
|
// TODO: ue JSON.stringify
|
||||||
self.logger.debug(normalizeInput(arguments));
|
self.logger.debug(self.normalizeInput(arguments));
|
||||||
};
|
};
|
||||||
context.console.trace = function() {
|
context.console.trace = function() {
|
||||||
self.logger.trace(normalizeInput(arguments));
|
self.logger.trace(self.normalizeInput(arguments));
|
||||||
};
|
};
|
||||||
context.console.dir = function() {
|
context.console.dir = function() {
|
||||||
self.logger.dir(normalizeInput(arguments));
|
self.logger.dir(self.normalizeInput(arguments));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,25 +133,36 @@ class Engine {
|
|||||||
|
|
||||||
pipelineService(_options) {
|
pipelineService(_options) {
|
||||||
let self = this;
|
let self = this;
|
||||||
this.events.emit("status", "Building Assets");
|
self.events.emit("status", "Building Assets");
|
||||||
let pipeline = new Pipeline({
|
const pipelineProcess = require('child_process').fork(utils.joinPath(__dirname, '../pipeline/pipeline.js'));
|
||||||
buildDir: this.config.buildDir,
|
|
||||||
contractsFiles: this.config.contractsFiles,
|
pipelineProcess.send({action: constants.pipeline.init, options: {
|
||||||
assetFiles: this.config.assetFiles,
|
buildDir: self.config.buildDir,
|
||||||
events: this.events,
|
contractsFiles: self.config.contractsFiles,
|
||||||
logger: this.logger,
|
assetFiles: self.config.assetFiles,
|
||||||
plugins: this.plugins
|
events: self.events,
|
||||||
|
pipelinePlugins: self.plugins.getPluginsFor('pipeline'),
|
||||||
|
pluginImports: self.plugins.getPluginsProperty('imports', 'imports')
|
||||||
|
}});
|
||||||
|
|
||||||
|
pipelineProcess.on('message', function (msg) {
|
||||||
|
if (msg.result === constants.pipeline.built) {
|
||||||
|
if (self.watch) {
|
||||||
|
self.watch.restart(); // Necessary because changing a file while it is writing can stop it from being watched
|
||||||
|
}
|
||||||
|
return self.events.emit('outputDone');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.result === constants.pipeline.log) {
|
||||||
|
self.logger.debug(self.normalizeInput(msg.message));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.events.on('code-generator-ready', function () {
|
|
||||||
|
self.events.on('code-generator-ready', function () {
|
||||||
self.events.request('code', function (abi, contractsJSON) {
|
self.events.request('code', function (abi, contractsJSON) {
|
||||||
self.currentAbi = abi;
|
self.currentAbi = abi;
|
||||||
self.contractsJSON = contractsJSON;
|
self.contractsJSON = contractsJSON;
|
||||||
pipeline.build(abi, contractsJSON, null, function() {
|
pipelineProcess.send({action: constants.pipeline.build, abi, contractsJSON, path: null});
|
||||||
if (self.watch) {
|
|
||||||
self.watch.restart(); // Necessary because changing a file while it is writing can stop it from being watched
|
|
||||||
}
|
|
||||||
self.events.emit('outputDone');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
let fs = require('../core/fs.js');
|
const fs = require('../core/fs.js');
|
||||||
let async = require('async');
|
const async = require('async');
|
||||||
var utils = require('../utils/utils.js');
|
const utils = require('../utils/utils.js');
|
||||||
const webpack = require("webpack");
|
const webpack = require("webpack");
|
||||||
|
const constants = require('../constants');
|
||||||
|
|
||||||
require("babel-preset-react");
|
require("babel-preset-react");
|
||||||
require("babel-preset-es2015");
|
require("babel-preset-es2015");
|
||||||
require("babel-preset-es2016");
|
require("babel-preset-es2016");
|
||||||
require("babel-preset-es2017");
|
require("babel-preset-es2017");
|
||||||
|
|
||||||
|
let pipeline;
|
||||||
|
|
||||||
class Pipeline {
|
class Pipeline {
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -15,8 +18,26 @@ class Pipeline {
|
|||||||
this.contractsFiles = options.contractsFiles;
|
this.contractsFiles = options.contractsFiles;
|
||||||
this.assetFiles = options.assetFiles;
|
this.assetFiles = options.assetFiles;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.logger = options.logger;
|
this.pipelinePlugins = options.pipelinePlugins;
|
||||||
this.plugins = options.plugins;
|
this.pluginImports = options.pluginImports;
|
||||||
|
|
||||||
|
this.interceptLogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
interceptLogs() {
|
||||||
|
const context = {};
|
||||||
|
context.console = console;
|
||||||
|
|
||||||
|
context.console.log = this.log;
|
||||||
|
context.console.warn = this.log;
|
||||||
|
context.console.info = this.log;
|
||||||
|
context.console.debug = this.log;
|
||||||
|
context.console.trace = this.log;
|
||||||
|
context.console.dir = this.log;
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
process.send({result: constants.pipeline.log, message: arguments});
|
||||||
}
|
}
|
||||||
|
|
||||||
build(abi, contractsJSON, path, callback) {
|
build(abi, contractsJSON, path, callback) {
|
||||||
@ -31,7 +52,7 @@ class Pipeline {
|
|||||||
importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.js');
|
importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.js');
|
||||||
importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js');
|
importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js');
|
||||||
|
|
||||||
self.plugins.getPluginsProperty('imports', 'imports').forEach(function (importObject) {
|
self.pluginImports.forEach(function (importObject) {
|
||||||
let [importName, importLocation] = importObject;
|
let [importName, importLocation] = importObject;
|
||||||
importsList[importName] = importLocation;
|
importsList[importName] = importLocation;
|
||||||
});
|
});
|
||||||
@ -48,7 +69,7 @@ class Pipeline {
|
|||||||
// limit:1 due to issues when downloading required files such as web3.js
|
// limit:1 due to issues when downloading required files such as web3.js
|
||||||
async.mapLimit(files, 1,
|
async.mapLimit(files, 1,
|
||||||
function(file, fileCb) {
|
function(file, fileCb) {
|
||||||
self.logger.trace("reading " + file.filename);
|
self.log("reading " + file.filename);
|
||||||
|
|
||||||
if (file.filename.indexOf('.js') >= 0) {
|
if (file.filename.indexOf('.js') >= 0) {
|
||||||
|
|
||||||
@ -98,11 +119,11 @@ class Pipeline {
|
|||||||
], function(err, _result) {
|
], function(err, _result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
process.chdir(realCwd);
|
process.chdir(realCwd);
|
||||||
self.logger.error(err);
|
self.log(err);
|
||||||
return fileCb(err);
|
return fileCb(err);
|
||||||
}
|
}
|
||||||
if (!fs.existsSync('./.embark/' + file.filename)) {
|
if (!fs.existsSync('./.embark/' + file.filename)) {
|
||||||
self.logger.error("couldn't find file: " + file.filename);
|
self.log("couldn't find file: " + file.filename);
|
||||||
return fileCb("couldn't find file: " + file.filename);
|
return fileCb("couldn't find file: " + file.filename);
|
||||||
}
|
}
|
||||||
let fileContent = fs.readFileSync('./.embark/' + file.filename).toString();
|
let fileContent = fs.readFileSync('./.embark/' + file.filename).toString();
|
||||||
@ -116,10 +137,10 @@ class Pipeline {
|
|||||||
},
|
},
|
||||||
function (err, contentFiles) {
|
function (err, contentFiles) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.warn('errors found while generating ' + targetFile);
|
self.log('errors found while generating ' + targetFile);
|
||||||
}
|
}
|
||||||
let dir = targetFile.split('/').slice(0, -1).join('/');
|
let dir = targetFile.split('/').slice(0, -1).join('/');
|
||||||
self.logger.trace("creating dir " + self.buildDir + dir);
|
self.log("creating dir " + self.buildDir + dir);
|
||||||
fs.mkdirpSync(self.buildDir + dir);
|
fs.mkdirpSync(self.buildDir + dir);
|
||||||
|
|
||||||
// if it's a directory
|
// if it's a directory
|
||||||
@ -132,7 +153,7 @@ class Pipeline {
|
|||||||
|
|
||||||
contentFiles.map(function (file) {
|
contentFiles.map(function (file) {
|
||||||
let filename = file.filename.replace(file.basedir + '/', '');
|
let filename = file.filename.replace(file.basedir + '/', '');
|
||||||
self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim);
|
self.log("writing file " + (self.buildDir + targetDir + filename).bold.dim);
|
||||||
|
|
||||||
fs.copySync(file.path, self.buildDir + targetDir + filename, {overwrite: true});
|
fs.copySync(file.path, self.buildDir + targetDir + filename, {overwrite: true});
|
||||||
});
|
});
|
||||||
@ -144,7 +165,7 @@ class Pipeline {
|
|||||||
return file.content;
|
return file.content;
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
|
|
||||||
self.logger.info("writing file " + (self.buildDir + targetFile).bold.dim);
|
self.log("writing file " + (self.buildDir + targetFile).bold.dim);
|
||||||
fs.writeFileSync(self.buildDir + targetFile, content);
|
fs.writeFileSync(self.buildDir + targetFile, content);
|
||||||
}
|
}
|
||||||
cb();
|
cb();
|
||||||
@ -159,11 +180,10 @@ class Pipeline {
|
|||||||
|
|
||||||
runPlugins(file, fileContent, fileCb) {
|
runPlugins(file, fileContent, fileCb) {
|
||||||
const self = this;
|
const self = this;
|
||||||
let pipelinePlugins = self.plugins.getPluginsFor('pipeline');
|
if (self.pipelinePlugins.length <= 0) {
|
||||||
if (pipelinePlugins.length <= 0) {
|
|
||||||
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
||||||
}
|
}
|
||||||
async.eachSeries(pipelinePlugins,
|
async.eachSeries(self.pipelinePlugins,
|
||||||
function(plugin, pluginCB) {
|
function(plugin, pluginCB) {
|
||||||
if (file.options && file.options.skipPipeline) {
|
if (file.options && file.options.skipPipeline) {
|
||||||
return pluginCB();
|
return pluginCB();
|
||||||
@ -175,7 +195,7 @@ class Pipeline {
|
|||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.error(err.message);
|
self.log(err.message);
|
||||||
}
|
}
|
||||||
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, basedir: file.basedir, modified: true});
|
||||||
}
|
}
|
||||||
@ -317,4 +337,21 @@ class Pipeline {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Pipeline;
|
|
||||||
|
process.on('message', (msg) => {
|
||||||
|
if (msg.action === constants.pipeline.init) {
|
||||||
|
pipeline = new Pipeline(msg.options);
|
||||||
|
return process.send({result: constants.pipeline.initiated});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.action === constants.pipeline.build) {
|
||||||
|
return pipeline.build(msg.abi, msg.contractsJSON, msg.path, (err, result) => {
|
||||||
|
process.send({result: constants.pipeline.built, error: err, data: result});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
process.on('exit', () => {
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
10
package-lock.json
generated
10
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "embark",
|
"name": "embark",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -6056,9 +6056,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"minipass": {
|
"minipass": {
|
||||||
"version": "2.2.4",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.0.tgz",
|
||||||
"integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==",
|
"integrity": "sha512-jWC2Eg+Np4bxah7llu1IrUNSJQxtLz/J+pOjTM0nFpJXGAaV18XBWhUn031Q1tAA/TJtA1jgwnOe9S2PQa4Lbg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"safe-buffer": "5.1.2",
|
"safe-buffer": "5.1.2",
|
||||||
"yallist": "3.0.2"
|
"yallist": "3.0.2"
|
||||||
@ -6076,7 +6076,7 @@
|
|||||||
"requires": {
|
"requires": {
|
||||||
"chownr": "1.0.1",
|
"chownr": "1.0.1",
|
||||||
"fs-minipass": "1.2.5",
|
"fs-minipass": "1.2.5",
|
||||||
"minipass": "2.2.4",
|
"minipass": "2.3.0",
|
||||||
"minizlib": "1.1.0",
|
"minizlib": "1.1.0",
|
||||||
"mkdirp": "0.5.1",
|
"mkdirp": "0.5.1",
|
||||||
"safe-buffer": "5.1.2",
|
"safe-buffer": "5.1.2",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user