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": {
|
||||
"contractFilesChanged": "contractFilesChanged",
|
||||
"contractConfigChanged": "contractConfigChanged"
|
||||
},
|
||||
"pipeline": {
|
||||
"init": "init",
|
||||
"build": "build",
|
||||
"initiated": "initiated",
|
||||
"built": "built",
|
||||
"log": "log"
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
let Web3 = require('web3');
|
||||
let Events = require('./events.js');
|
||||
let Logger = require('./logger.js');
|
||||
let Config = require('./config.js');
|
||||
let ContractsManager = require('../contracts/contracts.js');
|
||||
let DeployManager = require('../contracts/deploy_manager.js');
|
||||
let CodeGenerator = require('../contracts/code_generator.js');
|
||||
let ServicesMonitor = require('./services_monitor.js');
|
||||
let Pipeline = require('../pipeline/pipeline.js');
|
||||
let Watch = require('../pipeline/watch.js');
|
||||
let LibraryManager = require('../versions/library_manager.js');
|
||||
const Web3 = require('web3');
|
||||
const Events = require('./events.js');
|
||||
const Logger = require('./logger.js');
|
||||
const Config = require('./config.js');
|
||||
const ContractsManager = require('../contracts/contracts.js');
|
||||
const DeployManager = require('../contracts/deploy_manager.js');
|
||||
const CodeGenerator = require('../contracts/code_generator.js');
|
||||
const ServicesMonitor = require('./services_monitor.js');
|
||||
const Watch = require('../pipeline/watch.js');
|
||||
const LibraryManager = require('../versions/library_manager.js');
|
||||
const utils = require('../utils/utils');
|
||||
const constants = require('../constants');
|
||||
|
||||
class Engine {
|
||||
constructor(options) {
|
||||
@ -41,12 +42,7 @@ class Engine {
|
||||
}
|
||||
}
|
||||
|
||||
doInterceptLogs() {
|
||||
var self = this;
|
||||
let context = {};
|
||||
context.console = console;
|
||||
|
||||
let normalizeInput = function(input) {
|
||||
normalizeInput(input) {
|
||||
let args = Object.values(input);
|
||||
if (args.length === 0) {
|
||||
return "";
|
||||
@ -61,26 +57,31 @@ class Engine {
|
||||
if (Array.isArray(x)) { return x.join(','); }
|
||||
return x;
|
||||
}).toString() + ']');
|
||||
};
|
||||
}
|
||||
|
||||
doInterceptLogs() {
|
||||
var self = this;
|
||||
let context = {};
|
||||
context.console = console;
|
||||
|
||||
context.console.log = function() {
|
||||
self.logger.info(normalizeInput(arguments));
|
||||
self.logger.info(self.normalizeInput(arguments));
|
||||
};
|
||||
context.console.warn = function() {
|
||||
self.logger.warn(normalizeInput(arguments));
|
||||
self.logger.warn(self.normalizeInput(arguments));
|
||||
};
|
||||
context.console.info = function() {
|
||||
self.logger.info(normalizeInput(arguments));
|
||||
self.logger.info(self.normalizeInput(arguments));
|
||||
};
|
||||
context.console.debug = function() {
|
||||
// TODO: ue JSON.stringify
|
||||
self.logger.debug(normalizeInput(arguments));
|
||||
self.logger.debug(self.normalizeInput(arguments));
|
||||
};
|
||||
context.console.trace = function() {
|
||||
self.logger.trace(normalizeInput(arguments));
|
||||
self.logger.trace(self.normalizeInput(arguments));
|
||||
};
|
||||
context.console.dir = function() {
|
||||
self.logger.dir(normalizeInput(arguments));
|
||||
self.logger.dir(self.normalizeInput(arguments));
|
||||
};
|
||||
}
|
||||
|
||||
@ -132,25 +133,36 @@ class Engine {
|
||||
|
||||
pipelineService(_options) {
|
||||
let self = this;
|
||||
this.events.emit("status", "Building Assets");
|
||||
let pipeline = new Pipeline({
|
||||
buildDir: this.config.buildDir,
|
||||
contractsFiles: this.config.contractsFiles,
|
||||
assetFiles: this.config.assetFiles,
|
||||
events: this.events,
|
||||
logger: this.logger,
|
||||
plugins: this.plugins
|
||||
});
|
||||
this.events.on('code-generator-ready', function () {
|
||||
self.events.request('code', function (abi, contractsJSON) {
|
||||
self.currentAbi = abi;
|
||||
self.contractsJSON = contractsJSON;
|
||||
pipeline.build(abi, contractsJSON, null, function() {
|
||||
self.events.emit("status", "Building Assets");
|
||||
const pipelineProcess = require('child_process').fork(utils.joinPath(__dirname, '../pipeline/pipeline.js'));
|
||||
|
||||
pipelineProcess.send({action: constants.pipeline.init, options: {
|
||||
buildDir: self.config.buildDir,
|
||||
contractsFiles: self.config.contractsFiles,
|
||||
assetFiles: self.config.assetFiles,
|
||||
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
|
||||
}
|
||||
self.events.emit('outputDone');
|
||||
return self.events.emit('outputDone');
|
||||
}
|
||||
|
||||
if (msg.result === constants.pipeline.log) {
|
||||
self.logger.debug(self.normalizeInput(msg.message));
|
||||
}
|
||||
});
|
||||
|
||||
self.events.on('code-generator-ready', function () {
|
||||
self.events.request('code', function (abi, contractsJSON) {
|
||||
self.currentAbi = abi;
|
||||
self.contractsJSON = contractsJSON;
|
||||
pipelineProcess.send({action: constants.pipeline.build, abi, contractsJSON, path: null});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
let fs = require('../core/fs.js');
|
||||
let async = require('async');
|
||||
var utils = require('../utils/utils.js');
|
||||
const fs = require('../core/fs.js');
|
||||
const async = require('async');
|
||||
const utils = require('../utils/utils.js');
|
||||
const webpack = require("webpack");
|
||||
const constants = require('../constants');
|
||||
|
||||
require("babel-preset-react");
|
||||
require("babel-preset-es2015");
|
||||
require("babel-preset-es2016");
|
||||
require("babel-preset-es2017");
|
||||
|
||||
let pipeline;
|
||||
|
||||
class Pipeline {
|
||||
|
||||
constructor(options) {
|
||||
@ -15,8 +18,26 @@ class Pipeline {
|
||||
this.contractsFiles = options.contractsFiles;
|
||||
this.assetFiles = options.assetFiles;
|
||||
this.events = options.events;
|
||||
this.logger = options.logger;
|
||||
this.plugins = options.plugins;
|
||||
this.pipelinePlugins = options.pipelinePlugins;
|
||||
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) {
|
||||
@ -31,7 +52,7 @@ class Pipeline {
|
||||
importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.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;
|
||||
importsList[importName] = importLocation;
|
||||
});
|
||||
@ -48,7 +69,7 @@ class Pipeline {
|
||||
// limit:1 due to issues when downloading required files such as web3.js
|
||||
async.mapLimit(files, 1,
|
||||
function(file, fileCb) {
|
||||
self.logger.trace("reading " + file.filename);
|
||||
self.log("reading " + file.filename);
|
||||
|
||||
if (file.filename.indexOf('.js') >= 0) {
|
||||
|
||||
@ -98,11 +119,11 @@ class Pipeline {
|
||||
], function(err, _result) {
|
||||
if (err) {
|
||||
process.chdir(realCwd);
|
||||
self.logger.error(err);
|
||||
self.log(err);
|
||||
return fileCb(err);
|
||||
}
|
||||
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);
|
||||
}
|
||||
let fileContent = fs.readFileSync('./.embark/' + file.filename).toString();
|
||||
@ -116,10 +137,10 @@ class Pipeline {
|
||||
},
|
||||
function (err, contentFiles) {
|
||||
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('/');
|
||||
self.logger.trace("creating dir " + self.buildDir + dir);
|
||||
self.log("creating dir " + self.buildDir + dir);
|
||||
fs.mkdirpSync(self.buildDir + dir);
|
||||
|
||||
// if it's a directory
|
||||
@ -132,7 +153,7 @@ class Pipeline {
|
||||
|
||||
contentFiles.map(function (file) {
|
||||
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});
|
||||
});
|
||||
@ -144,7 +165,7 @@ class Pipeline {
|
||||
return file.content;
|
||||
}).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);
|
||||
}
|
||||
cb();
|
||||
@ -159,11 +180,10 @@ class Pipeline {
|
||||
|
||||
runPlugins(file, fileContent, fileCb) {
|
||||
const self = this;
|
||||
let pipelinePlugins = self.plugins.getPluginsFor('pipeline');
|
||||
if (pipelinePlugins.length <= 0) {
|
||||
if (self.pipelinePlugins.length <= 0) {
|
||||
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) {
|
||||
if (file.options && file.options.skipPipeline) {
|
||||
return pluginCB();
|
||||
@ -175,7 +195,7 @@ class Pipeline {
|
||||
},
|
||||
function (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});
|
||||
}
|
||||
@ -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",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -6056,9 +6056,9 @@
|
||||
}
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.2.4",
|
||||
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.2.4.tgz",
|
||||
"integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==",
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.0.tgz",
|
||||
"integrity": "sha512-jWC2Eg+Np4bxah7llu1IrUNSJQxtLz/J+pOjTM0nFpJXGAaV18XBWhUn031Q1tAA/TJtA1jgwnOe9S2PQa4Lbg==",
|
||||
"requires": {
|
||||
"safe-buffer": "5.1.2",
|
||||
"yallist": "3.0.2"
|
||||
@ -6076,7 +6076,7 @@
|
||||
"requires": {
|
||||
"chownr": "1.0.1",
|
||||
"fs-minipass": "1.2.5",
|
||||
"minipass": "2.2.4",
|
||||
"minipass": "2.3.0",
|
||||
"minizlib": "1.1.0",
|
||||
"mkdirp": "0.5.1",
|
||||
"safe-buffer": "5.1.2",
|
||||
|
Loading…
x
Reference in New Issue
Block a user