@zohodesk/codestandard-validator 1.0.0-exp-6 → 1.0.0-exp-7
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.
- package/build/hooks/Precommit/commit.js +9 -3
- package/build/hooks/Precommit/errorhelpers.js +2 -8
- package/build/hooks/Precommit/lint.js +8 -10
- package/build/hooks/Precommit/pre-commit-default.js +1 -1
- package/build/hooks/Precommit/utils.js +3 -13
- package/build/hooks/hook.js +1 -2
- package/build/utils/General/SonarQubeUtil.js +3 -7
- package/build/utils/HuskySetup/initializeHusky.js +2 -6
- package/build/utils/PluginsInstallation/installPlugins.js +2 -11
- package/package.json +1 -1
|
@@ -26,10 +26,16 @@ global.analytics = {
|
|
|
26
26
|
totalIssues: 0
|
|
27
27
|
};
|
|
28
28
|
async function preCommitHook() {
|
|
29
|
-
Logger.log(Logger.INFO_TYPE, "Executing pre commit hook...");
|
|
29
|
+
Logger.log(Logger.INFO_TYPE, "\n Executing pre commit hook...");
|
|
30
30
|
Logger.log(Logger.INFO_TYPE, `working dir: ${process.cwd()}`);
|
|
31
|
-
if (await handleMergeCommit())
|
|
32
|
-
|
|
31
|
+
if (await handleMergeCommit()) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
;
|
|
35
|
+
if (!(await ensurePluginsInstalled())) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
;
|
|
33
39
|
const stagedFiles = await safeGetStagedFiles();
|
|
34
40
|
if (stagedFiles.length === 0) {
|
|
35
41
|
Logger.log(Logger.INFO_TYPE, "No staged files. Commit skipped.");
|
|
@@ -4,17 +4,11 @@ const {
|
|
|
4
4
|
Logger
|
|
5
5
|
} = require("../../utils/Logger/Logger");
|
|
6
6
|
const {
|
|
7
|
-
|
|
7
|
+
execSync
|
|
8
8
|
} = require('child_process');
|
|
9
|
-
const {
|
|
10
|
-
promisify
|
|
11
|
-
} = require('util');
|
|
12
|
-
const execAsync = promisify(exec);
|
|
13
9
|
async function calculateGitDiffForFile(branch, file) {
|
|
14
10
|
try {
|
|
15
|
-
const {
|
|
16
|
-
stdout
|
|
17
|
-
} = await execAsync(`git diff -U0 ${branch.trim()} ${file}`);
|
|
11
|
+
const stdout = execSync(`git diff -U0 ${branch.trim()} ${file}`);
|
|
18
12
|
return stdout;
|
|
19
13
|
} catch (err) {
|
|
20
14
|
throw err;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
|
|
4
|
+
execSync
|
|
5
5
|
} = require('child_process');
|
|
6
|
-
const {
|
|
7
|
-
promisify
|
|
8
|
-
} = require('util');
|
|
9
6
|
const fs = require('fs');
|
|
10
7
|
const path = require('path');
|
|
11
8
|
const {
|
|
@@ -37,8 +34,6 @@ const {
|
|
|
37
34
|
const {
|
|
38
35
|
Logger
|
|
39
36
|
} = require('../../utils/Logger/Logger');
|
|
40
|
-
// const { default: fetchProjectIssuesViaCurl } = require('../../utils/General/SonarQubeUtil');
|
|
41
|
-
const execAsync = promisify(exec);
|
|
42
37
|
async function lintFiles(filePath) {
|
|
43
38
|
const ext = path.extname(filePath);
|
|
44
39
|
if (['.js', '.ts', '.tsx', '.jsx', '.properties'].includes(ext)) {
|
|
@@ -62,7 +57,7 @@ async function findEslintErrors(file) {
|
|
|
62
57
|
Logger.log(Logger.INFO_TYPE, 'Eslint executable not found. Make sure eslint plugin is installed');
|
|
63
58
|
return [];
|
|
64
59
|
}
|
|
65
|
-
return
|
|
60
|
+
return execSync(`npx --ignore-existing "${eslintPath}" --config "${eslintConfig}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${file}`).then(({
|
|
66
61
|
stderr
|
|
67
62
|
}) => stderr ? stderr.trim().split('\n') : []).catch(err => {
|
|
68
63
|
Logger.log(Logger.FAILURE_TYPE, err);
|
|
@@ -72,7 +67,7 @@ async function findEslintErrors(file) {
|
|
|
72
67
|
function findStyleLintErrors(filePath) {
|
|
73
68
|
const configFile = path.resolve(getNodeModulesPath(), '.stylelintrc.js');
|
|
74
69
|
const absolutePath = path.join(getRootDirectory(), filePath);
|
|
75
|
-
return
|
|
70
|
+
return execSync(`npx stylelint ${absolutePath} --config ${configFile}`, {
|
|
76
71
|
cwd: getNodeModulesPath()
|
|
77
72
|
}).then(({
|
|
78
73
|
stdout
|
|
@@ -87,7 +82,10 @@ async function runLintWorkflow(files, branch) {
|
|
|
87
82
|
};
|
|
88
83
|
var branchName = getBranchName();
|
|
89
84
|
for (const file of files) {
|
|
90
|
-
if (!getSupportedLanguage().includes(path.extname(file)))
|
|
85
|
+
if (!getSupportedLanguage().includes(path.extname(file))) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
;
|
|
91
89
|
const changeset = extractDiffHunks(await calculateGitDiffForFile(branchName, file));
|
|
92
90
|
const diff = {
|
|
93
91
|
old_path: file,
|
|
@@ -112,7 +110,7 @@ async function runLintWorkflow(files, branch) {
|
|
|
112
110
|
*/
|
|
113
111
|
// const { issues, hasIssue, totalIssues } = fetchProjectIssuesViaCurl("projectName");
|
|
114
112
|
});
|
|
115
|
-
Logger.log(Logger.INFO_TYPE,
|
|
113
|
+
// Logger.log(Logger.INFO_TYPE,global.analytics)
|
|
116
114
|
return global.analytics.status == 'FAILURE' ? true : false;
|
|
117
115
|
}
|
|
118
116
|
module.exports = {
|
|
@@ -222,7 +222,7 @@ function isOnlyWarningsPresentInFile(eslintErrorsPresent) {
|
|
|
222
222
|
*/
|
|
223
223
|
|
|
224
224
|
async function preCommitHook_default() {
|
|
225
|
-
Logger.log(Logger.INFO_TYPE, 'Executing pre commit hook...');
|
|
225
|
+
Logger.log(Logger.INFO_TYPE, '\n Executing pre commit hook...');
|
|
226
226
|
Logger.log(Logger.INFO_TYPE, `working dir : ${process.cwd()}`);
|
|
227
227
|
try {
|
|
228
228
|
let isMerge = await isMergeCommit();
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
|
|
4
|
+
execSync
|
|
5
5
|
} = require("child_process");
|
|
6
|
-
const {
|
|
7
|
-
promisify
|
|
8
|
-
} = require("util");
|
|
9
|
-
const fs = require("fs");
|
|
10
|
-
const path = require("path");
|
|
11
6
|
const {
|
|
12
7
|
getRootDirectory
|
|
13
8
|
} = require("../../utils/General/RootDirectoryUtils/getRootDirectory");
|
|
14
9
|
const {
|
|
15
10
|
checkIfPluginsAreInstalled
|
|
16
11
|
} = require("../../utils/PluginsInstallation/checkIfPluginsAreInstalled");
|
|
17
|
-
const execAsync = promisify(exec);
|
|
18
12
|
async function isMergeCommit() {
|
|
19
13
|
try {
|
|
20
|
-
const
|
|
21
|
-
stdout
|
|
22
|
-
} = await execAsync("git rev-parse -q --verify MERGE_HEAD");
|
|
14
|
+
const stdout = await execSync("git rev-parse -q --verify MERGE_HEAD");
|
|
23
15
|
return Boolean(stdout.trim());
|
|
24
16
|
} catch {
|
|
25
17
|
return false;
|
|
@@ -27,9 +19,7 @@ async function isMergeCommit() {
|
|
|
27
19
|
}
|
|
28
20
|
async function getStagedFiles() {
|
|
29
21
|
try {
|
|
30
|
-
const
|
|
31
|
-
stdout
|
|
32
|
-
} = await execAsync("git diff --staged --name-only");
|
|
22
|
+
const stdout = await execSync("git diff --staged --name-only");
|
|
33
23
|
const files = stdout.trim().split("\n").filter(Boolean);
|
|
34
24
|
return files.filter(file => fs.existsSync(path.resolve(getRootDirectory(), file)));
|
|
35
25
|
} catch {
|
package/build/hooks/hook.js
CHANGED
|
@@ -35,8 +35,7 @@ async function hooks() {
|
|
|
35
35
|
} = getPluginsToInstall();
|
|
36
36
|
await executeMethodsThatReturnBooleanValue('Some issue occurred in installing plugins', installPlugins, uninstalledPlugins);
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
if (process.env.defaultprecommit) {
|
|
38
|
+
if (process.env.CLIPRECOMMIT && Boolean(process.env.CLIPRECOMMIT) == true) {
|
|
40
39
|
require('./Precommit/pre-commit-default');
|
|
41
40
|
} else {
|
|
42
41
|
require('./Precommit/commit');
|
|
@@ -7,12 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
var _Logger = require("../Logger/Logger");
|
|
8
8
|
var _getGeneralInfo = require("./getGeneralInfo");
|
|
9
9
|
const {
|
|
10
|
-
|
|
10
|
+
execSync
|
|
11
11
|
} = require('child_process');
|
|
12
|
-
const {
|
|
13
|
-
promisify
|
|
14
|
-
} = require('util');
|
|
15
|
-
const execAsync = promisify(exec);
|
|
16
12
|
/**
|
|
17
13
|
* Constructs a URL for searching issues in SonarQube.
|
|
18
14
|
*
|
|
@@ -84,8 +80,8 @@ async function fetchProjectIssuesViaCurl(componentKey) {
|
|
|
84
80
|
try {
|
|
85
81
|
const token = 'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), process.env.DECRYPT_TOKEN);
|
|
86
82
|
const command = `curl --tlsv1.2 -s -u "${token}:" "${url}"`;
|
|
87
|
-
const output =
|
|
88
|
-
const json = JSON.parse(output);
|
|
83
|
+
const output = execSync(command).toString();
|
|
84
|
+
const json = JSON.parse(output.toString());
|
|
89
85
|
const {
|
|
90
86
|
issues,
|
|
91
87
|
hasIssue,
|
|
@@ -12,12 +12,8 @@ const {
|
|
|
12
12
|
Logger
|
|
13
13
|
} = require('../Logger/Logger');
|
|
14
14
|
const {
|
|
15
|
-
|
|
15
|
+
execSync
|
|
16
16
|
} = require('child_process');
|
|
17
|
-
const {
|
|
18
|
-
promisify
|
|
19
|
-
} = require('util');
|
|
20
|
-
const execAsync = promisify(exec);
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
19
|
* @function initializeHusky - creates a .husky folder at the root of the project with the husky execution script file
|
|
@@ -27,7 +23,7 @@ async function initializeHusky() {
|
|
|
27
23
|
let isNavigationToRootDirectorySuccessful = navigateToRootDirectory(getRootDirectory());
|
|
28
24
|
if (isNavigationToRootDirectorySuccessful) {
|
|
29
25
|
try {
|
|
30
|
-
|
|
26
|
+
execSync('npx husky@7 install');
|
|
31
27
|
return true;
|
|
32
28
|
} catch (error) {
|
|
33
29
|
Logger.log(Logger.FAILURE_TYPE, error.toString());
|
|
@@ -14,12 +14,8 @@ const {
|
|
|
14
14
|
} = require('../General/getNodeModulesPath');
|
|
15
15
|
const path = require('path');
|
|
16
16
|
const {
|
|
17
|
-
|
|
17
|
+
execSync
|
|
18
18
|
} = require('child_process');
|
|
19
|
-
const {
|
|
20
|
-
promisify
|
|
21
|
-
} = require('util');
|
|
22
|
-
const execAsync = promisify(exec);
|
|
23
19
|
|
|
24
20
|
/**
|
|
25
21
|
* @function installPlugins - installs uninstalled plugins for the project
|
|
@@ -32,17 +28,12 @@ async function installPlugins(pluginsToBeInstalled) {
|
|
|
32
28
|
const installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')} --legacy-peer-deps`;
|
|
33
29
|
Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
|
|
34
30
|
try {
|
|
35
|
-
let {
|
|
36
|
-
stdout,
|
|
37
|
-
stderr
|
|
38
|
-
} = await execAsync(installCommand, {
|
|
31
|
+
let stdout = await execSync(installCommand, {
|
|
39
32
|
cwd: getNodeModulesPath(),
|
|
40
33
|
shell: true
|
|
41
34
|
});
|
|
42
35
|
if (stdout) {
|
|
43
36
|
Logger.logger(stdout);
|
|
44
|
-
} else if (stderr) {
|
|
45
|
-
Logger.logger(stderr);
|
|
46
37
|
}
|
|
47
38
|
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
48
39
|
return restorePackageJsonContent(packageJsonBeforePluginsInstallation);
|