fix(deploy): misc. re-arrange scripts and organize
This commit is contained in:
committed by
mrugesh
parent
a6afaf1eb6
commit
c5fd478d9a
@ -0,0 +1,48 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`createRedirects matches the snapshot 1`] = `
|
||||
"#api redirect
|
||||
|
||||
/internal/* https://api.example.com/internal/:splat 200
|
||||
|
||||
# auth redirects
|
||||
/signin https://api.example.com/signin 200
|
||||
/signup https://api.example.com/signin 200
|
||||
/email-signin https://api.example.com/signin 200
|
||||
/login https://api.example.com/signin 200
|
||||
/deprecated-signin https://api.example.com/signin 200
|
||||
/logout https://api.example.com/signout 200
|
||||
/passwordless-change https://api.example.com/confirm-email 200
|
||||
|
||||
# certification redirects
|
||||
/:username/front-end-certification /certification/:username/legacy-front-end 301
|
||||
/:username/data-visualization-certification /certification/:username/legacy-data-visualization 301
|
||||
/:username/back-end-certification /certification/:username/legacy-back-end 301
|
||||
/:username/full-stack-certification /certification/:username/full-stack 301
|
||||
|
||||
# unsunscribe redirects
|
||||
/u/* https://api.example.com/u/:splat 200
|
||||
/unsunscribe/* https://api.example.com/unsunscribe/:splat 200
|
||||
/ue/* https://api.example.com/ue/:splat 200
|
||||
|
||||
# misc redirects
|
||||
/agile / 301
|
||||
/chat https://gitter.im/FreeCodeCamp/FreeCodeCamp 301
|
||||
/twitch https://twitch.tv/freecodecamp 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
|
||||
/news https://news.example.com 200
|
||||
/news/* https://news.example.com/:splat 200
|
||||
/forum/* https://forum.example.com/:splat 200
|
||||
/privacy https://forum.example.com/t/free-code-camp-privacy-policy/19545 301
|
||||
/nonprofit-project-instructions https://forum.example.com/t/how-free-code-camps-nonprofits-projects-work/19547 301
|
||||
/how-nonprofit-projects-work https://www.freecodecamp.org/news/open-source-for-good-1a0ea9f32d5a 301
|
||||
|
||||
"
|
||||
`;
|
69
tools/scripts/build/createRedirects.js
Normal file
69
tools/scripts/build/createRedirects.js
Normal file
@ -0,0 +1,69 @@
|
||||
const apiPlaceholderRE = /#\{\{API\}\}/g;
|
||||
const newsPlaceholderRE = /#\{\{NEWS\}\}/g;
|
||||
const forumPlacehilderRE = /#\{\{FORUM\}\}/g;
|
||||
|
||||
exports.createRedirects = function createRedirects(locations) {
|
||||
const { api, news, forum } = locations;
|
||||
|
||||
if (!(api && news && forum)) {
|
||||
throw new Error(`One or more locations are missing, all are required.
|
||||
|
||||
api: ${api}
|
||||
news: ${news}
|
||||
forum: ${forum}
|
||||
|
||||
`);
|
||||
}
|
||||
|
||||
return template
|
||||
.replace(apiPlaceholderRE, api)
|
||||
.replace(newsPlaceholderRE, news)
|
||||
.replace(forumPlacehilderRE, forum);
|
||||
};
|
||||
|
||||
/* eslint-disable max-len */
|
||||
const template = `#api redirect
|
||||
|
||||
/internal/* #{{API}}/internal/:splat 200
|
||||
|
||||
# auth redirects
|
||||
/signin #{{API}}/signin 200
|
||||
/signup #{{API}}/signin 200
|
||||
/email-signin #{{API}}/signin 200
|
||||
/login #{{API}}/signin 200
|
||||
/deprecated-signin #{{API}}/signin 200
|
||||
/logout #{{API}}/signout 200
|
||||
/passwordless-change #{{API}}/confirm-email 200
|
||||
|
||||
# certification redirects
|
||||
/:username/front-end-certification /certification/:username/legacy-front-end 301
|
||||
/:username/data-visualization-certification /certification/:username/legacy-data-visualization 301
|
||||
/:username/back-end-certification /certification/:username/legacy-back-end 301
|
||||
/:username/full-stack-certification /certification/:username/full-stack 301
|
||||
|
||||
# unsunscribe redirects
|
||||
/u/* #{{API}}/u/:splat 200
|
||||
/unsunscribe/* #{{API}}/unsunscribe/:splat 200
|
||||
/ue/* #{{API}}/ue/:splat 200
|
||||
|
||||
# misc redirects
|
||||
/agile / 301
|
||||
/chat https://gitter.im/FreeCodeCamp/FreeCodeCamp 301
|
||||
/twitch https://twitch.tv/freecodecamp 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
|
||||
/news #{{NEWS}} 200
|
||||
/news/* #{{NEWS}}/:splat 200
|
||||
/forum/* #{{FORUM}}/:splat 200
|
||||
/privacy #{{FORUM}}/t/free-code-camp-privacy-policy/19545 301
|
||||
/nonprofit-project-instructions #{{FORUM}}/t/how-free-code-camps-nonprofits-projects-work/19547 301
|
||||
/how-nonprofit-projects-work https://www.freecodecamp.org/news/open-source-for-good-1a0ea9f32d5a 301
|
||||
|
||||
`;
|
||||
/* eslint-enable max-len */
|
62
tools/scripts/build/createRedirects.test.js
Normal file
62
tools/scripts/build/createRedirects.test.js
Normal file
@ -0,0 +1,62 @@
|
||||
/* global describe expect it */
|
||||
|
||||
const { createRedirects } = require('./createRedirects');
|
||||
|
||||
const testLocations = {
|
||||
api: 'https://api.example.com',
|
||||
news: 'https://news.example.com',
|
||||
forum: 'https://forum.example.com'
|
||||
};
|
||||
|
||||
describe('createRedirects', () => {
|
||||
it('is a function', () => {
|
||||
expect(typeof createRedirects).toEqual('function');
|
||||
});
|
||||
|
||||
it('returns a string', () => {
|
||||
expect(typeof createRedirects(testLocations)).toEqual('string');
|
||||
});
|
||||
|
||||
it('replaces instances of `#{{...}}` with the locations provided', () => {
|
||||
expect.assertions(6);
|
||||
|
||||
const apiPlaceholderRE = /#\{\{API\}\}/;
|
||||
const newsPlaceholderRE = /#\{\{NEWS\}\}/;
|
||||
const forumPlaceholderRE = /#\{\{FORUM\}\}/;
|
||||
const redirects = createRedirects(testLocations);
|
||||
|
||||
const hasApiPlaceholder = apiPlaceholderRE.test(redirects);
|
||||
const hasNewsPlaceholder = newsPlaceholderRE.test(redirects);
|
||||
const hasForumPlaceholder = forumPlaceholderRE.test(redirects);
|
||||
|
||||
expect(hasApiPlaceholder).toBe(false);
|
||||
expect(hasNewsPlaceholder).toBe(false);
|
||||
expect(hasForumPlaceholder).toBe(false);
|
||||
|
||||
const { api, forum } = testLocations;
|
||||
expect(redirects.includes(`${api}/internal/:splat`)).toBe(true);
|
||||
expect(
|
||||
redirects.includes(`${forum}/t/free-code-camp-privacy-policy/19545 301`)
|
||||
).toBe(true);
|
||||
expect(redirects.includes(`${forum}`)).toBe(true);
|
||||
});
|
||||
|
||||
it('throws when any location is missing', () => {
|
||||
expect.assertions(3);
|
||||
|
||||
const api = 'api';
|
||||
const news = 'news';
|
||||
const forum = 'forum';
|
||||
|
||||
const noApi = { forum, news };
|
||||
const noNews = { api, forum };
|
||||
const noForum = { api, news };
|
||||
|
||||
expect(() => createRedirects(noApi)).toThrow();
|
||||
expect(() => createRedirects(noNews)).toThrow();
|
||||
expect(() => createRedirects(noForum)).toThrow();
|
||||
});
|
||||
|
||||
it('matches the snapshot', () =>
|
||||
expect(createRedirects(testLocations)).toMatchSnapshot());
|
||||
});
|
65
tools/scripts/build/ensure-env.js
Normal file
65
tools/scripts/build/ensure-env.js
Normal file
@ -0,0 +1,65 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const debug = require('debug');
|
||||
|
||||
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 { NODE_ENV } = process.env;
|
||||
|
||||
const {
|
||||
apiLocation: api,
|
||||
forumLocation: forum,
|
||||
locale,
|
||||
newsLocation: news
|
||||
} = 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');
|
||||
|
||||
if (NODE_ENV === 'production') {
|
||||
const redirects = createRedirects({ api, news, forum });
|
||||
fs.writeFile(`${clientStaticPath}/_redirects`, redirects, function(err) {
|
||||
if (err) {
|
||||
log('Error');
|
||||
console.error(err);
|
||||
}
|
||||
log('_redirects written');
|
||||
});
|
||||
} else {
|
||||
log(`ignoring creation of redirect file in ${NODE_ENV}`);
|
||||
}
|
||||
|
||||
const migrationMapPath = `${apiPath}/server/resources/pathMigration.json`;
|
||||
fs.access(migrationMapPath, err => {
|
||||
if (err && NODE_ENV !== 'production') {
|
||||
log('creating pathMigration');
|
||||
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);
|
||||
// eslint-disable-next-line
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
log('pathMigration present');
|
||||
return null;
|
||||
});
|
||||
|
||||
fs.writeFileSync(`${clientPath}/config/env.json`, JSON.stringify(env));
|
||||
fs.writeFileSync(`${globalConfigPath}/env.json`, JSON.stringify(env));
|
30
tools/scripts/build/ensure-path-migration-map.js
Normal file
30
tools/scripts/build/ensure-path-migration-map.js
Normal file
@ -0,0 +1,30 @@
|
||||
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);
|
||||
// eslint-disable-next-line
|
||||
process.exit(1);
|
||||
});
|
4966
tools/scripts/build/package-lock.json
generated
Normal file
4966
tools/scripts/build/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
tools/scripts/build/package.json
Normal file
25
tools/scripts/build/package.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "@freecodecamp/scripts-build",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "Build Scripts",
|
||||
"main": "NA",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/freeCodeCamp/freeCodeCamp.git"
|
||||
},
|
||||
"author": "freeCodeCamp.org",
|
||||
"license": "BSD-3-Clause",
|
||||
"bugs": {
|
||||
"url": "https://github.com/freeCodeCamp/freeCodeCamp/issues"
|
||||
},
|
||||
"homepage": "https://github.com/freeCodeCamp/freeCodeCamp#readme",
|
||||
"devDependencies": {
|
||||
"debug": "^4.0.1",
|
||||
"dotenv": "^6.0.0",
|
||||
"jest": "^24.8.0"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user