@zohodesk/codestandard-validator 0.0.4-exp-3 → 0.0.4-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/lib/postinstall.js +2 -3
- package/build/utils/FileAndFolderOperations/versionControl.js +25 -0
- package/build/utils/PluginsInstallation/arePluginsInstalled.js +4 -0
- package/build/utils/PluginsInstallation/checkIfPluginsAreInstalled.js +74 -20
- package/build/utils/PluginsInstallation/installPlugins.js +8 -3
- package/build/utils/PluginsInstallation/printUninstalledPlugins.js +1 -1
- package/package.json +1 -1
package/build/lib/postinstall.js
CHANGED
|
@@ -32,11 +32,10 @@ const {
|
|
|
32
32
|
async function postInstall() {
|
|
33
33
|
try {
|
|
34
34
|
await executeMethodsThatReturnBooleanValue("Some issue in writing node_modules path to json", writeFsPaths, null);
|
|
35
|
-
|
|
36
|
-
// isGitInitialized() ? await executeMethodsThatReturnBooleanValue( "Some issue occurred in setting up husky.", setupHusky, null) : null;
|
|
35
|
+
isGitInitialized() ? await executeMethodsThatReturnBooleanValue("Some issue occurred in setting up husky.", setupHusky, null) : null;
|
|
37
36
|
await executeMethodsThatReturnBooleanValue("Make sure zgit.csez.zohocorpin.com is accessible", cloneViaCdt, null);
|
|
38
37
|
await executeMethodsThatReturnBooleanValue("Some issue occurred in creating eslint config file.", createEslintConfigFile, null);
|
|
39
|
-
Logger.log(Logger.SUCCESS_TYPE, "Pre commit setup
|
|
38
|
+
Logger.log(Logger.SUCCESS_TYPE, "Pre commit setup successfull");
|
|
40
39
|
arePluginsInstalled();
|
|
41
40
|
} catch (error) {
|
|
42
41
|
Logger.log(Logger.FAILURE_TYPE, `Kindly retry npm install. & ${error.message}`);
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
};
|
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
const {
|
|
4
4
|
checkIfPluginsAreInstalled
|
|
5
5
|
} = require('./checkIfPluginsAreInstalled');
|
|
6
|
+
const {
|
|
7
|
+
installPlugins
|
|
8
|
+
} = require('./installPlugins');
|
|
6
9
|
const {
|
|
7
10
|
printUninstalledPlugins
|
|
8
11
|
} = require('./printUninstalledPlugins');
|
|
9
12
|
function arePluginsInstalled() {
|
|
10
13
|
let uninstalledPlugins = checkIfPluginsAreInstalled();
|
|
11
14
|
printUninstalledPlugins(uninstalledPlugins);
|
|
15
|
+
installPlugins();
|
|
12
16
|
}
|
|
13
17
|
module.exports = {
|
|
14
18
|
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,40 @@ function checkIfPluginsAreInstalled() {
|
|
|
107
127
|
return plugin;
|
|
108
128
|
}
|
|
109
129
|
}
|
|
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
|
+
}
|
|
110
164
|
module.exports = {
|
|
111
165
|
checkIfPluginsAreInstalled
|
|
112
166
|
};
|
|
@@ -12,16 +12,20 @@ const {
|
|
|
12
12
|
const {
|
|
13
13
|
Logger
|
|
14
14
|
} = require('../Logger/Logger');
|
|
15
|
+
const {
|
|
16
|
+
createVersionControlFile
|
|
17
|
+
} = require('../FileAndFolderOperations/versionControl');
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* @function installPlugins - installs uninstalled plugins for the project
|
|
18
21
|
* @returns {boolean} - indicating if plugins to be installed are installed successfully or not
|
|
19
22
|
*/
|
|
20
23
|
function installPlugins() {
|
|
21
|
-
let
|
|
22
|
-
|
|
24
|
+
let {
|
|
25
|
+
uninstalledPlugins: pluginsToBeInstalled
|
|
26
|
+
} = checkIfPluginsAreInstalled();
|
|
23
27
|
if (pluginsToBeInstalled.length > 0) {
|
|
24
|
-
let installCommand = `npm install --save
|
|
28
|
+
let installCommand = `npm install --no-save ${pluginsToBeInstalled.join(' ')}`;
|
|
25
29
|
Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
|
|
26
30
|
Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
|
|
27
31
|
let arePluginsInstalledSuccessfully = executeSynchronizedCommands(execSync, [installCommand, {
|
|
@@ -29,6 +33,7 @@ function installPlugins() {
|
|
|
29
33
|
}], '', 'Some issue occured while installing plugins', false, true);
|
|
30
34
|
if (arePluginsInstalledSuccessfully) {
|
|
31
35
|
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
36
|
+
createVersionControlFile(pluginsToBeInstalled);
|
|
32
37
|
return true;
|
|
33
38
|
} else {
|
|
34
39
|
Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins.Kindly retry the command");
|
|
@@ -15,7 +15,7 @@ function printUninstalledPlugins(uninstalledPlugins) {
|
|
|
15
15
|
uninstalledPlugins.uninstalledPlugins.map(plugin => {
|
|
16
16
|
Logger.log(Logger.INFO_TYPE, `"${plugin}"`);
|
|
17
17
|
});
|
|
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`)
|
|
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
19
|
} else if (uninstalledPlugins.uninstalledPlugins.length === 0 && uninstalledPlugins.noPluginMessage.trim() === '') {
|
|
20
20
|
Logger.log(Logger.INFO_TYPE, 'Plugins are installed already');
|
|
21
21
|
} else if (uninstalledPlugins.uninstalledPlugins.length === 0 && uninstalledPlugins.noPluginMessage.trim() !== '') {
|