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

Commit

Permalink
Merge pull request #22 from saiichihashimoto/mongod
Browse files Browse the repository at this point in the history
Mongod
  • Loading branch information
saiichihashimoto committed Feb 10, 2019
2 parents d28822d + b32fbc6 commit 9469b5a
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 62 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
lib
build
data
lib
node_modules
2 changes: 0 additions & 2 deletions Procfile

This file was deleted.

3 changes: 3 additions & 0 deletions bin/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions bin/react-node-scripts

This file was deleted.

42 changes: 42 additions & 0 deletions bin/react-node-scripts-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node
const path = require('path');
const program = require('commander');
const spawnAsync = require('./spawnAsync');

program
.option('--no-web')
.option('--no-server')
.action(({ web, server }) => Promise.resolve()
.then(() => server && spawnAsync(
require.resolve('@babel/cli/bin/babel'),
[
'src',

'--out-dir', 'lib',
'--config-file', path.resolve(__dirname, 'babel.config.js'),
'--copy-files',
'--delete-dir-on-start',
'--no-babelrc',
'--source-maps',
'--verbose',
],
{
env: {
...process.env,
NODE_ENV: 'production',
},
},
))
.then(() => web && spawnAsync(
require.resolve('react-scripts/bin/react-scripts'),
[
'build',
],
{
env: {
...process.env,
SKIP_PREFLIGHT_CHECK: true,
},
},
)))
.parse(process.argv);
41 changes: 41 additions & 0 deletions bin/react-node-scripts-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node
const path = require('path');
const program = require('commander');
const { existsSync } = require('fs');
const { homedir } = require('os');
const spawnAsync = require('./spawnAsync');

program
.option('--mongod')
.option('--no-web')
.option('--no-server')
.action(({ web, server, mongod }) => Promise.resolve()
// This triggers it to download the binary
.then(() => mongod && !existsSync(path.resolve(homedir(), '.mongodb-prebuilt')) && spawnAsync(
require.resolve('mongodb-prebuilt/built/bin/mongod'),
[
'--version',
],
))
.then(() => spawnAsync(
require.resolve('foreman/nf'),
[
'start',

'--procfile', path.resolve(__dirname, 'Procfile'),
Object.entries({ web, server, mongod })
.map(([key, val]) => `${key}=${val ? 1 : 0}`)
.join(','),
],
{
env: {
MONGO_URL: mongod && 'mongodb://localhost:27017/database',
SKIP_PREFLIGHT_CHECK: true,
...process.env,
root: __dirname,
NODE_ENV: 'development',
PORT: process.env.PORT || 3000,
},
},
)))
.parse(process.argv);
9 changes: 9 additions & 0 deletions bin/react-node-scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node
const program = require('commander');
const { version } = require('../package');

program
.version(version)
.command('build', 'builds the app')
.command('start', 'starts the app')
.parse(process.argv);
17 changes: 17 additions & 0 deletions bin/spawnAsync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { spawn } = require('child_process');

module.exports = function spawnAsync(command, args = [], options = {}) {
return new Promise((resolve, reject) => {
const subprocess = spawn(command, args, {
...options,
stdio: [process.stdin, process.stdout, process.stderr],
});

subprocess.on('error', reject);
subprocess.on('close', (code) => (
code ?
reject(code) :
resolve()
));
});
};
Loading

0 comments on commit 9469b5a

Please sign in to comment.