@zohodesk/codestandard-validator 1.0.0 → 1.1.0
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 +54 -0
- package/build/hooks/Precommit/errorhelpers.js +57 -0
- package/build/hooks/Precommit/guard.js +50 -0
- package/build/hooks/Precommit/lint.js +118 -0
- package/build/hooks/Precommit/pre-commit-default.js +369 -0
- package/build/hooks/Precommit/pre-commit.js +359 -355
- package/build/hooks/Precommit/utils.js +48 -0
- package/build/hooks/hook.js +18 -10
- package/build/lib/postinstall.js +23 -15
- package/build/setup/sample.config.js +3 -3
- package/build/utils/CloneCommonLinterRepo/cloneViaCdt.js +2 -2
- package/build/utils/General/SonarQubeUtil.js +108 -0
- package/build/utils/General/getGeneralInfo.js +1 -2
- package/build/utils/HuskySetup/configurePrecommitHook.js +4 -1
- package/build/utils/HuskySetup/initializeHusky.js +4 -4
- package/build/utils/Logger/Logger.js +3 -0
- package/build/utils/PluginsInstallation/installPlugins.js +30 -25
- package/changeLog.md +6 -1
- package/index.js +1 -1
- package/jsonUtils/MandatoryListRules.js +3 -0
- package/jsonUtils/commonLinterRepoDetails.js +0 -1
- package/package.json +3 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
execSync
|
|
5
|
+
} = require("child_process");
|
|
6
|
+
const {
|
|
7
|
+
getRootDirectory
|
|
8
|
+
} = require("../../utils/General/RootDirectoryUtils/getRootDirectory");
|
|
9
|
+
const {
|
|
10
|
+
checkIfPluginsAreInstalled
|
|
11
|
+
} = require("../../utils/PluginsInstallation/checkIfPluginsAreInstalled");
|
|
12
|
+
const fs = require("fs");
|
|
13
|
+
const path = require("path");
|
|
14
|
+
async function isMergeCommit() {
|
|
15
|
+
try {
|
|
16
|
+
const stdout = await execSync("git rev-parse -q --verify MERGE_HEAD").toString();
|
|
17
|
+
return Boolean(stdout.trim());
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function getStagedFiles() {
|
|
23
|
+
try {
|
|
24
|
+
const stdout = await execSync("git diff --staged --name-only").toString();
|
|
25
|
+
const files = stdout.trim().split("\n").filter(Boolean);
|
|
26
|
+
return files.filter(file => fs.existsSync(path.resolve(getRootDirectory(), file)));
|
|
27
|
+
} catch {
|
|
28
|
+
throw new Error("Couldn't fetch staged files");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function areAllPluginsInstalled() {
|
|
32
|
+
return checkIfPluginsAreInstalled().uninstalledPlugins.length === 0;
|
|
33
|
+
}
|
|
34
|
+
function isOnlyWarnings(errors) {
|
|
35
|
+
return !errors.some(line => /\b(error|✖)\b/.test(line));
|
|
36
|
+
}
|
|
37
|
+
function extractDiffHunks(diffText) {
|
|
38
|
+
return diffText.split("\n").filter(line => line.startsWith("@@") || line.startsWith("+") || line.startsWith("-"))
|
|
39
|
+
// skip file headers like "+++ b/" or "--- a/"
|
|
40
|
+
.filter(line => !line.startsWith("+++ ") && !line.startsWith("--- ")).join("\n");
|
|
41
|
+
}
|
|
42
|
+
module.exports = {
|
|
43
|
+
isMergeCommit,
|
|
44
|
+
isOnlyWarnings,
|
|
45
|
+
areAllPluginsInstalled,
|
|
46
|
+
getStagedFiles,
|
|
47
|
+
extractDiffHunks
|
|
48
|
+
};
|
package/build/hooks/hook.js
CHANGED
|
@@ -4,23 +4,27 @@ const {
|
|
|
4
4
|
getLastCommitHash,
|
|
5
5
|
getStoredCommitHash,
|
|
6
6
|
updateJsonFile
|
|
7
|
-
} = require(
|
|
7
|
+
} = require('../utils/General/getGeneralInfo');
|
|
8
8
|
const {
|
|
9
9
|
executeMethodsThatReturnBooleanValue
|
|
10
|
-
} = require(
|
|
10
|
+
} = require('../utils/General/wrapperFunctionToExecuteAFunction');
|
|
11
11
|
const {
|
|
12
12
|
cloneViaCdt
|
|
13
|
-
} = require(
|
|
13
|
+
} = require('../utils/CloneCommonLinterRepo/cloneViaCdt');
|
|
14
14
|
const {
|
|
15
15
|
getPluginsToInstall
|
|
16
|
-
} = require(
|
|
16
|
+
} = require('../utils/PluginsInstallation/checkIfPluginsAreInstalled');
|
|
17
17
|
const {
|
|
18
18
|
installPlugins
|
|
19
|
-
} = require(
|
|
20
|
-
const path = require(
|
|
19
|
+
} = require('../utils/PluginsInstallation/installPlugins');
|
|
20
|
+
const path = require('path');
|
|
21
21
|
const {
|
|
22
22
|
Logger
|
|
23
|
-
} = require(
|
|
23
|
+
} = require('../utils/Logger/Logger');
|
|
24
|
+
const config = require(path.join(process.cwd(), 'lint.config.js'));
|
|
25
|
+
process.env.SONARQUBE_EXTERNAL = config.metric_token;
|
|
26
|
+
process.env.SONARQUBE = config.meticHandler_api_token;
|
|
27
|
+
process.env.ZGIT_TOKEN = config.token;
|
|
24
28
|
async function hooks() {
|
|
25
29
|
var jsonFilePath = path.join(__dirname, '..', '..', 'jsonUtils', 'fsUtils.json');
|
|
26
30
|
if (!(getLastCommitHash() == getStoredCommitHash())) {
|
|
@@ -29,12 +33,16 @@ async function hooks() {
|
|
|
29
33
|
return data;
|
|
30
34
|
});
|
|
31
35
|
Logger.log(Logger.INFO_TYPE, `Some rules and plugins are being fetched from a remote source and installed...`);
|
|
32
|
-
await executeMethodsThatReturnBooleanValue(
|
|
36
|
+
await executeMethodsThatReturnBooleanValue('Make sure zgit.csez.zohocorpin.com is accessible', cloneViaCdt, null);
|
|
33
37
|
const {
|
|
34
38
|
uninstalledPlugins
|
|
35
39
|
} = getPluginsToInstall();
|
|
36
|
-
await executeMethodsThatReturnBooleanValue(
|
|
40
|
+
await executeMethodsThatReturnBooleanValue('Some issue occurred in installing plugins', installPlugins, uninstalledPlugins);
|
|
41
|
+
}
|
|
42
|
+
if (process.env.CLIPRECOMMIT && Boolean(process.env.CLIPRECOMMIT) == true) {
|
|
43
|
+
require('./Precommit/pre-commit-default');
|
|
44
|
+
} else {
|
|
45
|
+
require('./Precommit/commit');
|
|
37
46
|
}
|
|
38
|
-
require('./Precommit/pre-commit');
|
|
39
47
|
}
|
|
40
48
|
hooks();
|
package/build/lib/postinstall.js
CHANGED
|
@@ -2,41 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
cloneViaCdt
|
|
5
|
-
} = require(
|
|
5
|
+
} = require('../utils/CloneCommonLinterRepo/cloneViaCdt');
|
|
6
6
|
const {
|
|
7
7
|
setupHusky
|
|
8
|
-
} = require(
|
|
8
|
+
} = require('../utils/HuskySetup/setupHusky');
|
|
9
9
|
const {
|
|
10
10
|
createConfigFile
|
|
11
|
-
} = require(
|
|
11
|
+
} = require('../utils/ConfigFileUtils/createConfigFile');
|
|
12
12
|
const {
|
|
13
13
|
Logger
|
|
14
|
-
} = require(
|
|
14
|
+
} = require('../utils/Logger/Logger');
|
|
15
15
|
const {
|
|
16
16
|
executeMethodsThatReturnBooleanValue
|
|
17
|
-
} = require(
|
|
17
|
+
} = require('../utils/General/wrapperFunctionToExecuteAFunction');
|
|
18
18
|
const {
|
|
19
19
|
arePluginsInstalled
|
|
20
|
-
} = require(
|
|
20
|
+
} = require('../utils/PluginsInstallation/arePluginsInstalled');
|
|
21
21
|
const {
|
|
22
22
|
isGitInitialized
|
|
23
|
-
} = require(
|
|
23
|
+
} = require('../utils/GitActions/gitActions');
|
|
24
24
|
const {
|
|
25
25
|
writeFsPaths
|
|
26
|
-
} = require(
|
|
27
|
-
|
|
26
|
+
} = require('../utils/General/writeProjectDetailsToJson');
|
|
27
|
+
const path = require('path');
|
|
28
28
|
/**
|
|
29
29
|
* @function {postInstall} - This methods setup husky and configuration for executing project
|
|
30
30
|
* @returns {void}
|
|
31
31
|
*/
|
|
32
32
|
async function postInstall() {
|
|
33
33
|
try {
|
|
34
|
-
await executeMethodsThatReturnBooleanValue(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
await executeMethodsThatReturnBooleanValue('Some issue in writing node_modules path to json', writeFsPaths, null).then(() => {
|
|
35
|
+
const {
|
|
36
|
+
getNodeModulesPath
|
|
37
|
+
} = require('../utils/General/getNodeModulesPath');
|
|
38
|
+
const config = require(path.join(getNodeModulesPath(), 'lint.config.js'));
|
|
39
|
+
process.env.SONARQUBE_EXTERNAL = config.metric_token;
|
|
40
|
+
process.env.SONARQUBE = config.meticHandler_api_token;
|
|
41
|
+
process.env.ZGIT_TOKEN = config.token;
|
|
42
|
+
});
|
|
43
|
+
isGitInitialized() ? await executeMethodsThatReturnBooleanValue('Some issue occurred in setting up husky.', setupHusky, null) : null;
|
|
44
|
+
await executeMethodsThatReturnBooleanValue('Make sure zgit.csez.zohocorpin.com is accessible', cloneViaCdt, null);
|
|
45
|
+
await executeMethodsThatReturnBooleanValue('Some issue occurred in creating eslint config file.', createConfigFile, null);
|
|
46
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Pre commit setup successfull');
|
|
47
|
+
// arePluginsInstalled();
|
|
40
48
|
} catch (error) {
|
|
41
49
|
Logger.log(Logger.FAILURE_TYPE, `Kindly retry npm install. & ${error.message}`);
|
|
42
50
|
}
|
|
@@ -25,8 +25,8 @@ module.exports = {
|
|
|
25
25
|
impactBased: true,
|
|
26
26
|
lintReportPath: path.resolve(process.cwd(), "lint-report", "lintReport.json"),
|
|
27
27
|
metricServerHost: "https://client-linters.zdesk.csez.zohocorpin.com",
|
|
28
|
-
meticHandler_api_token: "
|
|
29
|
-
metric_token: "
|
|
28
|
+
meticHandler_api_token: "YWRtaW46YWRtaW4yMDI1",
|
|
29
|
+
metric_token: "sqa_371336f636584b54f662c6495a46228fdc6abaa8",
|
|
30
30
|
branchDiffPath: path.resolve(process.cwd(), "diffBranch.json"),
|
|
31
31
|
gitEndPoint: "https://zgit.csez.zohocorpin.com",
|
|
32
32
|
tsConfigurationPath: path.resolve(process.cwd(), 'tsconfig.json'),
|
|
@@ -34,7 +34,7 @@ module.exports = {
|
|
|
34
34
|
impactBasedPrecommit: true,
|
|
35
35
|
shouldWarningsAbortCommit: false,
|
|
36
36
|
pushMetricsOnPreCommit: true,
|
|
37
|
-
token: "
|
|
37
|
+
token: "k-CyU3t5CCA1Fyzm8dvN",
|
|
38
38
|
compareBranch: 'release',
|
|
39
39
|
supportedExtensions: ['.js', '.jsx', '.ts', '.tsx', '.properties']
|
|
40
40
|
};
|
|
@@ -46,7 +46,7 @@ function cloneViaCdt() {
|
|
|
46
46
|
token
|
|
47
47
|
} = getConfigurationPrecommit();
|
|
48
48
|
const currentEnv = getRunningEnv();
|
|
49
|
-
Logger.log(Logger.INFO_TYPE, `Application is running in the following environment:${currentEnv}`);
|
|
49
|
+
Logger.log(Logger.INFO_TYPE, `Application is running in the following environment:${currentEnv || "Development"}`);
|
|
50
50
|
|
|
51
51
|
// Clean up existing folder
|
|
52
52
|
const deleteDir = getDeleteDirPath();
|
|
@@ -54,7 +54,7 @@ function cloneViaCdt() {
|
|
|
54
54
|
|
|
55
55
|
// Construct endpoint with credentials if in CI or automation
|
|
56
56
|
const isAutomatedEnv = currentEnv === "CI" || currentEnv === "DEVAUTOMATION";
|
|
57
|
-
const authenticatedEndpoint = isAutomatedEnv ? `https://${user}:${
|
|
57
|
+
const authenticatedEndpoint = isAutomatedEnv ? `https://${user}:${process.env.ZGIT_TOKEN}@${endPoint}` : `https://${endPoint}`;
|
|
58
58
|
const cloneCommand = ['npx cdt clone', `--clone:type=${type}`, `--clone:url=${authenticatedEndpoint}`, `--clone:branch=${branch}`, `--clone:cacheDir=${cacheDirectory}`, `--clone:proj:name=${commonLinterRepoName}`].join(' ');
|
|
59
59
|
|
|
60
60
|
// Execute the CDT command
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _Logger = require("../Logger/Logger");
|
|
8
|
+
var _getGeneralInfo = require("./getGeneralInfo");
|
|
9
|
+
const {
|
|
10
|
+
execSync
|
|
11
|
+
} = require('child_process');
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a URL for searching issues in SonarQube.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} componentKey - The key of the component to search issues for.
|
|
16
|
+
* @returns {string} The fully constructed URL for the SonarQube issues search API.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function buildIssuesSearchUrl(componentKey) {
|
|
20
|
+
const {
|
|
21
|
+
metricServerHost = "https://client-linters.zdesk.csez.zohocorpin.com"
|
|
22
|
+
} = (0, _getGeneralInfo.getConfigurationPrecommit)();
|
|
23
|
+
const base = `${metricServerHost}/api/issues/search`;
|
|
24
|
+
const params = new URLSearchParams({
|
|
25
|
+
componentKeys: componentKey,
|
|
26
|
+
s: 'FILE_LINE',
|
|
27
|
+
resolved: 'false',
|
|
28
|
+
ps: '100',
|
|
29
|
+
facets: 'severities,types',
|
|
30
|
+
additionalFields: '_all',
|
|
31
|
+
timeZone: 'Asia/Calcutta'
|
|
32
|
+
});
|
|
33
|
+
return `${base}?${params.toString()}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Extract minimal issue info from SonarQube issues JSON.
|
|
38
|
+
*/
|
|
39
|
+
function extractIssues(json) {
|
|
40
|
+
var hasIssue = false;
|
|
41
|
+
var totalIssues = json.issues.length;
|
|
42
|
+
if (!json || !Array.isArray(json.issues)) return [];
|
|
43
|
+
return {
|
|
44
|
+
issues: json.issues.map(i => {
|
|
45
|
+
if (i.severity == 'MAJOR') {
|
|
46
|
+
hasIssue = true;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
key: i.key,
|
|
50
|
+
component: i.component,
|
|
51
|
+
severity: i.severity,
|
|
52
|
+
type: i.type,
|
|
53
|
+
message: i.message,
|
|
54
|
+
line: i.line,
|
|
55
|
+
rule: i.rule,
|
|
56
|
+
status: i.status
|
|
57
|
+
};
|
|
58
|
+
}),
|
|
59
|
+
hasIssue,
|
|
60
|
+
totalIssues
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Fetches project issues for a given component key using a cURL command.
|
|
66
|
+
*
|
|
67
|
+
* This function constructs a URL to search for issues, decrypts an API token,
|
|
68
|
+
* and executes a cURL command to retrieve the issues in JSON format. It then
|
|
69
|
+
* extracts and returns the issues along with the raw JSON response.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} componentKey - The key of the component for which issues are to be fetched.
|
|
72
|
+
* @returns {Object} An object containing:
|
|
73
|
+
* - {Object|null} raw: The raw JSON response from the API, or null if an error occurred.
|
|
74
|
+
* - {Array} issues: An array of extracted issues, or an empty array if an error occurred.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
async function fetchProjectIssuesViaCurl(componentKey) {
|
|
78
|
+
_Logger.Logger.log(_Logger.Logger.INFO_TYPE, `\n Fetching issues (curl) for component: ${componentKey}`);
|
|
79
|
+
const url = buildIssuesSearchUrl(componentKey);
|
|
80
|
+
try {
|
|
81
|
+
const token = process.env.SONARQUBE; //'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), ); // sonarqube
|
|
82
|
+
const command = `curl --tlsv1.2 -s -u "${token}:" "${url}"`;
|
|
83
|
+
const output = execSync(command).toString();
|
|
84
|
+
const json = JSON.parse(output.toString());
|
|
85
|
+
const {
|
|
86
|
+
issues,
|
|
87
|
+
hasIssue,
|
|
88
|
+
totalIssues
|
|
89
|
+
} = extractIssues(json);
|
|
90
|
+
_Logger.Logger.log(_Logger.Logger.INFO_TYPE, `Retrieved ${issues.length} issues.`);
|
|
91
|
+
return {
|
|
92
|
+
raw: json,
|
|
93
|
+
issues,
|
|
94
|
+
hasIssue,
|
|
95
|
+
totalIssues
|
|
96
|
+
};
|
|
97
|
+
} catch (err) {
|
|
98
|
+
_Logger.Logger.log(_Logger.Logger.FAILURE_TYPE, 'Issue fetching project issues (curl)');
|
|
99
|
+
_Logger.Logger.log(_Logger.Logger.FAILURE_TYPE, err);
|
|
100
|
+
return {
|
|
101
|
+
raw: null,
|
|
102
|
+
issues: [],
|
|
103
|
+
hasIssue: true,
|
|
104
|
+
totalIssues: 0
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
var _default = exports.default = fetchProjectIssuesViaCurl;
|
|
@@ -7,7 +7,6 @@ const {
|
|
|
7
7
|
execSync
|
|
8
8
|
} = require('child_process');
|
|
9
9
|
const {
|
|
10
|
-
readOnlyToken,
|
|
11
10
|
commitHashEndPoint
|
|
12
11
|
} = require('../../../jsonUtils/commonLinterRepoDetails');
|
|
13
12
|
const {
|
|
@@ -91,7 +90,7 @@ function getRunningEnv() {
|
|
|
91
90
|
function getLastCommitHash() {
|
|
92
91
|
try {
|
|
93
92
|
var _JSON$parse$;
|
|
94
|
-
const cmd = `curl --header "PRIVATE-TOKEN: ${
|
|
93
|
+
const cmd = `curl --header "PRIVATE-TOKEN: ${process.env.ZGIT_TOKEN}" --url ${commitHashEndPoint}`;
|
|
95
94
|
return (_JSON$parse$ = JSON.parse(execSync(cmd))[0]) === null || _JSON$parse$ === void 0 ? void 0 : _JSON$parse$.id;
|
|
96
95
|
} catch (err) {
|
|
97
96
|
Logger.log(Logger.FAILURE_TYPE, err);
|
|
@@ -14,6 +14,9 @@ const {
|
|
|
14
14
|
const {
|
|
15
15
|
executeSynchronizedCommands
|
|
16
16
|
} = require("../General/executeSyncCommands");
|
|
17
|
+
const {
|
|
18
|
+
getNodeModulesPath
|
|
19
|
+
} = require("../General/getNodeModulesPath");
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* @function configurePrecommitHook - creates the link to custom pre commit hook file and husky precommit file
|
|
@@ -26,7 +29,7 @@ function configurePrecommitHook() {
|
|
|
26
29
|
let huskyPrecommitHookContent = `#!/bin/sh
|
|
27
30
|
. "$(dirname "$0")/_/husky.sh"
|
|
28
31
|
|
|
29
|
-
"${customPrecomitHookPath}"
|
|
32
|
+
cd "${getNodeModulesPath()}" && "${customPrecomitHookPath}"
|
|
30
33
|
`;
|
|
31
34
|
let isCustomPrecommitConfigurationSuccessful = executeSynchronizedCommands(writeFileSync, [huskyPrecommitPath, huskyPrecommitHookContent, 'utf-8'], '', 'Could not create and write pre-commit.sh inisde husky directory', false, true);
|
|
32
35
|
if (isCustomPrecommitConfigurationSuccessful) {
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint-disable no-console */
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
execSync
|
|
7
|
-
} = require('child_process');
|
|
8
5
|
const {
|
|
9
6
|
navigateToRootDirectory
|
|
10
7
|
} = require('../General/RootDirectoryUtils/navigateToRootDirectory');
|
|
@@ -14,12 +11,15 @@ const {
|
|
|
14
11
|
const {
|
|
15
12
|
Logger
|
|
16
13
|
} = require('../Logger/Logger');
|
|
14
|
+
const {
|
|
15
|
+
execSync
|
|
16
|
+
} = require('child_process');
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @function initializeHusky - creates a .husky folder at the root of the project with the husky execution script file
|
|
20
20
|
* @returns {boolean} - indicating the success or failure of initializing husky process
|
|
21
21
|
*/
|
|
22
|
-
function initializeHusky() {
|
|
22
|
+
async function initializeHusky() {
|
|
23
23
|
let isNavigationToRootDirectorySuccessful = navigateToRootDirectory(getRootDirectory());
|
|
24
24
|
if (isNavigationToRootDirectorySuccessful) {
|
|
25
25
|
try {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
execSync
|
|
5
|
-
} = require('child_process');
|
|
6
3
|
const {
|
|
7
4
|
writeFileSync
|
|
8
5
|
} = require('fs');
|
|
@@ -15,36 +12,44 @@ const {
|
|
|
15
12
|
const {
|
|
16
13
|
getNodeModulesPath
|
|
17
14
|
} = require('../General/getNodeModulesPath');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const {
|
|
17
|
+
spawnSync,
|
|
18
|
+
spawn
|
|
19
|
+
} = require('child_process');
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* @function installPlugins - installs uninstalled plugins for the project
|
|
21
23
|
* @returns {boolean} - indicating if plugins to be installed are installed successfully or not
|
|
22
24
|
*/
|
|
23
|
-
function installPlugins(pluginsToBeInstalled) {
|
|
25
|
+
async function installPlugins(pluginsToBeInstalled) {
|
|
24
26
|
if (pluginsToBeInstalled.length > 0) {
|
|
25
27
|
let packageJsonBeforePluginsInstallation = getPackageJsonContentBeforeInstallingPlugins();
|
|
26
|
-
Logger.log(Logger.
|
|
27
|
-
const
|
|
28
|
-
Logger.log(Logger.INFO_TYPE, `Install command being executed: ${
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
28
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Installing rule plugins; this may take some time.');
|
|
29
|
+
const args = ['install', '--save-dev', ...pluginsToBeInstalled, '--legacy-peer-deps'];
|
|
30
|
+
Logger.log(Logger.INFO_TYPE, `Install command being executed: npm ${args.join(' ')}`);
|
|
31
|
+
const result = spawnSync('npm', args, {
|
|
32
|
+
cwd: getNodeModulesPath(),
|
|
33
|
+
shell: false,
|
|
34
|
+
encoding: 'utf8'
|
|
35
|
+
});
|
|
36
|
+
if (result.stdout) {
|
|
37
|
+
Logger.logger(result.stdout);
|
|
38
|
+
}
|
|
39
|
+
if (result.stderr) {
|
|
40
|
+
Logger.log(Logger.INFO_TYPE, result.stderr);
|
|
41
|
+
}
|
|
42
|
+
if (result.error) {
|
|
43
|
+
Logger.log(Logger.FAILURE_TYPE, 'Unable to install plugins. Spawn error.');
|
|
44
|
+
Logger.log(Logger.FAILURE_TYPE, result.error);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (result.status !== 0) {
|
|
48
|
+
Logger.log(Logger.FAILURE_TYPE, `npm exited with code ${result.status}`);
|
|
46
49
|
return false;
|
|
47
50
|
}
|
|
51
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
52
|
+
return restorePackageJsonContent(packageJsonBeforePluginsInstallation);
|
|
48
53
|
} else {
|
|
49
54
|
Logger.log(Logger.INFO_TYPE, 'Plugins are already installed');
|
|
50
55
|
return true;
|
|
@@ -66,7 +71,7 @@ function getPackageJsonContentBeforeInstallingPlugins() {
|
|
|
66
71
|
* @returns {Boolean} - indicating the success or failure of restoring package.json content
|
|
67
72
|
*/
|
|
68
73
|
function restorePackageJsonContent(packageJsonContentBeforePluginsInstallation) {
|
|
69
|
-
let packageJsonFilePath =
|
|
74
|
+
let packageJsonFilePath = path.join(getNodeModulesPath(), 'package.json');
|
|
70
75
|
let isPackageJsonRestored = executeSynchronizedCommands(writeFileSync, [packageJsonFilePath, JSON.stringify(packageJsonContentBeforePluginsInstallation, null, 2)], 'Package.json content restored successfully', 'Unable to restore package.json content', false, true);
|
|
71
76
|
return isPackageJsonRestored;
|
|
72
77
|
}
|
package/changeLog.md
CHANGED
|
@@ -35,4 +35,9 @@
|
|
|
35
35
|
# 1.0.0 - Support For Stylelint
|
|
36
36
|
|
|
37
37
|
1. Enhancement Parser support CSS files and linter
|
|
38
|
-
2. Clone Configuration Flow Enhancement Validation
|
|
38
|
+
2. Clone Configuration Flow Enhancement Validation
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# 1.1.0 - SonarQube Enable
|
|
42
|
+
|
|
43
|
+
1. Enable sonarqube with flag with backward compactibility
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/codestandard-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "library to enforce code standard using eslint",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"type": "commonjs",
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@zohodesk/codestandard-analytics": "1.1.2",
|
|
18
19
|
"@zohodesk-private/client_deployment_tool": "0.0.5",
|
|
19
20
|
"eslint": "8.26.0",
|
|
20
|
-
"stylelint":"16.23.0"
|
|
21
|
+
"stylelint": "16.23.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@babel/core": "7.24.7",
|