@itentialopensource/adapter-aruba_central 0.1.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/.eslintignore +6 -0
- package/.eslintrc.js +18 -0
- package/.gitlab/.gitkeep +0 -0
- package/.gitlab/issue_templates/.gitkeep +0 -0
- package/.gitlab/issue_templates/Default.md +17 -0
- package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
- package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
- package/.jshintrc +0 -0
- package/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +170 -0
- package/CHANGELOG.md +9 -0
- package/CODE_OF_CONDUCT.md +43 -0
- package/CONTRIBUTING.md +172 -0
- package/ENHANCE.md +69 -0
- package/LICENSE +201 -0
- package/PROPERTIES.md +641 -0
- package/README.md +337 -0
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +23717 -0
- package/adapterBase.js +1787 -0
- package/adapter_modifications/README.md +59 -0
- package/adapter_modifications/specificCallScript.js +97 -0
- package/adapter_modifications/update.js +532 -0
- package/adapter_modifications/updateFiles/components/adapter.js +164 -0
- package/adapter_modifications/updateFiles/components/entities/Installers/action.json +22 -0
- package/adapter_modifications/updateFiles/components/entities/Installers/mockdatafiles/mockdata.json +1 -0
- package/adapter_modifications/updateFiles/components/entities/Installers/schema.json +20 -0
- package/adapter_modifications/updateFiles/components/entities/Sites/action.json +22 -0
- package/adapter_modifications/updateFiles/components/entities/Sites/mockdatafiles/mockdata.json +1 -0
- package/adapter_modifications/updateFiles/components/entities/Sites/schema.json +20 -0
- package/adapter_modifications/updateFiles/components/methods.json +204 -0
- package/adapter_modifications/updateFiles/components/pronghorn.json +77 -0
- package/adapter_modifications/updateFiles/components/test/integration/adapterTestIntegration.js +76 -0
- package/adapter_modifications/updateFiles/components/test/unit/adapterTestUnit.js +58 -0
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/entities/.system/action.json +50 -0
- package/entities/.system/mockdatafiles/getToken-default.json +3 -0
- package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
- package/entities/.system/schema.json +19 -0
- package/entities/.system/schemaTokenReq.json +53 -0
- package/entities/.system/schemaTokenResp.json +53 -0
- package/entities/AOSS/action.json +168 -0
- package/entities/AOSS/mockdatafiles/apiHppcSwitchGetDevicePorts-default.json +17 -0
- package/entities/AOSS/mockdatafiles/apiHppcSwitchGetDeviceVlans-default.json +65 -0
- package/entities/AOSS/mockdatafiles/apiHppcSwitchGetGroupPorts-default.json +17 -0
- package/entities/AOSS/mockdatafiles/apiHppcSwitchGetGroupVlans-default.json +125 -0
- package/entities/AOSS/schema.json +26 -0
- package/entities/AP/action.json +150 -0
- package/entities/AP/schema.json +135 -0
- package/entities/APConfiguration/action.json +394 -0
- package/entities/APConfiguration/mockdatafiles/apiApClisGetApSettingsClis-default.json +3 -0
- package/entities/APConfiguration/mockdatafiles/apiApClisGetConfigurationClis-default.json +3 -0
- package/entities/APConfiguration/mockdatafiles/apiApClisGetDirtyDiff-default.json +10 -0
- package/entities/APConfiguration/mockdatafiles/apiApClisGetSwarmVariables-default.json +112 -0
- package/entities/APConfiguration/mockdatafiles/apiSystemConfigGetSystemConfig-default.json +10 -0
- package/entities/APConfiguration/schema.json +37 -0
- package/entities/APSettings/action.json +86 -0
- package/entities/APSettings/mockdatafiles/apiApSettingsGetApSettings-default.json +4 -0
- package/entities/APSettings/mockdatafiles/apiApSettingsGetApSettingsV2-default.json +5 -0
- package/entities/APSettings/schema.json +22 -0
- package/entities/CXConfiguration/action.json +250 -0
- package/entities/CXConfiguration/schema.json +30 -0
- package/entities/CaptivePortalLogo/action.json +65 -0
- package/entities/CaptivePortalLogo/mockdatafiles/apiCpLogoGetCpLogos-default.json +21 -0
- package/entities/CaptivePortalLogo/schema.json +21 -0
- package/entities/Certificates/action.json +85 -0
- package/entities/Certificates/mockdatafiles/apiCertificatesGetCertificates-default.json +29 -0
- package/entities/Certificates/schema.json +22 -0
- package/entities/Client/action.json +214 -0
- package/entities/Client/schema.json +193 -0
- package/entities/ConfigurationBackupAndRestore/action.json +189 -0
- package/entities/ConfigurationBackupAndRestore/mockdatafiles/apiGroupsGetBackupLogForSnapshot-default.json +3 -0
- package/entities/ConfigurationBackupAndRestore/mockdatafiles/apiGroupsGetBackupStatusForSnapshot-default.json +3 -0
- package/entities/ConfigurationBackupAndRestore/mockdatafiles/apiGroupsGetLastRestoreLogsForGroup-default.json +3 -0
- package/entities/ConfigurationBackupAndRestore/mockdatafiles/apiGroupsGetRestoreStatusForSnapshot-default.json +3 -0
- package/entities/ConfigurationBackupAndRestore/mockdatafiles/apiGroupsGetSnapshotsForGroup-default.json +65 -0
- package/entities/ConfigurationBackupAndRestore/schema.json +27 -0
- package/entities/ConfigurationMode/action.json +148 -0
- package/entities/ConfigurationMode/mockdatafiles/apiConfigModeGetCustConfigMode-default.json +35 -0
- package/entities/ConfigurationMode/mockdatafiles/apiConfigModeGetDeviceConfigMode-default.json +21 -0
- package/entities/ConfigurationMode/mockdatafiles/apiConfigModeGetDeviceSerialsConfigMode-default.json +13 -0
- package/entities/ConfigurationMode/mockdatafiles/apiConfigModeGetGroupConfigMode-default.json +17 -0
- package/entities/ConfigurationMode/schema.json +25 -0
- package/entities/DenylistClients/action.json +65 -0
- package/entities/DenylistClients/mockdatafiles/apiBlacklistClientGetBlacklistClients-default.json +13 -0
- package/entities/DenylistClients/schema.json +21 -0
- package/entities/Devices/action.json +191 -0
- package/entities/Devices/mockdatafiles/apiDevicesGetDevicesTemplateDetails-default.json +13 -0
- package/entities/Devices/mockdatafiles/apiDevicesGetGroupsTemplateDetails-default.json +13 -0
- package/entities/Devices/mockdatafiles/apiDevicesGetHashTemplateDetails-default.json +13 -0
- package/entities/Devices/schema.json +27 -0
- package/entities/Events/action.json +46 -0
- package/entities/Events/schema.json +130 -0
- package/entities/Gateway/action.json +318 -0
- package/entities/Gateway/schema.json +99 -0
- package/entities/Groups/action.json +290 -0
- package/entities/Groups/mockdatafiles/apiGroupsGetGroups-default.json +54 -0
- package/entities/Groups/mockdatafiles/apiGroupsGetGroupsProperties-default.json +224 -0
- package/entities/Groups/mockdatafiles/apiGroupsGetGroupsTemplateData-default.json +11 -0
- package/entities/Groups/mockdatafiles/apiGroupsGetGroupsV2-default.json +11 -0
- package/entities/Groups/schema.json +32 -0
- package/entities/Installers/action.json +24 -0
- package/entities/Installers/schema.json +19 -0
- package/entities/Label/action.json +228 -0
- package/entities/Label/schema.json +62 -0
- package/entities/MMMD/action.json +24 -0
- package/entities/MMMD/schema.json +19 -0
- package/entities/MSPTemplates/action.json +250 -0
- package/entities/MSPTemplates/mockdatafiles/apiTemplatesGetEndCustomerTemplates-default.json +23 -0
- package/entities/MSPTemplates/mockdatafiles/apiTemplatesGetMspCustomerTemplates-default.json +65 -0
- package/entities/MSPTemplates/mockdatafiles/apiTemplatesGetMspTmplDifferCustsGroups-default.json +110 -0
- package/entities/MSPTemplates/mockdatafiles/apiTemplatesGetMspTmplEndCustDifferGroups-default.json +13 -0
- package/entities/MSPTemplates/schema.json +30 -0
- package/entities/MobilityController/action.json +191 -0
- package/entities/MobilityController/schema.json +71 -0
- package/entities/NBUIGroupConfiguration/action.json +45 -0
- package/entities/NBUIGroupConfiguration/mockdatafiles/apiNbUiGroupConfigGetGroupCountry-default.json +3 -0
- package/entities/NBUIGroupConfiguration/schema.json +20 -0
- package/entities/Network/action.json +67 -0
- package/entities/Network/schema.json +76 -0
- package/entities/PreProvisionedGroup/action.json +44 -0
- package/entities/PreProvisionedGroup/schema.json +20 -0
- package/entities/SaveCommit/action.json +126 -0
- package/entities/SaveCommit/mockdatafiles/apiSaveCommitGetDeviceSerialsAutoCommitState-default.json +17 -0
- package/entities/SaveCommit/mockdatafiles/apiSaveCommitGetGroupsAutoCommitState-default.json +29 -0
- package/entities/SaveCommit/schema.json +24 -0
- package/entities/Site/action.json +186 -0
- package/entities/Site/schema.json +49 -0
- package/entities/Sites/action.json +24 -0
- package/entities/Sites/schema.json +19 -0
- package/entities/Swarm/action.json +88 -0
- package/entities/Swarm/schema.json +88 -0
- package/entities/SwarmConfig/action.json +86 -0
- package/entities/SwarmConfig/mockdatafiles/apiSwarmConfigGetSwarmConfig-default.json +4 -0
- package/entities/SwarmConfig/mockdatafiles/apiSwarmConfigGetSwarmConfigV2-default.json +7 -0
- package/entities/SwarmConfig/schema.json +22 -0
- package/entities/Switch/action.json +548 -0
- package/entities/Switch/schema.json +198 -0
- package/entities/Templates/action.json +106 -0
- package/entities/Templates/mockdatafiles/apiTemplatesGetTemplates-default.json +37 -0
- package/entities/Templates/schema.json +23 -0
- package/entities/VPN/action.json +45 -0
- package/entities/VPN/schema.json +31 -0
- package/entities/Variables/action.json +186 -0
- package/entities/Variables/mockdatafiles/apiDevicesGetDeviceTemplateVariables-default.json +10 -0
- package/entities/Variables/schema.json +27 -0
- package/entities/VariablesFirewall/action.json +126 -0
- package/entities/VariablesFirewall/schema.json +24 -0
- package/entities/WLANConfiguration/action.json +579 -0
- package/entities/WLANConfiguration/schema.json +46 -0
- package/error.json +190 -0
- package/package.json +86 -0
- package/pronghorn.json +20904 -0
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +1248 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/aruba_central_monitoring.json +14224 -0
- package/report/creationReport.json +850 -0
- package/sampleProperties.json +195 -0
- package/test/integration/adapterTestBasicGet.js +83 -0
- package/test/integration/adapterTestConnectivity.js +93 -0
- package/test/integration/adapterTestIntegration.js +7773 -0
- package/test/unit/adapterBaseTestUnit.js +949 -0
- package/test/unit/adapterTestUnit.js +10516 -0
- package/updatePackage.zip +0 -0
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +146 -0
- package/utils/basicGet.js +50 -0
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +178 -0
- package/utils/findPath.js +74 -0
- package/utils/methodDocumentor.js +225 -0
- package/utils/modify.js +154 -0
- package/utils/packModificationScript.js +35 -0
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +32 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +33 -0
- package/utils/tbScript.js +246 -0
- package/utils/tbUtils.js +490 -0
- package/utils/testRunner.js +298 -0
- package/utils/troubleshootingAdapter.js +195 -0
- package/versions.json +257 -0
- package/workflows/README.md +3 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
const fs = require('fs-extra');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawn } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const folder = process.argv[2];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* This is the file to run in order to update your existing adapter.
|
|
12
|
+
* Make sure the zip is in the adapter's top level directory, then navigate there in the terminal and run 'node update'.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @summary the main function to be run in this file.
|
|
17
|
+
* @function run
|
|
18
|
+
*/
|
|
19
|
+
function run() {
|
|
20
|
+
|
|
21
|
+
// To ensure that the names of each group are brought in.
|
|
22
|
+
console.log('Updating...\n');
|
|
23
|
+
const names = JSON.parse(fs.readFileSync(path.join(__dirname, `./${folder}/components/methods.json`), 'utf8'));
|
|
24
|
+
const toDeleteNames = names.toDelByName.map(d => d.fnName);
|
|
25
|
+
const toAppendNames = names.toAppByName.map(d => d.fnName);
|
|
26
|
+
const toAppByName = names.toAppByName.map(d => ({name: d.name, fnName: d.fnName, parameters: d.func.parameters}));
|
|
27
|
+
const toUpdateNames = [];
|
|
28
|
+
toDeleteNames.forEach((n) => {
|
|
29
|
+
toAppendNames.forEach((a) => {
|
|
30
|
+
if (n === a && !toUpdateNames.includes(n)) {
|
|
31
|
+
toUpdateNames.push(n);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Creating copy of this object to be used later.
|
|
37
|
+
const curAppByName = JSON.parse(JSON.stringify(toAppByName));
|
|
38
|
+
|
|
39
|
+
// This object will contain any methods we attempt to add but already exist in the adapter, marking them for versioning.
|
|
40
|
+
const reAddingMethods = {};
|
|
41
|
+
const reAddingEmitMethods = {};
|
|
42
|
+
|
|
43
|
+
const adapterName = __dirname.split('/')[__dirname.split('/').length - 2].split('-')[1];
|
|
44
|
+
// Note that this assumes that the adapter name starts with 'adapter-'; if it does not, this will have to be edited.
|
|
45
|
+
|
|
46
|
+
// Filtering out and adding functions to the pronghorn.
|
|
47
|
+
if (fs.existsSync(path.join(__dirname, '../pronghorn.json'))) {
|
|
48
|
+
let pFile = JSON.parse(fs.readFileSync(path.join(__dirname, '../pronghorn.json'), 'utf8'));
|
|
49
|
+
pFile.methods = pFile.methods.filter(m => !toDeleteNames.includes(m.name));
|
|
50
|
+
//console.log(pFile.methods);
|
|
51
|
+
const methsToAdd = JSON.parse(fs.readFileSync(path.join(__dirname, `./${folder}/components/pronghorn.json`)));
|
|
52
|
+
methsToAdd.forEach((m) => {
|
|
53
|
+
//console.log(m.input);
|
|
54
|
+
if (toUpdateNames.includes(m.name)) {
|
|
55
|
+
pFile.methods.push(m);
|
|
56
|
+
}
|
|
57
|
+
// loop through methods and check signatures for versioning
|
|
58
|
+
let version = false;
|
|
59
|
+
let alreadyExists = false;
|
|
60
|
+
pFile.methods.forEach((pm) => {
|
|
61
|
+
if (pm.name === m.name) {
|
|
62
|
+
alreadyExists = true;
|
|
63
|
+
if (pm.input.length !== m.input.length) {
|
|
64
|
+
version = true;
|
|
65
|
+
} else {
|
|
66
|
+
for (let x = 0; x < m.input.length; x++) {
|
|
67
|
+
if (pm.input[x].name !== m.input[x].name || pm.input[x].required !== m.input[x].required || pm.input[x].type !== m.input[x].type) {
|
|
68
|
+
version = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (version) {
|
|
75
|
+
// add for versioning
|
|
76
|
+
reAddingMethods[m.name] = {};
|
|
77
|
+
reAddingEmitMethods[m.name] = {};
|
|
78
|
+
reAddingMethods[m.name].pronghorn = m;
|
|
79
|
+
} else if (toAppendNames.includes(m.name) && !alreadyExists && !version) {
|
|
80
|
+
pFile.methods.push(m);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
fs.writeFileSync(path.join(__dirname, '../pronghorn.json'), JSON.stringify(pFile, null, 2));
|
|
84
|
+
} else {
|
|
85
|
+
console.log('Your pronghorn.json file is missing; are you sure your adapter works?');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (fs.existsSync(path.join(__dirname, '../test/unit/adapterTestUnit.js'))) {
|
|
89
|
+
let uFile = fs.readFileSync(path.join(__dirname, '../test/unit/adapterTestUnit.js'), 'utf8');
|
|
90
|
+
const last = uFile.split('\n').slice(uFile.split('\n').length - 3).join('\n');
|
|
91
|
+
let list = uFile.split('\n').slice(0, uFile.split('\n').length - 3).join('\n').split(/(?=\n {4}describe\()/g).filter((u) => {
|
|
92
|
+
let remain = true;
|
|
93
|
+
toDeleteNames.forEach((n) => {
|
|
94
|
+
if (u.indexOf('#'.concat(n, ' - ')) >= 0 || u.indexOf('#'.concat(n, 'Emit - ')) >= 0) {
|
|
95
|
+
remain = false;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return remain;
|
|
99
|
+
});
|
|
100
|
+
list = list.join('');
|
|
101
|
+
let uChanges = fs.readFileSync(path.join(__dirname, `./${folder}/components/test/unit/adapterTestUnit.js`), 'utf8');
|
|
102
|
+
const units = uChanges.split(/(?=\n {4}describe\()/g);
|
|
103
|
+
if (units.length > 0) {
|
|
104
|
+
list = list.concat('\n');
|
|
105
|
+
}
|
|
106
|
+
units.forEach((un) => {
|
|
107
|
+
const u = un.replace(/Test-append-adapter/g, `Test-${adapterName}-adapter`); // See above about adapter name starting with 'adapter-'.
|
|
108
|
+
let remain = true;
|
|
109
|
+
toAppendNames.forEach((n) => {
|
|
110
|
+
if (list.includes('#'.concat(n, ' - ')) && u.includes('#'.concat(n, ' - '))) {
|
|
111
|
+
remain = false;
|
|
112
|
+
if (reAddingMethods[n] && !reAddingMethods[n].unit) {
|
|
113
|
+
reAddingMethods[n].unit = u;
|
|
114
|
+
}
|
|
115
|
+
} else if (list.includes('#'.concat(n, 'Emit - ')) && u.includes('#'.concat(n, 'Emit - '))) {
|
|
116
|
+
remain = false;
|
|
117
|
+
if (reAddingEmitMethods[n] && !reAddingEmitMethods[n].unit) {
|
|
118
|
+
reAddingEmitMethods[n].unit = u;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (remain) {
|
|
123
|
+
list = list.concat(u);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
list = list.replace('\n\n\n ', '\n\n ').concat(last);
|
|
127
|
+
fs.writeFileSync(path.join(__dirname, '../test/unit/adapterTestUnit.js'), list);
|
|
128
|
+
} else {
|
|
129
|
+
console.log('Your unit test file does not exist, will not delete or add any tests.');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (fs.existsSync(path.join(__dirname, '../test/integration/adapterTestIntegration.js'))) {
|
|
133
|
+
let iFile = fs.readFileSync(path.join(__dirname, '../test/integration/adapterTestIntegration.js'), 'utf8');
|
|
134
|
+
const last = iFile.split('\n').slice(iFile.split('\n').length - 3).join('\n');
|
|
135
|
+
let list = iFile.split('\n').slice(0, iFile.split('\n').length - 3).join('\n').split(/(?=\n {4}describe\()|(?=\n {4}const [a-zA-Z]+)/g).filter((i) => {
|
|
136
|
+
let remain = true;
|
|
137
|
+
toDeleteNames.forEach((n) => {
|
|
138
|
+
if (i.indexOf('#'.concat(n, ' - ')) >= 0 || i.indexOf('#'.concat(n, 'Emit - ')) >= 0) {
|
|
139
|
+
remain = false;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return remain;
|
|
143
|
+
});
|
|
144
|
+
list = list.join('');
|
|
145
|
+
|
|
146
|
+
let iChanges = fs.readFileSync(path.join(__dirname, `./${folder}/components/test/integration/adapterTestIntegration.js`), 'utf8');
|
|
147
|
+
const integrations = iChanges.split(/(?=\n {4}describe\()|(?=\n {4}const [a-zA-Z]+)/g);
|
|
148
|
+
if (integrations.length > 0) {
|
|
149
|
+
list = list.concat('\n');
|
|
150
|
+
}
|
|
151
|
+
integrations.forEach((integ) => {
|
|
152
|
+
const i = integ.replace(/Test-append/g, `Test-${adapterName}`);
|
|
153
|
+
let remain = true;
|
|
154
|
+
// This portion determines if this part is a body parameter or test. Note that both body parameters and tests are both versioned if necessary.
|
|
155
|
+
let bodyParamMatch = i.match(/const [a-zA-Z]+BodyParam/g);
|
|
156
|
+
if (bodyParamMatch && list.match(bodyParamMatch[0])) {
|
|
157
|
+
if (reAddingMethods && !reAddingMethods.bodyParams) {
|
|
158
|
+
reAddingMethods.bodyParams = [];
|
|
159
|
+
}
|
|
160
|
+
reAddingMethods.bodyParams.push(i);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
toAppendNames.forEach((n) => {
|
|
164
|
+
if (list.includes('#'.concat(n, ' - ')) && i.includes('#'.concat(n, ' - '))) {
|
|
165
|
+
remain = false;
|
|
166
|
+
if (reAddingMethods[n] && !reAddingMethods[n].integration) {
|
|
167
|
+
reAddingMethods[n].integration = i;
|
|
168
|
+
}
|
|
169
|
+
} else if (list.includes('#'.concat(n, 'Emit - ')) && i.includes('#'.concat(n, 'Emit - '))) {
|
|
170
|
+
remain = false;
|
|
171
|
+
if (reAddingEmitMethods[n] && !reAddingEmitMethods[n].integration) {
|
|
172
|
+
reAddingEmitMethods[n].integration = i;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
if (remain) {
|
|
177
|
+
list = list.concat(i);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
list = list.replace('\n\n\n ', '\n\n ').concat(last);
|
|
181
|
+
fs.writeFileSync(path.join(__dirname, '../test/integration/adapterTestIntegration.js'), list);
|
|
182
|
+
} else {
|
|
183
|
+
console.log('Your integration test file does not exist, will not delete or add any tests.');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const uEntitiesDir = path.join(__dirname, `./${folder}/components/entities/`);
|
|
187
|
+
const uEntities = fs.readdirSync(uEntitiesDir, { withFileTypes: true })
|
|
188
|
+
.filter(files => files.isDirectory())
|
|
189
|
+
.map(files => files.name);
|
|
190
|
+
|
|
191
|
+
const entitiesDir = path.join(__dirname, '../entities');
|
|
192
|
+
const entities = fs.readdirSync(entitiesDir, { withFileTypes: true })
|
|
193
|
+
.filter(files => files.isDirectory())
|
|
194
|
+
.map(files => files.name);
|
|
195
|
+
const filtered = [];
|
|
196
|
+
entities.forEach((e) => {
|
|
197
|
+
if (!filtered.includes(e)) {
|
|
198
|
+
filtered.push(e);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
if (!fs.existsSync(path.join(__dirname, '../entities'))) {
|
|
202
|
+
fs.mkdirSync(path.join(__dirname, '../entities'));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
uEntities.forEach((e) => {
|
|
206
|
+
// If an entity that may attempt to have an action removed from it does not exist, it will be created with no actions in it. If it remains that way, a user can go and delete it later.
|
|
207
|
+
if (!fs.existsSync(path.join(__dirname, `../entities/${e}`))) {
|
|
208
|
+
fs.mkdirSync(path.join(__dirname, `../entities/${e}`));
|
|
209
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${e}/action.json`), "{\n \"actions\": [\n ]\n}\n");
|
|
210
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${e}/schema.json`), "{\n \"$id\": \"schema.json\",\n \"type\": \"object\",\n \"schema\": \"http://json-schema.org/draft-07/schema#\",\n \"translate\": false,\n \"dynamicfields\": true,\n \"properties\": {\n \"ph_request_type\": {\n \"type\": \"string\",\n \"description\": \"type of request (internal to adapter)\",\n \"default\": \"\",\n \"enum\": [\n ],\n \"external_name\": \"ph_request_type\"\n }\n },\n \"definitions\": {}\n}\n");
|
|
211
|
+
}
|
|
212
|
+
if (!fs.existsSync(path.join(__dirname, `../entities/${e}/action.json`))) {
|
|
213
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${e}/action.json`), "{\n \"actions\": [\n ]\n}\n");
|
|
214
|
+
}
|
|
215
|
+
if (!fs.existsSync(path.join(__dirname, `../entities/${e}/schema.json`))) {
|
|
216
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${e}/schema.json`), "{\n \"$id\": \"schema.json\",\n \"type\": \"object\",\n \"schema\": \"http://json-schema.org/draft-07/schema#\",\n \"translate\": false,\n \"dynamicfields\": true,\n \"properties\": {\n \"ph_request_type\": {\n \"type\": \"string\",\n \"description\": \"type of request (internal to adapter)\",\n \"default\": \"\",\n \"enum\": [\n ],\n \"external_name\": \"ph_request_type\"\n }\n },\n \"definitions\": {}\n}\n");
|
|
217
|
+
}
|
|
218
|
+
// The entities that will have functions deleted from them.
|
|
219
|
+
const thisEntityNames = names.toDelByName.filter(n => n.name === e).map(n => n.fnName);
|
|
220
|
+
|
|
221
|
+
// The entities that will have functions appended to them.
|
|
222
|
+
const thisMethodEntity = curAppByName.filter(n => n.name === e).map(n => n.fnName);
|
|
223
|
+
|
|
224
|
+
let aFile = JSON.parse(fs.readFileSync(path.join(__dirname, `../entities/${e}/action.json`), 'utf8'));
|
|
225
|
+
const aCopy = JSON.parse(JSON.stringify(aFile));
|
|
226
|
+
aFile.actions = aFile.actions.filter(a => !thisEntityNames.includes(a.name));
|
|
227
|
+
|
|
228
|
+
if (fs.readFileSync(path.join(__dirname, `./${folder}/components/entities/${e}/action.json`), 'utf8') !== '[]') {
|
|
229
|
+
let acts = JSON.parse(fs.readFileSync(path.join(__dirname, `./${folder}/components/entities/${e}/action.json`), 'utf8'));
|
|
230
|
+
acts.forEach((a) => {
|
|
231
|
+
if (reAddingMethods && Object.keys(reAddingMethods).includes(a.name)) {
|
|
232
|
+
reAddingMethods[a.name].action = a;
|
|
233
|
+
} else if (thisMethodEntity.includes(a.name) && !aFile.actions.map(ac => ac.name).includes(a.name)) {
|
|
234
|
+
aFile.actions.push(a);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${e}/action.json`), JSON.stringify(aFile, null, 2));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let sFile = JSON.parse(fs.readFileSync(path.join(__dirname, `../entities/${e}/schema.json`), 'utf8'));
|
|
241
|
+
sFile.properties.ph_request_type.enum = sFile.properties.ph_request_type.enum.filter(p => !thisEntityNames.includes(p));
|
|
242
|
+
if (fs.readFileSync(path.join(__dirname, `./${folder}/components/entities/${e}/schema.json`), 'utf8') !== '[]') {
|
|
243
|
+
let sches = JSON.parse(fs.readFileSync(path.join(__dirname, `./${folder}/components/entities/${e}/schema.json`), 'utf8')).properties.ph_request_type.enum;
|
|
244
|
+
sches.forEach((s) => {
|
|
245
|
+
if (reAddingMethods && Object.keys(reAddingMethods).includes(s)) {
|
|
246
|
+
reAddingMethods[s].schema = s;
|
|
247
|
+
} else if (thisMethodEntity.includes(s) && !sFile.properties.ph_request_type.enum.includes(s)) {
|
|
248
|
+
sFile.properties.ph_request_type.enum.push(s);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${e}/schema.json`), JSON.stringify(sFile, null, 2));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (!fs.existsSync(path.join(__dirname, `../entities/${e}/mockdatafiles`))) {
|
|
255
|
+
fs.mkdirSync(path.join(__dirname, `../entities/${e}/mockdatafiles`));
|
|
256
|
+
}
|
|
257
|
+
const mock = JSON.parse(fs.readFileSync(path.join(__dirname, `./${folder}/components/entities/${e}/mockdatafiles/mockdata.json`), 'utf8'));
|
|
258
|
+
mock.forEach((m) => {
|
|
259
|
+
if (m.entity === e) {
|
|
260
|
+
// Currently do not have a .id field in the mock data (will always end in -default); future improvement.
|
|
261
|
+
const fileName = m.name || m.function.concat(m.id || '-default.json');
|
|
262
|
+
if (!fs.existsSync(path.join(__dirname, `../entities/${e}/mockdatafiles/${fileName}`)) || toUpdateNames.includes(m.function) || !aCopy.actions.map(ac => ac.name).includes(m.function)) {
|
|
263
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${e}/mockdatafiles/${fileName}`), JSON.stringify(m.contents, null, 2));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
// thisEntityNames.forEach((n) => {
|
|
268
|
+
// console.log(`We are not currently deleting existing mock data. path entities/${e}/mockdatafiles/${n}-default.json is intact if it exists.`);
|
|
269
|
+
// });
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
if (fs.existsSync(path.join(__dirname, '../adapter.js'))) {
|
|
273
|
+
let adFile = fs.readFileSync(path.join(__dirname, '../adapter.js'), 'utf8');
|
|
274
|
+
let splitArray = adFile.split('}\n\nmodule');
|
|
275
|
+
//if (splitArray[1] === undefined) {
|
|
276
|
+
//splitArray = adFile.split('}\nmodule');
|
|
277
|
+
//}
|
|
278
|
+
|
|
279
|
+
// const last = adFile.split('\n').slice(adFile.split('\n').length - 4).join('\n');
|
|
280
|
+
let list = adFile.split('\n').slice(0, adFile.split('\n').length - 4).join('\n').split(/(?=\n {2}\/\*\*\n {3}\* @summary)/g).filter((u) => {
|
|
281
|
+
let remain = true;
|
|
282
|
+
toDeleteNames.forEach((n) => {
|
|
283
|
+
if (u.indexOf('\n '.concat(n, '(')) >= 0) {
|
|
284
|
+
remain = false;
|
|
285
|
+
} else if (reAddingMethods && Object.keys(reAddingMethods).includes(n)) {
|
|
286
|
+
remain = false;
|
|
287
|
+
reAddingMethods[n].adapter = u;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return remain;
|
|
291
|
+
}).join('');
|
|
292
|
+
let adChanges = fs.readFileSync(path.join(__dirname, `./${folder}/components/adapter.js`), 'utf8');
|
|
293
|
+
const adMethods = adChanges.split(/(?=\n {2}\/\*\*\n {3}\* @function)/g);
|
|
294
|
+
if (adMethods.length > 0) {
|
|
295
|
+
list = list.concat('\n');
|
|
296
|
+
}
|
|
297
|
+
adMethods.forEach((a) => {
|
|
298
|
+
let remain = true;
|
|
299
|
+
//console.log(toAppendNames);
|
|
300
|
+
|
|
301
|
+
toAppendNames.forEach((n) => {
|
|
302
|
+
if (list.includes(n.concat('(')) && a.includes(n.concat('('))) {
|
|
303
|
+
let checkPrefix = a.split('@function ');
|
|
304
|
+
checkPrefix = checkPrefix[1].split('\n');
|
|
305
|
+
checkPrefix = checkPrefix[0];
|
|
306
|
+
if (checkPrefix === n) {
|
|
307
|
+
remain = false;
|
|
308
|
+
if (reAddingMethods[n] && !reAddingMethods[n].adapter) {
|
|
309
|
+
reAddingMethods[n].adapter = a;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
/**
|
|
315
|
+
toAppendNames.forEach((n) => {
|
|
316
|
+
if (list.includes(n.concat('(')) && a.includes(n.concat('('))) {
|
|
317
|
+
remain = false;
|
|
318
|
+
if (reAddingMethods[n] && !reAddingMethods[n].adapter) {
|
|
319
|
+
reAddingMethods[n].adapter = a;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
**/
|
|
324
|
+
if (remain) {
|
|
325
|
+
list = list.concat(a);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
list = list.concat('}\n\nmodule', splitArray[1]);
|
|
329
|
+
fs.writeFileSync(path.join(__dirname, '../adapter.js'), list);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// This is the object to be used in determining what version to assign methods that already exist.
|
|
333
|
+
let versionList = {};
|
|
334
|
+
if (fs.existsSync(path.join(__dirname, '../versions.json'))) {
|
|
335
|
+
versionList = JSON.parse(fs.readFileSync(path.join(__dirname, '../versions.json'), 'utf8'));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const newAdapter = fs.readFileSync(path.join(__dirname, '../adapter.js'), 'utf8');
|
|
339
|
+
const methods = newAdapter.match(/\n {2}[a-zA-Z]+\(/g).map(s => s.substr(3, s.length - 4));
|
|
340
|
+
let aRet = fs.readFileSync(path.join(__dirname, '../adapter.js'), 'utf8');
|
|
341
|
+
let versionedAdapters = "";
|
|
342
|
+
methods.forEach((m) => {
|
|
343
|
+
if (['constructor', 'hasEntity', 'verifyCapability', 'updateEntityCache'].includes(m)) {
|
|
344
|
+
versionList[m] = -1;
|
|
345
|
+
return;
|
|
346
|
+
// Those are the default methods: should not ever change unless by user directly or itential update.
|
|
347
|
+
} else if (!Object.keys(versionList).includes(m)) {
|
|
348
|
+
versionList[m] = 0;
|
|
349
|
+
// This method does not yet exist, it will be added as the original (version 0).
|
|
350
|
+
}
|
|
351
|
+
// console.log(reAddingMethods['uploadFile']);
|
|
352
|
+
if (typeof reAddingMethods[m] !== 'undefined') {
|
|
353
|
+
versionList[m] += 1;
|
|
354
|
+
const newMethodName = `${m}__v${versionList[m]}`; // The old name, double underscore then v(version#)
|
|
355
|
+
//console.log(newMethodName);
|
|
356
|
+
// The below code replaces all existences of the previous name with the new one in the relevant files, then performs an append as it would if this were a unique method.
|
|
357
|
+
const ph = JSON.parse(fs.readFileSync(path.join(__dirname, '../pronghorn.json'), 'utf8'));
|
|
358
|
+
reAddingMethods[m].pronghorn.name = newMethodName;
|
|
359
|
+
reAddingMethods[m].pronghorn.route.path = `\/${newMethodName}`;
|
|
360
|
+
ph.methods.push(reAddingMethods[m].pronghorn);
|
|
361
|
+
fs.writeFileSync(path.join(__dirname, '../pronghorn.json'), JSON.stringify(ph, null, 2));
|
|
362
|
+
|
|
363
|
+
const uFile = fs.readFileSync(path.join(__dirname, '../test/unit/adapterTestUnit.js'), 'utf8');
|
|
364
|
+
const uLast = uFile.split('\n').slice(uFile.split('\n').length - 3).join('\n');
|
|
365
|
+
|
|
366
|
+
if (typeof reAddingMethods[m].unit !== 'undefined') {
|
|
367
|
+
reAddingMethods[m].unit = reAddingMethods[m].unit.replace(`#${m} `, `#${newMethodName} `).replace(`\.${m} `, `\.${newMethodName} `).replace(` ${m} `, ` ${newMethodName} `);
|
|
368
|
+
const re = new RegExp(`\\.${m}\\(`, 'g');
|
|
369
|
+
const re1 = new RegExp(`-${m}\\'`, 'g');
|
|
370
|
+
reAddingMethods[m].unit = reAddingMethods[m].unit.replace(re, `\.${newMethodName}\(`);
|
|
371
|
+
reAddingMethods[m].unit = reAddingMethods[m].unit.replace(re1, `-${newMethodName}\'`);
|
|
372
|
+
const uRet = uFile.split('\n').slice(0, uFile.split('\n').length - 3).join('\n').concat('\n', reAddingMethods[m].unit, uLast);
|
|
373
|
+
fs.writeFileSync(path.join(__dirname, '../test/unit/adapterTestUnit.js'), uRet);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const iFile = fs.readFileSync(path.join(__dirname, '../test/integration/adapterTestIntegration.js'), 'utf8');
|
|
377
|
+
const iLast = iFile.split('\n').slice(iFile.split('\n').length - 3).join('\n');
|
|
378
|
+
|
|
379
|
+
if (typeof reAddingMethods[m].integration !== 'undefined') {
|
|
380
|
+
reAddingMethods[m].integration = reAddingMethods[m].integration.replace(`#${m} - `, `#${newMethodName} - `).replace(`\.${m}\(`, `\.${newMethodName}\(`).replace(`\'${m}\'`, `\'${newMethodName}\'`).concat(reAddingMethods[m].integration.endsWith('\n') ? '' : '\n');
|
|
381
|
+
|
|
382
|
+
// check for typeof undefined
|
|
383
|
+
if (typeof reAddingMethods.bodyParams !== 'undefined') {
|
|
384
|
+
reAddingMethods.bodyParams.forEach((b) => {
|
|
385
|
+
const varName = b.split(' = ')[0].substring(10);
|
|
386
|
+
if (reAddingMethods[m].integration.match(new RegExp(varName.concat(',')))) {
|
|
387
|
+
const nb = b.replace(varName, `${varName}__v${versionList[m]}`);
|
|
388
|
+
reAddingMethods[m].integration = nb.concat(reAddingMethods[m].integration);
|
|
389
|
+
reAddingMethods[m].integration = reAddingMethods[m].integration.replace(new RegExp(varName.concat(','), 'g'), varName.concat(`__v${versionList[m]},`));
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const iRet = iFile.split('\n').slice(0, iFile.split('\n').length - 3).join('\n').concat('\n', reAddingMethods[m].integration, iLast);
|
|
395
|
+
fs.writeFileSync(path.join(__dirname, '../test/integration/adapterTestIntegration.js'), iRet);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const thisMethodEntity = curAppByName.filter(a => a.fnName === m)[0].name;
|
|
399
|
+
const action = JSON.parse(fs.readFileSync(path.join(__dirname, `../entities/${thisMethodEntity}/action.json`)));
|
|
400
|
+
|
|
401
|
+
if (typeof reAddingMethods[m].action !== 'undefined') {
|
|
402
|
+
reAddingMethods[m].action.name = newMethodName;
|
|
403
|
+
reAddingMethods[m].action.responseObjects.forEach((r) => {
|
|
404
|
+
r.mockFile = r.mockFile.replace(m, newMethodName);
|
|
405
|
+
});
|
|
406
|
+
action.actions.push(reAddingMethods[m].action);
|
|
407
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${thisMethodEntity}/action.json`), JSON.stringify(action, null, 2));
|
|
408
|
+
}
|
|
409
|
+
if (fs.readFileSync(path.join(__dirname, `./${folder}/components/entities/${thisMethodEntity}/schema.json`), 'utf8') !== '[]') {
|
|
410
|
+
const schema = JSON.parse(fs.readFileSync(path.join(__dirname, `../entities/${thisMethodEntity}/schema.json`)));
|
|
411
|
+
reAddingMethods[m].schema = newMethodName;
|
|
412
|
+
schema.properties.ph_request_type.enum.push(reAddingMethods[m].schema);
|
|
413
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${thisMethodEntity}/schema.json`), JSON.stringify(schema, null, 2));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const mock = JSON.parse(fs.readFileSync(path.join(__dirname, `./${folder}/components/entities/${thisMethodEntity}/mockdatafiles/mockdata.json`), 'utf8'));
|
|
417
|
+
mock.forEach((mo) => {
|
|
418
|
+
const moc = mo;
|
|
419
|
+
if (moc.function === m && thisMethodEntity === moc.entity) {
|
|
420
|
+
moc.name = moc.name.replace(m, newMethodName);
|
|
421
|
+
moc.function = newMethodName;
|
|
422
|
+
fs.writeFileSync(path.join(__dirname, `../entities/${thisMethodEntity}/mockdatafiles/${moc.name}`), JSON.stringify(moc.contents, null, 2));
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
if (typeof reAddingMethods[m].adapter !== 'undefined') {
|
|
427
|
+
reAddingMethods[m].adapter = reAddingMethods[m].adapter.replace(`\n ${m}(`, `\n ${newMethodName}(`).replace(`\@function ${m}`, `\@function ${newMethodName}`).replace(`adapter-${m}\'`, `adapter-${newMethodName}\'`).replace(new RegExp(`\'${m}\'`, 'g'), `\'${newMethodName}\'`);
|
|
428
|
+
versionedAdapters = versionedAdapters.concat('\n', reAddingMethods[m].adapter).replace(/\n{2,}/, '\n');
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (reAddingEmitMethods[m]) {
|
|
433
|
+
const newMethodName = `${m}__v${versionList[m]}`;
|
|
434
|
+
const newEmitMethodName = `${m}Emit__v${versionList[m]}`; // The old name, double underscore then v(version#)
|
|
435
|
+
|
|
436
|
+
const uFile = fs.readFileSync(path.join(__dirname, '../test/unit/adapterTestUnit.js'), 'utf8');
|
|
437
|
+
const uLast = uFile.split('\n').slice(uFile.split('\n').length - 3).join('\n');
|
|
438
|
+
|
|
439
|
+
if (typeof reAddingEmitMethods[m].unit !== 'undefined') {
|
|
440
|
+
reAddingEmitMethods[m].unit = reAddingEmitMethods[m].unit.replace(`#${m}Emit `, `#${newEmitMethodName} `).replace(`\.${m}Emit `, `\.${newEmitMethodName} `).replace(` ${m}Emit `, ` ${newEmitMethodName} `).replace(`\.${m}Emit\(`, `\.${newEmitMethodName}\(`).replace(`-${m}\'`, `-${newMethodName}\'`);
|
|
441
|
+
const uRet = uFile.split('\n').slice(0, uFile.split('\n').length - 3).join('\n').concat(reAddingEmitMethods[m].unit, uLast);
|
|
442
|
+
fs.writeFileSync(path.join(__dirname, '../test/unit/adapterTestUnit.js'), uRet);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const iFile = fs.readFileSync(path.join(__dirname, '../test/integration/adapterTestIntegration.js'), 'utf8');
|
|
446
|
+
const iLast = iFile.split('\n').slice(iFile.split('\n').length - 3).join('\n');
|
|
447
|
+
|
|
448
|
+
if (typeof reAddingEmitMethods[m].integration !== 'undefined') {
|
|
449
|
+
reAddingEmitMethods[m].integration = reAddingEmitMethods[m].integration.replace(`#${m}Emit - `, `#${newEmitMethodName} - `).replace(`\.${m}Emit\(`, `\.${newEmitMethodName}\(`).replace(`\'${m}Emit\'`, `\'${newEmitMethodName}\'`).concat(reAddingEmitMethods[m].integration.endsWith('\n') ? '' : '\n');
|
|
450
|
+
|
|
451
|
+
// check for typeof undefined
|
|
452
|
+
if (typeof reAddingEmitMethods.bodyParams !== 'undefined') {
|
|
453
|
+
reAddingEmitMethods.bodyParams.forEach((b) => {
|
|
454
|
+
const varName = b.split(' = ')[0].substring(10);
|
|
455
|
+
if (reAddingEmitMethods[m].integration.match(new RegExp(varName.concat(',')))) {
|
|
456
|
+
const nb = b.replace(varName, `${varName}__v${versionList[m]}`);
|
|
457
|
+
reAddingEmitMethods[m].integration = nb.concat(reAddingEmitMethods[m].integration);
|
|
458
|
+
reAddingEmitMethods[m].integration = reAddingEmitMethods[m].integration.replace(new RegExp(varName.concat(','), 'g'), varName.concat(`__v${versionList[m]},`));
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const iRet = iFile.split('\n').slice(0, iFile.split('\n').length - 3).join('\n').concat('\n', reAddingEmitMethods[m].integration, iLast);
|
|
464
|
+
fs.writeFileSync(path.join(__dirname, '../test/integration/adapterTestIntegration.js'), iRet);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
// Read in the adapter.js file and add the versioned adapters to the end. String manipulation to add correct brackets & export
|
|
471
|
+
if (versionedAdapters != "") {
|
|
472
|
+
let finalAdapter = fs.readFileSync(path.join(__dirname, '../adapter.js'), 'utf8');
|
|
473
|
+
const splitArray = finalAdapter.split('}\n\nmodule');
|
|
474
|
+
// const aFinal = finalAdapter.split('\n').slice(finalAdapter.split('\n').length - 4).join('\n')
|
|
475
|
+
// finalAdapter = finalAdapter.replace(aFinal, "");
|
|
476
|
+
// const adapterNameCaps = adapterName.charAt(0).toUpperCase() + adapterName.slice(1);
|
|
477
|
+
finalAdapter = splitArray[0].concat(versionedAdapters, '}\n\nmodule', splitArray[1]);
|
|
478
|
+
|
|
479
|
+
// write the new adapter.js and updated versions.json
|
|
480
|
+
fs.writeFileSync(path.join(__dirname, '../adapter.js'), finalAdapter);
|
|
481
|
+
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
fs.writeFileSync(path.join(__dirname, '../versions.json'), JSON.stringify(versionList, null, 2));
|
|
485
|
+
|
|
486
|
+
// Here, the lint, unit, and integration tests are run to ensure the operations succeeded. If not, the user may have to go and fix things.
|
|
487
|
+
console.log('Update Done\n')
|
|
488
|
+
console.log('Linting...\n');
|
|
489
|
+
const lint = spawn('npm', ['run', 'lint'], {
|
|
490
|
+
cwd: path.join(__dirname, '..')
|
|
491
|
+
});
|
|
492
|
+
let testLintErr = '';
|
|
493
|
+
lint.stderr.on('data', (err) => {
|
|
494
|
+
testLintErr = testLintErr.concat(err);
|
|
495
|
+
});
|
|
496
|
+
let testLintOut = '';
|
|
497
|
+
lint.stdout.on('data', (out) => {
|
|
498
|
+
testLintOut = testLintOut.concat(out);
|
|
499
|
+
});
|
|
500
|
+
lint.on('close', (code) => {
|
|
501
|
+
console.log(`Lint exited with code ${code}`);
|
|
502
|
+
if (code == 0) {
|
|
503
|
+
console.log('Lint test passed with no errors');
|
|
504
|
+
console.log('\n\nRunning unit and integration tests...\n\n');
|
|
505
|
+
} else {
|
|
506
|
+
console.log(testLintErr);
|
|
507
|
+
console.log('\n\nRunning unit and integration tests...\n\n')
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
const tests = spawn('npm', ['run', 'test'], {
|
|
512
|
+
cwd: path.join(__dirname, '..')
|
|
513
|
+
});
|
|
514
|
+
let testErr = '';
|
|
515
|
+
tests.stderr.on('data', (err) => {
|
|
516
|
+
testErr = testErr.concat(err);
|
|
517
|
+
});
|
|
518
|
+
let testOut = '';
|
|
519
|
+
tests.stdout.on('data', (out) => {
|
|
520
|
+
testOut = testOut.concat(out);
|
|
521
|
+
});
|
|
522
|
+
tests.on('close', (code) => {
|
|
523
|
+
console.log(`Tests exited with code ${code}`);
|
|
524
|
+
if (code === 0) {
|
|
525
|
+
console.log(testOut);
|
|
526
|
+
} else {
|
|
527
|
+
console.log(testErr);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
run();
|