Files
freeCodeCamp/tools/scripts/build/ensure-env.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

const fs = require('fs');
2018-09-06 15:18:48 +01:00
const path = require('path');
const debug = require('debug');
const log = debug('fcc:tools:ensure-env');
const env = require('../../../config/env');
const { getChallengesForLang } = require('../../../curriculum/getChallenges');
const { createPathMigrationMap } = require('../seed/createPathMigrationMap');
const apiPath = path.resolve(__dirname, '../../../api-server');
const clientPath = path.resolve(__dirname, '../../../client');
const globalConfigPath = path.resolve(__dirname, '../../../config');
const { FREECODECAMP_NODE_ENV } = process.env;
const { locale } = env;
2018-09-06 15:18:48 +01:00
const migrationMapPath = `${apiPath}/server/resources/pathMigration.json`;
fs.access(migrationMapPath, err => {
2019-08-19 01:19:40 +05:30
if (err && FREECODECAMP_NODE_ENV !== 'production') {
log('creating pathMigration');
return fs.writeFileSync(migrationMapPath, '{}');
}
2019-08-19 01:19:40 +05:30
if (FREECODECAMP_NODE_ENV === 'production') {
return getChallengesForLang(locale)
.then(createPathMigrationMap)
.then(map => {
fs.writeFileSync(migrationMapPath, JSON.stringify(map));
log('pathMigration has been written');
})
.catch(err => {
console.error(err);
2019-02-16 08:48:52 +00:00
// eslint-disable-next-line
process.exit(1);
});
}
log('pathMigration present');
return null;
});
2018-09-27 12:28:31 +05:30
fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env));
fs.writeFileSync(`${globalConfigPath}/env.json`, JSON.stringify(env));