@zohodesk/react-cli 0.0.1-beta.98 → 0.0.1-betaa.138.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +149 -0
  3. package/bin/cli.js +34 -29
  4. package/files/eslintrc.js +57 -0
  5. package/files/prettierrc.js +3 -0
  6. package/lib/babel/cmjs-plugins-presets.js +16 -9
  7. package/lib/babel/es-plugins-presets.js +26 -14
  8. package/lib/common/getEntries.js +31 -22
  9. package/lib/common/getPublicPathConfig.js +27 -13
  10. package/lib/common/index.js +21 -25
  11. package/lib/common/splitChunks.js +62 -53
  12. package/lib/common/templateParameters.js +10 -8
  13. package/lib/configs/jest.config.js +15 -25
  14. package/lib/configs/webpack.component.umd.config.js +31 -37
  15. package/lib/configs/webpack.css.umd.config.js +44 -47
  16. package/lib/configs/webpack.dev.config.js +70 -52
  17. package/lib/configs/webpack.docs.config.js +106 -106
  18. package/lib/configs/webpack.prod.config.js +95 -75
  19. package/lib/hooks/docsProptypeHook.js +32 -38
  20. package/lib/jest/commitedFilesResult.js +103 -74
  21. package/lib/jest/coverageCollector.js +41 -21
  22. package/lib/jest/jsonMaker.js +15 -16
  23. package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
  24. package/lib/jest/preProcessors/jsPreprocessor.js +3 -5
  25. package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
  26. package/lib/jest/result.js +90 -45
  27. package/lib/jest/run.js +43 -43
  28. package/lib/jest/setup.js +102 -95
  29. package/lib/loaderUtils/getCSSLoaders.js +21 -22
  30. package/lib/loaderUtils/getDevJsLoaders.js +25 -23
  31. package/lib/loaderUtils/index.js +11 -13
  32. package/lib/loaders/docsLoader.js +15 -15
  33. package/lib/loaders/docsPropsLoader.js +14 -17
  34. package/lib/loaders/fileLoader.js +33 -35
  35. package/lib/loaders/scriptInstrumentLoader.js +21 -20
  36. package/lib/loaders/workerLoader.js +136 -0
  37. package/lib/middlewares/HMRMiddleware.js +54 -45
  38. package/lib/middlewares/SSTMiddleware.js +8 -5
  39. package/lib/pluginUtils/getDevPlugins.js +114 -52
  40. package/lib/pluginUtils/getDocsPlugins.js +25 -29
  41. package/lib/pluginUtils/getLibraryPlugins.js +8 -10
  42. package/lib/pluginUtils/getProdPlugins.js +163 -74
  43. package/lib/pluginUtils/getServerPlugins.js +8 -11
  44. package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
  45. package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
  46. package/lib/pluginUtils/index.js +36 -43
  47. package/lib/plugins/CdnChangePlugin.js +63 -0
  48. package/lib/plugins/CleanupStatsPlugin.js +18 -32
  49. package/lib/plugins/CustomAttributePlugin.js +79 -0
  50. package/lib/plugins/CustomAttributePlugin.md +35 -0
  51. package/lib/plugins/EFCPlugin.js +185 -0
  52. package/lib/plugins/I18NInjectIntoIndexPlugin.js +118 -52
  53. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
  54. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
  55. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
  56. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
  57. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
  58. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
  59. package/lib/plugins/I18nSplitPlugin/README.md +25 -0
  60. package/lib/plugins/I18nSplitPlugin/index.js +185 -0
  61. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
  62. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
  63. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
  64. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
  65. package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
  66. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
  67. package/lib/plugins/ManifestPlugin.js +52 -63
  68. package/lib/plugins/ModuleStatsPlugin.js +83 -173
  69. package/lib/plugins/OptimizeJSPlugin.js +24 -41
  70. package/lib/plugins/PublicPathCallbackPlugin.js +42 -116
  71. package/lib/plugins/PublicPathChangePlugin.js +175 -284
  72. package/lib/plugins/ReportGeneratePlugin.js +150 -151
  73. package/lib/plugins/ResourceHintsPlugin.js +53 -35
  74. package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
  75. package/lib/plugins/ServiceWorkerPlugin.js +81 -57
  76. package/lib/plugins/ShadowDOMSupportPlugin.js +153 -234
  77. package/lib/plugins/SourceMapHookPlugin.js +21 -33
  78. package/lib/plugins/TPHashMappingPlugin.js +67 -0
  79. package/lib/plugins/UglifyCSSPlugin.js +23 -30
  80. package/lib/plugins/UnusedFilesFindPlugin.js +137 -152
  81. package/lib/plugins/index.js +100 -91
  82. package/lib/plugins/webpackwatchrunplugin.js +18 -30
  83. package/lib/postcss-plugins/ExcludeRTLPlugin.js +14 -17
  84. package/lib/schemas/index.js +336 -81
  85. package/lib/servers/clusterHubServer.js +22 -26
  86. package/lib/servers/docsServer.js +3 -5
  87. package/lib/servers/docsServerCore.js +84 -91
  88. package/lib/servers/helpServer.js +19 -21
  89. package/lib/servers/impactServer.js +99 -92
  90. package/lib/servers/mockserver.js +24 -24
  91. package/lib/servers/scrServer.js +78 -98
  92. package/lib/servers/server.js +101 -122
  93. package/lib/servers/ssServer.js +63 -61
  94. package/lib/sh/reportPublish.sh +1 -2
  95. package/lib/templates/CoverageScriptTemplate.js +45 -18
  96. package/lib/templates/WMSTemplate.js +17 -18
  97. package/lib/templates/linterConstant.js +6 -4
  98. package/lib/utils/babelPresets.js +12 -5
  99. package/lib/utils/clean.js +12 -11
  100. package/lib/utils/copy.js +12 -34
  101. package/lib/utils/copyTimezones.js +9 -16
  102. package/lib/utils/createEventStream.js +24 -19
  103. package/lib/utils/cssClassNameGenerate.js +44 -73
  104. package/lib/utils/cssURLReplacer.js +62 -56
  105. package/lib/utils/dependencyPostPublish.js +20 -19
  106. package/lib/utils/fileUtils.js +66 -54
  107. package/lib/utils/folderIterator.js +20 -21
  108. package/lib/utils/getComponents.js +70 -27
  109. package/lib/utils/getCurrentBranch.js +11 -17
  110. package/lib/utils/getDependenciesImpactList.js +114 -187
  111. package/lib/utils/getHash.js +9 -13
  112. package/lib/utils/getIp.js +9 -9
  113. package/lib/utils/getOptions.js +26 -29
  114. package/lib/utils/getServerURL.js +19 -10
  115. package/lib/utils/index.js +147 -126
  116. package/lib/utils/init.js +2 -2
  117. package/lib/utils/initPreCommitHook.js +40 -32
  118. package/lib/utils/jsonHelper.js +37 -21
  119. package/lib/utils/lint/addScripts.js +27 -0
  120. package/lib/utils/lint/checkExistingConfig.js +67 -0
  121. package/lib/utils/lint/copyConfigs.js +24 -0
  122. package/lib/utils/lint/index.js +54 -0
  123. package/lib/utils/lint/lintScripts.js +11 -0
  124. package/lib/utils/lint/lintSetup.js +31 -0
  125. package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
  126. package/lib/utils/lint/question.js +30 -0
  127. package/lib/utils/lintReporter.js +70 -56
  128. package/lib/utils/mailSender.js +12 -27
  129. package/lib/utils/pullOrigin.js +21 -18
  130. package/lib/utils/reinstallDependencies.js +76 -85
  131. package/lib/utils/removeAttributes.js +25 -23
  132. package/lib/utils/repoClone.js +47 -45
  133. package/lib/utils/request.js +64 -77
  134. package/lib/utils/rtl.js +22 -29
  135. package/lib/utils/setEnvVariables.js +5 -6
  136. package/lib/utils/ssTestHack.js +21 -19
  137. package/lib/utils/switchBranch.js +21 -20
  138. package/lib/utils/urlConcat.js +22 -0
  139. package/package.json +72 -67
@@ -1,16 +1,20 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var fs = require('fs');
7
- var os = require('os');
6
+ exports.setTestInfoStatus = exports.jsonHelper = exports.jsonConcate = exports.getRunnerDetail = exports.fileHandler = void 0;
8
7
 
9
- var _require = require('./'),
10
- getCurrentBranch = _require.getCurrentBranch;
8
+ let fs = require('fs');
11
9
 
12
- var getRunnerDetail = exports.getRunnerDetail = function getRunnerDetail() {
13
- var defaultObj = {
10
+ let os = require('os');
11
+
12
+ let {
13
+ getCurrentBranch
14
+ } = require('./');
15
+
16
+ let getRunnerDetail = () => {
17
+ let defaultObj = {
14
18
  jobDetails: {
15
19
  isRunByLocal: true,
16
20
  hostName: os.hostname(),
@@ -21,27 +25,28 @@ var getRunnerDetail = exports.getRunnerDetail = function getRunnerDetail() {
21
25
  return defaultObj;
22
26
  };
23
27
 
24
- var fileHandler = exports.fileHandler = {
25
- readFile: function readFile(path) {
26
- var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
27
-
28
+ exports.getRunnerDetail = getRunnerDetail;
29
+ let fileHandler = {
30
+ readFile: (path, callback = null) => {
28
31
  if (fs.existsSync(path)) {
29
32
  if (callback === null) {
30
33
  return fs.readFileSync(path);
31
34
  }
35
+
32
36
  callback(fs.readFileSync(path));
33
37
  } else {
34
38
  return fileHandler.writeFile(path, getRunnerDetail());
35
39
  }
36
40
  },
37
- writeFile: function writeFile(path, data) {
41
+ writeFile: (path, data) => {
38
42
  fs.writeFileSync(path, JSON.stringify(data));
39
43
  return JSON.stringify(data);
40
44
  }
41
45
  };
46
+ exports.fileHandler = fileHandler;
42
47
 
43
- var jsonConcate = exports.jsonConcate = function jsonConcate(receiverObj, senterObj) {
44
- Object.keys(senterObj).map(function (key) {
48
+ let jsonConcate = (receiverObj, senterObj) => {
49
+ Object.keys(senterObj).map(key => {
45
50
  if (Object.prototype.hasOwnProperty.call(receiverObj, key)) {
46
51
  if (receiverObj[key].constructor === {}.constructor && senterObj[key].constructor === {}.constructor) {
47
52
  jsonConcate(receiverObj[key], senterObj[key]);
@@ -53,29 +58,40 @@ var jsonConcate = exports.jsonConcate = function jsonConcate(receiverObj, senter
53
58
  } else {
54
59
  receiverObj[key] = senterObj[key];
55
60
  }
61
+
56
62
  return key;
57
63
  });
58
64
  return receiverObj;
59
65
  };
60
66
 
61
- var jsonHelper = exports.jsonHelper = function jsonHelper(path, pathArray, value) {
62
- var tempObj = {};
67
+ exports.jsonConcate = jsonConcate;
68
+
69
+ let jsonHelper = (path, pathArray, value) => {
70
+ let tempObj = {};
71
+
63
72
  if (typeof pathArray === 'string') {
64
73
  pathArray = pathArray.split('.'); //eslint-disable-line no-param-reassign
65
74
  }
66
- pathArray.slice(0).reverse().map(function (key) {
75
+
76
+ pathArray.slice(0).reverse().map(key => {
67
77
  tempObj = {};
68
78
  tempObj[key] = value;
69
79
  value = tempObj; // eslint-disable-line no-param-reassign
80
+
70
81
  return key;
71
82
  });
72
- var overAllObj = jsonConcate(JSON.parse(fileHandler.readFile(path)), tempObj);
83
+ let overAllObj = jsonConcate(JSON.parse(fileHandler.readFile(path)), tempObj);
73
84
  fileHandler.writeFile(path, overAllObj);
74
85
  };
75
86
 
76
- var setTestInfoStatus = exports.setTestInfoStatus = function setTestInfoStatus(filepath, status) {
77
- var buildObject = JSON.parse(fileHandler.readFile(filepath));
87
+ exports.jsonHelper = jsonHelper;
88
+
89
+ let setTestInfoStatus = (filepath, status) => {
90
+ let buildObject = JSON.parse(fileHandler.readFile(filepath));
91
+
78
92
  if (!buildObject.testInfo || buildObject.testInfo.isBuildVerified !== false) {
79
93
  jsonHelper(filepath, 'testInfo.isBuildVerified', status);
80
94
  }
81
- };
95
+ };
96
+
97
+ exports.setTestInfoStatus = setTestInfoStatus;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ const fs = require('fs');
4
+
5
+ const {
6
+ log
7
+ } = require('..');
8
+
9
+ function addScripts(scripts) {
10
+ fs.readFile('./package.json', 'utf8', (err, configFileString) => {
11
+ if (err) log('[LINT SETUP] No package.json in the current directory');else {
12
+ const configFile = JSON.parse(configFileString); // Still Object destructuring causes issue. 😐
13
+ // configFile.scripts = {
14
+ // ...configFile.scripts,
15
+ // ...scripts,
16
+ // };
17
+
18
+ configFile.scripts = Object.assign(configFile.scripts || {}, scripts);
19
+ const data = JSON.stringify(configFile, undefined, 2);
20
+ fs.writeFileSync('./package.json', data);
21
+ }
22
+ });
23
+ }
24
+
25
+ module.exports = {
26
+ addScripts
27
+ };
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ /* eslint-disable operator-linebreak */
4
+
5
+ /* eslint-disable implicit-arrow-linebreak */
6
+ const fs = require('fs');
7
+
8
+ const {
9
+ log
10
+ } = require('../../../lib/utils');
11
+
12
+ const {
13
+ question,
14
+ rl
15
+ } = require('./question');
16
+
17
+ const eslintConfigFiles = ['.eslintrc.js', '.eslintrc.cjs', '.eslintrc.yaml', '.eslintrc.yml', '.eslintrc.json', '.eslintrc'];
18
+ const prettierConfigFiles = ['.prettierrc.js', '.prettierrc.json', '.prettierrc', '.prettierrc.yml', '.prettierrc.yaml', '.prettierrc.json5', '.prettierrc.toml', '.prettierrc.cjs', '.prettier.config.js', '.prettier.config.cjs'];
19
+
20
+ function isConfigExists(fileNames) {
21
+ return fileNames.find(file => {
22
+ if (fs.existsSync(file)) return true;
23
+ return false;
24
+ });
25
+ }
26
+
27
+ async function checkConflicts(files) {
28
+ const conflictFile = isConfigExists(files);
29
+
30
+ if (conflictFile) {
31
+ log(`[LINT SETUP] There's already a config exists as named ${conflictFile}`);
32
+ const res = await question('[LINT SETUP] Do you want to overwrite? (y/n): '); // TODO: Next cycle: Need to delete the current config file.
33
+ // if (res === 'y') {
34
+ // exec(`rm ${conflictFile}`, (err) => {
35
+ // if (err) log(err);
36
+ // else {
37
+ // log('Deleted ', conflictFile);
38
+ // }
39
+ // });
40
+ // }
41
+
42
+ return res;
43
+ }
44
+
45
+ return false;
46
+ }
47
+
48
+ async function promptForPreCommitHook() {
49
+ const res = await question('[LINT SETUP] Do you need a pre-commit hook for formatting and check lint errors in cached files (newly changed)? (y/n): ');
50
+ return res;
51
+ }
52
+
53
+ const getChoices = async () => {
54
+ const eslint = await checkConflicts(eslintConfigFiles);
55
+ const prettier = await checkConflicts(prettierConfigFiles);
56
+ const isESLintAllowed = eslint === false || eslint === 'y';
57
+ const isPrettierAllowed = prettier === false || prettier === 'y';
58
+ const isHookInstallEnabled = (await promptForPreCommitHook()) === 'y';
59
+ rl.close();
60
+ return [isESLintAllowed, isPrettierAllowed, isHookInstallEnabled];
61
+ };
62
+
63
+ module.exports = {
64
+ eslintConfigFiles,
65
+ prettierConfigFiles,
66
+ getChoices
67
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ const fs = require('fs');
4
+
5
+ const {
6
+ log
7
+ } = require('../../../lib/utils');
8
+
9
+ async function copyConfigs(file) {
10
+ // copy the file in react-cli to current working directory
11
+ fs.readFile(require.resolve(`../../../files/${file}.js`), (err, data) => {
12
+ if (err) log("[LINT SETUP] There's error in reading the config file", file);else {
13
+ fs.writeFile(`.${file}.js`, data, writeError => {
14
+ if (writeError) {
15
+ log("[LINT SETUP] There's error in writing the config file: ", file, writeError);
16
+ } else {
17
+ log('[LINT SETUP] Added config file', file);
18
+ }
19
+ });
20
+ }
21
+ });
22
+ }
23
+
24
+ module.exports = copyConfigs;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ const {
4
+ eslintPackages,
5
+ prettierPackages,
6
+ eslintPrettierConfig,
7
+ runInstall,
8
+ installLintStaged
9
+ } = require('./lintSetup');
10
+
11
+ const {
12
+ log
13
+ } = require('../../../lib/utils');
14
+
15
+ const {
16
+ eslintConfigFiles,
17
+ prettierConfigFiles,
18
+ getChoices
19
+ } = require('./checkExistingConfig');
20
+
21
+ const copyConfigs = require('./copyConfigs');
22
+
23
+ async function main() {
24
+ const packages = [];
25
+ const [isESLintAllowed, isPrettierAllowed, isHookInstallEnabled] = await getChoices();
26
+
27
+ if (isESLintAllowed) {
28
+ copyConfigs('eslintrc', eslintConfigFiles);
29
+ packages.push(...eslintPackages);
30
+ }
31
+
32
+ if (isPrettierAllowed) {
33
+ copyConfigs('prettierrc', prettierConfigFiles);
34
+ packages.push(...prettierPackages);
35
+ }
36
+
37
+ if (isESLintAllowed && isPrettierAllowed) {
38
+ packages.push(...eslintPrettierConfig);
39
+ }
40
+
41
+ if (packages.length) {
42
+ const process = runInstall(packages);
43
+ process.on('close', () => {
44
+ if (isHookInstallEnabled) {
45
+ installLintStaged();
46
+ }
47
+ });
48
+ } else if (isHookInstallEnabled) {
49
+ installLintStaged();
50
+ }
51
+ }
52
+
53
+ log('[LINT SETUP] Beginning configuration...');
54
+ main();
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ const {
4
+ addScripts
5
+ } = require('./addScripts');
6
+
7
+ const scripts = {
8
+ lintSetup: 'react-cli lint-setup && npm run lintExtInstall && echo "If changes not reflected kindly restart your VSCode."',
9
+ lintExtInstall: 'code --install-extension dbaeumer.vscode-eslint && code --install-extension esbenp.prettier-vscode'
10
+ };
11
+ addScripts(scripts);
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ const {
4
+ spawn
5
+ } = require('child_process');
6
+
7
+ const eslintPackages = ['eslint', 'eslint-config-airbnb', 'eslint-plugin-import', 'eslint-plugin-jsx-a11y', 'eslint-plugin-react', 'eslint-plugin-react-hooks', 'eslint-plugin-css-modules', '@zohodesk/eslint-plugin-react-performance', '@zohodesk/eslint-plugin-zsecurity'];
8
+ const prettierPackages = ['prettier'];
9
+ const eslintPrettierConfig = ['eslint-config-prettier']; // const npmInstall = `npm i --save-dev ${devDependencies.join(' ')}`;
10
+
11
+ function runInstall(packages) {
12
+ return spawn('npm', ['i', ...packages, '--save-dev'], {
13
+ detached: true,
14
+ stdio: 'inherit'
15
+ });
16
+ }
17
+
18
+ function installLintStaged() {
19
+ spawn('npx', ['mrm', 'lint-staged'], {
20
+ detached: true,
21
+ stdio: 'inherit'
22
+ });
23
+ }
24
+
25
+ module.exports = {
26
+ eslintPackages,
27
+ prettierPackages,
28
+ eslintPrettierConfig,
29
+ installLintStaged,
30
+ runInstall
31
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ const {
4
+ installLintStaged
5
+ } = require('./lintSetup');
6
+
7
+ installLintStaged();
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ /* eslint-disable no-await-in-loop */
4
+
5
+ /* eslint-disable implicit-arrow-linebreak */
6
+ const readline = require('readline');
7
+
8
+ const rl = readline.createInterface({
9
+ input: process.stdin,
10
+ output: process.stdout
11
+ });
12
+
13
+ const question = qn => new Promise(res => {
14
+ rl.question(qn, ans => res(ans));
15
+ });
16
+
17
+ async function main(qn) {
18
+ let answer;
19
+
20
+ while (!['n', 'y'].includes(answer)) {
21
+ answer = (await question(qn)).toLowerCase();
22
+ }
23
+
24
+ return answer;
25
+ }
26
+
27
+ module.exports = {
28
+ question: main,
29
+ rl
30
+ };
@@ -1,27 +1,35 @@
1
- 'use strict';
2
-
3
- var getOptions = require('./getOptions').default;
4
- var fs = require('fs');
5
- var coverageCollector = require('../jest/coverageCollector');
6
- var path = require('path');
7
-
8
- var _require = require('../templates/linterConstant'),
9
- htmlTemplate = _require.htmlTemplate,
10
- endTag = _require.endTag;
11
-
12
- var _getOptions = getOptions(),
13
- _getOptions$esLint = _getOptions.esLint,
14
- srcBranch = _getOptions$esLint.srcBranch,
15
- targetBranch = _getOptions$esLint.targetBranch,
16
- serviceName = _getOptions$esLint.serviceName,
17
- impactServerDomain = _getOptions$esLint.impactServerDomain,
18
- impactRun = _getOptions$esLint.impactRun,
19
- reportType = _getOptions$esLint.reportType,
20
- reportPath = _getOptions$esLint.reportPath;
1
+ "use strict";
2
+
3
+ let getOptions = require('./getOptions').default;
4
+
5
+ let fs = require('fs');
6
+
7
+ let coverageCollector = require('../jest/coverageCollector');
8
+
9
+ let path = require('path');
10
+
11
+ let {
12
+ htmlTemplate,
13
+ endTag
14
+ } = require('../templates/linterConstant');
15
+
16
+ let {
17
+ esLint: {
18
+ srcBranch,
19
+ targetBranch,
20
+ serviceName,
21
+ impactServerDomain,
22
+ impactRun,
23
+ reportType,
24
+ reportPath
25
+ }
26
+ } = getOptions();
21
27
 
22
28
  function writeFile(filePath, data) {
23
29
  filePath = path.join(process.cwd(), filePath); //eslint-disable-line
24
- var dirName = path.dirname(filePath);
30
+
31
+ let dirName = path.dirname(filePath);
32
+
25
33
  if (!fs.existsSync(dirName)) {
26
34
  fs.mkdirSync(dirName);
27
35
  fs.writeFileSync(filePath, data);
@@ -30,51 +38,55 @@ function writeFile(filePath, data) {
30
38
  }
31
39
  }
32
40
 
33
- var formatter = {
34
- jsonFormatter: function jsonFormatter(data) {
35
- var finalList = [];
36
- data.forEach(function (errorFileObj) {
37
- var tempMessageList = [];
38
- errorFileObj.messages.forEach(function (messageObj) {
41
+ let formatter = {
42
+ jsonFormatter: data => {
43
+ let finalList = [];
44
+ data.forEach(errorFileObj => {
45
+ let tempMessageList = [];
46
+ errorFileObj.messages.forEach(messageObj => {
39
47
  if (messageObj.ruleId === '@zohodesk/zsecurity/no-protocol-check' || messageObj.ruleId === '@zohodesk/zsecurity/no-unsecure-html') {
40
48
  tempMessageList.push(messageObj);
41
49
  }
42
50
  });
51
+
43
52
  if (tempMessageList.length > 0) {
44
53
  finalList.push(errorFileObj);
45
54
  }
46
55
  });
47
56
  return finalList;
48
57
  },
49
- htmlFormatter: function htmlFormatter(data) {
58
+ htmlFormatter: data => {
50
59
  data = formatter.jsonFormatter(data); //eslint-disable-line
60
+
51
61
  if (data.length > 0) {
52
- var liTag = '';
53
- data.forEach(function (errorFileObj) {
54
- liTag = liTag + '<li class="pkLi"><div class="pkRow"> <div class="pkArrowCont" onclick="toggleWrapper(this)"> <div class="pkArrow"></div></div><div class="pkFileName">File Name :</div><div class="pkUrl">' + errorFileObj.filePath + '</div></div><div class="pkDetails"><div class="pkDetailsHead"> <div class="pkDetailsCol">Line No</div><div class="pkDetailsCol">Type</div><div class="pkDetailsCol">Message</div><div class="pkDetailsCol">Name</div></div><div class="pkDetailsBody">';
55
- var messageTag = '';
56
- errorFileObj.messages.forEach(function (messageObj) {
57
- var errorType = messageObj.severity == 2 ? 'Error' : 'Warning'; //eslint-disable-line
58
- messageTag = messageTag + '<div class="pkDetailsRow"><div class="pkDetailsCol">' + messageObj.line + '</div><div class="pkDetailsCol pkError">' + errorType + '</div><div class="pkDetailsCol">' + messageObj.message + '</div><div class="pkDetailsCol">' + messageObj.ruleId + '</div></div>';
62
+ let liTag = '';
63
+ data.forEach(errorFileObj => {
64
+ liTag = `${liTag}<li class="pkLi"><div class="pkRow"> <div class="pkArrowCont" onclick="toggleWrapper(this)"> <div class="pkArrow"></div></div><div class="pkFileName">File Name :</div><div class="pkUrl">${errorFileObj.filePath}</div></div><div class="pkDetails"><div class="pkDetailsHead"> <div class="pkDetailsCol">Line No</div><div class="pkDetailsCol">Type</div><div class="pkDetailsCol">Message</div><div class="pkDetailsCol">Name</div></div><div class="pkDetailsBody">`;
65
+ let messageTag = '';
66
+ errorFileObj.messages.forEach(messageObj => {
67
+ let errorType = messageObj.severity == 2 ? 'Error' : 'Warning'; //eslint-disable-line
68
+
69
+ messageTag = `${messageTag}<div class="pkDetailsRow"><div class="pkDetailsCol">${messageObj.line}</div><div class="pkDetailsCol pkError">${errorType}</div><div class="pkDetailsCol">${messageObj.message}</div><div class="pkDetailsCol">${messageObj.ruleId}</div></div>`;
59
70
  });
60
- liTag = liTag + messageTag + '</div></div></li>';
71
+ liTag = `${liTag + messageTag}</div></div></li>`;
61
72
  });
62
-
63
- return htmlTemplate + '<ul class="pkUl">' + liTag + '</ul>' + endTag;
73
+ return `${htmlTemplate}<ul class="pkUl">${liTag}</ul>${endTag}`;
64
74
  }
65
- return htmlTemplate + '<div class="pkEmpty"><div>No test results with found</div></div>' + endTag;
75
+
76
+ return `${htmlTemplate}<div class="pkEmpty"><div>No test results with found</div></div>${endTag}`;
66
77
  },
67
- xmlFormatter: function xmlFormatter(data) {
78
+ xmlFormatter: data => {
68
79
  data = formatter.jsonFormatter(data); //eslint-disable-line
69
- var startTag = '<jscheck>';
70
- var engTag = '</jscheck>';
71
- var bodyContent = '';
72
- data.forEach(function (errorFileObj) {
73
- var startOfFile = '<file name="' + errorFileObj.filePath + '">';
74
- var endOfFile = '</file>';
75
- var messageContent = '';
76
- errorFileObj.messages.forEach(function (messageObj) {
77
- messageContent = messageContent + '<violation fromLine = "' + messageObj.line + '" type ="' + messageObj.ruleId + '" message ="' + messageObj.message + '" ></violation>';
80
+
81
+ let startTag = '<jscheck>';
82
+ let engTag = '</jscheck>';
83
+ let bodyContent = '';
84
+ data.forEach(errorFileObj => {
85
+ let startOfFile = `<file name="${errorFileObj.filePath}">`;
86
+ let endOfFile = '</file>';
87
+ let messageContent = '';
88
+ errorFileObj.messages.forEach(messageObj => {
89
+ messageContent = `${messageContent}<violation fromLine = "${messageObj.line}" type ="${messageObj.ruleId}" message ="${messageObj.message}" ></violation>`;
78
90
  });
79
91
  bodyContent = bodyContent + startOfFile + messageContent + endOfFile;
80
92
  });
@@ -83,7 +95,8 @@ var formatter = {
83
95
  };
84
96
 
85
97
  function formatSplitter(inputJson) {
86
- var outputData = void 0;
98
+ let outputData;
99
+
87
100
  if (reportType === 'json') {
88
101
  outputData = JSON.stringify(formatter.jsonFormatter(inputJson));
89
102
  } else if (reportType === 'html') {
@@ -91,12 +104,13 @@ function formatSplitter(inputJson) {
91
104
  } else if (reportType === 'xml') {
92
105
  outputData = formatter.xmlFormatter(inputJson);
93
106
  }
107
+
94
108
  writeFile(reportPath, outputData);
95
109
  }
96
110
 
97
111
  module.exports = function (results) {
98
- var erroredFileObjectList = [];
99
- results.forEach(function (fileObject) {
112
+ let erroredFileObjectList = [];
113
+ results.forEach(fileObject => {
100
114
  if (fileObject.errorCount > 0) {
101
115
  erroredFileObjectList.push({
102
116
  filePath: fileObject.filePath,
@@ -106,14 +120,14 @@ module.exports = function (results) {
106
120
  });
107
121
  }
108
122
  });
123
+
109
124
  if (impactRun) {
110
- coverageCollector(srcBranch, targetBranch, serviceName, impactServerDomain).then(function () {
111
- var res = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
125
+ coverageCollector(srcBranch, targetBranch, serviceName, impactServerDomain).then((res = {}) => {
126
+ let impactList = [];
112
127
 
113
- var impactList = [];
114
128
  if (res.STATUS) {
115
129
  if (res.LIST.length > 0) {
116
- erroredFileObjectList.forEach(function (errFileObj) {
130
+ erroredFileObjectList.forEach(errFileObj => {
117
131
  if (res.LIST.indexOf(errFileObj.shortPath) > -1) {
118
132
  impactList.push(errFileObj);
119
133
  }
@@ -1,14 +1,10 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
3
+ var _nodemailer = _interopRequireDefault(require("nodemailer"));
4
4
 
5
- var _nodemailer = require('nodemailer');
5
+ var _index = require("./index");
6
6
 
7
- var _nodemailer2 = _interopRequireDefault(_nodemailer);
8
-
9
- var _index = require('./index');
10
-
11
- var _jsonHelper = require('./jsonHelper');
7
+ var _jsonHelper = require("./jsonHelper");
12
8
 
13
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
10
 
@@ -17,41 +13,30 @@ if (process.argv.length <= 6) {
17
13
  process.exit(-1);
18
14
  }
19
15
 
20
- var _process$argv$slice = process.argv.slice(2),
21
- _process$argv$slice2 = _slicedToArray(_process$argv$slice, 8),
22
- from = _process$argv$slice2[0],
23
- pass = _process$argv$slice2[1],
24
- to = _process$argv$slice2[2],
25
- subject = _process$argv$slice2[3],
26
- html = _process$argv$slice2[4],
27
- cc = _process$argv$slice2[5],
28
- user = _process$argv$slice2[6],
29
- reportURL = _process$argv$slice2[7];
16
+ let [from, pass, to, subject, html, cc, user, reportURL] = process.argv.slice(2);
17
+ (0, _jsonHelper.jsonHelper)(`${process.cwd()}/result.json`, 'Report_URL', reportURL);
30
18
 
31
- (0, _jsonHelper.jsonHelper)(process.cwd() + '/result.json', 'Report_URL', reportURL);
32
-
33
- var transporter = _nodemailer2.default.createTransport({
19
+ let transporter = _nodemailer.default.createTransport({
34
20
  host: 'smtp.tsi.zohocorpin.com',
35
21
  port: 25,
36
22
  secure: false,
37
23
  auth: {
38
- user: user,
39
- pass: pass
24
+ user,
25
+ pass
40
26
  }
41
27
  });
42
28
 
43
- var mailOptions = {
29
+ let mailOptions = {
44
30
  from: from,
45
31
  to: to,
46
32
  cc: cc,
47
33
  subject: subject,
48
34
  html: html
49
35
  };
50
-
51
- transporter.sendMail(mailOptions, function (error, info) {
36
+ transporter.sendMail(mailOptions, (error, info) => {
52
37
  if (error) {
53
38
  (0, _index.log)(error);
54
39
  } else {
55
- (0, _index.log)('Email sent: ' + info.response);
40
+ (0, _index.log)(`Email sent: ${info.response}`);
56
41
  }
57
42
  });