mirror of https://github.com/embarklabs/embark.git
cleanup pipeline; start preparing for plugin based pipeline file generation
This commit is contained in:
parent
457badf8b6
commit
15c2381f26
|
@ -219,26 +219,8 @@ class ContractDeployer {
|
|||
this.plugins.runActionsForEvent('deploy:contract:deployed', {contract: contract}, (err) => {
|
||||
callback(err);
|
||||
});
|
||||
// this.registerContract(contract, callback);
|
||||
}
|
||||
|
||||
// TODO: should be done in a module as part of the event registration
|
||||
// registerContract(contract, callback) {
|
||||
// this.events.request('code-generator:contract:custom', contract, (contractCode) => {
|
||||
// this.events.request('runcode:eval', contractCode, (err) => {
|
||||
// if (err) {
|
||||
// return callback(err);
|
||||
// }
|
||||
// this.events.request('runcode:eval', contract.className, (err, result) => {
|
||||
// if (err) {
|
||||
// return callback(err);
|
||||
// }
|
||||
// this.events.emit("runcode:register", contract.className, result, callback);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
logFunction(contract) {
|
||||
return contract.silent ? this.logger.trace.bind(this.logger) : this.logger.info.bind(this.logger);
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ class DeployManager {
|
|||
console.dir("== async.auto");
|
||||
console.dir(Object.keys(contractDeploys));
|
||||
console.dir(contractDeploys);
|
||||
async.auto(contractDeploys, 1, function(_err, _results) {
|
||||
async.auto(contractDeploys, function(_err, _results) {
|
||||
if (_err) {
|
||||
console.dir("error deploying contracts")
|
||||
console.dir(_err)
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
const path = require('path');
|
||||
import { dappPath, fileTreeSort } from 'embark-utils';
|
||||
|
||||
class API {
|
||||
|
||||
constructor(embark, _options) {
|
||||
this.plugins = embark.config.plugins;
|
||||
}
|
||||
|
||||
registerAPIs() {
|
||||
let plugin = this.plugins.createPlugin('deployment', {});
|
||||
plugin.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/file',
|
||||
(req, res) => {
|
||||
try {
|
||||
this.apiGuardBadFile(req.query.path);
|
||||
} catch (error) {
|
||||
return res.send({ error: error.message });
|
||||
}
|
||||
|
||||
const name = path.basename(req.query.path);
|
||||
const content = this.fs.readFileSync(req.query.path, 'utf8');
|
||||
res.send({ name, content, path: req.query.path });
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
'post',
|
||||
'/embark-api/folders',
|
||||
(req, res) => {
|
||||
try {
|
||||
this.apiGuardBadFile(req.body.path);
|
||||
} catch (error) {
|
||||
return res.send({ error: error.message });
|
||||
}
|
||||
|
||||
this.fs.mkdirpSync(req.body.path);
|
||||
const name = path.basename(req.body.path);
|
||||
res.send({ name, path: req.body.path });
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
'post',
|
||||
'/embark-api/files',
|
||||
(req, res) => {
|
||||
try {
|
||||
this.apiGuardBadFile(req.body.path);
|
||||
} catch (error) {
|
||||
return res.send({ error: error.message });
|
||||
}
|
||||
|
||||
this.fs.writeFileSync(req.body.path, req.body.content, { encoding: 'utf8' });
|
||||
const name = path.basename(req.body.path);
|
||||
res.send({ name, path: req.body.path, content: req.body.content });
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
'delete',
|
||||
'/embark-api/file',
|
||||
(req, res) => {
|
||||
try {
|
||||
this.apiGuardBadFile(req.query.path, { ensureExists: true });
|
||||
} catch (error) {
|
||||
return res.send({ error: error.message });
|
||||
}
|
||||
this.fs.removeSync(req.query.path);
|
||||
res.send();
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/files',
|
||||
(req, res) => {
|
||||
const rootPath = dappPath();
|
||||
|
||||
const walk = (dir, filelist = []) => this.fs.readdirSync(dir).map(name => {
|
||||
let isRoot = rootPath === dir;
|
||||
if (this.fs.statSync(path.join(dir, name)).isDirectory()) {
|
||||
return {
|
||||
isRoot,
|
||||
name,
|
||||
dirname: dir,
|
||||
path: path.join(dir, name),
|
||||
isHidden: (name.indexOf('.') === 0 || name === "node_modules"),
|
||||
children: fileTreeSort(walk(path.join(dir, name), filelist))
|
||||
};
|
||||
}
|
||||
return {
|
||||
name,
|
||||
isRoot,
|
||||
path: path.join(dir, name),
|
||||
dirname: dir,
|
||||
isHidden: (name.indexOf('.') === 0 || name === "node_modules")
|
||||
};
|
||||
});
|
||||
const files = fileTreeSort(walk(dappPath()));
|
||||
res.send(files);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
apiGuardBadFile(pathToCheck, options = {ensureExists: false}) {
|
||||
const dir = path.dirname(pathToCheck);
|
||||
const error = new Error('Path is invalid');
|
||||
if (options.ensureExists && !this.fs.existsSync(pathToCheck)) {
|
||||
throw error;
|
||||
}
|
||||
if (!dir.startsWith(dappPath())) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = API;
|
|
@ -1,11 +1,15 @@
|
|||
const path = require('path');
|
||||
const async = require('async');
|
||||
import { __ } from 'embark-i18n';
|
||||
import { dappPath, joinPath, LongRunningProcessTimer, fileTreeSort } from 'embark-utils';
|
||||
import { dappPath, joinPath, LongRunningProcessTimer } from 'embark-utils';
|
||||
import { ProcessLauncher } from 'embark-core';
|
||||
const constants = require('embark-core/constants');
|
||||
const WebpackConfigReader = require('./webpackConfigReader');
|
||||
|
||||
const PipelineAPI = require('./api.js');
|
||||
|
||||
// TODO: pipeline should just generate files, but doesn't necessarily know much about them
|
||||
// specially their structure (i.e doesn't care if it's embarkjs or contracts or storage etc..)
|
||||
|
||||
class Pipeline {
|
||||
constructor(embark, options) {
|
||||
this.embark = embark;
|
||||
|
@ -29,6 +33,10 @@ class Pipeline {
|
|||
this.pipelineConfig = pipelineConfig;
|
||||
});
|
||||
|
||||
this.events.setCommandHandler('pipeline:generateAll', (cb) => {
|
||||
this.generateAll(cb);
|
||||
});
|
||||
|
||||
this.events.setCommandHandler('pipeline:build', (options, callback) => {
|
||||
if (!this.pipelineConfig.enabled) {
|
||||
return this.buildContracts([], callback);
|
||||
|
@ -38,111 +46,19 @@ class Pipeline {
|
|||
this.events.setCommandHandler('pipeline:build:contracts', callback => this.buildContracts([], callback));
|
||||
this.fs.removeSync(this.buildDir);
|
||||
|
||||
let plugin = this.plugins.createPlugin('deployment', {});
|
||||
plugin.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/file',
|
||||
(req, res) => {
|
||||
try {
|
||||
this.apiGuardBadFile(req.query.path);
|
||||
} catch (error) {
|
||||
return res.send({error: error.message});
|
||||
this.api = new PipelineAPI(embark, options);
|
||||
this.api.registerAPIs();
|
||||
}
|
||||
|
||||
const name = path.basename(req.query.path);
|
||||
const content = this.fs.readFileSync(req.query.path, 'utf8');
|
||||
res.send({name, content, path: req.query.path});
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
'post',
|
||||
'/embark-api/folders',
|
||||
(req, res) => {
|
||||
try {
|
||||
this.apiGuardBadFile(req.body.path);
|
||||
} catch (error) {
|
||||
return res.send({error: error.message});
|
||||
}
|
||||
|
||||
this.fs.mkdirpSync(req.body.path);
|
||||
const name = path.basename(req.body.path);
|
||||
res.send({name, path: req.body.path});
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
'post',
|
||||
'/embark-api/files',
|
||||
(req, res) => {
|
||||
try {
|
||||
this.apiGuardBadFile(req.body.path);
|
||||
} catch (error) {
|
||||
return res.send({error: error.message});
|
||||
}
|
||||
|
||||
this.fs.writeFileSync(req.body.path, req.body.content, {encoding: 'utf8'});
|
||||
const name = path.basename(req.body.path);
|
||||
res.send({name, path: req.body.path, content: req.body.content});
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
'delete',
|
||||
'/embark-api/file',
|
||||
(req, res) => {
|
||||
try {
|
||||
this.apiGuardBadFile(req.query.path, {ensureExists: true});
|
||||
} catch (error) {
|
||||
return res.send({error: error.message});
|
||||
}
|
||||
this.fs.removeSync(req.query.path);
|
||||
res.send();
|
||||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/files',
|
||||
(req, res) => {
|
||||
const rootPath = dappPath();
|
||||
|
||||
const walk = (dir, filelist = []) => this.fs.readdirSync(dir).map(name => {
|
||||
let isRoot = rootPath === dir;
|
||||
if (this.fs.statSync(path.join(dir, name)).isDirectory()) {
|
||||
return {
|
||||
isRoot,
|
||||
name,
|
||||
dirname: dir,
|
||||
path: path.join(dir, name),
|
||||
isHidden: (name.indexOf('.') === 0 || name === "node_modules"),
|
||||
children: fileTreeSort(walk(path.join(dir, name), filelist))
|
||||
};
|
||||
}
|
||||
return {
|
||||
name,
|
||||
isRoot,
|
||||
path: path.join(dir, name),
|
||||
dirname: dir,
|
||||
isHidden: (name.indexOf('.') === 0 || name === "node_modules")
|
||||
};
|
||||
});
|
||||
const files = fileTreeSort(walk(dappPath()));
|
||||
res.send(files);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
apiGuardBadFile(pathToCheck, options = {ensureExists: false}) {
|
||||
const dir = path.dirname(pathToCheck);
|
||||
const error = new Error('Path is invalid');
|
||||
if (options.ensureExists && !this.fs.existsSync(pathToCheck)) {
|
||||
throw error;
|
||||
}
|
||||
if (!dir.startsWith(dappPath())) {
|
||||
throw error;
|
||||
}
|
||||
generateAll(cb) {
|
||||
console.dir("generating all files");
|
||||
// TODO:
|
||||
// placeholder: not actually needed?? it seems to be done on the server
|
||||
// * create placeholder
|
||||
// * check registered code and generate files
|
||||
// * remove placeholder
|
||||
// * placeholder can be a plugin as well or different module
|
||||
cb();
|
||||
}
|
||||
|
||||
build({modifiedAssets}, callback) {
|
||||
|
|
|
@ -146,13 +146,21 @@ class Engine {
|
|||
webpackConfigName: this.webpackConfigName,
|
||||
useDashboard: this.useDashboard
|
||||
});
|
||||
this.events.on('code-generator-ready', function (modifiedAssets) {
|
||||
self.events.request('code', function (abi, contractsJSON) {
|
||||
self.events.request('pipeline:build', {abi, contractsJSON, modifiedAssets}, () => {
|
||||
// this.events.on('code-generator-ready', function (modifiedAssets) {
|
||||
// self.events.request('code', function (abi, contractsJSON) {
|
||||
// self.events.request('pipeline:build', {abi, contractsJSON, modifiedAssets}, () => {
|
||||
// self.events.emit('outputDone');
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// TODO: move this to cmd_controller and define all such behaviour there
|
||||
this.events.on('contracts:deploy:afterAll', () => {
|
||||
self.events.request('pipeline:generateAll', () => {
|
||||
console.dir("outputDone")
|
||||
self.events.emit('outputDone');
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
serviceMonitor() {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require('ejs');
|
||||
|
||||
const Templates = {
|
||||
vanilla_contract: require('./vanilla-contract.js.ejs')
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue