flow: lots

This commit is contained in:
cha0s 2018-09-08 22:54:33 -05:00
parent 93c1cc60ae
commit e68d3e8e5a
7 changed files with 3779 additions and 20 deletions

View File

@ -3,6 +3,7 @@ const {spawnSync} = require('child_process');
const fs = require('fs');
const dotenv = require('dotenv');
const mkdirp = require('mkdirp');
const {emitObject, emitString} = require('./compose');
@ -18,7 +19,7 @@ services.push('gateway');
const composeFile = emitString(emitObject(services));
spawnSync('mkdir', ['-p', distPath]);
mkdirp.sync(distPath);
fs.writeFileSync(
path.join(distPath, 'docker-compose.yml'), composeFile
@ -44,7 +45,7 @@ for (const service of services) {
const servicePath = path.join(cwd, 'services', service);
const serviceDistPath = path.join(distPath, service);
spawnSync('mkdir', ['-p', serviceDistPath]);
mkdirp.sync(serviceDistPath);
spawnSync('docker', [
'run',
@ -68,10 +69,7 @@ for (const service of services) {
stdio: 'inherit',
});
spawnSync('rm', [
'-rf',
path.join(serviceDistPath, 'node_modules'),
path.join(serviceDistPath, 'package.json'),
path.join(serviceDistPath, 'yarn.lock'),
]);
require('rimraf').sync(
path.join(serviceDistPath, '{node_modules,package.json,yarn.lock}')
)
}

View File

@ -20,8 +20,7 @@ exports.emitObject = function(services) {
composeFile.services[service] = emitService(service);
const modulePath = `./services/${service}/compose`;
try {
require(modulePath)(composeFile.services[service]);
console.log('compose');
require(modulePath)(composeFile.services[service], composeFile);
}
catch (error) {
const message = `Cannot find module '${modulePath}'`;

3
dev.js
View File

@ -18,6 +18,9 @@ const composeFile = emitString(emitObject(services));
debug('Compose file:');
debug(composeFile);
debug('Ensuring dist directory exists...');
require('mkdirp').sync(path.join(process.cwd(), 'dist', 'dev'));
['down', 'up'].reduce((promise, op) => {
const child = spawn('docker-compose', [

View File

@ -10,10 +10,13 @@
"dev": "node dev.js"
},
"dependencies": {
"@truss/truss": "^1.2.5",
"chalk": "^2.4.1",
"debug": "^3.1.0",
"dotenv": "^6.0.0",
"js-yaml": "^3.12.0",
"mkdirp": "^0.5.1",
"rimraf": "^2.6.2",
"supports-color": "^5.5.0"
},
"license": "UNLICENSED"

View File

@ -2,9 +2,9 @@ const http = require('http');
const debug = require('debug')('truss:gateway');
const {createDispatcher, sendActionToService} = require('@truss/truss');
import {createDispatcher, sendActionToService} from '@truss/truss';
let listener = require('./listener');
let listener = require('./listener').default;
// ---
@ -100,6 +100,6 @@ function invokeHook(services, hook, args) {
if (module.hot) {
module.hot.accept('./listener', () => {
listener = require('./listener');
listener = require('./listener').default;
});
}

View File

@ -2,11 +2,11 @@ const bodyParser = require('body-parser');
const debug = require('debug')('truss:gateway:listener');
const {sendActionToService} = require('@truss/truss');
import {sendActionToService} from '@truss/truss';
const parser = bodyParser.json();
module.exports = function(serviceMap, req, res) { parser(req, res, () => {
export default function(serviceMap, req, res) { parser(req, res, () => {
debug(`HTTP ${req.method} ${req.url}`);
// map to action
@ -47,10 +47,10 @@ module.exports = function(serviceMap, req, res) { parser(req, res, () => {
sendActionToService(
action, serviceMap.executors[action.type]
).then(({status, html}) => {
).then(({status, headers, html}) => {
// deliver
res.writeHead(status || 200);
res.writeHead(status || 200, headers);
res.end(html);
}).catch(console.error);

3762
yarn.lock

File diff suppressed because it is too large Load Diff