@zohodesk/codestandard-validator 0.0.4 → 0.0.6
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/lib/cli.js +7 -1
- package/build/lib/postinstall.js +1 -1
- package/build/setup/sample.config.js +4 -3
- package/build/utils/CloneCommonLinterRepo/cloneViaCdt.js +3 -2
- package/build/utils/FileAndFolderOperations/versionControl.js +30 -0
- package/build/utils/General/getGeneralInfo.js +4 -5
- package/build/utils/HuskySetup/initializeHusky.js +1 -1
- package/build/utils/HuskySetup/setupHusky.js +8 -51
- package/build/utils/PluginsInstallation/arePluginsInstalled.js +12 -2
- package/build/utils/PluginsInstallation/checkIfPluginsAreInstalled.js +85 -20
- package/build/utils/PluginsInstallation/installPlugins.js +44 -7
- package/build/utils/PluginsInstallation/printUninstalledPlugins.js +5 -5
- package/changeLog.md +16 -6
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
File without changes
|
package/build/lib/cli.js
CHANGED
|
@@ -15,6 +15,9 @@ const {
|
|
|
15
15
|
const {
|
|
16
16
|
installPlugins
|
|
17
17
|
} = require("../utils/PluginsInstallation/installPlugins");
|
|
18
|
+
const {
|
|
19
|
+
checkIfPluginsAreInstalled
|
|
20
|
+
} = require("../utils/PluginsInstallation/checkIfPluginsAreInstalled");
|
|
18
21
|
const [,, action, ...options] = process.argv;
|
|
19
22
|
async function run() {
|
|
20
23
|
switch (action) {
|
|
@@ -30,7 +33,10 @@ async function run() {
|
|
|
30
33
|
}
|
|
31
34
|
case "setupPlugins":
|
|
32
35
|
{
|
|
33
|
-
|
|
36
|
+
const {
|
|
37
|
+
uninstalledPlugins
|
|
38
|
+
} = checkIfPluginsAreInstalled();
|
|
39
|
+
await executeMethodsThatReturnBooleanValue("Some issue occurred in installing plugins", installPlugins, uninstalledPlugins);
|
|
34
40
|
break;
|
|
35
41
|
}
|
|
36
42
|
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 successfull");
|
|
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} meticHandler_api_token - The token for authentication with the SonarQube server.
|
|
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
|
+
meticHandler_api_token: "oyRcKJZxm2RkXytfAzVtmyRlLIftou5anC==",
|
|
28
28
|
metric_token: "zxh_9737850jh2l53ml17223929ihii73072j54j2260",
|
|
29
29
|
branchDiffPath: path.resolve(process.cwd(), "diffBranch.json"),
|
|
30
30
|
gitEndPoint: "https://zgit.csez.zohocorpin.com",
|
|
@@ -33,5 +33,6 @@ module.exports = {
|
|
|
33
33
|
impactBasedPrecommit: true,
|
|
34
34
|
shouldWarningsAbortCommit: false,
|
|
35
35
|
token: "w-OkG3f5OOM1Rkly8phZ",
|
|
36
|
-
compareBranch: 'release'
|
|
36
|
+
compareBranch: 'release',
|
|
37
|
+
supportedExtensions: ['.js', '.jsx', '.ts', '.tsx', '.properties']
|
|
37
38
|
};
|
|
@@ -46,8 +46,9 @@ function cloneViaCdt() {
|
|
|
46
46
|
removeFolder(getDeleteDirPath());
|
|
47
47
|
const userName = user;
|
|
48
48
|
var absoluteEndPoint = `https://${endPoint}`;
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const runningEnv = getRunningEnv();
|
|
50
|
+
if (runningEnv === "CI" || runningEnv === "DEVAUTOMATION") {
|
|
51
|
+
Logger.log(Logger.INFO_TYPE, `Running in ${runningEnv}`);
|
|
51
52
|
absoluteEndPoint = `https://${userName}:${decrypt(token, 12)}@${endPoint}`;
|
|
52
53
|
}
|
|
53
54
|
var commandToCloneCommonConfigRepo = `npx cdt clone --clone:type=${type} --clone:url=${absoluteEndPoint} --clone:branch=${branch} --clone:cacheDir=${cacheDirectory} --clone:proj:name=${commonLinterRepoName}`;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
const {
|
|
14
|
+
existsSync
|
|
15
|
+
} = require("fs");
|
|
16
|
+
function createVersionControlFile(uninstalledPlugins) {
|
|
17
|
+
Logger.log(Logger.INFO_TYPE, `Rule Plugin Versions are Noted in pluginVersionControl.js`);
|
|
18
|
+
const versionfilePath = path.join(getNodeModulesPath(), 'node_modules', '@zohodesk', 'codestandard-validator', 'pluginVersionControl.js');
|
|
19
|
+
if (existsSync(versionfilePath)) {
|
|
20
|
+
writeFileSync(versionfilePath, `module.exports.plugins = [${uninstalledPlugins.map(plugin => {
|
|
21
|
+
return JSON.stringify({
|
|
22
|
+
plugin: `${plugin}`,
|
|
23
|
+
time: `${new Date()}`
|
|
24
|
+
});
|
|
25
|
+
}).join(',')}]`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
module.exports = {
|
|
29
|
+
createVersionControlFile
|
|
30
|
+
};
|
|
@@ -54,11 +54,10 @@ function getConfigurationPrecommit() {
|
|
|
54
54
|
* @returns {Array<string>}
|
|
55
55
|
*/
|
|
56
56
|
function getSupportedLanguage() {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_language
|
|
61
|
-
_language.push('.tsx');
|
|
57
|
+
const {
|
|
58
|
+
supportedExtensions
|
|
59
|
+
} = getConfigurationPrecommit();
|
|
60
|
+
const _language = supportedExtensions;
|
|
62
61
|
return _language;
|
|
63
62
|
}
|
|
64
63
|
function getRunningEnv() {
|
|
@@ -23,7 +23,7 @@ function initializeHusky() {
|
|
|
23
23
|
let isNavigationToRootDirectorySuccessful = navigateToRootDirectory(getRootDirectory());
|
|
24
24
|
if (isNavigationToRootDirectorySuccessful) {
|
|
25
25
|
try {
|
|
26
|
-
execSync('npx husky install');
|
|
26
|
+
execSync('npx husky@7 install');
|
|
27
27
|
return true;
|
|
28
28
|
} catch (error) {
|
|
29
29
|
Logger.log(Logger.FAILURE_TYPE, error.toString());
|
|
@@ -1,21 +1,8 @@
|
|
|
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');
|
|
11
4
|
const initializeHusky = require('./initializeHusky');
|
|
12
5
|
const configurePrecommitHook = require('./configurePrecommitHook');
|
|
13
|
-
const {
|
|
14
|
-
getNodeModulesPath
|
|
15
|
-
} = require('../General/getNodeModulesPath');
|
|
16
|
-
const {
|
|
17
|
-
executeSynchronizedCommands
|
|
18
|
-
} = require('../General/executeSyncCommands');
|
|
19
6
|
const {
|
|
20
7
|
Logger
|
|
21
8
|
} = require('../Logger/Logger');
|
|
@@ -26,51 +13,21 @@ let isCustomPrecommitConfigurationSuccessful = false;
|
|
|
26
13
|
* @returns {boolean} - indicating whether entire custom precommit hook setup using husky process is success or failure
|
|
27
14
|
*/
|
|
28
15
|
function setupHusky() {
|
|
29
|
-
let
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
}
|
|
16
|
+
let isHuskyInitializedSuccessfully = initializeHusky();
|
|
17
|
+
if (isHuskyInitializedSuccessfully) {
|
|
18
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Husky installation successful');
|
|
19
|
+
isCustomPrecommitConfigurationSuccessful = configurePrecommitHook();
|
|
20
|
+
if (isCustomPrecommitConfigurationSuccessful) {
|
|
21
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Custom pre commit hook setup was successful');
|
|
22
|
+
return true;
|
|
42
23
|
} else {
|
|
24
|
+
Logger.log(Logger.FAILURE_TYPE, 'Couldn\'t configure custom pre commit hook');
|
|
43
25
|
return false;
|
|
44
26
|
}
|
|
45
27
|
} else {
|
|
46
|
-
Logger.log(Logger.FAILURE_TYPE, 'Some issue in installing husky package.');
|
|
47
28
|
return false;
|
|
48
29
|
}
|
|
49
30
|
}
|
|
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
|
-
}
|
|
74
31
|
module.exports = {
|
|
75
32
|
setupHusky
|
|
76
33
|
};
|
|
@@ -6,9 +6,19 @@ const {
|
|
|
6
6
|
const {
|
|
7
7
|
printUninstalledPlugins
|
|
8
8
|
} = require('./printUninstalledPlugins');
|
|
9
|
+
const {
|
|
10
|
+
installPlugins
|
|
11
|
+
} = require('./installPlugins');
|
|
9
12
|
function arePluginsInstalled() {
|
|
10
|
-
let
|
|
11
|
-
|
|
13
|
+
let {
|
|
14
|
+
uninstalledPlugins,
|
|
15
|
+
noPluginMessage
|
|
16
|
+
} = checkIfPluginsAreInstalled();
|
|
17
|
+
let areAllPluginsInstalled = uninstalledPlugins.length === 0 ? true : false;
|
|
18
|
+
if (!areAllPluginsInstalled) {
|
|
19
|
+
installPlugins(uninstalledPlugins);
|
|
20
|
+
}
|
|
21
|
+
// printUninstalledPlugins(uninstalledPlugins,noPluginMessage)
|
|
12
22
|
}
|
|
13
23
|
module.exports = {
|
|
14
24
|
arePluginsInstalled
|
|
@@ -74,30 +74,50 @@ function getAllPlugins() {
|
|
|
74
74
|
*/
|
|
75
75
|
function checkIfPluginsAreInstalled() {
|
|
76
76
|
const pluginsForCurrentRepo = getAllPlugins();
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
var uninstalledPlugins = [];
|
|
78
|
+
var plugin = {
|
|
79
79
|
noPluginMessage: '',
|
|
80
80
|
uninstalledPlugins: []
|
|
81
81
|
};
|
|
82
|
-
let pluginsIndevDependencies = {}
|
|
83
|
-
let pluginNamesOfDevDependencyPlugins = []
|
|
84
|
-
let arePluginsPresentIndevDependencies = false
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
// let pluginsIndevDependencies = {}
|
|
83
|
+
// let pluginNamesOfDevDependencyPlugins = []
|
|
84
|
+
// let arePluginsPresentIndevDependencies = false
|
|
85
|
+
// var arePluginsPresentForCurrentRepo = false
|
|
86
|
+
|
|
87
|
+
// if(existsSync(path.join(getNodeModulesPath(),'package.json'))){
|
|
88
|
+
// let packageJsonContent = require(path.join(getNodeModulesPath(),'package.json'))
|
|
89
|
+
// pluginsIndevDependencies = packageJsonContent.devDependencies
|
|
90
|
+
|
|
91
|
+
// if(pluginsIndevDependencies !== undefined){
|
|
92
|
+
// arePluginsPresentIndevDependencies = true
|
|
93
|
+
// pluginNamesOfDevDependencyPlugins = Object.keys(pluginsIndevDependencies)
|
|
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;
|
|
94
116
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (arePluginsPresentForCurrentRepo || arePluginsPresentIndevDependencies) {
|
|
100
|
-
uninstalledPlugins = getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, pluginsIndevDependencies);
|
|
117
|
+
return `${packageName}@${version}`;
|
|
118
|
+
}).filter(Boolean);
|
|
119
|
+
if (uninstalledPlugins.length > 0) {
|
|
120
|
+
// uninstalledPlugins = getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, pluginsIndevDependencies);
|
|
101
121
|
plugin.noPluginMessage = '';
|
|
102
122
|
plugin.uninstalledPlugins = uninstalledPlugins;
|
|
103
123
|
return plugin;
|
|
@@ -107,6 +127,51 @@ function checkIfPluginsAreInstalled() {
|
|
|
107
127
|
return plugin;
|
|
108
128
|
}
|
|
109
129
|
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @function returnExactPluginVersion - to return the exact plugin version after removing caret or tilde symbol if present
|
|
133
|
+
* @param {string} pluginVersion
|
|
134
|
+
* @returns {string} - which represents exactPluginVersion
|
|
135
|
+
*/
|
|
136
|
+
function returnExactPluginVersion(pluginVersion) {
|
|
137
|
+
return pluginVersion.replace(/[\^~]/, '');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @function checkPluginsPresentInNodemodules - to check if the plugin is present in the node_modules of the project
|
|
142
|
+
* @param {string} rulePluginName
|
|
143
|
+
* @returns
|
|
144
|
+
*/
|
|
145
|
+
function checkPluginsPresentInNodemodules(rulePluginName) {
|
|
146
|
+
try {
|
|
147
|
+
const pluginPath = require.resolve(rulePluginName.toString());
|
|
148
|
+
return {
|
|
149
|
+
pluginPath: pluginPath,
|
|
150
|
+
isPluginPresent: existsSync(pluginPath)
|
|
151
|
+
};
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return {
|
|
154
|
+
pluginPath: "",
|
|
155
|
+
isPluginPresent: false
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @function checkPluginHasProperVersion - to check if the plugin has the proper version`
|
|
162
|
+
* @param {string} rulePluginName
|
|
163
|
+
* @param {string} installationPath
|
|
164
|
+
* @param {string} remotePluginVersion
|
|
165
|
+
* @returns
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
function checkPluginHasProperVersion(rulePluginName, installationPath, remotePluginVersion) {
|
|
169
|
+
const pluginPathArray = installationPath.toString().split(rulePluginName);
|
|
170
|
+
const rulePluginPackageJSONPath = path.join(pluginPathArray[0], rulePluginName, 'package.json');
|
|
171
|
+
const remotePluginExactVersion = returnExactPluginVersion(remotePluginVersion);
|
|
172
|
+
const packageJsonPluginExactVersion = returnExactPluginVersion(require(rulePluginPackageJSONPath).version);
|
|
173
|
+
return remotePluginExactVersion == packageJsonPluginExactVersion ? true : false;
|
|
174
|
+
}
|
|
110
175
|
module.exports = {
|
|
111
176
|
checkIfPluginsAreInstalled
|
|
112
177
|
};
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
const {
|
|
4
4
|
execSync
|
|
5
5
|
} = require('child_process');
|
|
6
|
+
const {
|
|
7
|
+
writeFileSync
|
|
8
|
+
} = require('fs');
|
|
6
9
|
const {
|
|
7
10
|
checkIfPluginsAreInstalled
|
|
8
11
|
} = require('./checkIfPluginsAreInstalled');
|
|
@@ -12,34 +15,68 @@ const {
|
|
|
12
15
|
const {
|
|
13
16
|
Logger
|
|
14
17
|
} = require('../Logger/Logger');
|
|
18
|
+
const {
|
|
19
|
+
createVersionControlFile
|
|
20
|
+
} = require('../FileAndFolderOperations/versionControl');
|
|
21
|
+
const {
|
|
22
|
+
getNodeModulesPath
|
|
23
|
+
} = require('../General/getNodeModulesPath');
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
26
|
* @function installPlugins - installs uninstalled plugins for the project
|
|
18
27
|
* @returns {boolean} - indicating if plugins to be installed are installed successfully or not
|
|
19
28
|
*/
|
|
20
|
-
function installPlugins() {
|
|
21
|
-
let uninstalledPlugins = checkIfPluginsAreInstalled()
|
|
22
|
-
let pluginsToBeInstalled = uninstalledPlugins.uninstalledPlugins;
|
|
29
|
+
function installPlugins(pluginsToBeInstalled) {
|
|
30
|
+
// let {uninstalledPlugins : pluginsToBeInstalled} = checkIfPluginsAreInstalled()
|
|
23
31
|
if (pluginsToBeInstalled.length > 0) {
|
|
32
|
+
let packageJsonBeforePluginsInstallation = getPackageJsonContentBeforeInstallingPlugins();
|
|
24
33
|
let installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')}`;
|
|
25
34
|
Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
|
|
26
35
|
Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
|
|
27
36
|
let arePluginsInstalledSuccessfully = executeSynchronizedCommands(execSync, [installCommand, {
|
|
28
|
-
stdio: 'inherit'
|
|
37
|
+
stdio: 'inherit',
|
|
38
|
+
cwd: getNodeModulesPath()
|
|
29
39
|
}], '', 'Some issue occured while installing plugins', false, true);
|
|
30
40
|
if (arePluginsInstalledSuccessfully) {
|
|
31
41
|
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
32
|
-
|
|
42
|
+
let isPackageJsonRestored = restorePackageJsonContent(packageJsonBeforePluginsInstallation);
|
|
43
|
+
if (isPackageJsonRestored) {
|
|
44
|
+
createVersionControlFile(pluginsToBeInstalled);
|
|
45
|
+
// return true
|
|
46
|
+
} else {
|
|
47
|
+
Logger.log(Logger.FAILURE_TYPE, 'Unable to restore package.json content');
|
|
48
|
+
// return false
|
|
49
|
+
}
|
|
33
50
|
} else {
|
|
34
51
|
Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins.Kindly retry the command");
|
|
35
|
-
return false
|
|
52
|
+
// return false
|
|
36
53
|
}
|
|
37
54
|
} else {
|
|
38
55
|
Logger.log(Logger.INFO_TYPE, 'Plugins are already installed');
|
|
39
|
-
return true
|
|
56
|
+
// return true
|
|
40
57
|
}
|
|
41
58
|
}
|
|
42
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @function getPackageJsonContentBeforeInstallingPlugins - to get the content of package.json before installing plugins
|
|
62
|
+
* @returns {Object} - package.json content before installing plugins
|
|
63
|
+
*/
|
|
64
|
+
function getPackageJsonContentBeforeInstallingPlugins() {
|
|
65
|
+
let packageJsonFilePath = `${getNodeModulesPath()}/package.json`;
|
|
66
|
+
let packageJsonContentBeforePluginsInstallation = require(packageJsonFilePath);
|
|
67
|
+
return packageJsonContentBeforePluginsInstallation;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @function restorePackageJsonContent - restore the same content as it was before installing plugins
|
|
72
|
+
* @returns {Boolean} - indicating the success or failure of restoring package.json content
|
|
73
|
+
*/
|
|
74
|
+
function restorePackageJsonContent(packageJsonContentBeforePluginsInstallation) {
|
|
75
|
+
let packageJsonFilePath = `${getNodeModulesPath()}/package.json`;
|
|
76
|
+
let isPackageJsonRestored = executeSynchronizedCommands(writeFileSync, [packageJsonFilePath, JSON.stringify(packageJsonContentBeforePluginsInstallation, null, 2)], 'Package.json content restored successfully', 'Unable to restore package.json content', false, true);
|
|
77
|
+
return isPackageJsonRestored;
|
|
78
|
+
}
|
|
79
|
+
|
|
43
80
|
// function appendInstalledPluginsToPackageJson(pluginsToBeAppendedInPackageJson){
|
|
44
81
|
// let packageJsonFilePath = `${nodeModulesPathOfProject}/package.json`
|
|
45
82
|
// let packageJsonContent = require(packageJsonFilePath)
|
|
@@ -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, noPluginMessage) {
|
|
12
12
|
let commandToInstallPlugins = 'npx ZDPrecommit setupPlugins';
|
|
13
|
-
if (uninstalledPlugins.
|
|
13
|
+
if (uninstalledPlugins.length !== 0) {
|
|
14
14
|
Logger.log(Logger.INFO_TYPE, 'The following plugins are not installed:');
|
|
15
|
-
uninstalledPlugins.
|
|
15
|
+
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.
|
|
19
|
+
} else if (uninstalledPlugins.length === 0 && noPluginMessage.trim() === '') {
|
|
20
20
|
Logger.log(Logger.INFO_TYPE, 'Plugins are installed already');
|
|
21
|
-
} else if (uninstalledPlugins.
|
|
21
|
+
} else if (uninstalledPlugins.length === 0 && noPluginMessage.trim() !== '') {
|
|
22
22
|
Logger.log(Logger.INFO_TYPE, 'No plugins present for the repository');
|
|
23
23
|
}
|
|
24
24
|
}
|
package/changeLog.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
1. Testing version of the library
|
|
5
5
|
|
|
6
6
|
# 0.0.1
|
|
7
|
-
|
|
7
|
+
1. This version was mistakenly published without the build folder which will be corrected in the next release
|
|
8
8
|
|
|
9
9
|
# 0.0.2 - first stable release of the library
|
|
10
10
|
1. Sets up a custom precommit hook using husky
|
|
@@ -12,11 +12,21 @@
|
|
|
12
12
|
3. Based on the cloned configuration folder creates a eslint config file
|
|
13
13
|
4. Checks for eslint rule violations in the staged files(Impact based) and aborts/allows commit accordingly
|
|
14
14
|
|
|
15
|
-
# 0.0.3 -
|
|
15
|
+
# 0.0.3 - modifications in usage of Husky package
|
|
16
|
+
1. The husky package is not installed and the required huksy package version is temporarily downloaded from npm registry and used
|
|
17
|
+
|
|
16
18
|
|
|
17
19
|
# 0.0.4 - configuration based Execution
|
|
18
20
|
|
|
19
|
-
1. Avoid linting deleted files that have been staged.
|
|
20
|
-
2. Added configuration for linting based on impacted lines or the entire file.
|
|
21
|
-
3. Added configuration to abort commits if there are warnings or issues.
|
|
22
|
-
4. Environment-specific clone configuration added.
|
|
21
|
+
1. Avoid linting deleted files that have been staged.
|
|
22
|
+
2. Added configuration for linting based on impacted lines or the entire file.
|
|
23
|
+
3. Added configuration to abort commits if there are warnings or issues.
|
|
24
|
+
4. Environment-specific clone configuration added.
|
|
25
|
+
|
|
26
|
+
# 0.0.5 - Automatic eslint plugins installation
|
|
27
|
+
1. The required eslint plugins configured for a repository will be automatically installed during the installation of the library
|
|
28
|
+
|
|
29
|
+
# 0.0.6 - Support extended for .properties file
|
|
30
|
+
|
|
31
|
+
1. The file types that are supported by this library can now be configured using the configuration file "lint.config.js"
|
|
32
|
+
2. Support for .properties file is also extended in this version along with existing support for file types .js, .jsx, .ts, .tsx
|