Skip to content

Commit

Permalink
Fix the babel-node error when there is no schema.json
Browse files Browse the repository at this point in the history
  • Loading branch information
lvarayut committed Mar 16, 2016
1 parent f6c726e commit 6039fa4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "Relay Starter Kit - Integrated with Relay, GraphQL, Express, ES6/ES7, JSX, Webpack, Babel, Material Design Lite, and PostCSS",
"scripts": {
"start": "babel-node server/index.js",
"start": "npm run update && babel-node server/index.js",
"update": "babel-node server/utils/updateSchema.js",
"deploy": "NODE_ENV=production webpack --config webpack.production.config.js && NODE_ENV=production npm start"
},
Expand Down
3 changes: 0 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ if (config.env === 'development') {
app.use('/', express.static(path.join(__dirname, '../build')));
app.listen(config.port, () => console.log(`Relay is listening on port ${config.port}`));

// Update schema.json and schema.graphql
updateSchema();

// Watch JavaScript files in the data folder for changes, and update schema.json and schema.graphql
gaze(path.join(__dirname, 'data/*.js'), (err, watcher) => {
if (err) console.error('Error: Watching files in data folder');
Expand Down
12 changes: 11 additions & 1 deletion server/utils/babelRelayPlugin.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
module.exports = require('babel-relay-plugin')(require('../data/schema.json').data);
var fs = require('fs');
var path = require('path');
var jsonFile = path.join(__dirname, '../data/schema.json');

// Read the schema.json file only if it exists, this fixed
// the problem of using babelRelayPlugin, defined in .babelrc,
// and running npm run update when the file doesn't exist
fs.access(jsonFile, fs.F_OK, function(err) {
if (!err) module.exports = require('babel-relay-plugin')(require(jsonFile).data);
});

0 comments on commit 6039fa4

Please sign in to comment.