chore: flow

This commit is contained in:
cha0s 2018-09-02 07:25:51 -05:00
parent 6c8ef04f7a
commit 93c1cc60ae
7 changed files with 29 additions and 3193 deletions

View File

@ -6,7 +6,7 @@ const dotenv = require('dotenv');
const {emitObject, emitString} = require('./compose');
['.common.env', '.prod.env', '.env'].forEach((filename) => {
['.common.env', '.production.env', '.env'].forEach((filename) => {
dotenv.config({path: path.join(__dirname, filename)});
});
@ -31,7 +31,7 @@ fs.copyFileSync(
fs.appendFileSync(
path.join(distPath, '.env'),
fs.readFileSync(path.join(cwd, '.prod.env')),
fs.readFileSync(path.join(cwd, '.production.env')),
);
fs.appendFileSync(
@ -49,7 +49,7 @@ for (const service of services) {
spawnSync('docker', [
'run',
'--env-file', './.common.env',
'--env-file', './.prod.env',
'--env-file', './.production.env',
'--env-file', './.env',
'-e', 'DEBUG=truss:*',

View File

@ -18,11 +18,20 @@ exports.emitObject = function(services) {
for (const service of services) {
composeFile.services[service] = emitService(service);
const modulePath = `./services/${service}/compose`;
try {
require(modulePath)(composeFile.services[service]);
console.log('compose');
}
catch (error) {
const message = `Cannot find module '${modulePath}'`;
if (message !== error.message) {
console.error(error);
process.exit(1);
}
}
}
const gatewayPort = process.env.GATEWAY_PORT || 8000;
composeFile.services.gateway.ports = [`${gatewayPort}:8000`];
return composeFile;
}

View File

@ -0,0 +1,5 @@
module.exports = (config) => {
const gatewayPort = process.env.GATEWAY_PORT || 8000;
config.ports = [`${gatewayPort}:8000`];
};

View File

@ -49,7 +49,7 @@ ${type}.
// hey, listen
const httpServer = http.createServer();
reduceServiceMap$.then((serviceMap) => {
debug(`service map: ${JSON.stringify(serviceMap)}`);
debug(`service map: ${JSON.stringify(serviceMap, null, ' ')}`);
const port = process.env.GATEWAY_PORT || 8000;
httpServer.listen(port);
@ -78,8 +78,12 @@ reduceServiceMap$.then((serviceMap) => {
}).catch(console.error);
function invokeHookFlat(services, hook, args) {
debug(`invoking hook flat(${hook}(${JSON.stringify(args)}))...`);
debug(`invoking hook flat(${hook}(${JSON.stringify(args, null, ' ')}))...`);
invokeHookFlatInternal(services, hook, args);
}
function invokeHookFlatInternal(services, hook, args) {
const action = {type: 'truss/hook', payload: {hook, args}};
return Promise.all(services.map((service) => {
return sendActionToService(action, service);
@ -87,9 +91,9 @@ function invokeHookFlat(services, hook, args) {
}
function invokeHook(services, hook, args) {
debug(`invoking hook ${hook}(${JSON.stringify(args)})...`);
debug(`invoking hook ${hook}(${JSON.stringify(args, null, ' ')})...`);
return invokeHookFlat(services, hook, args).then((result) => {
return invokeHookFlatInternal(services, hook, args).then((result) => {
return result.reduce((l, r, i) => (l[services[i]] = r, l), {});
});
}

View File

@ -10,7 +10,7 @@ module.exports = function(serviceMap, req, res) { parser(req, res, () => {
debug(`HTTP ${req.method} ${req.url}`);
// map to action
const action = {payload: {url: req.url}};
const action = {type: undefined, payload: {url: req.url}};
switch (req.method) {
case 'POST':

File diff suppressed because it is too large Load Diff