From 960339f6eb160315229abbe8b3ae44c96125b9ee Mon Sep 17 00:00:00 2001 From: Doug Wade Date: Mon, 30 May 2016 00:33:10 -0700 Subject: [PATCH] Add .reactserverrc to generator --- .../generators/app/index.js | 3 ++- .../generators/app/templates/_reactserverrc | 25 +++++++++++++++++++ packages/generator-react-server/test/app.js | 20 +++++++++------ 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 packages/generator-react-server/generators/app/templates/_reactserverrc diff --git a/packages/generator-react-server/generators/app/index.js b/packages/generator-react-server/generators/app/index.js index 03f09fcea..af00bc82c 100644 --- a/packages/generator-react-server/generators/app/index.js +++ b/packages/generator-react-server/generators/app/index.js @@ -31,7 +31,8 @@ module.exports = yeoman.Base.extend({ [ '_babelrc', - '_gitignore' + '_gitignore', + '_reactserverrc' ].forEach(function (filename) { var fn = filename.replace('_', '.'); _this.fs.copyTpl( diff --git a/packages/generator-react-server/generators/app/templates/_reactserverrc b/packages/generator-react-server/generators/app/templates/_reactserverrc new file mode 100644 index 000000000..b6d8f73da --- /dev/null +++ b/packages/generator-react-server/generators/app/templates/_reactserverrc @@ -0,0 +1,25 @@ +{ + "routes": "./routes.js" + "host": "localhost", + "port": 3000, + "js-port": 3001, + "hot": false, + "minify": false, + "long-term-caching": false, + "compile-only": false, + "js-url": undefined, + "https": false, + "https-key": undefined, + "https-cert": undefined, + "https-ca": undefined, + "https-pfx": undefined, + "https-passphrase": undefined, + "log-level": debug, + "env": { + "staging": { + "port": "4000" + }, + "production": { + "port": "80" + } +} diff --git a/packages/generator-react-server/test/app.js b/packages/generator-react-server/test/app.js index bd779f00e..476e7c89f 100644 --- a/packages/generator-react-server/test/app.js +++ b/packages/generator-react-server/test/app.js @@ -14,6 +14,7 @@ test('generator-react-server:app creates default files', async t => { .toPromise(); t.true(await exists('.babelrc', testDir)); t.true(await exists('.gitignore', testDir)); + t.true(await exists('.reactserverrc', testDir)); t.true(await exists('hello-world-page.js', testDir)); t.true(await exists('hello-world.js', testDir)); t.true(await exists('package.json', testDir)); @@ -33,6 +34,7 @@ test('generator-react-server:app creates docker files', async t => { .toPromise(); t.true(await exists('.babelrc', testDir)); t.true(await exists('.gitignore', testDir)); + t.true(await exists('.reactserverrc', testDir)); t.true(await exists('hello-world-page.js', testDir)); t.true(await exists('hello-world.js', testDir)); t.true(await exists('package.json', testDir)); @@ -51,10 +53,10 @@ test('generator-react-server:app passes the test target', async t => { .withPrompts({name: 'foo', dockerCfg: false}) .toPromise(); await installDeps(); - t.true(await runsSuccessfully('npm test')); + t.true(await runsSuccessfully('npm test', testDir)); }); -async function exists(filename, dir) { +function exists(filename, dir) { filename = path.join(dir, filename); return new Promise((resolve) => { fs.access(filename, fs.F_OK, (err) => { @@ -63,22 +65,24 @@ async function exists(filename, dir) { }); } -async function runsSuccessfully(command) { +function runsSuccessfully(command, dir) { return new Promise((resolve) => { - cp.exec(command, (error) => { + cp.exec(command, { + cwd: dir + }, (error) => { resolve(!error); - }) + }); }); } -async function installDeps() { - return new Promise((resolve) => { +function installDeps() { + return new Promise((resolve, reject) => { cp.exec('npm install', (error) => { if (error) { reject(error); } else { resolve(); } - }) + }); }); }