@zohodesk/codestandard-validator 0.0.0-exp-1
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/.babelrc +19 -0
- package/README.md +3 -0
- package/bin/cli.js +3 -0
- package/bin/execute.js +3 -0
- package/bin/postinstall.js +3 -0
- package/build/grafana-config/grafana-config.js +16 -0
- package/build/grafana-config/grfanaAPI.js +72 -0
- package/build/hooks/Precommit/filterUtils.js +42 -0
- package/build/hooks/Precommit/pre-commit.js +235 -0
- package/build/lib/cli.js +47 -0
- package/build/lib/postinstall.js +44 -0
- package/build/setup/initialSetup.js +60 -0
- package/build/utils/CloneCommonLinterRepo/HelperFunctions/helpers.js +16 -0
- package/build/utils/CloneCommonLinterRepo/cloneViaCdt.js +41 -0
- package/build/utils/EslintConfigFileUtils/createEslintConfigFile.js +54 -0
- package/build/utils/EslintConfigFileUtils/getEslintExecutablePath.js +24 -0
- package/build/utils/EslintConfigFileUtils/getLintConfiguration.js +52 -0
- package/build/utils/ExtensionInstallation/installEslintExtension.js +25 -0
- package/build/utils/FileAndFolderOperations/deleteFile.js +28 -0
- package/build/utils/FileAndFolderOperations/filterFiles.js +41 -0
- package/build/utils/FileAndFolderOperations/getFileContent.js +23 -0
- package/build/utils/FileAndFolderOperations/grantExecutionPermission.js +35 -0
- package/build/utils/FileAndFolderOperations/removeFolder.js +37 -0
- package/build/utils/General/RootDirectoryUtils/getRootDirectory.js +23 -0
- package/build/utils/General/RootDirectoryUtils/navigateToRootDirectory.js +25 -0
- package/build/utils/General/executeSyncCommands.js +40 -0
- package/build/utils/General/getGeneralInfo.js +31 -0
- package/build/utils/General/getLibraryInstalledLocation.js +18 -0
- package/build/utils/General/getNodeModulesPath.js +14 -0
- package/build/utils/General/wrapperFunctionToExecuteAFunction.js +39 -0
- package/build/utils/General/writeProjectDetailsToJson.js +18 -0
- package/build/utils/GitActions/gitActions.js +88 -0
- package/build/utils/HuskySetup/configurePrecommitHook.js +39 -0
- package/build/utils/HuskySetup/initializeHusky.js +35 -0
- package/build/utils/HuskySetup/setupHusky.js +76 -0
- package/build/utils/Logger/Logger.js +26 -0
- package/build/utils/PluginsInstallation/arePluginsInstalled.js +15 -0
- package/build/utils/PluginsInstallation/checkIfPluginsAreInstalled.js +112 -0
- package/build/utils/PluginsInstallation/installPlugins.js +91 -0
- package/build/utils/PluginsInstallation/printUninstalledPlugins.js +27 -0
- package/build/utils/PrecommitUsingGitSetup/update-git-precommithook.js +37 -0
- package/changeLog.md +7 -0
- package/configuration/common/.eslintrc.js +18 -0
- package/configuration/common/index.js +9 -0
- package/configuration/common/pluginVersion.js +7 -0
- package/configuration/common/rule_configuration/configurations.js +9 -0
- package/configuration/services/desk_client_app/.eslintrc.js +18 -0
- package/configuration/services/desk_client_app/index.js +16 -0
- package/configuration/services/desk_client_app/pluginVersion.js +17 -0
- package/configuration/services/desk_client_app/rule_configuration/architectureRules/bestPracticeRules.js +9 -0
- package/configuration/services/desk_client_app/rule_configuration/i18nRules/noHardcodingRuleExcludes.js +32 -0
- package/index.js +8 -0
- package/jsonUtils/commonLinterRepoDetails.js +17 -0
- package/package.json +27 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const {
|
|
5
|
+
readdirSync
|
|
6
|
+
} = require('fs');
|
|
7
|
+
const {
|
|
8
|
+
getNodeModulesPath
|
|
9
|
+
} = require('../General/getNodeModulesPath');
|
|
10
|
+
const {
|
|
11
|
+
executeSynchronizedCommands
|
|
12
|
+
} = require('../General/executeSyncCommands');
|
|
13
|
+
const {
|
|
14
|
+
getLibraryInstalledLocation
|
|
15
|
+
} = require('../General/getLibraryInstalledLocation');
|
|
16
|
+
function getEslintExecutablePath() {
|
|
17
|
+
let eslintLibraryName = 'eslint';
|
|
18
|
+
let librariesInNodeModulesOfProject = executeSynchronizedCommands(readdirSync, [path.join(getNodeModulesPath(), 'node_modules')], '', 'Unable to get the plugins inside node_modules', true, false);
|
|
19
|
+
let isEslintInstalledinProject = librariesInNodeModulesOfProject.some(library => library === eslintLibraryName);
|
|
20
|
+
return isEslintInstalledinProject ? path.join(getNodeModulesPath(), 'node_modules', eslintLibraryName, 'bin', 'eslint.js') : path.join(getLibraryInstalledLocation(), 'node_modules', eslintLibraryName, 'bin', 'eslint.js');
|
|
21
|
+
}
|
|
22
|
+
module.exports = {
|
|
23
|
+
getEslintExecutablePath
|
|
24
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const {
|
|
5
|
+
existsSync
|
|
6
|
+
} = require('fs');
|
|
7
|
+
const {
|
|
8
|
+
endPoint,
|
|
9
|
+
commonLinterRepoName
|
|
10
|
+
} = require("../../../jsonUtils/commonLinterRepoDetails.js");
|
|
11
|
+
const {
|
|
12
|
+
getRepoName
|
|
13
|
+
} = require('../GitActions/gitActions');
|
|
14
|
+
const {
|
|
15
|
+
getLibraryInstalledLocation
|
|
16
|
+
} = require('../General/getLibraryInstalledLocation');
|
|
17
|
+
const {
|
|
18
|
+
executeMethodsThatMayThrowException
|
|
19
|
+
} = require("../General/wrapperFunctionToExecuteAFunction");
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @function getLintConfiguration - returns eslint configuration file from common linters repo
|
|
23
|
+
* @returns {object} - containing properties of the eslint configuration file
|
|
24
|
+
*/
|
|
25
|
+
function getServicePathElseCommon() {
|
|
26
|
+
const repoName = getRepoName();
|
|
27
|
+
const libraryInstalledLocation = getLibraryInstalledLocation();
|
|
28
|
+
let commonConfigPath = path.join(libraryInstalledLocation, commonLinterRepoName, 'common', 'index.js');
|
|
29
|
+
const _configurationPath = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'index.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'index.js') : commonConfigPath;
|
|
30
|
+
let _pathOfServiceSpecificEslintConfigFile = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.eslintrc.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.eslintrc.js') : path.join(libraryInstalledLocation, commonLinterRepoName, 'common', '.eslintrc.js');
|
|
31
|
+
let _pluginVersionPath = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'pluginVersion.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'pluginVersion.js') : undefined;
|
|
32
|
+
return {
|
|
33
|
+
configurationPath: _configurationPath,
|
|
34
|
+
pathOfServiceSpecificEslintConfigFile: _pathOfServiceSpecificEslintConfigFile,
|
|
35
|
+
pluginVersionPath: _pluginVersionPath
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function getLintConfigurationUtil() {
|
|
39
|
+
const {
|
|
40
|
+
configurationPath
|
|
41
|
+
} = getServicePathElseCommon();
|
|
42
|
+
const exceptionHandleObject = {
|
|
43
|
+
rulesConfig: [{}, {}],
|
|
44
|
+
plugins: [],
|
|
45
|
+
extendPlugins: []
|
|
46
|
+
};
|
|
47
|
+
return executeMethodsThatMayThrowException(exceptionHandleObject, `Kindly Ensure that Configuration is setup in Configuration repo \n ${endPoint}`, require, configurationPath);
|
|
48
|
+
}
|
|
49
|
+
module.exports = {
|
|
50
|
+
getLintConfigurationUtil,
|
|
51
|
+
getServicePathElseCommon
|
|
52
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
execSync
|
|
5
|
+
} = require('child_process');
|
|
6
|
+
const {
|
|
7
|
+
executeSynchronizedCommands
|
|
8
|
+
} = require('../General/executeSyncCommands');
|
|
9
|
+
const {
|
|
10
|
+
Logger
|
|
11
|
+
} = require('../Logger/Logger');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @function installEslintExtension - installs eslint extension for vscode
|
|
15
|
+
* @returns {boolean} - indicating the success or failure of installing eslint extension for vscode
|
|
16
|
+
*/
|
|
17
|
+
function installEslintExtension() {
|
|
18
|
+
let eslintExtensionCode = 'dbaeumer.vscode-eslint';
|
|
19
|
+
Logger.log(Logger.INFO_TYPE, 'Installing eslint extension for Vscode....');
|
|
20
|
+
let isEslintExtensionInstalledSuccessfully = executeSynchronizedCommands(execSync, [`code --install-extension ${eslintExtensionCode}`], 'Eslint extension for vscode installed successfully! If eslint errors not being reported in editor, kindly restart Vscode', 'Unable to install eslint extension for vscode', false, true);
|
|
21
|
+
return isEslintExtensionInstalledSuccessfully;
|
|
22
|
+
}
|
|
23
|
+
module.exports = {
|
|
24
|
+
installEslintExtension
|
|
25
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
existsSync,
|
|
5
|
+
unlinkSync
|
|
6
|
+
} = require('fs');
|
|
7
|
+
const {
|
|
8
|
+
Logger
|
|
9
|
+
} = require('../Logger/Logger');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @function deleteFile - deletes the provided file
|
|
13
|
+
* @param {string} filePath - path of file to be deleted
|
|
14
|
+
*/
|
|
15
|
+
function deleteFile(filePath) {
|
|
16
|
+
if (existsSync(filePath)) {
|
|
17
|
+
try {
|
|
18
|
+
unlinkSync(filePath);
|
|
19
|
+
Logger.log(Logger.SUCCESS_TYPE, `${filePath} deleted successfully`);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
Logger.log(Logger.FAILURE_TYPE, err);
|
|
22
|
+
throw new Error(`Error while deleting the file: ${filePath}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
module.exports = {
|
|
27
|
+
deleteFile
|
|
28
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
Logger
|
|
5
|
+
} = require('../Logger/Logger');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @function filterFiles - removes certain files from set of source files
|
|
9
|
+
* @param {Array} arrayOfFilesToBeFiltered - array of files which must be filtered
|
|
10
|
+
* @param {Array} filesToBeRemoved - array of files that need to be removed
|
|
11
|
+
* @param {boolean} isConfigFileNeedToBeRemoved - indicating whether eslint config file should be removed or not
|
|
12
|
+
* @returns {Array} - containing the resultant set of files after filtering
|
|
13
|
+
*/
|
|
14
|
+
function filterFiles(arrayOfFilesToBeFiltered, filesToBeRemoved, isConfigFileNeedToBeRemoved = false) {
|
|
15
|
+
if (filesToBeRemoved.length !== 0) {
|
|
16
|
+
if (isConfigFileNeedToBeRemoved) {
|
|
17
|
+
arrayOfFilesToBeFiltered.filter(file => {
|
|
18
|
+
let isConfigFileModified = filesToBeRemoved.some(fileToBeRemoved => file.includes(fileToBeRemoved));
|
|
19
|
+
if (isConfigFileModified) {
|
|
20
|
+
Logger.log(Logger.INFO_TYPE, 'The eslint config file should not be modified locally. Update the file in the common repo for linters.');
|
|
21
|
+
Logger.log(Logger.FAILURE_TYPE, 'Kindly revert the changes in eslint config file and commit the rest.');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
let filteredArrayofFilesWithoutConfigFile = arrayOfFilesToBeFiltered.filter(file => {
|
|
27
|
+
let isFileToBeRemovedPresent = filesToBeRemoved.some(fileToBeRemoved => file.includes(fileToBeRemoved));
|
|
28
|
+
if (!isFileToBeRemovedPresent) {
|
|
29
|
+
return true;
|
|
30
|
+
} else {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return filteredArrayofFilesWithoutConfigFile;
|
|
35
|
+
} else if (filesToBeRemoved.length === 0) {
|
|
36
|
+
return arrayOfFilesToBeFiltered;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
module.exports = {
|
|
40
|
+
filterFiles
|
|
41
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const {
|
|
5
|
+
Logger
|
|
6
|
+
} = require('../Logger/Logger');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @function getFileContent - retrieves the content of a file
|
|
10
|
+
* @param {string} utilsPath - path of file whose content must be retrieved
|
|
11
|
+
* @param {string} defaultPath - path to default file whose content must be retrieved if actula file not present
|
|
12
|
+
* @returns {string} - content of the file provided
|
|
13
|
+
*/
|
|
14
|
+
function getFileContent(utilsPath, defaultPath = undefined) {
|
|
15
|
+
try {
|
|
16
|
+
return require(fs.existsSync(utilsPath) ? utilsPath : defaultPath);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
Logger.log(Logger.FAILURE_TYPE, `path is not valid ...`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
module.exports = {
|
|
22
|
+
getFileContent
|
|
23
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const {
|
|
7
|
+
Logger
|
|
8
|
+
} = require('../Logger/Logger');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @function grantExecutionPermission - grnats execution permission to set of files
|
|
12
|
+
* @param {Array} filesToWhichExecutionPermissionToBeGiven
|
|
13
|
+
* @returns {boolean} - indicating whether execution permission given to all provided files
|
|
14
|
+
* @note - this method gives execution permission only if operating system is either Mac or Linux
|
|
15
|
+
*/
|
|
16
|
+
function grantExecutionPermission(filesToWhichExecutionPermissionToBeGiven) {
|
|
17
|
+
let ostype = os.type();
|
|
18
|
+
if (ostype === 'Darwin' || ostype === 'Linux') {
|
|
19
|
+
let filesThatWereGivenExecutionPermission = filesToWhichExecutionPermissionToBeGiven.filter(file => {
|
|
20
|
+
try {
|
|
21
|
+
fs.chmodSync(file, '755');
|
|
22
|
+
Logger.log(Logger.SUCCESS_TYPE, `execution permission given to ${file}`);
|
|
23
|
+
return true;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
Logger.log(Logger.FAILURE_TYPE, error);
|
|
26
|
+
Logger.log(Logger.FAILURE_TYPE, `Unable to give execution permission to ${file}`);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return filesThatWereGivenExecutionPermission.length === filesToWhichExecutionPermissionToBeGiven.length ? true : false;
|
|
31
|
+
} else {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
module.exports = grantExecutionPermission;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
existsSync,
|
|
5
|
+
rmSync
|
|
6
|
+
} = require('fs');
|
|
7
|
+
const {
|
|
8
|
+
Logger
|
|
9
|
+
} = require('../Logger/Logger');
|
|
10
|
+
const {
|
|
11
|
+
executeSynchronizedCommands
|
|
12
|
+
} = require('../General/executeSyncCommands');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @function removeFolder - removes the given folder if it exists
|
|
16
|
+
* @param {string} folderPath - path to folder that must be removed
|
|
17
|
+
* @returns {void}
|
|
18
|
+
*/
|
|
19
|
+
function removeFolder(folderPath) {
|
|
20
|
+
try {
|
|
21
|
+
let isCommonConfigFolderPresent = existsSync(folderPath);
|
|
22
|
+
if (isCommonConfigFolderPresent) {
|
|
23
|
+
executeSynchronizedCommands(rmSync, [folderPath, {
|
|
24
|
+
recursive: true,
|
|
25
|
+
force: true
|
|
26
|
+
}], 'common linter configuration folder removed successfully', 'Unable to remove the common linter configuration folder', false, false);
|
|
27
|
+
} else {
|
|
28
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Configuration folder not present');
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
Logger.log(Logger.FAILURE_TYPE, error);
|
|
32
|
+
Logger.log(Logger.FAILURE_TYPE, 'Unable to check if common linter configuration folder is present');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
module.exports = {
|
|
36
|
+
removeFolder
|
|
37
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
spawnSync
|
|
5
|
+
} = require('child_process');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @function getRootDirectory - returns the root directory of the project
|
|
9
|
+
* @returns {string} - indicating the root diretory of the project
|
|
10
|
+
*/
|
|
11
|
+
function getRootDirectory() {
|
|
12
|
+
let rootDir = spawnSync('git', ["rev-parse", "--show-toplevel"], {
|
|
13
|
+
shell: true,
|
|
14
|
+
encoding: 'utf-8'
|
|
15
|
+
});
|
|
16
|
+
if (!(rootDir.status == 0)) {
|
|
17
|
+
return process.cwd();
|
|
18
|
+
}
|
|
19
|
+
return rootDir.stdout.toString().trim();
|
|
20
|
+
}
|
|
21
|
+
module.exports = {
|
|
22
|
+
getRootDirectory
|
|
23
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
Logger
|
|
5
|
+
} = require("../../Logger/Logger");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @function navigateToRootDirectory - navigates to root directory of the project
|
|
9
|
+
* @param {string} rootDir - root directory of the project
|
|
10
|
+
* @returns {boolean} - indicating the success or failure of navigation to root directory of the project
|
|
11
|
+
*/
|
|
12
|
+
function navigateToRootDirectory(rootDir) {
|
|
13
|
+
Logger.log(Logger.INFO_TYPE, `rootDir:${rootDir}`);
|
|
14
|
+
try {
|
|
15
|
+
process.chdir(rootDir);
|
|
16
|
+
Logger.log(Logger.SUCCESS_TYPE, "Successfully navigated to root directory");
|
|
17
|
+
return true;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
Logger.log(Logger.FAILURE_TYPE, "Couldn't navigate to root directory", error);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
module.exports = {
|
|
24
|
+
navigateToRootDirectory
|
|
25
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
Logger
|
|
5
|
+
} = require('../Logger/Logger');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @function executeSynchronizedCommands - a wrapper function to execute synchronized command within try catch and return either the result of command or boolean value indicating the success or failure of command execution
|
|
9
|
+
* @param {Function} command - function to be executed
|
|
10
|
+
* @param {Array} commandArgs - arguments to be passed to the function to be executed
|
|
11
|
+
* @param {string} successMessage - success message to should be logged on successful execution of the provided function
|
|
12
|
+
* @param {string} errorMessage - failure message to be logged when the given function execution fails
|
|
13
|
+
* @param {boolean} shouldCommandResultBeReturned - indicates if output of command to be returned
|
|
14
|
+
* @param {boolean} shouldReturnBooleanValue - indicates if boolean value corresponding to command execution output be returned
|
|
15
|
+
* @returns {boolean | string} - returns either a boolean indicating the success or failure of the command executed or the result returned by the executed command
|
|
16
|
+
*/
|
|
17
|
+
function executeSynchronizedCommands(command, commandArgs, successMessage = '', errorMessage = '', shouldCommandResultBeReturned = false, shouldReturnBooleanValue = false) {
|
|
18
|
+
try {
|
|
19
|
+
if (shouldCommandResultBeReturned) {
|
|
20
|
+
return command(...commandArgs);
|
|
21
|
+
} else if (!shouldCommandResultBeReturned) {
|
|
22
|
+
command(...commandArgs);
|
|
23
|
+
}
|
|
24
|
+
if (successMessage.trim() !== '') {
|
|
25
|
+
Logger.log(Logger.SUCCESS_TYPE, successMessage);
|
|
26
|
+
}
|
|
27
|
+
if (shouldReturnBooleanValue) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
Logger.log(Logger.FAILURE_TYPE, error);
|
|
32
|
+
Logger.log(Logger.FAILURE_TYPE, errorMessage);
|
|
33
|
+
if (shouldReturnBooleanValue) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
module.exports = {
|
|
39
|
+
executeSynchronizedCommands
|
|
40
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @function getTimeStampInfo - to fetch various timestamp details
|
|
7
|
+
* @returns {object} - each property of the object denotes various timestamp details
|
|
8
|
+
*/
|
|
9
|
+
function getTimeStampInfo() {
|
|
10
|
+
const date = new Date();
|
|
11
|
+
return {
|
|
12
|
+
date: date.getDate(),
|
|
13
|
+
hours: date.getHours(),
|
|
14
|
+
minute: date.getMinutes(),
|
|
15
|
+
second: date.getSeconds(),
|
|
16
|
+
month: date.getMonth() + 1,
|
|
17
|
+
year: date.getFullYear()
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @function getEnv - to fetch the os type
|
|
23
|
+
* @returns {string} - indicates the os
|
|
24
|
+
*/
|
|
25
|
+
function getEnv() {
|
|
26
|
+
return os.type();
|
|
27
|
+
}
|
|
28
|
+
module.exports = {
|
|
29
|
+
getTimeStampInfo,
|
|
30
|
+
getEnv
|
|
31
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const {
|
|
5
|
+
getNodeModulesPath
|
|
6
|
+
} = require('./getNodeModulesPath');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @function getLibraryInstalledLocation - fetches the absolute path where library is installed
|
|
10
|
+
* @returns {string} - path where library is installed
|
|
11
|
+
*/
|
|
12
|
+
function getLibraryInstalledLocation() {
|
|
13
|
+
const libraryInstalledLocation = path.join(getNodeModulesPath(), 'node_modules', '@zohodesk', 'codestandard-validator');
|
|
14
|
+
return libraryInstalledLocation;
|
|
15
|
+
}
|
|
16
|
+
module.exports = {
|
|
17
|
+
getLibraryInstalledLocation
|
|
18
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @function getNodeModulesPath - fetches the absolute path where node_modules of project is present
|
|
7
|
+
* @returns {string} - path where node_modules of the project is present
|
|
8
|
+
*/
|
|
9
|
+
function getNodeModulesPath() {
|
|
10
|
+
return require(path.join(__dirname, '..', '..', '..', 'jsonUtils', 'fsUtils.json')).nodeModulesPath;
|
|
11
|
+
}
|
|
12
|
+
module.exports = {
|
|
13
|
+
getNodeModulesPath
|
|
14
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
Logger
|
|
5
|
+
} = require('../Logger/Logger');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @function executeMethodsThatReturnBooleanValue - wrapper method to execute certain commands/methods that return a boolean value
|
|
9
|
+
* @param {string} consoleMessage - message that must be printed on failure of the method to be executed
|
|
10
|
+
* @param {Function} _callback - the function to be executed
|
|
11
|
+
* @param {...any} params - arguments to be passed to the method to be executed
|
|
12
|
+
*/
|
|
13
|
+
async function executeMethodsThatReturnBooleanValue(consoleMessage, _callback, ...params) {
|
|
14
|
+
if (!(await _callback(...params))) {
|
|
15
|
+
throw new Error(consoleMessage);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {any} handleObject - default value to be retunred if the function to be executed encounters an exception
|
|
22
|
+
* @param {string} consoleMessage - message to be logged if the function to be executed fails
|
|
23
|
+
* @param {Function} _callback - method/command to be executed
|
|
24
|
+
* @param {...any} params - arguments to be passed to the method/command to be executed
|
|
25
|
+
* @returns {any} - the result returned by the executed method/command or the default return value provided in argument
|
|
26
|
+
*/
|
|
27
|
+
function executeMethodsThatMayThrowException(handleObject, consoleMessage, _callback, ...params) {
|
|
28
|
+
try {
|
|
29
|
+
return _callback(...params);
|
|
30
|
+
} catch (err) {
|
|
31
|
+
Logger.log(Logger.FAILURE_TYPE, err);
|
|
32
|
+
Logger.log(Logger.FAILURE_TYPE, consoleMessage);
|
|
33
|
+
return handleObject;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
module.exports = {
|
|
37
|
+
executeMethodsThatReturnBooleanValue,
|
|
38
|
+
executeMethodsThatMayThrowException
|
|
39
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const {
|
|
5
|
+
writeFileSync
|
|
6
|
+
} = require('fs');
|
|
7
|
+
const {
|
|
8
|
+
executeSynchronizedCommands
|
|
9
|
+
} = require('./executeSyncCommands');
|
|
10
|
+
function writeFsPaths() {
|
|
11
|
+
var fileContent = {
|
|
12
|
+
nodeModulesPath: path.resolve(process.cwd(), '..', '..', '..')
|
|
13
|
+
};
|
|
14
|
+
return executeSynchronizedCommands(writeFileSync, [path.join(process.cwd(), 'jsonUtils', 'fsUtils.json'), JSON.stringify(fileContent), 'utf-8'], 'node_modules path updated in json file', 'Unable to write node_modules path to json file', false, true);
|
|
15
|
+
}
|
|
16
|
+
module.exports = {
|
|
17
|
+
writeFsPaths
|
|
18
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
spawnSync,
|
|
5
|
+
execSync
|
|
6
|
+
} = require("child_process");
|
|
7
|
+
const {
|
|
8
|
+
executeMethodsThatMayThrowException
|
|
9
|
+
} = require("../General/wrapperFunctionToExecuteAFunction");
|
|
10
|
+
const {
|
|
11
|
+
executeSynchronizedCommands
|
|
12
|
+
} = require("../General/executeSyncCommands");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @function getGitUserName - to get the git username
|
|
16
|
+
* @returns {string | null} - returns the username or null if command execution encounters an exception
|
|
17
|
+
*/
|
|
18
|
+
function getGitUserName() {
|
|
19
|
+
const userHandler = () => {
|
|
20
|
+
const userName = exeSpawnSync("git", ["config", "user.email"]);
|
|
21
|
+
if (userName == null) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return userName.pop().split("@")[0];
|
|
25
|
+
};
|
|
26
|
+
return executeMethodsThatMayThrowException(null, 'kindly initialize git properly', userHandler, null);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @function getRepoName - to get the git repository name
|
|
31
|
+
* @returns {string | null} - returns the git reponame or null if command execution encounters an exception
|
|
32
|
+
*/
|
|
33
|
+
function getRepoName() {
|
|
34
|
+
const repoHandler = () => {
|
|
35
|
+
const repoName = exeSpawnSync("git", ["remote", "get-url", "origin"]);
|
|
36
|
+
if (repoName == null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return repoName.pop().split("/").pop().split(".")[0];
|
|
40
|
+
};
|
|
41
|
+
return executeMethodsThatMayThrowException(null, 'kindly initialize git properly', repoHandler, null);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @function getBranchName - to get the current branch name
|
|
46
|
+
* @returns {string | null} - returns the git reponame or null if command execution encounters an exception
|
|
47
|
+
*/
|
|
48
|
+
function getBranchName() {
|
|
49
|
+
const branchHandler = () => {
|
|
50
|
+
var branchName = exeSpawnSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]); // to get current branch
|
|
51
|
+
if (branchName == null) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return branchName.shift().trim();
|
|
55
|
+
};
|
|
56
|
+
return executeMethodsThatMayThrowException(null, 'kindly initialize git properly', branchHandler, null);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param {Function} command - comamnd/function to be executed
|
|
62
|
+
* @param {*} params - parameters to be passed to the command/function to be executed
|
|
63
|
+
* @returns {null | any}
|
|
64
|
+
*/
|
|
65
|
+
function exeSpawnSync(command, params = []) {
|
|
66
|
+
const demon_process = spawnSync(command, params, {
|
|
67
|
+
shell: true
|
|
68
|
+
});
|
|
69
|
+
if (!(demon_process.status == 0)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return demon_process.stdout.toString().split("\n").filter(Boolean);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @function isGitInitialized - to check if git is initialized
|
|
77
|
+
* @returns {boolean} - inidcating whether the repo is git initialized or not
|
|
78
|
+
*/
|
|
79
|
+
function isGitInitialized() {
|
|
80
|
+
const isGit = executeSynchronizedCommands(execSync, ['git status'], '', "Kindly initialize git using \"git init\" ", false, true);
|
|
81
|
+
return isGit;
|
|
82
|
+
}
|
|
83
|
+
module.exports = {
|
|
84
|
+
getBranchName,
|
|
85
|
+
getGitUserName,
|
|
86
|
+
getRepoName,
|
|
87
|
+
isGitInitialized
|
|
88
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
writeFileSync
|
|
5
|
+
} = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const grantExecutionPermission = require("../FileAndFolderOperations/grantExecutionPermission");
|
|
8
|
+
const {
|
|
9
|
+
getRootDirectory
|
|
10
|
+
} = require("../General/RootDirectoryUtils/getRootDirectory");
|
|
11
|
+
const {
|
|
12
|
+
getLibraryInstalledLocation
|
|
13
|
+
} = require("../General/getLibraryInstalledLocation");
|
|
14
|
+
const {
|
|
15
|
+
executeSynchronizedCommands
|
|
16
|
+
} = require("../General/executeSyncCommands");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @function configurePrecommitHook - creates the link to custom pre commit hook file and husky precommit file
|
|
20
|
+
* @returns {boolean} - indicates if custom precommit hook created successfully or not
|
|
21
|
+
*/
|
|
22
|
+
function configurePrecommitHook() {
|
|
23
|
+
let rootDirectory = getRootDirectory();
|
|
24
|
+
let customPrecomitHookPath = path.join(getLibraryInstalledLocation(), "bin", "execute.js");
|
|
25
|
+
let huskyPrecommitPath = path.join(rootDirectory, ".husky", "pre-commit");
|
|
26
|
+
let huskyPrecommitHookContent = `#!/bin/sh
|
|
27
|
+
. "$(dirname "$0")/_/husky.sh"
|
|
28
|
+
|
|
29
|
+
"${customPrecomitHookPath}"
|
|
30
|
+
`;
|
|
31
|
+
let isCustomPrecommitConfigurationSuccessful = executeSynchronizedCommands(writeFileSync, [huskyPrecommitPath, huskyPrecommitHookContent, 'utf-8'], '', 'Could not create and write pre-commit.sh inisde husky directory', false, true);
|
|
32
|
+
if (isCustomPrecommitConfigurationSuccessful) {
|
|
33
|
+
let isExecutionPermissionGivenSuccessfully = grantExecutionPermission([huskyPrecommitPath, customPrecomitHookPath]);
|
|
34
|
+
return isExecutionPermissionGivenSuccessfully;
|
|
35
|
+
} else {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
module.exports = configurePrecommitHook;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
execSync
|
|
7
|
+
} = require('child_process');
|
|
8
|
+
const {
|
|
9
|
+
navigateToRootDirectory
|
|
10
|
+
} = require('../General/RootDirectoryUtils/navigateToRootDirectory');
|
|
11
|
+
const {
|
|
12
|
+
getRootDirectory
|
|
13
|
+
} = require('../General/RootDirectoryUtils/getRootDirectory');
|
|
14
|
+
const {
|
|
15
|
+
Logger
|
|
16
|
+
} = require('../Logger/Logger');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @function initializeHusky - creates a .husky folder at the root of the project with the husky execution script file
|
|
20
|
+
* @returns {boolean} - indicating the success or failure of initializing husky process
|
|
21
|
+
*/
|
|
22
|
+
function initializeHusky() {
|
|
23
|
+
let isNavigationToRootDirectorySuccessful = navigateToRootDirectory(getRootDirectory());
|
|
24
|
+
if (isNavigationToRootDirectorySuccessful) {
|
|
25
|
+
try {
|
|
26
|
+
execSync('npx husky install');
|
|
27
|
+
return true;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
Logger.log(Logger.FAILURE_TYPE, error.toString());
|
|
30
|
+
Logger.log(Logger.FAILURE_TYPE, 'Couldn\'t initialize husky');
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
module.exports = initializeHusky;
|