feat(docker): Prep master for docker deploys
This commit is contained in:
committed by
mrugesh mohapatra
parent
9e4583b1f3
commit
d79f9f4899
@ -1,18 +1,16 @@
|
||||
const apiPlaceholderRE = /#\{\{API\}\}/g;
|
||||
const homePlaceholderRE = /#\{\{HOME\}\}/g;
|
||||
const forumPlacehilderRE = /#\{\{FORUM\}\}/g;
|
||||
const forumProxyPlaceholderRE = /#\{\{FORUM_PROXY\}\}/g;
|
||||
|
||||
exports.createRedirects = function createRedirects(locations) {
|
||||
const { api, home, forum, forumProxy } = locations;
|
||||
const { api, home, forum } = locations;
|
||||
|
||||
if (!(api && home && forum && forumProxy)) {
|
||||
if (!(api && home && forum )) {
|
||||
throw new Error(`One or more locations are missing, all are required.
|
||||
|
||||
api: ${api}
|
||||
home: ${home}
|
||||
forum: ${forum}
|
||||
forumProxy: ${forumProxy}
|
||||
|
||||
`);
|
||||
}
|
||||
@ -20,8 +18,7 @@ exports.createRedirects = function createRedirects(locations) {
|
||||
return template
|
||||
.replace(apiPlaceholderRE, api)
|
||||
.replace(homePlaceholderRE, home)
|
||||
.replace(forumPlacehilderRE, forum)
|
||||
.replace(forumProxyPlaceholderRE, forumProxy);
|
||||
.replace(forumPlacehilderRE, forum);
|
||||
};
|
||||
|
||||
/* eslint-disable max-len */
|
||||
@ -49,18 +46,18 @@ const template = `#api redirect
|
||||
/ue/* #{{API}}/ue/:splat
|
||||
|
||||
# misc redirects
|
||||
/agile / 200
|
||||
/agile / 301
|
||||
/chat https://gitter.im/FreeCodeCamp/FreeCodeCamp 301
|
||||
/twitch https://twitch.tv/freecodecamp 301
|
||||
/nonprofits-form / 200
|
||||
/pmi-acp-agile-project-managers / 200
|
||||
/pmi-acp-agile-project-managers-form / 200
|
||||
/stories / 200
|
||||
/all-stories / 200
|
||||
/field-guide/* #{{FORUM}} 301
|
||||
/nonprofits-form / 301
|
||||
/pmi-acp-agile-project-managers / 301
|
||||
/pmi-acp-agile-project-managers-form / 301
|
||||
/stories / 301
|
||||
/all-stories / 301
|
||||
/field-guide/* /forum 301
|
||||
/learn-to-code /learn 200
|
||||
/map /learn 200
|
||||
/forum/* #{{FORUM_PROXY}} 200
|
||||
/forum/* #{{FORUM}}/:splat
|
||||
/privacy #{{HOME}}/forum/t/free-code-camp-privacy-policy/19545 301
|
||||
/nonprofit-project-instructions #{{HOME}}/forum/t/how-free-code-camps-nonprofits-projects-work/19547 301
|
||||
/how-nonprofit-projects-work https://medium.freecodecamp.org/open-source-for-good-1a0ea9f32d5a 301
|
||||
|
@ -2,37 +2,26 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const debug = require('debug');
|
||||
|
||||
const envPath = path.resolve(__dirname, '../../.env');
|
||||
require('dotenv').config({ path: envPath });
|
||||
const env = require('../../config/env');
|
||||
|
||||
const { getChallengesForLang } = require('../../curriculum/getChallenges');
|
||||
const { createPathMigrationMap } = require('./seed/createPathMigrationMap');
|
||||
|
||||
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,
|
||||
LOCALE: locale,
|
||||
NODE_ENV: NODE_ENV
|
||||
} = process.env;
|
||||
|
||||
const locations = {
|
||||
homeLocation: home,
|
||||
apiLocation: api,
|
||||
forumLocation: forum,
|
||||
forumProxyLocation: forumProxy
|
||||
};
|
||||
const { NODE_ENV } = process.env;
|
||||
|
||||
const { homeLocation: home, apiLocation: api, forumLocation: forum, locale } = env;
|
||||
|
||||
const apiPath = path.resolve(__dirname, '../../api-server');
|
||||
const clientPath = path.resolve(__dirname, '../../client');
|
||||
const clientStaticPath = path.resolve(clientPath, 'static');
|
||||
const globalConfigPath = path.resolve(__dirname, '../../config');
|
||||
const env = Object.assign(locations, {locale});
|
||||
|
||||
if (NODE_ENV === 'production') {
|
||||
const redirects = createRedirects({ api, home, forum, forumProxy });
|
||||
const redirects = createRedirects({ api, home, forum });
|
||||
fs.writeFile(`${clientStaticPath}/_redirects`, redirects, function(err) {
|
||||
if (err) {
|
||||
log('Error');
|
||||
@ -44,13 +33,23 @@ if (NODE_ENV === 'production') {
|
||||
log(`ignoring creation of redirect file in ${NODE_ENV}`);
|
||||
}
|
||||
|
||||
fs.access(`${apiPath}/server/resources/pathMigration.json`, err => {
|
||||
if (err) {
|
||||
const migrationMapPath = `${apiPath}/server/resources/pathMigration.json`;
|
||||
fs.access(migrationMapPath, err => {
|
||||
if (err && NODE_ENV !== 'production') {
|
||||
log('creating pathMigration');
|
||||
return fs.writeFileSync(
|
||||
`${apiPath}/server/resources/pathMigration.json`,
|
||||
'{}'
|
||||
);
|
||||
return fs.writeFileSync(migrationMapPath, '{}');
|
||||
}
|
||||
if (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);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
log('pathMigration present');
|
||||
return null;
|
||||
|
29
tools/scripts/ensure-path-migration-map.js
Normal file
29
tools/scripts/ensure-path-migration-map.js
Normal file
@ -0,0 +1,29 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const debug = require('debug');
|
||||
|
||||
const { getChallengesForLang } = require('../../curriculum/getChallenges');
|
||||
const { createPathMigrationMap } = require('./seed/createPathMigrationMap');
|
||||
|
||||
const log = debug('fcc:tools:ensure-env');
|
||||
|
||||
log.enabled = true;
|
||||
|
||||
const apiPath = path.resolve(__dirname, '../../api-server');
|
||||
|
||||
const migrationMapPath = `${apiPath}/server/resources/pathMigration.json`;
|
||||
|
||||
// The migrationMap is to try and resolve pre-learn challenge urls to
|
||||
// current challenge urls
|
||||
// defaulting to english as there were no other languages available
|
||||
// that would require this mapping
|
||||
getChallengesForLang('english')
|
||||
.then(createPathMigrationMap)
|
||||
.then(map => {
|
||||
fs.writeFileSync(migrationMapPath, JSON.stringify(map));
|
||||
log('pathMigration has been written');
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
41
tools/scripts/seed/package-lock.json
generated
41
tools/scripts/seed/package-lock.json
generated
@ -1661,7 +1661,8 @@
|
||||
"ansi-regex": {
|
||||
"version": "2.1.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"aproba": {
|
||||
"version": "1.2.0",
|
||||
@ -1682,12 +1683,14 @@
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
@ -1702,17 +1705,20 @@
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
@ -1829,7 +1835,8 @@
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
@ -1841,6 +1848,7 @@
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
@ -1855,6 +1863,7 @@
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
@ -1862,12 +1871,14 @@
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.2.4",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.1",
|
||||
"yallist": "^3.0.0"
|
||||
@ -1886,6 +1897,7 @@
|
||||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
@ -1966,7 +1978,8 @@
|
||||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
@ -1978,6 +1991,7 @@
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@ -2063,7 +2077,8 @@
|
||||
"safe-buffer": {
|
||||
"version": "5.1.1",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
@ -2099,6 +2114,7 @@
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
@ -2118,6 +2134,7 @@
|
||||
"version": "3.0.1",
|
||||
"bundled": true,
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ansi-regex": "^2.0.0"
|
||||
}
|
||||
@ -2161,12 +2178,14 @@
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"yallist": {
|
||||
"version": "3.0.2",
|
||||
"bundled": true,
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user