Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Commit

Permalink
feat(redis): run redis-server
Browse files Browse the repository at this point in the history
There's no redis-prebuilt so I'm stuck with this
  • Loading branch information
saiichihashimoto committed Feb 12, 2019
1 parent 7490ab5 commit 48872db
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Thumbs.db
build
coverage
data
dump.rdb
lib
node_modules/
yarn.lock
56 changes: 14 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions src/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
web: react-scripts start --color
server: nodemon --config $root/nodemon.json --exec babel-node $src -- --config-file=$root/babel.config.js --no-babelrc
mongod: mkdir -p data/db && mongod --dbpath data/db --bind_ip 127.0.0.1
# Order of Colors
# https://github.com/strongloop/node-foreman/blob/master/lib/colors.js#L7

# magenta
# blue
# cyan
# green
# yellow
# red
# bright_magenta
# bright_cyan
# bright_blue
# bright_green
# bright_yellow
# bright_red

web: react-scripts start --color
server: nodemon --config $root/nodemon.json --exec babel-node $src -- --config-file=$root/babel.config.js --no-babelrc
cyan: echo cyan && tail -f /dev/null
mongod: mkdir -p data/db && mongod --dbpath data/db --bind_ip 127.0.0.1
yellow: echo yellow && tail -f /dev/null
redis: redis-server
73 changes: 65 additions & 8 deletions src/react-node-scripts-start.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
import Listr from 'listr';
import execa from 'execa';
import opn from 'opn';
import path from 'path';
Expand All @@ -20,27 +21,74 @@ function start(args) {

command
.option('--mongod')
.option('--redis')
.option('--ngrok')
.option('--no-web')
.option('--no-server')
.parse(args);

const { web, server, mongod, ngrok } = command;
const { web, server, mongod, redis, ngrok } = command;

const mongodUrl = mongod && 'mongodb://localhost:27017/database';
const redisUrl = redis && 'redis://localhost:6379';

const {
env: {
MONGO_URL = mongod && 'mongodb://localhost:27017/database',
PORT = 3000,
SKIP_PREFLIGHT_CHECK = true,

MONGODB_URI = mongodUrl,
MONGOHQ_URL = mongodUrl,
ORMONGO_URL = mongodUrl,

OPENREDIS_URL = redisUrl,
REDISCLOUD_URL = redisUrl,
REDISGREEN_URL = redisUrl,
REDISTOGO_URL = redisUrl,
REDIS_URL = redisUrl,

...env
},
} = process;

return Promise.resolve()
.then(() => (
// Downloads the mongod binary
mongod &&
!existsSync(path.resolve(homedir(), '.mongodb-prebuilt')) &&
execa('mongod', ['--version'], options)
new Listr(
[
{
title: 'Downloading mongod',
enabled: () => mongod && !existsSync(path.resolve(homedir(), '.mongodb-prebuilt')),
task: () => execa('mongod', ['--version']).stdout,
},
],
{
renderer: process.env.NODE_ENV === 'test' ? 'silent' : /* istanbul ignore next */ 'default',
exitOnError: false,
concurrent: true,
},
)
.run()
.then(
/* istanbul ignore next line */
() => process.env.NODE_ENV !== 'test' && console.log(), // eslint-disable-line no-console
(err) => {
const { errors } = err;

/* istanbul ignore next line */
errors
.filter(({ stdout }) => stdout)
.forEach(({ stdout }) => console.log(stdout)); // eslint-disable-line no-console
/* istanbul ignore next line */
errors
.filter(({ stderr }) => stderr)
.forEach(({ stderr }) => console.error(stderr)); // eslint-disable-line no-console

// eslint-disable-next-line no-param-reassign
err.code = err.code || errors.find(({ code }) => code).code;

throw err;
},
)
))
.then(() => Promise.all([
execa(
Expand All @@ -49,7 +97,7 @@ function start(args) {
'start',

'--procfile', path.resolve(__dirname, 'Procfile'),
Object.entries({ web, server, mongod })
Object.entries({ web, server, cyan: false, mongod, yellow: false, redis })
.map(([key, val]) => `${key}=${val ? 1 : 0}`)
.join(','),
],
Expand All @@ -60,10 +108,19 @@ function start(args) {
src: existsSync('./src/index.server.js') ? 'src/index.server' : 'src',
NODE_ENV: 'development',
root: __dirname,
MONGO_URL,
PORT,
SKIP_PREFLIGHT_CHECK,

MONGODB_URI,
MONGOHQ_URL,
ORMONGO_URL,

OPENREDIS_URL,
REDISCLOUD_URL,
REDISGREEN_URL,
REDISTOGO_URL,
REDIS_URL,

...(ngrok && {
// We have to set DANGEROUSLY_DISABLE_HOST_CHECK
// Otherwise we get "Invalid Host header" error
Expand Down
Loading

0 comments on commit 48872db

Please sign in to comment.