This repository has been archived by the owner on Aug 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
354 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules | ||
lib | ||
build | ||
data | ||
lib | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
)); | ||
}); | ||
}; |
Oops, something went wrong.