fix(build): Ensure env for build

pull/18096/head
Bouncey 2018-09-06 15:18:48 +01:00 committed by Stuart Taylor
parent 5b7b3ca33c
commit 9224613a74
2 changed files with 9 additions and 5 deletions

View File

@ -40,7 +40,7 @@
], ],
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "gatsby build", "build": "node ../config/ensure-env.js && gatsby build",
"develop": "gatsby develop", "develop": "gatsby develop",
"format": "prettier --write '**/*.js'", "format": "prettier --write '**/*.js'",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"

View File

@ -1,10 +1,14 @@
require('dotenv').config(); require('dotenv').config();
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path');
const env = require('./env'); const env = require('./env');
fs.access('./api-server/server/rev-manifest.json', function(err) { const apiPath = path.resolve(__dirname, '../api-server');
const clientPath = path.resolve(__dirname, '../client');
fs.access(`${apiPath}/server/rev-manifest.json`, function(err) {
if (err) { if (err) {
console.log('\n\ncreating manifest\n\n'); console.log('\n\ncreating manifest\n\n');
return fs.writeFileSync('./api-server/server/rev-manifest.json', '{}'); return fs.writeFileSync('./api-server/server/rev-manifest.json', '{}');
@ -13,7 +17,7 @@ fs.access('./api-server/server/rev-manifest.json', function(err) {
return null; return null;
}); });
fs.access('./api-server/server/resources/pathMigration.json', err => { fs.access(`${apiPath}/server/resources/pathMigration.json`, err => {
if (err) { if (err) {
console.log('\n\ncreating pathMigration\n\n'); console.log('\n\ncreating pathMigration\n\n');
return fs.writeFileSync( return fs.writeFileSync(
@ -25,6 +29,6 @@ fs.access('./api-server/server/resources/pathMigration.json', err => {
return null; return null;
}); });
fs.ensureDir('./client/config/').then(() => fs.ensureDir(`${clientPath}/config/`).then(() =>
fs.writeFileSync('./client/config/env.json', JSON.stringify(env)) fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env))
); );