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

Commit

Permalink
feat(mongod): mongod!
Browse files Browse the repository at this point in the history
resolves #21
  • Loading branch information
saiichihashimoto committed Feb 10, 2019
1 parent aa0c565 commit b32fbc6
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
lib
build
data
lib
node_modules
2 changes: 1 addition & 1 deletion bin/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +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: echo TODO # mkdir -p data/db && mongod --dbpath data/db --bind_ip 127.0.0.1
mongod: mkdir -p data/db && mongod --dbpath data/db --bind_ip 127.0.0.1
69 changes: 31 additions & 38 deletions bin/react-node-scripts-build.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
#!/usr/bin/env node
const path = require('path');
const program = require('commander');
const { spawnSync } = require('child_process');
const spawnAsync = require('./spawnAsync');

program
.option('--no-web')
.option('--no-server')
.action(({ web, server }) => {
if (server) {
spawnSync(
require.resolve('@babel/cli/bin/babel'),
[
'src',
.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',
},
stdio: [process.stdin, process.stdout, process.stderr],
'--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',
},
);
}
if (web) {
spawnSync(
require.resolve('react-scripts/bin/react-scripts'),
[
'build',
],
{
env: {
...process.env,
SKIP_PREFLIGHT_CHECK: true,
},
stdio: [process.stdin, process.stdout, process.stderr],
},
))
.then(() => web && spawnAsync(
require.resolve('react-scripts/bin/react-scripts'),
[
'build',
],
{
env: {
...process.env,
SKIP_PREFLIGHT_CHECK: true,
},
);
}
})
},
)))
.parse(process.argv);
50 changes: 30 additions & 20 deletions bin/react-node-scripts-start.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
#!/usr/bin/env node
const path = require('path');
const program = require('commander');
const { spawnSync } = require('child_process');
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 }) => spawnSync(
require.resolve('foreman/nf'),
[
'start',
.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: {
...process.env,
root: __dirname,
NODE_ENV: 'development',
SKIP_PREFLIGHT_CHECK: true,
PORT: process.env.PORT || 3000,
'--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,
},
},
stdio: [process.stdin, process.stdout, process.stderr],
},
))
)))
.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 b32fbc6

Please sign in to comment.