@zohodesk/codestandard-validator 0.0.4-exp-15 → 0.0.4-exp-17
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/bin/cli.js +0 -0
- package/build/hooks/Precommit/pre-commit.js +3 -21
- package/build/lib/cli.js +1 -7
- package/build/lib/postinstall.js +1 -1
- package/build/setup/sample.config.js +2 -2
- package/build/utils/CloneCommonLinterRepo/cloneViaCdt.js +3 -24
- package/build/utils/General/getGeneralInfo.js +1 -11
- package/build/utils/HuskySetup/initializeHusky.js +1 -1
- package/build/utils/HuskySetup/setupHusky.js +51 -8
- package/build/utils/PluginsInstallation/arePluginsInstalled.js +2 -5
- package/build/utils/PluginsInstallation/checkIfPluginsAreInstalled.js +20 -74
- package/build/utils/PluginsInstallation/installPlugins.js +5 -12
- package/build/utils/PluginsInstallation/printUninstalledPlugins.js +5 -5
- package/package.json +1 -1
- package/build/utils/FileAndFolderOperations/versionControl.js +0 -25
- package/build/utils/General/Hash.js +0 -21
- package/build/utils/PluginsInstallation/Worker/installPluginsByWoker.js +0 -35
- package/build/utils/PluginsInstallation/Worker/worker.js +0 -33
package/bin/cli.js
CHANGED
|
File without changes
|
|
@@ -28,9 +28,6 @@ const {
|
|
|
28
28
|
getConfigurationPrecommit,
|
|
29
29
|
getSupportedLanguage
|
|
30
30
|
} = require('../../utils/General/getGeneralInfo');
|
|
31
|
-
const {
|
|
32
|
-
getRootDirectory
|
|
33
|
-
} = require('../../utils/General/RootDirectoryUtils/getRootDirectory');
|
|
34
31
|
const {
|
|
35
32
|
impactBasedPrecommit,
|
|
36
33
|
shouldWarningsAbortCommit
|
|
@@ -65,7 +62,7 @@ async function getStagedFiles() {
|
|
|
65
62
|
if (error) {
|
|
66
63
|
if (error != null) reject("Couldn't fetch staged files");
|
|
67
64
|
} else if (stderr) {
|
|
68
|
-
resolve(
|
|
65
|
+
resolve(stderr.trim().split('\n'));
|
|
69
66
|
} else if (stdout.trim() === '') {
|
|
70
67
|
resolve(stdout.trim());
|
|
71
68
|
}
|
|
@@ -73,21 +70,6 @@ async function getStagedFiles() {
|
|
|
73
70
|
});
|
|
74
71
|
}
|
|
75
72
|
|
|
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
|
-
|
|
91
73
|
/**
|
|
92
74
|
* @function findEslintErrors - method Lint given file based on given configuration
|
|
93
75
|
* @param {*} file - path of file to lint
|
|
@@ -293,9 +275,9 @@ async function preCommitHook() {
|
|
|
293
275
|
Logger.log(Logger.INFO_TYPE, 'Error executing pre commit hook');
|
|
294
276
|
}
|
|
295
277
|
if (shouldAbortCommit) {
|
|
296
|
-
Logger.log(Logger.FAILURE_TYPE, `There are eslint errors
|
|
278
|
+
Logger.log(Logger.FAILURE_TYPE, `There are eslint errors present. So commit is aborted. If possible try to fix the eslint warnings also.`);
|
|
297
279
|
process.exit(1);
|
|
298
|
-
} else
|
|
280
|
+
} else {
|
|
299
281
|
Logger.log(Logger.SUCCESS_TYPE, `Commit Successful`);
|
|
300
282
|
process.exit(0);
|
|
301
283
|
}
|
package/build/lib/cli.js
CHANGED
|
@@ -15,9 +15,6 @@ const {
|
|
|
15
15
|
const {
|
|
16
16
|
installPlugins
|
|
17
17
|
} = require("../utils/PluginsInstallation/installPlugins");
|
|
18
|
-
const {
|
|
19
|
-
checkIfPluginsAreInstalled
|
|
20
|
-
} = require("../utils/PluginsInstallation/checkIfPluginsAreInstalled");
|
|
21
18
|
const [,, action, ...options] = process.argv;
|
|
22
19
|
async function run() {
|
|
23
20
|
switch (action) {
|
|
@@ -33,10 +30,7 @@ async function run() {
|
|
|
33
30
|
}
|
|
34
31
|
case "setupPlugins":
|
|
35
32
|
{
|
|
36
|
-
|
|
37
|
-
uninstalledPlugins
|
|
38
|
-
} = checkIfPluginsAreInstalled();
|
|
39
|
-
await executeMethodsThatReturnBooleanValue("Some issue occurred in installing plugins", installPlugins, uninstalledPlugins);
|
|
33
|
+
await executeMethodsThatReturnBooleanValue("Some issue occurred in installing plugins", installPlugins, null);
|
|
40
34
|
break;
|
|
41
35
|
}
|
|
42
36
|
case "setupExtension":
|
package/build/lib/postinstall.js
CHANGED
|
@@ -35,7 +35,7 @@ async function postInstall() {
|
|
|
35
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
|
-
Logger.log(Logger.SUCCESS_TYPE, "Pre commit setup
|
|
38
|
+
Logger.log(Logger.SUCCESS_TYPE, "Pre commit setup successful");
|
|
39
39
|
arePluginsInstalled();
|
|
40
40
|
} catch (error) {
|
|
41
41
|
Logger.log(Logger.FAILURE_TYPE, `Kindly retry npm install. & ${error.message}`);
|
|
@@ -8,7 +8,7 @@ const path = require("path");
|
|
|
8
8
|
* @property {boolean} impactBased - Indicates if the linting is impact-based.
|
|
9
9
|
* @property {string} lintReportPath - The path to the lint report JSON file.
|
|
10
10
|
* @property {string} metricServerHost - The URL of the SonarQube server.
|
|
11
|
-
* @property {string}
|
|
11
|
+
* @property {string} exemptionInstanceHost - This is Exemption running host URL
|
|
12
12
|
* @property {string} metric_token - The token for authentication with the SonarQube server.
|
|
13
13
|
* @property {string} gitEndPoint - API EndPoint for Git Actions
|
|
14
14
|
* @property {string} tsConfigurationPath - The path of the ts configuration Path
|
|
@@ -24,7 +24,7 @@ module.exports = {
|
|
|
24
24
|
impactBased: true,
|
|
25
25
|
lintReportPath: path.resolve(process.cwd(), "lint-report", "lintReport.json"),
|
|
26
26
|
metricServerHost: "https://client-linters.zohodesk.csez.zohocorpin.com",
|
|
27
|
-
|
|
27
|
+
exemptionInstanceHost: "",
|
|
28
28
|
metric_token: "zxh_9737850jh2l53ml17223929ihii73072j54j2260",
|
|
29
29
|
branchDiffPath: path.resolve(process.cwd(), "diffBranch.json"),
|
|
30
30
|
gitEndPoint: "https://zgit.csez.zohocorpin.com",
|
|
@@ -16,42 +16,21 @@ const {
|
|
|
16
16
|
const {
|
|
17
17
|
executeSynchronizedCommands
|
|
18
18
|
} = require('../General/executeSyncCommands');
|
|
19
|
-
|
|
19
|
+
const {
|
|
20
20
|
type,
|
|
21
21
|
endPoint,
|
|
22
22
|
branch,
|
|
23
23
|
cacheDirectory,
|
|
24
|
-
commonLinterRepoName
|
|
25
|
-
user
|
|
24
|
+
commonLinterRepoName
|
|
26
25
|
} = require('../../../jsonUtils/commonLinterRepoDetails');
|
|
27
|
-
const {
|
|
28
|
-
getConfigurationPrecommit,
|
|
29
|
-
getRunningEnv
|
|
30
|
-
} = require("../General/getGeneralInfo");
|
|
31
|
-
const {
|
|
32
|
-
decrypt
|
|
33
|
-
} = require("../General/Hash");
|
|
34
|
-
const {
|
|
35
|
-
Logger
|
|
36
|
-
} = require("../Logger/Logger");
|
|
37
26
|
/**
|
|
38
27
|
* @function cloneViaCdt - Using the "clint development tool" clones the common linter_configuration repo into precommit library
|
|
39
28
|
* @returns {boolean} - indicating the success or failure of the cloning process
|
|
40
29
|
*/
|
|
41
30
|
|
|
42
31
|
function cloneViaCdt() {
|
|
43
|
-
const {
|
|
44
|
-
token
|
|
45
|
-
} = getConfigurationPrecommit();
|
|
46
32
|
removeFolder(getDeleteDirPath());
|
|
47
|
-
const
|
|
48
|
-
var absoluteEndPoint = `https://${endPoint}`;
|
|
49
|
-
const runningEnv = getRunningEnv();
|
|
50
|
-
if (runningEnv === "CI" || runningEnv === "DEVAUTOMATION") {
|
|
51
|
-
Logger.log(Logger.INFO_TYPE, `Running in ${runningEnv}`);
|
|
52
|
-
absoluteEndPoint = `https://${userName}:${decrypt(token, 12)}@${endPoint}`;
|
|
53
|
-
}
|
|
54
|
-
var commandToCloneCommonConfigRepo = `npx cdt clone --clone:type=${type} --clone:url=${absoluteEndPoint} --clone:branch=${branch} --clone:cacheDir=${cacheDirectory} --clone:proj:name=${commonLinterRepoName}`;
|
|
33
|
+
const commandToCloneCommonConfigRepo = `npx cdt clone --clone:type=${type} --clone:url=${endPoint} --clone:branch=${branch} --clone:cacheDir=${cacheDirectory} --clone:proj:name=${commonLinterRepoName}`;
|
|
55
34
|
let isCommonConfigurationClonedSuccessfully = executeSynchronizedCommands(execSync, [commandToCloneCommonConfigRepo, {
|
|
56
35
|
cwd: getClonedDirPath()
|
|
57
36
|
}], `Lint Configuration Cloned Successfully - ${getRepoName() || 'common'}`, 'Could not clone the linters common repo', false, true);
|
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
const os = require('os');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const fs = require("fs");
|
|
6
|
-
const {
|
|
7
|
-
execSync
|
|
8
|
-
} = require('child_process');
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
8
|
* @function getTimeStampInfo - to fetch various timestamp details
|
|
@@ -61,16 +58,9 @@ function getSupportedLanguage() {
|
|
|
61
58
|
_language.push('.tsx');
|
|
62
59
|
return _language;
|
|
63
60
|
}
|
|
64
|
-
function getRunningEnv() {
|
|
65
|
-
const command = "npm config get lint_env";
|
|
66
|
-
return execSync(command, {
|
|
67
|
-
shell: true
|
|
68
|
-
}).toString().trim();
|
|
69
|
-
}
|
|
70
61
|
module.exports = {
|
|
71
62
|
getSupportedLanguage,
|
|
72
63
|
getTimeStampInfo,
|
|
73
64
|
getEnv,
|
|
74
|
-
getConfigurationPrecommit
|
|
75
|
-
getRunningEnv
|
|
65
|
+
getConfigurationPrecommit
|
|
76
66
|
};
|
|
@@ -23,7 +23,7 @@ function initializeHusky() {
|
|
|
23
23
|
let isNavigationToRootDirectorySuccessful = navigateToRootDirectory(getRootDirectory());
|
|
24
24
|
if (isNavigationToRootDirectorySuccessful) {
|
|
25
25
|
try {
|
|
26
|
-
execSync('npx husky
|
|
26
|
+
execSync('npx husky install');
|
|
27
27
|
return true;
|
|
28
28
|
} catch (error) {
|
|
29
29
|
Logger.log(Logger.FAILURE_TYPE, error.toString());
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/* eslint-disable no-console */
|
|
4
|
+
const {
|
|
5
|
+
execSync
|
|
6
|
+
} = require('child_process');
|
|
7
|
+
const {
|
|
8
|
+
readdirSync
|
|
9
|
+
} = require('fs');
|
|
10
|
+
const path = require('path');
|
|
4
11
|
const initializeHusky = require('./initializeHusky');
|
|
5
12
|
const configurePrecommitHook = require('./configurePrecommitHook');
|
|
13
|
+
const {
|
|
14
|
+
getNodeModulesPath
|
|
15
|
+
} = require('../General/getNodeModulesPath');
|
|
16
|
+
const {
|
|
17
|
+
executeSynchronizedCommands
|
|
18
|
+
} = require('../General/executeSyncCommands');
|
|
6
19
|
const {
|
|
7
20
|
Logger
|
|
8
21
|
} = require('../Logger/Logger');
|
|
@@ -13,21 +26,51 @@ let isCustomPrecommitConfigurationSuccessful = false;
|
|
|
13
26
|
* @returns {boolean} - indicating whether entire custom precommit hook setup using husky process is success or failure
|
|
14
27
|
*/
|
|
15
28
|
function setupHusky() {
|
|
16
|
-
let
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
let isHuskyPackageInstalled = installHuskyPackage();
|
|
30
|
+
if (isHuskyPackageInstalled) {
|
|
31
|
+
let isHuskyInitializedSuccessfully = initializeHusky();
|
|
32
|
+
if (isHuskyInitializedSuccessfully) {
|
|
33
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Husky installation successful');
|
|
34
|
+
isCustomPrecommitConfigurationSuccessful = configurePrecommitHook();
|
|
35
|
+
if (isCustomPrecommitConfigurationSuccessful) {
|
|
36
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Custom pre commit hook setup was successful');
|
|
37
|
+
return true;
|
|
38
|
+
} else {
|
|
39
|
+
Logger.log(Logger.FAILURE_TYPE, 'Couldn\'t configure custom pre commit hook');
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
23
42
|
} else {
|
|
24
|
-
Logger.log(Logger.FAILURE_TYPE, 'Couldn\'t configure custom pre commit hook');
|
|
25
43
|
return false;
|
|
26
44
|
}
|
|
27
45
|
} else {
|
|
46
|
+
Logger.log(Logger.FAILURE_TYPE, 'Some issue in installing husky package.');
|
|
28
47
|
return false;
|
|
29
48
|
}
|
|
30
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @function installHuskyPackage - installs husky package if not installed for the project
|
|
53
|
+
* @returns {boolean} - indicating if husky package installed successfully or not
|
|
54
|
+
*/
|
|
55
|
+
function installHuskyPackage() {
|
|
56
|
+
const nodeModulesPathOfProject = path.join(getNodeModulesPath(), 'node_modules');
|
|
57
|
+
let pluginsInNodeModules = executeSynchronizedCommands(readdirSync, [nodeModulesPathOfProject], '', 'Unable to get directories in node_modules when checking if husky is installed', true, false);
|
|
58
|
+
let husky = {
|
|
59
|
+
packageName: 'husky',
|
|
60
|
+
version: '^7.0.4'
|
|
61
|
+
};
|
|
62
|
+
let isHuskyInstalled = pluginsInNodeModules.includes(husky.packageName) ? true : false;
|
|
63
|
+
if (!isHuskyInstalled) {
|
|
64
|
+
Logger.log(Logger.INFO_TYPE, 'Installing husky package ....');
|
|
65
|
+
let installCommand = `npm install ${husky.packageName}@${husky.version} --save-dev`;
|
|
66
|
+
let isHuskyPackageInstalled = executeSynchronizedCommands(execSync, [installCommand, {
|
|
67
|
+
stdio: 'inherit'
|
|
68
|
+
}], 'Husky package Installed Successfully', 'Unable to install husky package', false, true);
|
|
69
|
+
return isHuskyPackageInstalled;
|
|
70
|
+
}
|
|
71
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Husky package already installed!');
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
31
74
|
module.exports = {
|
|
32
75
|
setupHusky
|
|
33
76
|
};
|
|
@@ -7,11 +7,8 @@ const {
|
|
|
7
7
|
printUninstalledPlugins
|
|
8
8
|
} = require('./printUninstalledPlugins');
|
|
9
9
|
function arePluginsInstalled() {
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
noPluginMessage
|
|
13
|
-
} = checkIfPluginsAreInstalled();
|
|
14
|
-
printUninstalledPlugins(uninstalledPlugins, noPluginMessage);
|
|
10
|
+
let uninstalledPlugins = checkIfPluginsAreInstalled();
|
|
11
|
+
printUninstalledPlugins(uninstalledPlugins);
|
|
15
12
|
}
|
|
16
13
|
module.exports = {
|
|
17
14
|
arePluginsInstalled
|
|
@@ -74,50 +74,30 @@ function getAllPlugins() {
|
|
|
74
74
|
*/
|
|
75
75
|
function checkIfPluginsAreInstalled() {
|
|
76
76
|
const pluginsForCurrentRepo = getAllPlugins();
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
let uninstalledPlugins = [];
|
|
78
|
+
let plugin = {
|
|
79
79
|
noPluginMessage: '',
|
|
80
80
|
uninstalledPlugins: []
|
|
81
81
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// }
|
|
95
|
-
// else if(pluginsIndevDependencies === undefined){
|
|
96
|
-
// Logger.log(Logger.INFO_TYPE,'No devDependencies present!')
|
|
97
|
-
// }
|
|
98
|
-
// }
|
|
99
|
-
// else{
|
|
100
|
-
// arePluginsPresentIndevDependencies = false
|
|
101
|
-
// }
|
|
102
|
-
|
|
103
|
-
// arePluginsPresentForCurrentRepo = pluginsForCurrentRepo.length !== 0 ? true : false
|
|
104
|
-
|
|
105
|
-
uninstalledPlugins = pluginsForCurrentRepo.map(plugin => {
|
|
106
|
-
const {
|
|
107
|
-
packageName,
|
|
108
|
-
version
|
|
109
|
-
} = plugin;
|
|
110
|
-
const {
|
|
111
|
-
isPluginPresent,
|
|
112
|
-
pluginPath
|
|
113
|
-
} = checkPluginsPresentInNodemodules(packageName);
|
|
114
|
-
if (isPluginPresent && checkPluginHasProperVersion(packageName, pluginPath, version)) {
|
|
115
|
-
return false;
|
|
82
|
+
let pluginsIndevDependencies = {};
|
|
83
|
+
let pluginNamesOfDevDependencyPlugins = [];
|
|
84
|
+
let arePluginsPresentIndevDependencies = false;
|
|
85
|
+
let arePluginsPresentForCurrentRepo = false;
|
|
86
|
+
if (existsSync(path.join(getNodeModulesPath(), 'package.json'))) {
|
|
87
|
+
let packageJsonContent = require(path.join(getNodeModulesPath(), 'package.json'));
|
|
88
|
+
pluginsIndevDependencies = packageJsonContent.devDependencies;
|
|
89
|
+
if (pluginsIndevDependencies !== undefined) {
|
|
90
|
+
arePluginsPresentIndevDependencies = true;
|
|
91
|
+
pluginNamesOfDevDependencyPlugins = Object.keys(pluginsIndevDependencies);
|
|
92
|
+
} else if (pluginsIndevDependencies === undefined) {
|
|
93
|
+
Logger.log(Logger.INFO_TYPE, 'No devDependencies present!');
|
|
116
94
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
95
|
+
} else {
|
|
96
|
+
arePluginsPresentIndevDependencies = false;
|
|
97
|
+
}
|
|
98
|
+
arePluginsPresentForCurrentRepo = pluginsForCurrentRepo.length !== 0 ? true : false;
|
|
99
|
+
if (arePluginsPresentForCurrentRepo || arePluginsPresentIndevDependencies) {
|
|
100
|
+
uninstalledPlugins = getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, pluginsIndevDependencies);
|
|
121
101
|
plugin.noPluginMessage = '';
|
|
122
102
|
plugin.uninstalledPlugins = uninstalledPlugins;
|
|
123
103
|
return plugin;
|
|
@@ -127,40 +107,6 @@ function checkIfPluginsAreInstalled() {
|
|
|
127
107
|
return plugin;
|
|
128
108
|
}
|
|
129
109
|
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @function checkPluginsPresentInNodemodules - to check if the plugin is present in the node_modules of the project
|
|
133
|
-
* @param {string} rulePluginName
|
|
134
|
-
* @returns
|
|
135
|
-
*/
|
|
136
|
-
function checkPluginsPresentInNodemodules(rulePluginName) {
|
|
137
|
-
try {
|
|
138
|
-
const pluginPath = require.resolve(rulePluginName.toString());
|
|
139
|
-
return {
|
|
140
|
-
pluginPath: pluginPath,
|
|
141
|
-
isPluginPresent: existsSync(pluginPath)
|
|
142
|
-
};
|
|
143
|
-
} catch (error) {
|
|
144
|
-
return {
|
|
145
|
-
pluginPath: "",
|
|
146
|
-
isPluginPresent: false
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @function checkPluginHasProperVersion - to check if the plugin has the proper version`
|
|
153
|
-
* @param {string} rulePluginName
|
|
154
|
-
* @param {string} installationPath
|
|
155
|
-
* @param {string} remotePluginVersion
|
|
156
|
-
* @returns
|
|
157
|
-
*/
|
|
158
|
-
|
|
159
|
-
function checkPluginHasProperVersion(rulePluginName, installationPath, remotePluginVersion) {
|
|
160
|
-
const pluginPathArray = installationPath.toString().split(rulePluginName);
|
|
161
|
-
const rulePluginPackageJSONPath = path.join(pluginPathArray[0], rulePluginName, 'package.json');
|
|
162
|
-
return remotePluginVersion == require(rulePluginPackageJSONPath).version ? true : false;
|
|
163
|
-
}
|
|
164
110
|
module.exports = {
|
|
165
111
|
checkIfPluginsAreInstalled
|
|
166
112
|
};
|
|
@@ -12,30 +12,23 @@ const {
|
|
|
12
12
|
const {
|
|
13
13
|
Logger
|
|
14
14
|
} = require('../Logger/Logger');
|
|
15
|
-
const {
|
|
16
|
-
createVersionControlFile
|
|
17
|
-
} = require('../FileAndFolderOperations/versionControl');
|
|
18
|
-
const {
|
|
19
|
-
getNodeModulesPath
|
|
20
|
-
} = require('../General/getNodeModulesPath');
|
|
21
15
|
|
|
22
16
|
/**
|
|
23
17
|
* @function installPlugins - installs uninstalled plugins for the project
|
|
24
18
|
* @returns {boolean} - indicating if plugins to be installed are installed successfully or not
|
|
25
19
|
*/
|
|
26
|
-
function installPlugins(
|
|
27
|
-
|
|
20
|
+
function installPlugins() {
|
|
21
|
+
let uninstalledPlugins = checkIfPluginsAreInstalled();
|
|
22
|
+
let pluginsToBeInstalled = uninstalledPlugins.uninstalledPlugins;
|
|
28
23
|
if (pluginsToBeInstalled.length > 0) {
|
|
29
|
-
let installCommand = `npm install --save ${pluginsToBeInstalled.join(' ')}`;
|
|
24
|
+
let installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')}`;
|
|
30
25
|
Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
|
|
31
26
|
Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
|
|
32
27
|
let arePluginsInstalledSuccessfully = executeSynchronizedCommands(execSync, [installCommand, {
|
|
33
|
-
stdio: 'inherit'
|
|
34
|
-
cwd: getNodeModulesPath()
|
|
28
|
+
stdio: 'inherit'
|
|
35
29
|
}], '', 'Some issue occured while installing plugins', false, true);
|
|
36
30
|
if (arePluginsInstalledSuccessfully) {
|
|
37
31
|
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
38
|
-
createVersionControlFile(pluginsToBeInstalled);
|
|
39
32
|
return true;
|
|
40
33
|
} else {
|
|
41
34
|
Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins.Kindly retry the command");
|
|
@@ -8,17 +8,17 @@ const {
|
|
|
8
8
|
* @function printUninstalledPlugins - to notify the user regarding plugins for the repository has been installed or not
|
|
9
9
|
* @param {Array} uninstalledPlugins - contains list of uninstalled plugins for the project
|
|
10
10
|
*/
|
|
11
|
-
function printUninstalledPlugins(uninstalledPlugins
|
|
11
|
+
function printUninstalledPlugins(uninstalledPlugins) {
|
|
12
12
|
let commandToInstallPlugins = 'npx ZDPrecommit setupPlugins';
|
|
13
|
-
if (uninstalledPlugins.length !== 0) {
|
|
13
|
+
if (uninstalledPlugins.uninstalledPlugins.length !== 0) {
|
|
14
14
|
Logger.log(Logger.INFO_TYPE, 'The following plugins are not installed:');
|
|
15
|
-
uninstalledPlugins.map(plugin => {
|
|
15
|
+
uninstalledPlugins.uninstalledPlugins.map(plugin => {
|
|
16
16
|
Logger.log(Logger.INFO_TYPE, `"${plugin}"`);
|
|
17
17
|
});
|
|
18
18
|
Logger.log(Logger.FAILURE_TYPE, `Kindly execute the command \x1b[37m"${commandToInstallPlugins}\x1b[0m" \x1b[31mfrom the location where package.json of the repo is present to install the plugins`);
|
|
19
|
-
} else if (uninstalledPlugins.length === 0 && noPluginMessage.trim() === '') {
|
|
19
|
+
} else if (uninstalledPlugins.uninstalledPlugins.length === 0 && uninstalledPlugins.noPluginMessage.trim() === '') {
|
|
20
20
|
Logger.log(Logger.INFO_TYPE, 'Plugins are installed already');
|
|
21
|
-
} else if (uninstalledPlugins.length === 0 && noPluginMessage.trim() !== '') {
|
|
21
|
+
} else if (uninstalledPlugins.uninstalledPlugins.length === 0 && uninstalledPlugins.noPluginMessage.trim() !== '') {
|
|
22
22
|
Logger.log(Logger.INFO_TYPE, 'No plugins present for the repository');
|
|
23
23
|
}
|
|
24
24
|
}
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const {
|
|
5
|
-
getNodeModulesPath
|
|
6
|
-
} = require('../General/getNodeModulesPath');
|
|
7
|
-
const {
|
|
8
|
-
writeFileSync
|
|
9
|
-
} = require('fs');
|
|
10
|
-
const {
|
|
11
|
-
Logger
|
|
12
|
-
} = require('../Logger/Logger');
|
|
13
|
-
function createVersionControlFile(uninstalledPlugins) {
|
|
14
|
-
Logger.log(Logger.INFO_TYPE, `Rule Plugin Versions are Noted in pluginVersionControl.js`);
|
|
15
|
-
const versionfilePath = path.join(getNodeModulesPath(), 'node_modules', '@zohodesk', 'codestandard-validator', 'pluginVersionControl.js');
|
|
16
|
-
writeFileSync(versionfilePath, `module.exports.plugins = [${uninstalledPlugins.map(plugin => {
|
|
17
|
-
return JSON.stringify({
|
|
18
|
-
plugin: `${plugin}`,
|
|
19
|
-
time: `${new Date()}`
|
|
20
|
-
});
|
|
21
|
-
}).join(',')}]`);
|
|
22
|
-
}
|
|
23
|
-
module.exports = {
|
|
24
|
-
createVersionControlFile
|
|
25
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.encrypt = exports.decrypt = void 0;
|
|
7
|
-
const caesarCipher = (str, shift) => {
|
|
8
|
-
return str.split("").map(char => {
|
|
9
|
-
let code = char.charCodeAt();
|
|
10
|
-
if (code >= 65 && code <= 90) {
|
|
11
|
-
return String.fromCharCode((code - 65 + shift) % 26 + 65);
|
|
12
|
-
} else if (code >= 97 && code <= 122) {
|
|
13
|
-
return String.fromCharCode((code - 97 + shift) % 26 + 97);
|
|
14
|
-
}
|
|
15
|
-
return char;
|
|
16
|
-
}).join("");
|
|
17
|
-
};
|
|
18
|
-
const encrypt = (plaintext, shift) => caesarCipher(plaintext, shift);
|
|
19
|
-
exports.encrypt = encrypt;
|
|
20
|
-
const decrypt = (ciphertext, shift) => caesarCipher(ciphertext, 26 - shift);
|
|
21
|
-
exports.decrypt = decrypt;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
Worker
|
|
5
|
-
} = require('worker_threads');
|
|
6
|
-
async function installPluginsByWorker(plugins) {
|
|
7
|
-
try {
|
|
8
|
-
const results = await Promise.all(plugins.map(pkg => runWorker({
|
|
9
|
-
packageName: pkg.packageName,
|
|
10
|
-
version: pkg.version
|
|
11
|
-
})));
|
|
12
|
-
console.log('Package are installed By from workers:', results.join('\n'));
|
|
13
|
-
} catch (error) {
|
|
14
|
-
console.error('Error:', error);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function runWorker(data) {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
const worker = new Worker(`${__dirname}/worker.js`, {
|
|
20
|
-
workerData: data
|
|
21
|
-
});
|
|
22
|
-
worker.on('message', result => {
|
|
23
|
-
resolve(result);
|
|
24
|
-
});
|
|
25
|
-
worker.on('error', error => {
|
|
26
|
-
reject(error);
|
|
27
|
-
});
|
|
28
|
-
worker.on('exit', code => {
|
|
29
|
-
if (code !== 0) {
|
|
30
|
-
reject(new Error(`Worker stopped with exit code ${code}`));
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
module.exports = installPluginsByWorker;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
workerData,
|
|
5
|
-
parentPort
|
|
6
|
-
} = require('worker_threads');
|
|
7
|
-
const {
|
|
8
|
-
spawnSync
|
|
9
|
-
} = require('child_process');
|
|
10
|
-
const {
|
|
11
|
-
getNodeModulesPath
|
|
12
|
-
} = require('../../General/getNodeModulesPath');
|
|
13
|
-
function performanceInstalllation({
|
|
14
|
-
packageName,
|
|
15
|
-
version
|
|
16
|
-
}) {
|
|
17
|
-
const start = performance.now();
|
|
18
|
-
try {
|
|
19
|
-
require.resolve(packageName);
|
|
20
|
-
} catch (err) {
|
|
21
|
-
spawnSync('npm', ['install', `${packageName}@${version}`, '--no-save'], {
|
|
22
|
-
stdio: 'inherit',
|
|
23
|
-
cwd: getNodeModulesPath()
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
const end = performance.now();
|
|
27
|
-
return `Package ${packageName}@${version} installed successfully and installed in ${end - start} ms`;
|
|
28
|
-
}
|
|
29
|
-
const result = performanceInstalllation({
|
|
30
|
-
packageName: workerData.packageName,
|
|
31
|
-
version: workerData.version
|
|
32
|
-
});
|
|
33
|
-
parentPort.postMessage(result);
|