@zohodesk/testinglibrary 0.0.1 → 0.0.2

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.
@@ -1,19 +1,51 @@
1
- const path = require('path')
2
-
3
- function getRootPath() {
4
- return path.resolve(__dirname, '../', '../');
5
- }
6
-
7
- function getRootNodeModulesPath() {
8
- return path.resolve(getRootPath(), 'node_modules');
9
- }
10
-
11
- function getBinPath() {
12
- return path.resolve(getRootNodeModulesPath(), '.bin');
13
- }
14
-
15
- module.exports = {
16
- getRootPath,
17
- getBinPath,
18
- getRootNodeModulesPath
1
+ const path = require('path')
2
+ const fs = require('fs');
3
+ const { Logger } = require('./logger');
4
+ const getFilePathWithExtension = require('./getFilePath');
5
+
6
+ function findBinaryPath(directory, command) {
7
+ const binaryPath = path.join(directory, '.bin', getFilePathWithExtension(command));
8
+ if (fs.existsSync(binaryPath)) {
9
+ return binaryPath;
10
+ }
11
+
12
+ // Recursively search parent directories. Might be time-consuming ?? Can we look for npm module like which?
13
+ const parentDir = path.dirname(directory);
14
+ if (parentDir === directory) {
15
+ return null;
16
+ }
17
+
18
+ return findBinaryPath(parentDir, command);
19
+ }
20
+
21
+ function getRootPath() {
22
+ return path.resolve(__dirname, '../', '../');
23
+ }
24
+
25
+ function getRootNodeModulesPath() {
26
+ return path.resolve(getRootPath(), 'node_modules');
27
+ }
28
+
29
+ function getBinPath(command) {
30
+ const packageNodeModulesPath = getRootNodeModulesPath();
31
+ return findBinaryPath(packageNodeModulesPath, command);
32
+
33
+ }
34
+
35
+
36
+ function getExecutableBinaryPath(command) {
37
+ const binPath = getBinPath(command);
38
+ if (binPath !== null) {
39
+ return binPath;
40
+ } else {
41
+ Logger.log(Logger.FAILURE_TYPE, `Error: Could not find executable bin file. Make sure to npm install before proceeding`);
42
+ process.exit();
43
+ }
44
+ }
45
+
46
+ module.exports = {
47
+ getRootPath,
48
+ getBinPath,
49
+ getRootNodeModulesPath,
50
+ getExecutableBinaryPath
19
51
  }