2018-09-06 15:31:05 +01:00
|
|
|
const fs = require('fs');
|
2018-09-06 15:18:48 +01:00
|
|
|
const path = require('path');
|
2018-10-08 00:00:50 +01:00
|
|
|
const debug = require('debug');
|
|
|
|
|
|
|
|
const envPath = path.resolve(__dirname, '../../.env');
|
|
|
|
require('dotenv').config({ path: envPath });
|
2018-09-06 14:58:51 +01:00
|
|
|
|
2018-09-27 20:21:53 +05:30
|
|
|
const env = require('../../config/env');
|
2018-10-08 00:00:50 +01:00
|
|
|
const { createRedirects } = require('./createRedirects');
|
|
|
|
|
|
|
|
const log = debug('fcc:tools:ensure-env');
|
|
|
|
const {
|
|
|
|
HOME_LOCATION: home,
|
|
|
|
API_LOCATION: api,
|
|
|
|
FORUM_LOCATION: forum,
|
|
|
|
FORUM_PROXY_LOCATION: forumProxy
|
|
|
|
} = process.env;
|
2018-09-06 14:58:51 +01:00
|
|
|
|
2018-09-27 20:21:53 +05:30
|
|
|
const apiPath = path.resolve(__dirname, '../../api-server');
|
|
|
|
const clientPath = path.resolve(__dirname, '../../client');
|
2018-10-08 00:00:50 +01:00
|
|
|
const clientStaticPath = path.resolve(clientPath, 'static');
|
|
|
|
|
|
|
|
const redirects = createRedirects({ api, home, forum, forumProxy });
|
|
|
|
|
|
|
|
fs.writeFile(`${clientStaticPath}/_redirects`, redirects, function(err) {
|
|
|
|
if (err) {
|
|
|
|
log('Error');
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
log('_redirects written');
|
|
|
|
});
|
2018-09-06 15:18:48 +01:00
|
|
|
|
|
|
|
fs.access(`${apiPath}/server/rev-manifest.json`, function(err) {
|
2018-09-06 14:58:51 +01:00
|
|
|
if (err) {
|
2018-10-08 00:00:50 +01:00
|
|
|
log('creating manifest');
|
2018-09-06 15:31:05 +01:00
|
|
|
return fs.writeFileSync(`${apiPath}/server/rev-manifest.json`, '{}');
|
2018-05-27 10:57:18 +01:00
|
|
|
}
|
2018-10-08 00:00:50 +01:00
|
|
|
log('rev-manifest present');
|
2018-09-06 14:58:51 +01:00
|
|
|
return null;
|
|
|
|
});
|
2018-05-27 10:57:18 +01:00
|
|
|
|
2018-09-06 15:18:48 +01:00
|
|
|
fs.access(`${apiPath}/server/resources/pathMigration.json`, err => {
|
2018-09-06 14:58:51 +01:00
|
|
|
if (err) {
|
2018-10-08 00:00:50 +01:00
|
|
|
log('creating pathMigration');
|
2018-09-06 14:58:51 +01:00
|
|
|
return fs.writeFileSync(
|
2018-09-06 15:31:05 +01:00
|
|
|
`${apiPath}/server/resources/pathMigration.json`,
|
2018-09-06 14:58:51 +01:00
|
|
|
'{}'
|
|
|
|
);
|
2018-05-27 10:57:18 +01:00
|
|
|
}
|
2018-10-08 00:00:50 +01:00
|
|
|
log('pathMigration present');
|
2018-09-06 14:58:51 +01:00
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
2018-09-27 12:28:31 +05:30
|
|
|
fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env));
|