From 8c1a54d85cb29d6803e72cc56b8724f6df6bb6e9 Mon Sep 17 00:00:00 2001 From: OskarAhl Date: Thu, 9 May 2019 14:31:10 +0200 Subject: [PATCH 1/2] 1. Point production to master 2. Point staging to dev 3. Remove `--section` from release but keep option of having sections --- build/babel.js | 20 ------------------- build/config/constants.js | 39 ++++++++++++++++--------------------- build/config/helpers.js | 26 ------------------------- build/config/init.js | 8 +++----- build/copy.js | 7 ------- build/cssmin.js | 9 +-------- build/embedFonts.js | 9 +-------- build/postcss.js | 9 +-------- build/sass.js | 12 +----------- build/shell.js | 2 +- build/webpack.js | 13 ------------- build/webpack/config_app.js | 23 ---------------------- scripts/render.js | 11 ++--------- 13 files changed, 27 insertions(+), 161 deletions(-) delete mode 100644 build/webpack/config_app.js diff --git a/build/babel.js b/build/babel.js index 416df3e51dc3..c7ff45a485d6 100644 --- a/build/babel.js +++ b/build/babel.js @@ -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 { diff --git a/build/config/constants.js b/build/config/constants.js index f921b4ce165d..7c314d446096 100644 --- a/build/config/constants.js +++ b/build/config/constants.js @@ -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 = { diff --git a/build/config/helpers.js b/build/config/helpers.js index 1da64add1ea1..62c8e8540e91 100644 --- a/build/config/helpers.js +++ b/build/config/helpers.js @@ -1,5 +1,3 @@ -const Constants = require('./constants'); - const isRelease = (grunt) => grunt.cli.tasks[0] === 'release'; const getReleaseTarget = (grunt) => { @@ -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, '__')}` ); @@ -48,7 +24,6 @@ const generateCompileCommand = (params) => ( params || '', global.branch ? `-b ${global.branch_prefix}${global.branch}` : '', global.path ? `-p ${global.path}` : '', - `-s ${global.section}`, ], ].join(' ') ); @@ -56,7 +31,6 @@ const generateCompileCommand = (params) => ( module.exports = { isRelease, getReleaseTarget, - getSection, getGhpagesCloneFolder, getDistPath, generateCompileCommand, diff --git a/build/config/init.js b/build/config/init.js index e2aeb37c90b1..2ca80a11e58c 100644 --- a/build/config/init.js +++ b/build/config/init.js @@ -13,7 +13,7 @@ const initGlobals = (grunt) => { } // ----- section ----- - global.section = Helpers.getSection(grunt); + global.section = Constants.config.section; // ----- branch info ----- if (global.release_target) { @@ -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; diff --git a/build/copy.js b/build/copy.js index 95aa307cf174..1e0dbbe2bee5 100644 --- a/build/copy.js +++ b/build/copy.js @@ -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] }; diff --git a/build/cssmin.js b/build/cssmin.js index 190b57148a41..9e504192eaed 100644 --- a/build/cssmin.js +++ b/build/cssmin.js @@ -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 { diff --git a/build/embedFonts.js b/build/embedFonts.js index 9566608345b9..56d7b28b2f2d 100644 --- a/build/embedFonts.js +++ b/build/embedFonts.js @@ -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] }; diff --git a/build/postcss.js b/build/postcss.js index 26378ccd1f0f..dfe4e2fbdcf9 100644 --- a/build/postcss.js +++ b/build/postcss.js @@ -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 { diff --git a/build/sass.js b/build/sass.js index 951e0f69d665..998f78eb7276 100644 --- a/build/sass.js +++ b/build/sass.js @@ -1,6 +1,6 @@ const sass = require('node-sass'); -module.exports = function (grunt) { +module.exports = function () { const options = { style: 'expanded', implementation: sass, @@ -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] }; diff --git a/build/shell.js b/build/shell.js index ae6c042ac8ec..df71eccf5c01 100644 --- a/build/shell.js +++ b/build/shell.js @@ -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: { diff --git a/build/webpack.js b/build/webpack.js index 9f24116d9187..f49f61adfad2 100644 --- a/build/webpack.js +++ b/build/webpack.js @@ -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]; diff --git a/build/webpack/config_app.js b/build/webpack/config_app.js deleted file mode 100644 index 5c4cc6cdfdb6..000000000000 --- a/build/webpack/config_app.js +++ /dev/null @@ -1,23 +0,0 @@ -const path = require('path'); -const makeCacheGroup = require('./helpers').makeCacheGroup; -const PATHS = require('./paths'); -const getPlugins = require('./plugins'); - -const appConfig = (grunt) => ({ - entry: { - [global.is_release ? 'binary.min' : 'binary']: path.resolve(PATHS.SRC, 'javascript'), - }, - output: { - path: path.resolve(PATHS.DIST, 'js'), - }, - optimization: { - splitChunks: { - cacheGroups: { - ...makeCacheGroup('vendor', -20, 'node_modules'), - }, - }, - }, - plugins: getPlugins('app', grunt), -}); - -module.exports = appConfig; diff --git a/scripts/render.js b/scripts/render.js index c4e772f77c85..43e6d83e4bf3 100755 --- a/scripts/render.js +++ b/scripts/render.js @@ -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}`)); From 943102ab3919af4e031ca97e519e11122bbc548f Mon Sep 17 00:00:00 2001 From: OskarAhl Date: Thu, 9 May 2019 14:47:52 +0200 Subject: [PATCH 2/2] update release and section readme --- README.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/README.md b/README.md index 61fad73b5beb..1a24a6f14f61 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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`