@zohodesk/codestandard-validator 0.0.4-exp-7 → 0.0.4-exp-9
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/cli.js +7 -1
- package/build/utils/PluginsInstallation/Worker/installPluginsByWoker.js +35 -0
- package/build/utils/PluginsInstallation/Worker/worker.js +30 -0
- package/build/utils/PluginsInstallation/arePluginsInstalled.js +1 -1
- package/build/utils/PluginsInstallation/checkIfPluginsAreInstalled.js +4 -1
- package/build/utils/PluginsInstallation/installPlugins.js +8 -21
- package/build/utils/PluginsInstallation/printUninstalledPlugins.js +2 -2
- package/package.json +1 -1
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
|
+
let {
|
|
37
|
+
uninstalledPlugins
|
|
38
|
+
} = checkIfPluginsAreInstalled();
|
|
39
|
+
await executeMethodsThatReturnBooleanValue("Some issue occurred in installing plugins", installPlugins, uninstalledPlugins);
|
|
34
40
|
break;
|
|
35
41
|
}
|
|
36
42
|
case "setupExtension":
|
|
@@ -0,0 +1,35 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
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(workerData.packageName, workerData.version);
|
|
30
|
+
parentPort.postMessage(result);
|
|
@@ -114,7 +114,10 @@ function checkIfPluginsAreInstalled() {
|
|
|
114
114
|
if (isPluginPresent && checkPluginHasProperVersion(packageName, pluginPath, version)) {
|
|
115
115
|
return false;
|
|
116
116
|
}
|
|
117
|
-
return
|
|
117
|
+
return {
|
|
118
|
+
packageName,
|
|
119
|
+
version
|
|
120
|
+
};
|
|
118
121
|
}).filter(Boolean);
|
|
119
122
|
if (uninstalledPlugins.length > 0) {
|
|
120
123
|
// uninstalledPlugins = getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, pluginsIndevDependencies);
|
|
@@ -1,42 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
execSync
|
|
5
|
-
} = require('child_process');
|
|
6
|
-
const {
|
|
7
|
-
checkIfPluginsAreInstalled
|
|
8
|
-
} = require('./checkIfPluginsAreInstalled');
|
|
9
|
-
const {
|
|
10
|
-
executeSynchronizedCommands
|
|
11
|
-
} = require('../General/executeSyncCommands');
|
|
12
3
|
const {
|
|
13
4
|
Logger
|
|
14
5
|
} = require('../Logger/Logger');
|
|
15
6
|
const {
|
|
16
7
|
createVersionControlFile
|
|
17
8
|
} = require('../FileAndFolderOperations/versionControl');
|
|
9
|
+
const {
|
|
10
|
+
default: installPluginsByWorker
|
|
11
|
+
} = require('./Worker/installPluginsByWoker');
|
|
18
12
|
|
|
19
13
|
/**
|
|
20
14
|
* @function installPlugins - installs uninstalled plugins for the project
|
|
21
15
|
* @returns {boolean} - indicating if plugins to be installed are installed successfully or not
|
|
22
16
|
*/
|
|
23
|
-
function installPlugins() {
|
|
24
|
-
let {
|
|
25
|
-
uninstalledPlugins: pluginsToBeInstalled
|
|
26
|
-
} = checkIfPluginsAreInstalled();
|
|
17
|
+
function installPlugins(pluginsToBeInstalled) {
|
|
27
18
|
if (pluginsToBeInstalled.length > 0) {
|
|
28
|
-
let installCommand = `npm install --no-save ${pluginsToBeInstalled.join(' ')}`;
|
|
29
19
|
Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
|
|
30
|
-
|
|
31
|
-
let arePluginsInstalledSuccessfully = executeSynchronizedCommands(execSync, [installCommand, {
|
|
32
|
-
stdio: 'inherit'
|
|
33
|
-
}], '', 'Some issue occured while installing plugins', false, true);
|
|
34
|
-
if (arePluginsInstalledSuccessfully) {
|
|
20
|
+
try {
|
|
35
21
|
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
22
|
+
installPluginsByWorker(pluginsToBeInstalled);
|
|
36
23
|
createVersionControlFile(pluginsToBeInstalled);
|
|
37
24
|
return true;
|
|
38
|
-
}
|
|
39
|
-
Logger.log(Logger.FAILURE_TYPE,
|
|
25
|
+
} catch (error) {
|
|
26
|
+
Logger.log(Logger.FAILURE_TYPE, `Unable to install plugins.Kindly retry the command - ${error.message}`);
|
|
40
27
|
return false;
|
|
41
28
|
}
|
|
42
29
|
} else {
|
|
@@ -9,11 +9,11 @@ const {
|
|
|
9
9
|
* @param {Array} uninstalledPlugins - contains list of uninstalled plugins for the project
|
|
10
10
|
*/
|
|
11
11
|
function printUninstalledPlugins(uninstalledPlugins) {
|
|
12
|
-
let commandToInstallPlugins = 'npx ZDPrecommit setupPlugins'
|
|
12
|
+
// let commandToInstallPlugins = 'npx ZDPrecommit setupPlugins'
|
|
13
13
|
if (uninstalledPlugins.uninstalledPlugins.length !== 0) {
|
|
14
14
|
Logger.log(Logger.INFO_TYPE, 'The following plugins are not installed:');
|
|
15
15
|
uninstalledPlugins.uninstalledPlugins.map(plugin => {
|
|
16
|
-
Logger.log(Logger.INFO_TYPE, `"${plugin}"`);
|
|
16
|
+
Logger.log(Logger.INFO_TYPE, `"${plugin.packageName}@${plugin.version}"`);
|
|
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
19
|
} else if (uninstalledPlugins.uninstalledPlugins.length === 0 && uninstalledPlugins.noPluginMessage.trim() === '') {
|