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

View File

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

3
dev.js
View File

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

View File

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

View File

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

3762
yarn.lock

File diff suppressed because it is too large Load Diff