@itentialopensource/adapter-git 0.3.10 → 0.4.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/.eslintrc.js +1 -0
- package/AUTH.md +4 -4
- package/ENHANCE.md +3 -3
- package/PROPERTIES.md +30 -10
- package/README.md +138 -74
- package/SUMMARY.md +2 -2
- package/SYSTEMINFO.md +1 -1
- package/TAB1.md +2 -2
- package/TAB2.md +5 -5
- package/TROUBLESHOOT.md +1 -1
- package/package.json +18 -20
- package/test/integration/adapterTestIntegration.js +1 -38
- package/test/unit/adapterTestUnit.js +1 -38
- package/utils/adapterInfo.js +114 -164
- package/utils/argParser.js +44 -0
- package/utils/logger.js +26 -0
- package/utils/artifactize.js +0 -146
- package/utils/packModificationScript.js +0 -35
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itentialopensource/adapter-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Itential adapter to run git commands",
|
|
5
5
|
"main": "adapter.js",
|
|
6
6
|
"wizardVersion": "2.44.7",
|
|
7
|
-
"engineVersion": "1.
|
|
7
|
+
"engineVersion": "1.69.14",
|
|
8
8
|
"adapterType": "library",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"artifactize": "npm i && node utils/packModificationScript.js",
|
|
11
10
|
"preinstall": "node utils/setup.js",
|
|
12
11
|
"deinstall": "node utils/removeHooks.js",
|
|
13
12
|
"lint": "node --max_old_space_size=4096 ./node_modules/eslint/bin/eslint.js . --ext .json --ext .js",
|
|
@@ -20,10 +19,9 @@
|
|
|
20
19
|
},
|
|
21
20
|
"keywords": [
|
|
22
21
|
"Itential",
|
|
23
|
-
"
|
|
22
|
+
"Itential Platform",
|
|
24
23
|
"Automation",
|
|
25
24
|
"Integration",
|
|
26
|
-
"App-Artifacts",
|
|
27
25
|
"Adapter",
|
|
28
26
|
"DevOps",
|
|
29
27
|
"NetOps",
|
|
@@ -41,23 +39,23 @@
|
|
|
41
39
|
"author": "Itential",
|
|
42
40
|
"homepage": "https://gitlab.com/itentialopensource/adapters/adapter-git#readme",
|
|
43
41
|
"dependencies": {
|
|
44
|
-
"ajv": "
|
|
45
|
-
"avsc": "
|
|
46
|
-
"fs-extra": "
|
|
47
|
-
"isomorphic-git": "
|
|
48
|
-
"json-query": "
|
|
49
|
-
"readline-sync": "
|
|
50
|
-
"uuid": "
|
|
42
|
+
"ajv": "8.17.1",
|
|
43
|
+
"avsc": "5.4.21",
|
|
44
|
+
"fs-extra": "11.3.0",
|
|
45
|
+
"isomorphic-git": "1.21.0",
|
|
46
|
+
"json-query": "2.2.2",
|
|
47
|
+
"readline-sync": "1.4.10",
|
|
48
|
+
"uuid": "3.0.1",
|
|
49
|
+
"mocha": "10.8.2",
|
|
50
|
+
"winston": "3.17.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"chai": "
|
|
54
|
-
"eslint": "
|
|
55
|
-
"eslint-config-airbnb-base": "
|
|
56
|
-
"eslint-plugin-import": "
|
|
57
|
-
"eslint-plugin-json": "
|
|
58
|
-
"
|
|
59
|
-
"testdouble": "^3.18.0",
|
|
60
|
-
"winston": "^3.13.1"
|
|
53
|
+
"chai": "4.5.0",
|
|
54
|
+
"eslint": "8.57.0",
|
|
55
|
+
"eslint-config-airbnb-base": "15.0.0",
|
|
56
|
+
"eslint-plugin-import": "2.31.0",
|
|
57
|
+
"eslint-plugin-json": "3.1.0",
|
|
58
|
+
"testdouble": "3.18.0"
|
|
61
59
|
},
|
|
62
60
|
"private": false
|
|
63
61
|
}
|
|
@@ -14,11 +14,11 @@ const winston = require('winston');
|
|
|
14
14
|
const { expect } = require('chai');
|
|
15
15
|
const { use } = require('chai');
|
|
16
16
|
const td = require('testdouble');
|
|
17
|
+
const log = require('../../utils/logger');
|
|
17
18
|
|
|
18
19
|
const anything = td.matchers.anything();
|
|
19
20
|
|
|
20
21
|
// stub and attemptTimeout are used throughout the code so set them here
|
|
21
|
-
let logLevel = 'none';
|
|
22
22
|
const stub = true;
|
|
23
23
|
const isRapidFail = false;
|
|
24
24
|
const isSaveMockData = false;
|
|
@@ -55,43 +55,6 @@ global.pronghornProps = {
|
|
|
55
55
|
|
|
56
56
|
global.$HOME = `${__dirname}/../..`;
|
|
57
57
|
|
|
58
|
-
// set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
|
|
59
|
-
// this you may error on log.trace calls.
|
|
60
|
-
const myCustomLevels = {
|
|
61
|
-
levels: {
|
|
62
|
-
spam: 6,
|
|
63
|
-
trace: 5,
|
|
64
|
-
debug: 4,
|
|
65
|
-
info: 3,
|
|
66
|
-
warn: 2,
|
|
67
|
-
error: 1,
|
|
68
|
-
none: 0
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// need to see if there is a log level passed in
|
|
73
|
-
process.argv.forEach((val) => {
|
|
74
|
-
// is there a log level defined to be passed in?
|
|
75
|
-
if (val.indexOf('--LOG') === 0) {
|
|
76
|
-
// get the desired log level
|
|
77
|
-
const inputVal = val.split('=')[1];
|
|
78
|
-
|
|
79
|
-
// validate the log level is supported, if so set it
|
|
80
|
-
if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
|
|
81
|
-
logLevel = inputVal;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// need to set global logging
|
|
87
|
-
global.log = winston.createLogger({
|
|
88
|
-
level: logLevel,
|
|
89
|
-
levels: myCustomLevels.levels,
|
|
90
|
-
transports: [
|
|
91
|
-
new winston.transports.Console()
|
|
92
|
-
]
|
|
93
|
-
});
|
|
94
|
-
|
|
95
58
|
/**
|
|
96
59
|
* Runs the common asserts for test
|
|
97
60
|
*/
|
|
@@ -17,13 +17,13 @@ const { expect } = require('chai');
|
|
|
17
17
|
const { use } = require('chai');
|
|
18
18
|
const td = require('testdouble');
|
|
19
19
|
const Ajv = require('ajv');
|
|
20
|
+
const log = require('../../utils/logger');
|
|
20
21
|
|
|
21
22
|
const ajv = new Ajv({ strictSchema: false, allErrors: true, allowUnionTypes: true });
|
|
22
23
|
|
|
23
24
|
const anything = td.matchers.anything();
|
|
24
25
|
|
|
25
26
|
// stub and attemptTimeout are used throughout the code so set them here
|
|
26
|
-
let logLevel = 'none';
|
|
27
27
|
const stub = true;
|
|
28
28
|
const isRapidFail = false;
|
|
29
29
|
const attemptTimeout = 120000;
|
|
@@ -56,43 +56,6 @@ global.pronghornProps = {
|
|
|
56
56
|
|
|
57
57
|
global.$HOME = `${__dirname}/../..`;
|
|
58
58
|
|
|
59
|
-
// set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
|
|
60
|
-
// this you may error on log.trace calls.
|
|
61
|
-
const myCustomLevels = {
|
|
62
|
-
levels: {
|
|
63
|
-
spam: 6,
|
|
64
|
-
trace: 5,
|
|
65
|
-
debug: 4,
|
|
66
|
-
info: 3,
|
|
67
|
-
warn: 2,
|
|
68
|
-
error: 1,
|
|
69
|
-
none: 0
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// need to see if there is a log level passed in
|
|
74
|
-
process.argv.forEach((val) => {
|
|
75
|
-
// is there a log level defined to be passed in?
|
|
76
|
-
if (val.indexOf('--LOG') === 0) {
|
|
77
|
-
// get the desired log level
|
|
78
|
-
const inputVal = val.split('=')[1];
|
|
79
|
-
|
|
80
|
-
// validate the log level is supported, if so set it
|
|
81
|
-
if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
|
|
82
|
-
logLevel = inputVal;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// need to set global logging
|
|
88
|
-
global.log = winston.createLogger({
|
|
89
|
-
level: logLevel,
|
|
90
|
-
levels: myCustomLevels.levels,
|
|
91
|
-
transports: [
|
|
92
|
-
new winston.transports.Console()
|
|
93
|
-
]
|
|
94
|
-
});
|
|
95
|
-
|
|
96
59
|
/**
|
|
97
60
|
* Runs the error asserts for the test
|
|
98
61
|
*/
|
package/utils/adapterInfo.js
CHANGED
|
@@ -1,20 +1,94 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/* @copyright Itential, LLC
|
|
2
|
+
/* @copyright Itential, LLC 2025 */
|
|
3
|
+
|
|
3
4
|
/* eslint global-require:warn */
|
|
4
5
|
/* eslint import/no-dynamic-require:warn */
|
|
5
6
|
/* eslint prefer-destructuring:warn */
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* This script will determine the information about the adapter and store
|
|
10
|
+
* it into a file in the adapter. This is self contained and only depends on
|
|
11
|
+
* finding files within the adapter to gather information.
|
|
12
|
+
*
|
|
13
|
+
* This utility is used when adapters are committed and pushed. It is not used by
|
|
14
|
+
* any customers nor is it references in any scripts.
|
|
15
|
+
*/
|
|
16
|
+
|
|
7
17
|
const path = require('path');
|
|
8
18
|
const fs = require('fs-extra');
|
|
9
19
|
|
|
10
20
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
21
|
+
* @summary Count the number of lines in a file
|
|
22
|
+
* @param {string} filePath - The path to the file
|
|
23
|
+
* @returns {number} The total number of lines in the file
|
|
24
|
+
*/
|
|
25
|
+
function countLinesInFile(filePath) {
|
|
26
|
+
if (fs.existsSync(filePath)) {
|
|
27
|
+
const cFile = fs.readFileSync(filePath, 'utf8');
|
|
28
|
+
return cFile.split('\n').length;
|
|
29
|
+
}
|
|
30
|
+
console.log(`Missing - ${path.basename(filePath)}`);
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @summary Count the number of lines across multiple files
|
|
36
|
+
* @param {array} filePaths - An array of file paths
|
|
37
|
+
* @returns {number} The total number of lines across all files
|
|
38
|
+
*/
|
|
39
|
+
function countLinesInFiles(filePaths) {
|
|
40
|
+
return filePaths.reduce((total, filePath) => total + countLinesInFile(filePath), 0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @summary Count the number of lines in all json files within an entity directory
|
|
45
|
+
* @param {string} entityDir - The entity directory
|
|
46
|
+
* @returns {number} The total number of lines across all JSON files in the entity directory
|
|
47
|
+
*/
|
|
48
|
+
function countEntityLines(entityDir) {
|
|
49
|
+
let totalLines = 0;
|
|
50
|
+
|
|
51
|
+
if (!fs.existsSync(entityDir)) {
|
|
52
|
+
console.log('Could not find the entities directory');
|
|
53
|
+
return totalLines;
|
|
54
|
+
}
|
|
55
|
+
const entities = fs.readdirSync(entityDir);
|
|
56
|
+
for (let e = 0; e < entities.length; e += 1) {
|
|
57
|
+
const entityPath = path.join(entityDir, entities[e]);
|
|
58
|
+
if (fs.statSync(entityPath).isDirectory()) {
|
|
59
|
+
const jsonFiles = fs.readdirSync(entityPath).filter((f) => f.endsWith('.json'));
|
|
60
|
+
for (let j = 0; j < jsonFiles.length; j += 1) {
|
|
61
|
+
totalLines += countLinesInFile(path.join(entityPath, jsonFiles[j]));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return totalLines;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @summary Count the number of test cases in a file
|
|
70
|
+
* @param {string} filePath - The path to the test file
|
|
71
|
+
* @returns {number} The total number of test cases in the file
|
|
13
72
|
*/
|
|
73
|
+
function countTestsInFile(filePath) {
|
|
74
|
+
if (fs.existsSync(filePath)) {
|
|
75
|
+
const tFile = fs.readFileSync(filePath, 'utf8');
|
|
76
|
+
const ttestCount = tFile.split('it(\'').length;
|
|
77
|
+
return ttestCount;
|
|
78
|
+
}
|
|
79
|
+
console.log(`Missing - ${path.basename(filePath)}`);
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
14
82
|
|
|
15
83
|
/**
|
|
16
|
-
*
|
|
84
|
+
* @summary Count the number of test cases across multiple files
|
|
85
|
+
* @param {array} filePaths - An array of test file paths
|
|
86
|
+
* @returns {number} The total number of test cases across all files
|
|
17
87
|
*/
|
|
88
|
+
function countTestsInFiles(filePaths) {
|
|
89
|
+
return filePaths.reduce((total, filePath) => total + countTestsInFile(filePath), 0);
|
|
90
|
+
}
|
|
91
|
+
|
|
18
92
|
function adapterInfo() {
|
|
19
93
|
// set the base pase of the adapter - tool shoud be one level up in utils
|
|
20
94
|
let adaptdir = __dirname;
|
|
@@ -23,172 +97,43 @@ function adapterInfo() {
|
|
|
23
97
|
if (adaptdir.endsWith('/utils')) {
|
|
24
98
|
adaptdir = adaptdir.substring(0, adaptdir.length - 6);
|
|
25
99
|
}
|
|
100
|
+
|
|
101
|
+
// if no package.json then not in right place - end with error
|
|
102
|
+
if (!fs.existsSync(`${adaptdir}/package.json`)) {
|
|
103
|
+
throw new Error('Missing - package.json');
|
|
104
|
+
}
|
|
26
105
|
const pack = require(`${adaptdir}/package.json`);
|
|
27
106
|
infoRes.version = pack.version;
|
|
28
107
|
|
|
29
108
|
let configCount = 0;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (fs.existsSync(`${adaptdir}/propertiesSchema.json`)) {
|
|
37
|
-
const cFile = fs.readFileSync(`${adaptdir}/propertiesSchema.json`, 'utf8');
|
|
38
|
-
configCount += cFile.split('\n').length;
|
|
39
|
-
} else {
|
|
40
|
-
console.log('Missing - propertiesSchema.json');
|
|
41
|
-
}
|
|
42
|
-
if (fs.existsSync(`${adaptdir}/error.json`)) {
|
|
43
|
-
const cFile = fs.readFileSync(`${adaptdir}/error.json`, 'utf8');
|
|
44
|
-
configCount += cFile.split('\n').length;
|
|
45
|
-
} else {
|
|
46
|
-
console.log('Missing - error.json');
|
|
47
|
-
}
|
|
48
|
-
const entitydir = path.join(adaptdir, '/entities');
|
|
49
|
-
if (fs.existsSync(entitydir) && fs.statSync(entitydir).isDirectory()) {
|
|
50
|
-
const entities = fs.readdirSync(entitydir);
|
|
51
|
-
// need to go through each entity in the entities directory
|
|
52
|
-
for (let e = 0; e < entities.length; e += 1) {
|
|
53
|
-
if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
|
|
54
|
-
const cfiles = fs.readdirSync(entitydir);
|
|
55
|
-
for (let c = 0; c < cfiles.length; c += 1) {
|
|
56
|
-
if (cfiles[c].endsWith('.json')) {
|
|
57
|
-
const ccFile = fs.readFileSync(`${entitydir}/${entities[e]}/${cfiles[c]}`, 'utf8');
|
|
58
|
-
configCount += ccFile.split('\n').length;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
console.log('Could not find the entities directory');
|
|
65
|
-
}
|
|
109
|
+
const configFiles = ['pronghorn.json', 'propertiesSchema.json', 'error.json'].map((f) => path.join(adaptdir, f));
|
|
110
|
+
configCount = countLinesInFiles(configFiles);
|
|
111
|
+
|
|
112
|
+
const entityDir = path.join(adaptdir, '/entities');
|
|
113
|
+
configCount += countEntityLines(entityDir);
|
|
114
|
+
|
|
66
115
|
infoRes.configLines = configCount;
|
|
67
116
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
scodeCount += sFile.split('\n').length;
|
|
72
|
-
} else {
|
|
73
|
-
console.log('Missing - utils/artifactize.js');
|
|
74
|
-
}
|
|
75
|
-
if (fs.existsSync(`${adaptdir}/utils/basicGet.js`)) {
|
|
76
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/basicGet.js`, 'utf8');
|
|
77
|
-
scodeCount += sFile.split('\n').length;
|
|
78
|
-
} else {
|
|
79
|
-
console.log('Missing - utils/basicGet.js');
|
|
80
|
-
}
|
|
81
|
-
if (fs.existsSync(`${adaptdir}/utils/checkMigrate.js`)) {
|
|
82
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/checkMigrate.js`, 'utf8');
|
|
83
|
-
scodeCount += sFile.split('\n').length;
|
|
84
|
-
} else {
|
|
85
|
-
console.log('Missing - utils/checkMigrate.js');
|
|
86
|
-
}
|
|
87
|
-
if (fs.existsSync(`${adaptdir}/utils/findPath.js`)) {
|
|
88
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/findPath.js`, 'utf8');
|
|
89
|
-
scodeCount += sFile.split('\n').length;
|
|
90
|
-
} else {
|
|
91
|
-
console.log('Missing - utils/findPath.js');
|
|
92
|
-
}
|
|
93
|
-
if (fs.existsSync(`${adaptdir}/utils/modify.js`)) {
|
|
94
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/modify.js`, 'utf8');
|
|
95
|
-
scodeCount += sFile.split('\n').length;
|
|
96
|
-
} else {
|
|
97
|
-
console.log('Missing - utils/modify.js');
|
|
98
|
-
}
|
|
99
|
-
if (fs.existsSync(`${adaptdir}/utils/packModificationScript.js`)) {
|
|
100
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/packModificationScript.js`, 'utf8');
|
|
101
|
-
scodeCount += sFile.split('\n').length;
|
|
102
|
-
} else {
|
|
103
|
-
console.log('Missing - utils/packModificationScript.js');
|
|
104
|
-
}
|
|
105
|
-
if (fs.existsSync(`${adaptdir}/utils/setup.js`)) {
|
|
106
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/setup.js`, 'utf8');
|
|
107
|
-
scodeCount += sFile.split('\n').length;
|
|
108
|
-
} else {
|
|
109
|
-
console.log('Missing - utils/setup.js');
|
|
110
|
-
}
|
|
111
|
-
if (fs.existsSync(`${adaptdir}/utils/tbScript.js`)) {
|
|
112
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/tbScript.js`, 'utf8');
|
|
113
|
-
scodeCount += sFile.split('\n').length;
|
|
114
|
-
} else {
|
|
115
|
-
console.log('Missing - utils/tbScript.js');
|
|
116
|
-
}
|
|
117
|
-
if (fs.existsSync(`${adaptdir}/utils/tbUtils.js`)) {
|
|
118
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/tbUtils.js`, 'utf8');
|
|
119
|
-
scodeCount += sFile.split('\n').length;
|
|
120
|
-
} else {
|
|
121
|
-
console.log('Missing - utils/tbUtils.js');
|
|
122
|
-
}
|
|
123
|
-
if (fs.existsSync(`${adaptdir}/utils/testRunner.js`)) {
|
|
124
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/testRunner.js`, 'utf8');
|
|
125
|
-
scodeCount += sFile.split('\n').length;
|
|
126
|
-
} else {
|
|
127
|
-
console.log('Missing - utils/testRunner.js');
|
|
128
|
-
}
|
|
129
|
-
if (fs.existsSync(`${adaptdir}/utils/troubleshootingAdapter.js`)) {
|
|
130
|
-
const sFile = fs.readFileSync(`${adaptdir}/utils/troubleshootingAdapter.js`, 'utf8');
|
|
131
|
-
scodeCount += sFile.split('\n').length;
|
|
132
|
-
} else {
|
|
133
|
-
console.log('Missing - utils/troubleshootingAdapter.js');
|
|
134
|
-
}
|
|
135
|
-
infoRes.scriptLines = scodeCount;
|
|
117
|
+
const utilFiles = ['argParser', 'checkMigrate.js', 'entitiesToDB.js', 'findPath.js', 'logger.js', 'methodDocumentor.js', 'modify.js', 'mongoDbConnection.js',
|
|
118
|
+
'mongoUtils.js', 'setup.js', 'taskMover.js', 'tbScript.js', 'tbUtils.js', 'testRunner.js', 'troubleshootingAdapter.js', 'updateAdapterConfig.js'
|
|
119
|
+
].map((f) => path.join(adaptdir, 'utils', f));
|
|
136
120
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
infoRes.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
let ttestCount = 0;
|
|
154
|
-
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`)) {
|
|
155
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestBasicGet.js`, 'utf8');
|
|
156
|
-
tcodeCount += tFile.split('\n').length;
|
|
157
|
-
ttestCount += tFile.split('it(\'').length;
|
|
158
|
-
} else {
|
|
159
|
-
console.log('Missing - test/integration/adapterTestBasicGet.js');
|
|
160
|
-
}
|
|
161
|
-
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`)) {
|
|
162
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestConnectivity.js`, 'utf8');
|
|
163
|
-
tcodeCount += tFile.split('\n').length;
|
|
164
|
-
ttestCount += tFile.split('it(\'').length;
|
|
165
|
-
} else {
|
|
166
|
-
console.log('Missing - test/integration/adapterTestConnectivity.js');
|
|
167
|
-
}
|
|
168
|
-
if (fs.existsSync(`${adaptdir}/test/integration/adapterTestIntegration.js`)) {
|
|
169
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/integration/adapterTestIntegration.js`, 'utf8');
|
|
170
|
-
tcodeCount += tFile.split('\n').length;
|
|
171
|
-
ttestCount += tFile.split('it(\'').length;
|
|
172
|
-
} else {
|
|
173
|
-
console.log('Missing - test/integration/adapterTestIntegration.js');
|
|
174
|
-
}
|
|
175
|
-
if (fs.existsSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`)) {
|
|
176
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterBaseTestUnit.js`, 'utf8');
|
|
177
|
-
tcodeCount += tFile.split('\n').length;
|
|
178
|
-
ttestCount += tFile.split('it(\'').length;
|
|
179
|
-
} else {
|
|
180
|
-
console.log('Missing - test/unit/adapterBaseTestUnit.js');
|
|
181
|
-
}
|
|
182
|
-
if (fs.existsSync(`${adaptdir}/test/unit/adapterTestUnit.js`)) {
|
|
183
|
-
const tFile = fs.readFileSync(`${adaptdir}/test/unit/adapterTestUnit.js`, 'utf8');
|
|
184
|
-
tcodeCount += tFile.split('\n').length;
|
|
185
|
-
ttestCount += tFile.split('it(\'').length;
|
|
186
|
-
} else {
|
|
187
|
-
console.log('Missing - test/unit/adapterTestUnit.js');
|
|
188
|
-
}
|
|
189
|
-
infoRes.testLines = tcodeCount;
|
|
190
|
-
infoRes.testCases = ttestCount;
|
|
191
|
-
infoRes.totalCodeLines = scodeCount + codeCount + tcodeCount;
|
|
121
|
+
infoRes.scriptLines = countLinesInFiles(utilFiles);
|
|
122
|
+
|
|
123
|
+
const adapterFiles = ['adapter.js', 'adapterBase.js'].map((f) => path.join(adaptdir, f));
|
|
124
|
+
infoRes.codeLines = countLinesInFiles(adapterFiles);
|
|
125
|
+
|
|
126
|
+
const testFiles = [
|
|
127
|
+
'test/integration/adapterTestBasicGet.js',
|
|
128
|
+
'test/integration/adapterTestConnectivity.js',
|
|
129
|
+
'test/integration/adapterTestIntegration.js',
|
|
130
|
+
'test/unit/adapterBaseTestUnit.js',
|
|
131
|
+
'test/unit/adapterTestUnit.js'
|
|
132
|
+
].map((f) => path.join(adaptdir, f));
|
|
133
|
+
infoRes.testLines = countLinesInFiles(testFiles);
|
|
134
|
+
infoRes.testCases = countTestsInFiles(testFiles);
|
|
135
|
+
|
|
136
|
+
infoRes.totalCodeLines = infoRes.scriptLines + infoRes.codeLines + infoRes.testLines;
|
|
192
137
|
|
|
193
138
|
if (fs.existsSync(`${adaptdir}/pronghorn.json`)) {
|
|
194
139
|
// Read the entity schema from the file system
|
|
@@ -203,4 +148,9 @@ function adapterInfo() {
|
|
|
203
148
|
fs.writeFileSync(`${adaptdir}/report/adapterInfo.json`, JSON.stringify(infoRes, null, 2));
|
|
204
149
|
}
|
|
205
150
|
|
|
206
|
-
|
|
151
|
+
try {
|
|
152
|
+
adapterInfo();
|
|
153
|
+
} catch (err) {
|
|
154
|
+
console.error(err.message);
|
|
155
|
+
process.exit();
|
|
156
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const customLevels = {
|
|
2
|
+
spam: 6,
|
|
3
|
+
trace: 5,
|
|
4
|
+
debug: 4,
|
|
5
|
+
info: 3,
|
|
6
|
+
warn: 2,
|
|
7
|
+
error: 1,
|
|
8
|
+
none: 0
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function parseArgs(argv = process.argv) {
|
|
12
|
+
let properties = null;
|
|
13
|
+
let logLevel = 'none';
|
|
14
|
+
let maxCalls = 5;
|
|
15
|
+
let host = null;
|
|
16
|
+
|
|
17
|
+
argv.forEach((val) => {
|
|
18
|
+
if (val.startsWith('--PROPS=')) {
|
|
19
|
+
// get the properties
|
|
20
|
+
const inputVal = val.split('=')[1];
|
|
21
|
+
properties = JSON.parse(inputVal);
|
|
22
|
+
} else if (val.startsWith('--LOG=')) {
|
|
23
|
+
// get the desired log level
|
|
24
|
+
const level = val.split('=')[1];
|
|
25
|
+
// validate the log level is supported, if so set it
|
|
26
|
+
if (Object.hasOwnProperty.call(customLevels, level)) {
|
|
27
|
+
logLevel = level;
|
|
28
|
+
}
|
|
29
|
+
} else if (val.startsWith('--MAXCALLS=')) {
|
|
30
|
+
const override = parseInt(val.split('=')[1], 10);
|
|
31
|
+
if (!Number.isNaN(override) && override > 0) {
|
|
32
|
+
maxCalls = override;
|
|
33
|
+
}
|
|
34
|
+
} else if (val.startsWith('--HOST=')) {
|
|
35
|
+
[, host] = val.split('=');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
properties, logLevel, maxCalls, host
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = { parseArgs };
|
package/utils/logger.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// utils/logger.js
|
|
2
|
+
const winston = require('winston');
|
|
3
|
+
const { parseArgs } = require('./argParser');
|
|
4
|
+
|
|
5
|
+
const customLevels = {
|
|
6
|
+
spam: 6,
|
|
7
|
+
trace: 5,
|
|
8
|
+
debug: 4,
|
|
9
|
+
info: 3,
|
|
10
|
+
warn: 2,
|
|
11
|
+
error: 1,
|
|
12
|
+
none: 0
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Only set global logger if it doesn't already exist (i.e., not provided by app)
|
|
16
|
+
if (!global.log) {
|
|
17
|
+
const { logLevel = 'info' } = parseArgs();
|
|
18
|
+
|
|
19
|
+
global.log = winston.createLogger({
|
|
20
|
+
level: logLevel,
|
|
21
|
+
levels: customLevels,
|
|
22
|
+
transports: [new winston.transports.Console()]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = global.log;
|