Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #17

Merged
merged 3 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,10 @@ In order to remove the created folders from your gh-pages, you can use either:
- `grunt shell:compile_dev --path=about-us` to re-compile only template(s) which serve about-us path in URL.
- To fix eslint errors run `npm run eslint`

### Sections
The codebase is divided into different sections. Passing `--section=[all|app|app_2]` to almost all grunt commands causes to run it on the specified section (excluding tests since it should run on the whole source code).

Current sections are:
- `app` represents current version of the website including `app`, `static`, `landing_pages` folders in the source code.
- `app_2` is the next version which its source code is mainly inside the `app_2` folders.
- `all` denotes to all available sections and is the default value if `--section` is not specified.

Although section is mandatory for release, but it is optional for the rest of commands as there is a default value (`all`).

## Release

```
grunt release --{release type}=1 --section=app|app_2 [--cleanup] [--reset]
grunt release --{release type}=1 [--cleanup] [--reset]
```
(The value is needed when more than one option is used)

Expand All @@ -101,9 +91,6 @@ grunt release --{release type}=1 --section=app|app_2 [--cleanup] [--reset]
- In order to prevent accidentally releasing to the wrong target, it is mandatory to provide one of these parameters.
- Your remote origin will be checked to be the correct target of the given parameter.
- Your current branch will be checked to be the correct branch of the given parameter.
- `--section` (mandatory)
- In order to prevent mistakes during the release, it is mandatory to specify the section.
- Valid section depends on the release target. Please refer to `release_config` [here](https://github.com/binary-com/deriv-com/blob/new-app/build/config/constants.js).
- `--cleanup` [optional]
- Create CNAME file with proper value according to remote origin
- Deploy to gh-pages with the option `add: false`
Expand Down
20 changes: 0 additions & 20 deletions build/babel.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
module.exports = function (grunt) {
const config = {
app: {
options: {
minified : true,
plugins : ['transform-remove-strict-mode'],
presets : ['env'],
sourceMap : true,
sourceType: 'script',
},
files : [
{
expand: true,
cwd : 'src/javascript/landing_pages/',
src : ['*.js'],
dest : global.dist + '/js/landing_pages/'
},
],
},
app_2: {},
get all() {
return this.app;
},
};

return {
Expand Down
39 changes: 17 additions & 22 deletions build/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,40 @@ const release_targets = {
/**
* branch : the required branch that should be checked out when releasing
* target_folder : the folder name in gh-pages to release to
* valid_sections: the list of sections that can use for this release
* origin : the required origin that local clone should point to (also the target repo to release to, when `target_repo` not available)
* target_repo : the target repo to release to
* CNAME : creates a CNAME file based on this entry to push alongside the release when needed
*/
const release_config = {
production: {
branch : 'master',
target_folder : '',
valid_sections: ['app_2'],
origin : release_targets.production.repo,
target_repo : release_targets.production.target_repo,
CNAME : release_targets.production.CNAME,
branch : 'master',
target_folder: '',
origin : release_targets.production.repo,
target_repo : release_targets.production.target_repo,
CNAME : release_targets.production.CNAME,
},
staging: {
branch : 'master',
target_folder : '',
valid_sections: ['app_2'],
origin : release_targets.staging.repo,
CNAME : release_targets.staging.CNAME,
branch : 'dev',
target_folder: '',
origin : release_targets.staging.repo,
CNAME : release_targets.staging.CNAME,
},
translations: {
branch : 'translations',
target_folder : 'translations',
valid_sections: ['app'],
origin : release_targets.staging.repo,
CNAME : release_targets.staging.CNAME,
branch : 'translations',
target_folder: 'translations',
origin : release_targets.staging.repo,
CNAME : release_targets.staging.CNAME,
},
};

const node_modules_paths = {
smartcharts : 'node_modules/smartcharts-beta',
smartcharts: 'node_modules/smartcharts-beta',
};

const config = {
branch_prefix : 'br_',
valid_sections : ['all', 'app', 'app_2'],
default_section: 'all',
app_2_folder : 'app',
branch_prefix: 'br_',
section : 'app_2',
app_2_folder : 'app',
};

module.exports = {
Expand Down
26 changes: 0 additions & 26 deletions build/config/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const Constants = require('./constants');

const isRelease = (grunt) => grunt.cli.tasks[0] === 'release';

const getReleaseTarget = (grunt) => {
Expand All @@ -12,28 +10,6 @@ const getReleaseTarget = (grunt) => {
return release_target;
};

const validateSection = (grunt, section) => {
let { valid_sections } = Constants.config;

if (isRelease(grunt)) {
valid_sections = [...global.release_config[global.release_target].valid_sections];

if (!grunt.option('section')) { // To prevent mistakes, section is mandatory when releasing
grunt.fail.fatal(`It is mandatory to specify the section when releasing. (--section=...)\nValid sections are: ${valid_sections.join(', ')}`);
}
}

if (!valid_sections.includes(section)) {
grunt.fail.fatal(`Unknown or wrong section: '${section}'.\nValid sections are: ${valid_sections.join(', ')}.`);
}
};

const getSection = (grunt) => {
const section = grunt.option('section') || Constants.config.default_section;
validateSection(grunt, section);
return section;
};

const getGhpagesCloneFolder = () => ( // clone each repo to a unique folder to prevent local cache issues when releasing
`.grunt/grunt-gh-pages/gh-pages/${/^.*:(.*)\.git$/g.exec(global.release_info.target_repo)[1].replace(/\//g, '__')}`
);
Expand All @@ -48,15 +24,13 @@ const generateCompileCommand = (params) => (
params || '',
global.branch ? `-b ${global.branch_prefix}${global.branch}` : '',
global.path ? `-p ${global.path}` : '',
`-s ${global.section}`,
],
].join(' ')
);

module.exports = {
isRelease,
getReleaseTarget,
getSection,
getGhpagesCloneFolder,
getDistPath,
generateCompileCommand,
Expand Down
8 changes: 3 additions & 5 deletions build/config/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const initGlobals = (grunt) => {
}

// ----- section -----
global.section = Helpers.getSection(grunt);
global.section = Constants.config.section;

// ----- branch info -----
if (global.release_target) {
Expand All @@ -27,10 +27,8 @@ const initGlobals = (grunt) => {
global.branch_prefix = '';
global.branch = global.release_info.target_folder;

if (global.release_target === 'staging' && global.section === 'all') {
grunt.option('cleanup', true); // always cleanup when releasing to staging
} else if (global.release_info.valid_sections.length > 1 && global.section !== 'all' && grunt.option('cleanup')) {
grunt.fail.fatal(`can't release only one section to ${global.release_target} with --cleanup`);
if (global.release_target === 'staging' || global.release_target === 'production') {
grunt.option('cleanup', true); // always cleanup when releasing to staging or production
}
} else {
global.branch_prefix = Constants.config.branch_prefix;
Expand Down
7 changes: 0 additions & 7 deletions build/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ module.exports = function (grunt) {
{ expand: true, cwd: `${global.node_modules_paths.smartcharts}/dist/`, src: ['smartcharts.css*'], dest: `${global.dist_app_2}/css/` },
],
},
get all() {
return {
files: [
...this.app_2.files,
],
};
},
};

return { [global.section]: config[global.section] };
Expand Down
9 changes: 1 addition & 8 deletions build/cssmin.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
module.exports = function (grunt) {
module.exports = function () {
const files = {
app: [],
app_2: [
{ src: `${global.dist_app_2}/css/app_2.css`, dest: `${global.dist_app_2}/css/app_2.min.css` },
],
get all() {
return [
...this.app,
...this.app_2,
];
},
};

return {
Expand Down
9 changes: 1 addition & 8 deletions build/embedFonts.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
module.exports = function (grunt) {
module.exports = function () {
const app_2_file = `${global.dist}/app/css/app_2.css`;

const config = {
app: {},
app_2: {
files: {
[app_2_file]: [app_2_file],
},
},
get all() {
return {
...this.app,
...this.app_2,
};
}
};

return { [global.section]: config[global.section] };
Expand Down
9 changes: 1 addition & 8 deletions build/postcss.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module.exports = function (grunt) {
module.exports = function () {
const src = {
app : `${global.dist}/css/{app,common,static}.css`,
app_2: `${global.dist_app_2}/css/app_2.css`,
get all() {
return [
this.app,
this.app_2,
];
},
};

return {
Expand Down
12 changes: 1 addition & 11 deletions build/sass.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const sass = require('node-sass');

module.exports = function (grunt) {
module.exports = function () {
const options = {
style: 'expanded',
implementation: sass,
Expand All @@ -18,17 +18,7 @@ module.exports = function (grunt) {
});

const config = {
app : generateConfig(['*.scss', '!app_2.scss'], `${global.dist}/css`),
app_2: generateConfig(['app_2.scss'], `${global.dist_app_2}/css`),
get all() {
return {
options,
files: [
...this.app.files,
...this.app_2.files,
],
};
},
};

return { [global.section]: config[global.section] };
Expand Down
2 changes: 1 addition & 1 deletion build/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module.exports = function (grunt) {
prompt('Starting the release to \'translations\'\n'),
'git fetch origin translations:translations',
'git checkout translations',
'grunt release --translations --section=app --color',
'grunt release --translations --color',
'git checkout master',
].join(' && '),
options: {
Expand Down
13 changes: 0 additions & 13 deletions build/webpack.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const appConfig = require('./webpack/config_app');
const app2Config = require('./webpack/config_app_2');
const commonConfig = require('./webpack/config_common');
const PATHS = require('./webpack/paths');
const getPlugins = require('./webpack/plugins');

module.exports = function (grunt) {
const common_config = commonConfig(grunt);

const config = {
app : [webpackMerge.smart(common_config, appConfig(grunt))],
app_2: [webpackMerge.smart(common_config, app2Config(grunt))],
get all() {
return [
...this.app,
...this.app_2,
];
},
};

const section = config[global.section];
Expand Down
23 changes: 0 additions & 23 deletions build/webpack/config_app.js

This file was deleted.

11 changes: 2 additions & 9 deletions scripts/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,18 @@ program
.option('-d, --dev', 'Build for your gh-pages')
.option('-b, --branch [branchname]', 'Build your changes to a sub-folder named: branchname')
.option('-p, --path [save_as]', 'Compile only the template(s) that match the regex save_as')
.option('-s, --section [section]', `Compile only the template(s) of the specified section. Valid sections are ${build_config.valid_sections.join(', ')}. Defaults to ${build_config.default_section}`)
.option('-v, --verbose', 'Displays the list of paths to be compiled')
.option('-t, --translations', 'Update messages.pot with new translations')
.option('-j, --js-translations', 'Update js translation files in src/javascript/_autogenerated/')
.parse(process.argv);

program.section = build_config.section;

const is_translation = (program.translations || program.jsTranslations);
if (is_translation && (program.dev || program.path || program.section)) {
outputHelp('-t or -j cannot be used alongside other parameters');
}

if (!program.section) {
program.section = 'all';
} else if (!build_config.valid_sections.includes(program.section)) {
outputHelp(`Unknown section: '${program.section}'. Valid sections are: ${build_config.valid_sections.join(', ')}.`);
} else if (program.section === 'app') {
program.section = '';
}

function outputHelp(error_message) {
program.outputHelp(str => {
console.error(color.red(` ERROR: ${error_message}`));
Expand Down