@zohodesk/codestandard-validator 0.0.2-exp-11 → 0.0.2-exp-13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,9 @@ const {
28
28
  getConfigurationPrecommit,
29
29
  getSupportedLanguage
30
30
  } = require('../../utils/General/getGeneralInfo');
31
+ const {
32
+ getRootDirectory
33
+ } = require('../../utils/General/RootDirectoryUtils/getRootDirectory');
31
34
  const {
32
35
  impactBasedPrecommit,
33
36
  shouldWarningsAbortCommit
@@ -62,7 +65,7 @@ async function getStagedFiles() {
62
65
  if (error) {
63
66
  if (error != null) reject("Couldn't fetch staged files");
64
67
  } else if (stderr) {
65
- resolve(stderr.trim().split('\n'));
68
+ resolve(filterDeltedFileFromStagedFiles(stderr.trim().split('\n')));
66
69
  } else if (stdout.trim() === '') {
67
70
  resolve(stdout.trim());
68
71
  }
@@ -70,6 +73,21 @@ async function getStagedFiles() {
70
73
  });
71
74
  }
72
75
 
76
+ /**
77
+ * @function {filterDeltedFileFromStagedFiles} - filter deleted staged files
78
+ * @param {Array<string>} files - staged files
79
+ * @returns
80
+ */
81
+ function filterDeltedFileFromStagedFiles(files) {
82
+ return files.filter(file => {
83
+ const absolutePath = path.resolve(getRootDirectory(), file);
84
+ if (fs.existsSync(absolutePath)) {
85
+ return true;
86
+ }
87
+ return false;
88
+ });
89
+ }
90
+
73
91
  /**
74
92
  * @function findEslintErrors - method Lint given file based on given configuration
75
93
  * @param {*} file - path of file to lint
@@ -31,8 +31,8 @@ const {
31
31
  */
32
32
  async function postInstall() {
33
33
  try {
34
- await executeMethodsThatReturnBooleanValue("Some issue in writing node_modules path to json", writeFsPaths, null);
35
- isGitInitialized() ? await executeMethodsThatReturnBooleanValue("Some issue occurred in setting up husky.", setupHusky, null) : null;
34
+ // await executeMethodsThatReturnBooleanValue( "Some issue in writing node_modules path to json", writeFsPaths,null);
35
+ // isGitInitialized() ? await executeMethodsThatReturnBooleanValue( "Some issue occurred in setting up husky.", setupHusky, null) : null;
36
36
  await executeMethodsThatReturnBooleanValue("Make sure zgit.csez.zohocorpin.com is accessible", cloneViaCdt, null);
37
37
  await executeMethodsThatReturnBooleanValue("Some issue occurred in creating eslint config file.", createEslintConfigFile, null);
38
38
  Logger.log(Logger.SUCCESS_TYPE, "Pre commit setup successful");
@@ -16,13 +16,16 @@ const {
16
16
  const {
17
17
  executeSynchronizedCommands
18
18
  } = require('../General/executeSyncCommands');
19
- const {
19
+ var {
20
20
  type,
21
21
  endPoint,
22
22
  branch,
23
23
  cacheDirectory,
24
24
  commonLinterRepoName
25
25
  } = require('../../../jsonUtils/commonLinterRepoDetails');
26
+ const {
27
+ cliArgsToObject
28
+ } = require("../General/getGeneralInfo");
26
29
  /**
27
30
  * @function cloneViaCdt - Using the "clint development tool" clones the common linter_configuration repo into precommit library
28
31
  * @returns {boolean} - indicating the success or failure of the cloning process
@@ -30,7 +33,14 @@ const {
30
33
 
31
34
  function cloneViaCdt() {
32
35
  removeFolder(getDeleteDirPath());
33
- const commandToCloneCommonConfigRepo = `npx cdt clone --clone:type=${type} --clone:url=${endPoint} --clone:branch=${branch} --clone:cacheDir=${cacheDirectory} --clone:proj:name=${commonLinterRepoName}`;
36
+ const cliArgs = cliArgsToObject(process.argv);
37
+ const userName = cliArgs.lintUsername || undefined;
38
+ const token = cliArgs.lintToken || undefined;
39
+ var absoluteEndPoint = `https://${endPoint}`;
40
+ if (userName && token) {
41
+ absoluteEndPoint = `https://${userName}:${token}@${endPoint}`;
42
+ }
43
+ var commandToCloneCommonConfigRepo = `npx cdt clone --clone:type=${type} --clone:url=${absoluteEndPoint} --clone:branch=${branch} --clone:cacheDir=${cacheDirectory} --clone:proj:name=${commonLinterRepoName}`;
34
44
  let isCommonConfigurationClonedSuccessfully = executeSynchronizedCommands(execSync, [commandToCloneCommonConfigRepo, {
35
45
  cwd: getClonedDirPath()
36
46
  }], `Lint Configuration Cloned Successfully - ${getRepoName() || 'common'}`, 'Could not clone the linters common repo', false, true);
@@ -58,9 +58,33 @@ function getSupportedLanguage() {
58
58
  _language.push('.tsx');
59
59
  return _language;
60
60
  }
61
+
62
+ /**
63
+ * @function cliArgsToObject - convert cli argument to object
64
+ * @param {Array<string>} cliArgs - cli argument from enduser
65
+ * @param {any} isKeyNeedToBeAdded - option
66
+ * @returns {Object}
67
+ */
68
+ function cliArgsToObject(cliArgs, isKeyNeedToBeAdded = null) {
69
+ const processEnv = {};
70
+ cliArgs.forEach(option => {
71
+ if (/^--./.test(option)) {
72
+ const equIndex = option.indexOf('=');
73
+ let key = option.slice(2, equIndex);
74
+ let value = option.slice(equIndex + 1);
75
+ if (equIndex === -1) {
76
+ key = option.slice(2);
77
+ value = true;
78
+ }
79
+ processEnv[key] = value;
80
+ }
81
+ });
82
+ return processEnv;
83
+ }
61
84
  module.exports = {
62
85
  getSupportedLanguage,
63
86
  getTimeStampInfo,
64
87
  getEnv,
65
- getConfigurationPrecommit
88
+ getConfigurationPrecommit,
89
+ cliArgsToObject
66
90
  };
@@ -9,9 +9,10 @@
9
9
  */
10
10
 
11
11
  module.exports = {
12
- endPoint: "https://zgit.csez.zohocorpin.com/code_standard/client_linter/linter_configuration.git",
12
+ endPoint: "zgit.csez.zohocorpin.com/code_standard/client_linter/linter_configuration.git",
13
13
  branch: "master",
14
14
  cacheDirectory: "./",
15
15
  commonLinterRepoName: "configuration",
16
- type: "git"
16
+ type: "git",
17
+ user:"rajasekar.hm"
17
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "0.0.2-exp-11",
3
+ "version": "0.0.2-exp-13",
4
4
  "description": "library to enforce code standard using eslint",
5
5
  "main": "index.js",
6
6
  "scripts": {