2019-08-30 20:50:20 +00:00
|
|
|
import {__} from 'embark-i18n';
|
2019-09-05 20:04:52 +00:00
|
|
|
import {canonicalHost, defaultHost} from 'embark-utils';
|
2019-08-30 20:50:20 +00:00
|
|
|
|
|
|
|
export default class Namesystem {
|
|
|
|
constructor(embark, _options) {
|
|
|
|
this.embark = embark;
|
|
|
|
this.events = this.embark.events;
|
2019-09-05 20:04:52 +00:00
|
|
|
this.embarkConfig = embark.config.embarkConfig;
|
|
|
|
this.namesystemConfig = this.embark.config.namesystemConfig;
|
2019-08-30 20:50:20 +00:00
|
|
|
|
|
|
|
this.namesystemNodes = {};
|
|
|
|
this.events.setCommandHandler("namesystem:node:register", (clientName, startCb) => {
|
|
|
|
this.namesystemNodes[clientName] = startCb;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.events.setCommandHandler("namesystem:node:start", (namesystemConfig, cb) => {
|
|
|
|
const clientName = namesystemConfig.provider;
|
|
|
|
const client = this.namesystemNodes[clientName];
|
|
|
|
if (!client) return cb(__("Namesystem client %s not found", clientName));
|
|
|
|
|
|
|
|
client.apply(client, [
|
|
|
|
() => {
|
|
|
|
this.events.emit("namesystem:started", clientName);
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
2019-09-05 20:04:52 +00:00
|
|
|
embark.registerActionForEvent("pipeline:generateAll:before", this.addArtifactFile.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
addArtifactFile(_params, cb) {
|
|
|
|
this.events.request("pipeline:register", {
|
|
|
|
path: [this.embarkConfig.generationDir, 'config'],
|
|
|
|
file: 'namesystem.json',
|
|
|
|
format: 'json',
|
|
|
|
content: this.namesystemConfig
|
|
|
|
}, cb);
|
2019-08-30 20:50:20 +00:00
|
|
|
}
|
|
|
|
}
|