@zohodesk/codestandard-validator 0.0.6-exp-18 → 0.0.6-exp-21
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/lint.js +138 -237
- package/build/hooks/Precommit/pre-commit.js +297 -29
- package/build/lib/cli.js +8 -6
- package/build/lib/postinstall.js +1 -1
- package/build/utils/CloneCommonLinterRepo/cloneViaCdt.js +2 -2
- package/build/utils/ConfigFileUtils/createConfigFiles.js +68 -0
- package/build/utils/ConfigFileUtils/getEslintExecutablePath.js +24 -0
- package/build/utils/ConfigFileUtils/getLintConfiguration.js +54 -0
- package/build/utils/FileAndFolderOperations/versionControl.js +8 -7
- package/build/utils/General/getGeneralInfo.js +1 -55
- package/build/utils/General/writeProjectDetailsToJson.js +2 -7
- package/build/utils/PluginsInstallation/Worker/installPluginsByWoker.js +5 -2
- package/build/utils/PluginsInstallation/arePluginsInstalled.js +9 -5
- package/build/utils/PluginsInstallation/checkIfPluginsAreInstalled.js +57 -0
- package/build/utils/PluginsInstallation/installPlugins.js +76 -22
- package/package.json +1 -1
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
const {
|
|
4
4
|
Worker
|
|
5
5
|
} = require('worker_threads');
|
|
6
|
+
const {
|
|
7
|
+
Logger
|
|
8
|
+
} = require('../../Logger/Logger');
|
|
6
9
|
async function installPluginsByWorker(plugins) {
|
|
7
10
|
try {
|
|
8
11
|
const results = await Promise.all(plugins.map(pkg => runWorker({
|
|
9
12
|
packageName: pkg.packageName,
|
|
10
13
|
version: pkg.version
|
|
11
14
|
})));
|
|
12
|
-
|
|
15
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Package are installed By from workers:', results.join('\n'));
|
|
13
16
|
} catch (error) {
|
|
14
|
-
|
|
17
|
+
Logger.log(Logger.FAILURE_TYPE, 'Error:', error);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
function runWorker(data) {
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
executeMethodsThatReturnBooleanValue
|
|
5
|
-
} = require('../General/wrapperFunctionToExecuteAFunction');
|
|
6
3
|
const {
|
|
7
4
|
checkIfPluginsAreInstalled
|
|
8
5
|
} = require('./checkIfPluginsAreInstalled');
|
|
6
|
+
const {
|
|
7
|
+
printUninstalledPlugins
|
|
8
|
+
} = require('./printUninstalledPlugins');
|
|
9
9
|
const {
|
|
10
10
|
installPlugins
|
|
11
11
|
} = require('./installPlugins');
|
|
12
|
-
|
|
12
|
+
function arePluginsInstalled() {
|
|
13
13
|
let {
|
|
14
14
|
uninstalledPlugins,
|
|
15
15
|
noPluginMessage
|
|
16
16
|
} = checkIfPluginsAreInstalled();
|
|
17
|
-
|
|
17
|
+
let areAllPluginsInstalled = uninstalledPlugins.length === 0 ? true : false;
|
|
18
|
+
if (!areAllPluginsInstalled) {
|
|
19
|
+
installPlugins(uninstalledPlugins);
|
|
20
|
+
}
|
|
21
|
+
// printUninstalledPlugins(uninstalledPlugins,noPluginMessage)
|
|
18
22
|
}
|
|
19
23
|
module.exports = {
|
|
20
24
|
arePluginsInstalled
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
+
readdirSync,
|
|
4
5
|
existsSync
|
|
5
6
|
} = require('fs');
|
|
6
7
|
const path = require('path');
|
|
8
|
+
const {
|
|
9
|
+
getNodeModulesPath
|
|
10
|
+
} = require('../General/getNodeModulesPath');
|
|
7
11
|
const {
|
|
8
12
|
Logger
|
|
9
13
|
} = require('../Logger/Logger');
|
|
10
14
|
const {
|
|
11
15
|
getLibraryInstalledLocation
|
|
12
16
|
} = require('../General/getLibraryInstalledLocation');
|
|
17
|
+
const {
|
|
18
|
+
executeSynchronizedCommands
|
|
19
|
+
} = require('../General/executeSyncCommands');
|
|
13
20
|
const {
|
|
14
21
|
endPoint,
|
|
15
22
|
commonLinterRepoName
|
|
@@ -20,6 +27,32 @@ const {
|
|
|
20
27
|
const {
|
|
21
28
|
getServicePathElseCommon
|
|
22
29
|
} = require('../EslintConfigFileUtils/getLintConfiguration');
|
|
30
|
+
function getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, devDependencies) {
|
|
31
|
+
let pluginsInNodeModules = executeSynchronizedCommands(readdirSync, [path.join(getNodeModulesPath(), 'node_modules')], '', 'Unable to get the plugins inside node_modules', true, false);
|
|
32
|
+
let pluginsToBeInstalled = [];
|
|
33
|
+
pluginsForCurrentRepo.filter(plugin => {
|
|
34
|
+
if (plugin.packageName.startsWith('@')) {
|
|
35
|
+
let scope = plugin.packageName.split('/')[0];
|
|
36
|
+
let pluginName = plugin.packageName.split('/')[1];
|
|
37
|
+
let scopedPlugins = executeSynchronizedCommands(readdirSync, [path.join(getNodeModulesPath(), 'node_modules', scope)], '', 'Unable to get the plugins inside the scope inside node_modules', true, false);
|
|
38
|
+
let isPluginInstalled = scopedPlugins.includes(pluginName) ? true : false;
|
|
39
|
+
if (!isPluginInstalled) {
|
|
40
|
+
pluginsToBeInstalled.push(`${plugin.packageName}@${plugin.version}`);
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
let isPluginInstalled = pluginsInNodeModules.includes(plugin.packageName) ? true : false;
|
|
44
|
+
if (!isPluginInstalled) {
|
|
45
|
+
pluginsToBeInstalled.push(`${plugin.packageName}@${plugin.version}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (pluginNamesOfDevDependencyPlugins.includes(plugin.packageName)) {
|
|
49
|
+
if (plugin.version !== devDependencies[plugin.packageName]) {
|
|
50
|
+
pluginsToBeInstalled.push(`${plugin.packageName}@${plugin.version}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return pluginsToBeInstalled;
|
|
55
|
+
}
|
|
23
56
|
function getAllPlugins() {
|
|
24
57
|
let serviceSpecificPlugins = [];
|
|
25
58
|
const pathToCommonPluginsFile = path.join(getLibraryInstalledLocation(), commonLinterRepoName, 'common', 'pluginVersion.js');
|
|
@@ -46,6 +79,29 @@ function checkIfPluginsAreInstalled() {
|
|
|
46
79
|
noPluginMessage: '',
|
|
47
80
|
uninstalledPlugins: []
|
|
48
81
|
};
|
|
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
|
+
|
|
49
105
|
uninstalledPlugins = pluginsForCurrentRepo.map(plugin => {
|
|
50
106
|
const {
|
|
51
107
|
packageName,
|
|
@@ -61,6 +117,7 @@ function checkIfPluginsAreInstalled() {
|
|
|
61
117
|
return `${packageName}@${version}`;
|
|
62
118
|
}).filter(Boolean);
|
|
63
119
|
if (uninstalledPlugins.length > 0) {
|
|
120
|
+
// uninstalledPlugins = getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, pluginsIndevDependencies);
|
|
64
121
|
plugin.noPluginMessage = '';
|
|
65
122
|
plugin.uninstalledPlugins = uninstalledPlugins;
|
|
66
123
|
return plugin;
|
|
@@ -6,6 +6,9 @@ const {
|
|
|
6
6
|
const {
|
|
7
7
|
writeFileSync
|
|
8
8
|
} = require('fs');
|
|
9
|
+
const {
|
|
10
|
+
checkIfPluginsAreInstalled
|
|
11
|
+
} = require('./checkIfPluginsAreInstalled');
|
|
9
12
|
const {
|
|
10
13
|
executeSynchronizedCommands
|
|
11
14
|
} = require('../General/executeSyncCommands');
|
|
@@ -24,30 +27,34 @@ const {
|
|
|
24
27
|
* @returns {boolean} - indicating if plugins to be installed are installed successfully or not
|
|
25
28
|
*/
|
|
26
29
|
function installPlugins(pluginsToBeInstalled) {
|
|
27
|
-
|
|
30
|
+
// let {uninstalledPlugins : pluginsToBeInstalled} = checkIfPluginsAreInstalled()
|
|
31
|
+
if (pluginsToBeInstalled.length > 0) {
|
|
32
|
+
let packageJsonBeforePluginsInstallation = getPackageJsonContentBeforeInstallingPlugins();
|
|
33
|
+
let installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')}`;
|
|
34
|
+
Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
|
|
35
|
+
Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
|
|
36
|
+
let arePluginsInstalledSuccessfully = executeSynchronizedCommands(execSync, [installCommand, {
|
|
37
|
+
stdio: 'inherit',
|
|
38
|
+
cwd: getNodeModulesPath()
|
|
39
|
+
}], '', 'Some issue occured while installing plugins', false, true);
|
|
40
|
+
if (arePluginsInstalledSuccessfully) {
|
|
41
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
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
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins.Kindly retry the command");
|
|
52
|
+
// return false
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
28
55
|
Logger.log(Logger.INFO_TYPE, 'Plugins are already installed');
|
|
29
|
-
return true
|
|
30
|
-
}
|
|
31
|
-
const packageJsonBackup = getPackageJsonContentBeforeInstallingPlugins();
|
|
32
|
-
const installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')}`;
|
|
33
|
-
Logger.log(Logger.INFO_TYPE, 'Installing plugins...');
|
|
34
|
-
Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
|
|
35
|
-
const installed = executeSynchronizedCommands(execSync, [installCommand, {
|
|
36
|
-
stdio: 'inherit',
|
|
37
|
-
cwd: getNodeModulesPath()
|
|
38
|
-
}], '', 'Some issue occurred while installing plugins', false, true);
|
|
39
|
-
if (!installed) {
|
|
40
|
-
Logger.log(Logger.FAILURE_TYPE, 'Unable to install plugins. Kindly retry the command');
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
44
|
-
const restored = restorePackageJsonContent(packageJsonBackup);
|
|
45
|
-
if (!restored) {
|
|
46
|
-
Logger.log(Logger.FAILURE_TYPE, 'Unable to restore package.json content');
|
|
47
|
-
return false;
|
|
56
|
+
// return true
|
|
48
57
|
}
|
|
49
|
-
createVersionControlFile(pluginsToBeInstalled);
|
|
50
|
-
return true;
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
/**
|
|
@@ -69,6 +76,53 @@ function restorePackageJsonContent(packageJsonContentBeforePluginsInstallation)
|
|
|
69
76
|
let isPackageJsonRestored = executeSynchronizedCommands(writeFileSync, [packageJsonFilePath, JSON.stringify(packageJsonContentBeforePluginsInstallation, null, 2)], 'Package.json content restored successfully', 'Unable to restore package.json content', false, true);
|
|
70
77
|
return isPackageJsonRestored;
|
|
71
78
|
}
|
|
79
|
+
|
|
80
|
+
// function appendInstalledPluginsToPackageJson(pluginsToBeAppendedInPackageJson){
|
|
81
|
+
// let packageJsonFilePath = `${nodeModulesPathOfProject}/package.json`
|
|
82
|
+
// let packageJsonContent = require(packageJsonFilePath)
|
|
83
|
+
// let devDependencies = packageJsonContent.devDependencies
|
|
84
|
+
// let pluginsToBeAddedInDevDependencies = {}
|
|
85
|
+
|
|
86
|
+
// executeSynchronizedCommands(process.chdir,[nodeModulesPathOfProject],'','Unable to navigate to node_modules path when trying to revert changes in package.json',false,false)
|
|
87
|
+
|
|
88
|
+
// let gitDiffOutput = executeSynchronizedCommands(execSync,['git diff --name-only'],'','Unable to execute git diff command while checking if package.json is changed',true,false).toString().trim()
|
|
89
|
+
// let isPackageJsonChanged = gitDiffOutput.includes('package.json') ? true : false
|
|
90
|
+
|
|
91
|
+
// if(isPackageJsonChanged){
|
|
92
|
+
// let packageJsonChangesRevertCommand = `git checkout "${packageJsonFilePath}"`
|
|
93
|
+
// isPackageJsonChangesRevertedSuccessfully = executeSynchronizedCommands(execSync,[packageJsonChangesRevertCommand,{stdio:'inherit'}],'Changes in package.json reverted successfully','Unable to revert the changes in package.json file',false,true)
|
|
94
|
+
|
|
95
|
+
// if(isPackageJsonChangesRevertedSuccessfully){
|
|
96
|
+
// pluginsToBeAppendedInPackageJson.map(uninstalledPlugin => {
|
|
97
|
+
// if(uninstalledPlugin.startsWith('@')){
|
|
98
|
+
// let indexOfAtCharacter = uninstalledPlugin.indexOf('@')
|
|
99
|
+
// let indexOfSecondOccurenceOfAtCharacter = uninstalledPlugin.indexOf('@',indexOfAtCharacter + 1)
|
|
100
|
+
// let unInstalledPluginName = uninstalledPlugin.slice(0,indexOfSecondOccurenceOfAtCharacter)
|
|
101
|
+
// let unInstalledPluginVersion = uninstalledPlugin.slice(indexOfSecondOccurenceOfAtCharacter + 1)
|
|
102
|
+
// pluginsToBeAddedInDevDependencies[unInstalledPluginName] = unInstalledPluginVersion
|
|
103
|
+
// }
|
|
104
|
+
// else{
|
|
105
|
+
// pluginsToBeAddedInDevDependencies[uninstalledPlugin.split('@')[0]] = uninstalledPlugin.split('@')[1]
|
|
106
|
+
// }
|
|
107
|
+
// })
|
|
108
|
+
// let updatedPluginsIndevDependencies = {
|
|
109
|
+
// ...devDependencies,
|
|
110
|
+
// ...pluginsToBeAddedInDevDependencies
|
|
111
|
+
// }
|
|
112
|
+
// packageJsonContent.devDependencies = updatedPluginsIndevDependencies
|
|
113
|
+
|
|
114
|
+
// let modifiedPackageJson = {
|
|
115
|
+
// ...packageJsonContent,
|
|
116
|
+
// }
|
|
117
|
+
// let isPluginsAddedInPackageJson = executeSynchronizedCommands(writeFileSync,[packageJsonFilePath,JSON.stringify(modifiedPackageJson,null,2)],'Newly installed plugins successfully added to package.json','Unable to append installed plugins to package.json',false,true)
|
|
118
|
+
// return isPluginsAddedInPackageJson
|
|
119
|
+
// }
|
|
120
|
+
// else{
|
|
121
|
+
// return true
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
124
|
+
// }
|
|
125
|
+
|
|
72
126
|
module.exports = {
|
|
73
127
|
installPlugins
|
|
74
128
|
};
|