@itentialopensource/adapter-godaddy 0.2.0

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.
Files changed (106) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +18 -0
  3. package/.gitlab/.gitkeep +0 -0
  4. package/.gitlab/issue_templates/.gitkeep +0 -0
  5. package/.gitlab/issue_templates/Default.md +17 -0
  6. package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
  7. package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
  8. package/.jshintrc +3 -0
  9. package/AUTH.md +34 -0
  10. package/BROKER.md +199 -0
  11. package/CALLS.md +748 -0
  12. package/CHANGELOG.md +9 -0
  13. package/CODE_OF_CONDUCT.md +43 -0
  14. package/CONTRIBUTING.md +13 -0
  15. package/ENHANCE.md +69 -0
  16. package/LICENSE +201 -0
  17. package/PROPERTIES.md +641 -0
  18. package/README.md +346 -0
  19. package/SUMMARY.md +9 -0
  20. package/SYSTEMINFO.md +13 -0
  21. package/TROUBLESHOOT.md +47 -0
  22. package/adapter.js +9144 -0
  23. package/adapterBase.js +1452 -0
  24. package/changelogs/CHANGELOG.md +0 -0
  25. package/entities/.generic/action.json +214 -0
  26. package/entities/.generic/schema.json +28 -0
  27. package/entities/.system/action.json +50 -0
  28. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  29. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  30. package/entities/.system/schema.json +19 -0
  31. package/entities/.system/schemaTokenReq.json +53 -0
  32. package/entities/.system/schemaTokenResp.json +53 -0
  33. package/entities/Abuse/action.json +66 -0
  34. package/entities/Abuse/schema.json +21 -0
  35. package/entities/Actions/action.json +66 -0
  36. package/entities/Actions/mockdatafiles/getV2CustomersCustomerIdDomainsDomainActions-default.json +126 -0
  37. package/entities/Actions/schema.json +21 -0
  38. package/entities/Aftermarket/action.json +44 -0
  39. package/entities/Aftermarket/schema.json +20 -0
  40. package/entities/Agreements/action.json +25 -0
  41. package/entities/Agreements/mockdatafiles/getAgreements-default.json +8 -0
  42. package/entities/Agreements/schema.json +19 -0
  43. package/entities/Certificate/action.json +517 -0
  44. package/entities/Certificate/mockdatafiles/certificateGetEntitlement-default.json +205 -0
  45. package/entities/Certificate/mockdatafiles/getDomainInformationByCertificateId-default.json +32 -0
  46. package/entities/Certificate/schema.json +43 -0
  47. package/entities/Countries/action.json +46 -0
  48. package/entities/Countries/schema.json +20 -0
  49. package/entities/Domains/action.json +696 -0
  50. package/entities/Domains/mockdatafiles/domainsForwardsGet-default.json +12 -0
  51. package/entities/Domains/mockdatafiles/getAgreement-default.json +8 -0
  52. package/entities/Domains/mockdatafiles/listDomains-default.json +198 -0
  53. package/entities/Domains/mockdatafiles/recordGet-default.json +24 -0
  54. package/entities/Domains/mockdatafiles/suggest-default.json +11 -0
  55. package/entities/Domains/mockdatafiles/tlds-default.json +14 -0
  56. package/entities/Domains/schema.json +52 -0
  57. package/entities/Notifications/action.json +107 -0
  58. package/entities/Notifications/mockdatafiles/getV2CustomersCustomerIdDomainsNotificationsOptIn-default.json +32 -0
  59. package/entities/Notifications/schema.json +23 -0
  60. package/entities/Orders/action.json +46 -0
  61. package/entities/Orders/schema.json +20 -0
  62. package/entities/Parking/action.json +46 -0
  63. package/entities/Parking/schema.json +20 -0
  64. package/entities/Shoppers/action.json +126 -0
  65. package/entities/Shoppers/schema.json +24 -0
  66. package/entities/Subscriptions/action.json +107 -0
  67. package/entities/Subscriptions/mockdatafiles/productGroups-default.json +10 -0
  68. package/entities/Subscriptions/schema.json +23 -0
  69. package/error.json +190 -0
  70. package/metadata.json +54 -0
  71. package/package.json +82 -0
  72. package/pronghorn.json +15805 -0
  73. package/propertiesDecorators.json +14 -0
  74. package/propertiesSchema.json +1661 -0
  75. package/refs?service=git-upload-pack +0 -0
  76. package/report/adapter-openapi.json +13714 -0
  77. package/report/adapter-openapi.yaml +20419 -0
  78. package/report/adapterInfo.json +10 -0
  79. package/report/creationReport.json +765 -0
  80. package/report/godaddy.json +13714 -0
  81. package/report/updateReport1706477552013.json +120 -0
  82. package/sampleProperties.json +254 -0
  83. package/test/integration/adapterTestBasicGet.js +83 -0
  84. package/test/integration/adapterTestConnectivity.js +142 -0
  85. package/test/integration/adapterTestIntegration.js +2925 -0
  86. package/test/unit/adapterBaseTestUnit.js +1024 -0
  87. package/test/unit/adapterTestUnit.js +4900 -0
  88. package/utils/adapterInfo.js +206 -0
  89. package/utils/addAuth.js +94 -0
  90. package/utils/artifactize.js +146 -0
  91. package/utils/basicGet.js +50 -0
  92. package/utils/checkMigrate.js +63 -0
  93. package/utils/entitiesToDB.js +179 -0
  94. package/utils/findPath.js +74 -0
  95. package/utils/methodDocumentor.js +273 -0
  96. package/utils/modify.js +152 -0
  97. package/utils/packModificationScript.js +35 -0
  98. package/utils/patches2bundledDeps.js +90 -0
  99. package/utils/pre-commit.sh +32 -0
  100. package/utils/removeHooks.js +20 -0
  101. package/utils/setup.js +33 -0
  102. package/utils/taskMover.js +309 -0
  103. package/utils/tbScript.js +239 -0
  104. package/utils/tbUtils.js +489 -0
  105. package/utils/testRunner.js +298 -0
  106. package/utils/troubleshootingAdapter.js +193 -0
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ /* @copyright Itential, LLC 2019 */
3
+
4
+ const path = require('path');
5
+ const { spawnSync } = require('child_process');
6
+ const fs = require('fs-extra');
7
+ const { createBundle } = require('./artifactize');
8
+
9
+ const nodeEntryPath = path.resolve('.');
10
+ createBundle(nodeEntryPath).then((pathObj) => {
11
+ const { bundlePath, bundledAdapterPath } = pathObj;
12
+ const npmIgnorePath = path.join(bundledAdapterPath, '.npmignore');
13
+ const adapterPackagePath = path.join(bundledAdapterPath, 'package.json');
14
+ const artifactPackagePath = path.join(bundlePath, 'package.json');
15
+
16
+ // remove node_modules from .npmIgnore so that node_modules are included in the resulting tar from npm pack
17
+ let npmIgnoreString;
18
+ if (fs.existsSync(npmIgnorePath)) {
19
+ npmIgnoreString = fs.readFileSync(npmIgnorePath, 'utf8');
20
+ npmIgnoreString = npmIgnoreString.replace('node_modules', '');
21
+ npmIgnoreString = npmIgnoreString.replace('\n\n', '\n');
22
+ fs.writeFileSync(npmIgnorePath, npmIgnoreString);
23
+ }
24
+
25
+ // add files to package so that node_modules are included in the resulting tar from npm pack
26
+ const adapterPackage = fs.readJSONSync(adapterPackagePath);
27
+ adapterPackage.files = ['*'];
28
+ fs.writeJSONSync(artifactPackagePath, adapterPackage, { spaces: 2 });
29
+ const npmResult = spawnSync('npm', ['pack', '-q', bundlePath], { cwd: path.resolve(bundlePath, '..') });
30
+ if (npmResult.status === 0) {
31
+ fs.removeSync(bundlePath);
32
+ console.log('Bundle folder removed');
33
+ }
34
+ console.log('Script successful');
35
+ });
@@ -0,0 +1,90 @@
1
+ const fs = require('fs');
2
+ const semverSatisfies = require('semver/functions/satisfies');
3
+ const packageJson = require('../package.json');
4
+
5
+ try {
6
+ // pattern supplied by semver.org via https://regex101.com/r/vkijKf/1/ but removed gm from end to only match a single semver
7
+ // const semverPat = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
8
+ // pattern supplied by semver.org via https://regex101.com/r/Ly7O1x/3/ with following changes
9
+ // removed P's from before capturing group names and
10
+ // removed gm from end to only match a single semver
11
+ // const semverPat = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
12
+
13
+ const patches = (fs.existsSync('./patches')) ? fs.readdirSync('./patches', { withFileTypes: true }) : [];
14
+ if (!patches.length) {
15
+ console.error('\nno patches - nothing to do\n');
16
+ process.exitCode = 1;
17
+ }
18
+
19
+ const dependencies = packageJson.dependencies || {};
20
+ if (!Object.keys(dependencies).length) {
21
+ console.error('\nno dependencies - nothing to do\n');
22
+ process.exitCode = 1;
23
+ }
24
+
25
+ let changed = false;
26
+ console.error('\nprocessing patches');
27
+ const bundledDependencies = packageJson.bundledDependencies || packageJson.bundleDependencies || [];
28
+
29
+ patches.forEach((patch) => {
30
+ if (!patch.isFile()) {
31
+ console.error(`${patch.name} skipped, is not a regular file`);
32
+ return;
33
+ }
34
+ if (!patch.name.endsWith('.patch')) {
35
+ console.error(`${patch.name} skipped, does not end with .patch`);
36
+ return;
37
+ }
38
+ const splits = patch.name.slice(0, -6).split('+');
39
+ if (splits.length > 4) {
40
+ console.error(`${patch.name} skipped, does not follow the naming convention (cannot use '+' other than to separate scope/package/semver and at most once within semver)`);
41
+ return;
42
+ }
43
+ const scope = splits[0][0] === '@' ? splits.shift() : null;
44
+ const packageName = splits.shift();
45
+ const semver = splits.join('+');
46
+ // const { groups } = semver.match(semverPat);
47
+ const file = scope ? `${scope}/${packageName}` : packageName;
48
+ if (dependencies[file] && semverSatisfies(semver, dependencies[file])) {
49
+ if (!bundledDependencies.includes(file)) {
50
+ bundledDependencies.push(file);
51
+ console.error(`added ${file} to bundledDependencies`);
52
+ changed = true;
53
+ } else {
54
+ console.error(`bundledDependencies already has ${file}`);
55
+ }
56
+ } else {
57
+ const depmsg = dependencies[file] ? `version mismatch (${dependencies[file]}) in dependencies` : 'not found in dependencies';
58
+ console.error(`patch ${patch.name} ${depmsg}`);
59
+ }
60
+ });
61
+
62
+ if (!packageJson.bundledDependencies && bundledDependencies.length) {
63
+ delete packageJson.bundleDependencies;
64
+ packageJson.bundledDependencies = bundledDependencies;
65
+ console.error('renaming bundleDependencies to bundledDependencies');
66
+ changed = true;
67
+ }
68
+ if (changed) {
69
+ fs.writeFileSync('./package.json.new', JSON.stringify(packageJson, null, 2));
70
+ console.error('wrote package.json.new');
71
+ fs.renameSync('./package.json', './package.json.old');
72
+ console.error('moved package.json to package.json.old');
73
+ fs.renameSync('./package.json.new', './package.json');
74
+ console.error('moved package.json.new to package.json');
75
+ } else {
76
+ console.error('no changes\n');
77
+ process.exitCode = 1;
78
+ }
79
+ } catch (e) {
80
+ if (e) {
81
+ // caught error, exit with status 2 to signify abject failure
82
+ console.error(`\ncaught exception - ${e}\n`);
83
+ process.exitCode = 2;
84
+ } else {
85
+ // caught false, exit with status 1 to signify nothing done
86
+ process.exitCode = 1;
87
+ }
88
+ } finally {
89
+ console.error('done\n');
90
+ }
@@ -0,0 +1,32 @@
1
+ #!/bin/sh
2
+ # @copyright Itential, LLC 2019
3
+
4
+ #exit on any failure in the pipeline
5
+ set -e
6
+
7
+ # --------------------------------------------------
8
+ # pre-commit
9
+ # --------------------------------------------------
10
+ # Contains the standard set of tasks to runbefore
11
+ # committing changes to the repo. If any tasks fail
12
+ # then the commit will be aborted.
13
+ # --------------------------------------------------
14
+
15
+ printf "%b" "Running pre-commit hooks...\\n"
16
+
17
+ # verify testing script is stubbed and no credentials
18
+ node utils/testRunner.js -r
19
+
20
+ # update the adapter information file
21
+ node utils/adapterInfo.js
22
+ node utils/methodDocumentor.js
23
+ git add CALLS.md report/adapterInfo.json
24
+
25
+ # security audit on the code
26
+ npm audit --registry=https://registry.npmjs.org --audit-level=moderate
27
+
28
+ # lint the code
29
+ npm run lint
30
+
31
+ # test the code
32
+ npm run test
@@ -0,0 +1,20 @@
1
+ const fs = require('fs');
2
+
3
+ /**
4
+ * This script will uninstall pre-commit or pre-push hooks in case there's ever a need to
5
+ * commit/push something that has issues
6
+ */
7
+
8
+ const precommitPath = '.git/hooks/pre-commit';
9
+ const prepushPath = '.git/hooks/pre-push';
10
+ fs.unlink(precommitPath, (err) => {
11
+ if (err && err.code !== 'ENOENT') {
12
+ console.log(`${err.message}`);
13
+ }
14
+ });
15
+
16
+ fs.unlink(prepushPath, (err) => {
17
+ if (err && err.code !== 'ENOENT') {
18
+ console.log(`${err.message}`);
19
+ }
20
+ });
package/utils/setup.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ /* @copyright Itential, LLC 2019 */
3
+
4
+ const fs = require('fs');
5
+
6
+ /**
7
+ * This script will execute before an npm install command. The purpose is to
8
+ * write out some standard git hooks that will enable folks working on this
9
+ * project to benefit from the protections that the hooks provide.
10
+ */
11
+
12
+ const precommit = fs.readFileSync('utils/pre-commit.sh', 'utf8');
13
+
14
+ fs.stat('.git', (err) => {
15
+ if (err == null) {
16
+ // git repo, not an npm repo.
17
+ // add pre-commit hook if it doesn't exist
18
+ fs.stat('.git/hooks/pre-commit', (statErr) => {
19
+ if (statErr == null || statErr.code === 'ENOENT') {
20
+ fs.writeFile('.git/hooks/pre-commit', precommit, {
21
+ mode: 0o755
22
+ }, (writeErr) => {
23
+ if (writeErr) {
24
+ return console.log(writeErr.message);
25
+ }
26
+ return null;
27
+ });
28
+ } else {
29
+ console.log(statErr.message);
30
+ }
31
+ });
32
+ }
33
+ });
@@ -0,0 +1,309 @@
1
+ /* eslint-disable */
2
+ const fs = require('fs');
3
+
4
+ const blacklistTasks = [
5
+ 'genericAdapterRequest',
6
+ 'genericAdapterRequestNoBasePath',
7
+ 'hasEntities',
8
+ 'healthcheck'
9
+ ];
10
+
11
+ const adapterBaseTasks = [
12
+ 'getDevicesFiltered',
13
+ 'isAlive',
14
+ 'getConfig',
15
+ 'getDevice',
16
+ 'iapUpdateAdapterConfiguration',
17
+ 'iapFindAdapterPath',
18
+ 'iapSuspendAdapter',
19
+ 'iapUnsuspendAdapter',
20
+ 'iapGetAdapterQueue',
21
+ 'iapTroubleshootAdapter',
22
+ 'iapRunAdapterHealthcheck',
23
+ 'iapRunAdapterConnectivity',
24
+ 'iapRunAdapterBasicGet',
25
+ 'iapMoveAdapterEntitiesToDB',
26
+ 'getDevice',
27
+ 'getDevicesFiltered',
28
+ 'isAlive',
29
+ 'getConfig',
30
+ 'iapGetDeviceCount',
31
+ 'iapRunAdapterLint',
32
+ 'iapRunAdapterTests',
33
+ 'iapGetAdapterInventory'
34
+ ];
35
+
36
+ function updatePronghorn(tasks, original, updated) {
37
+ const originalFile = require(original);
38
+ const unusedMethods = [];
39
+ const usedMethods = originalFile.methods.filter((method) => {
40
+ if (tasks.includes(method.name)) {
41
+ unusedMethods.push(method);
42
+ return false;
43
+ }
44
+ return true;
45
+ });
46
+ //write used and unused to new files
47
+ let updatedFile;
48
+ if (!fs.existsSync(updated)) {
49
+ updatedFile = { ...originalFile, methods: [], src: 'adapter-inactive.js' };
50
+ } else {
51
+ updatedFile = require(updated);
52
+ }
53
+ updatedFile.methods = updatedFile.methods.concat(unusedMethods);
54
+ originalFile.methods = usedMethods;
55
+ fs.writeFileSync(updated, JSON.stringify(updatedFile, null, 2));
56
+ fs.writeFileSync(original, JSON.stringify(originalFile, null, 2));
57
+ return 'Done';
58
+ }
59
+
60
+ function flipTaskFlag(task, pronghornPath, value)
61
+ {
62
+ const pronghorn = require(pronghornPath);
63
+ const index = pronghorn.methods.findIndex((method) => method.name === task);
64
+ pronghorn.methods[index] = { ...pronghorn.methods[index], task: value };
65
+ fs.writeFileSync(pronghornPath, JSON.stringify(pronghorn, null, 2));
66
+ }
67
+
68
+ //Return array of relevant paths given adapter directory
69
+ function createPaths(currentAdapter) {
70
+ const paths = [];
71
+ const filePaths = [
72
+ 'adapter.js',
73
+ 'pronghorn.json',
74
+ 'test/integration/adapterTestIntegration.js',
75
+ 'test/unit/adapterTestUnit.js',
76
+ 'adapter-inactive.js',
77
+ 'pronghorn-inactive.json',
78
+ ];
79
+ filePaths.forEach((file) => {
80
+ paths.push(`${currentAdapter}/${file}`);
81
+ });
82
+ return paths;
83
+ }
84
+
85
+ function insert(str, index, value) {
86
+ return str.substr(0, index) + value + str.substr(index);
87
+ }
88
+
89
+ //modify adapter js
90
+ //original - path to file containing tasks we want to remove
91
+ // updated - path to file we want to move the tasks to
92
+ function updateAdapterJs(tasks, original, updated, adapterDir) {
93
+ if (!fs.existsSync(original)) {
94
+ //could do this or just let the error ocurr lower down and catch in warpper
95
+ throw new Error(`Original file ${original} does not exist.`);
96
+ }
97
+ let originalFile = fs.readFileSync(original, 'utf8');
98
+ let updatedFile;
99
+ if (!fs.existsSync(updated)) {
100
+ const adapterExport = require(`${adapterDir}/pronghorn.json`).export;
101
+ updatedFile = `/* @copyright Itential, LLC 2019 */\n\n/* eslint import/no-dynamic-require: warn */\n/* eslint no-unused-vars: warn */\n/* global log */\n\nconst path = require('path');\n\nconst AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));\n\nclass ${adapterExport}Inactive extends AdapterBaseCl {}\n`;
102
+ //To do handles backup files where og doesn't exist
103
+ } else {
104
+ updatedFile = fs.readFileSync(updated, 'utf8');
105
+ }
106
+
107
+ tasks.forEach((method) => {
108
+ //accounting for different js docs format
109
+ const comment = originalFile.indexOf(`* @function ${method}`);
110
+ const start = originalFile.slice(0, comment).lastIndexOf('/**');
111
+ if (start !== -1) {
112
+ //next comment block
113
+ const end = originalFile.indexOf('/**\n', start + 1);
114
+ let func = end === -1
115
+ ? originalFile.substring(start - 3, originalFile.lastIndexOf('}'))
116
+ : originalFile.substring(start, end);
117
+ originalFile = originalFile.replace(func, '');
118
+ func = '\n ' + func.trim() + '\n';
119
+ updatedFile = insert(updatedFile, updatedFile.lastIndexOf('}'), func);
120
+ } else {
121
+ console.log(`Task ${method} wasn't found in original file. Skipping.`);
122
+ }
123
+ });
124
+ fs.writeFileSync(original, originalFile, 'utf8');
125
+ fs.writeFileSync(updated, updatedFile, 'utf8');
126
+ return 'done';
127
+ }
128
+
129
+ //Update test file for when we deactivate a task
130
+ function deactivateTest(adapterPath, testPath, tasks) {
131
+ let unitTest = fs.readFileSync(`${adapterPath}/${testPath}`, 'utf8');
132
+ tasks.forEach((task) => {
133
+ const searchStr = `describe('#${task}`;
134
+ unitTest = unitTest.replace(searchStr, `describe.skip('#${task}`);
135
+ });
136
+ fs.writeFileSync(`${adapterPath}/${testPath}`, unitTest, 'utf8');
137
+ }
138
+
139
+ //Update test file when we activate tasks
140
+ function activateTest(adapterPath, testPath, tasks) {
141
+ let unitTest = fs.readFileSync(`${adapterPath}/${testPath}`, 'utf8');
142
+ //tasks ==> toMove
143
+ tasks.forEach((task) => {
144
+ const searchStr = `describe.skip('#${task}`;
145
+ unitTest = unitTest.replace(searchStr, `describe('#${task}`);
146
+ });
147
+ fs.writeFileSync(`${adapterPath}/${testPath}`, unitTest, 'utf8');
148
+ }
149
+
150
+ //backups are not actually being written back
151
+ function rollbackChanges(adapterPath) {
152
+ const backups = fs.readdirSync(`${adapterPath}/temp`); //this is an array of file names not the full path
153
+ const filePaths = createPaths(adapterPath);
154
+ for (let i = 0; i < backups.length; i++) {
155
+ const file = fs.readFileSync(`${adapterPath}/temp/${backups[i]}`, 'utf8'); //make sure this is getting the file
156
+ const currentFile = filePaths.find((path) => {
157
+ const index = path.split('/').length - 1;
158
+ const fileName = path.split('/')[index];
159
+ return fileName === backups[i].replace('temp-', '');
160
+ }); //returns undefined if no match
161
+
162
+ if (currentFile) {
163
+ fs.writeFileSync(currentFile, file, 'utf8');
164
+ }
165
+ }
166
+ //inactive didn't exist before script
167
+ if (!backups.includes('temp-adapter-inactive.js')) {
168
+ fs.unlinkSync(`${adapterPath}/pronghorn-inactive.json`);
169
+ fs.unlinkSync(`${adapterPath}/adapter-inactive.js`);
170
+ }
171
+ deleteBackups(adapterPath);
172
+ }
173
+
174
+ function deleteBackups(adapterPath) {
175
+ fs.rmSync(`${adapterPath}/temp`, { recursive: true });
176
+ }
177
+
178
+ function activateTasks(adapterDir, tasks) {
179
+ const toDelete = [];
180
+ const backupFiles = [];
181
+ const filePaths = createPaths(adapterDir);
182
+ try {
183
+ //take backup of each file here
184
+ if (!fs.existsSync(`${adapterDir}/temp`)) {
185
+ fs.mkdirSync(`${adapterDir}/temp`);
186
+ }
187
+ filePaths.forEach((filePath) => {
188
+ if (fs.existsSync(filePath)) {
189
+ const index = filePath.split('/').length - 1;
190
+ const backupName = `temp-${filePath.split('/')[index]}`;
191
+ backupFiles.push(`${adapterDir}/temp/${backupName}`);
192
+ fs.copyFileSync(filePath, `${adapterDir}/temp/${backupName}`);
193
+ } else {
194
+ //File doesn't exist before script
195
+ toDelete.push(filePath);
196
+ }
197
+ });
198
+ tasks = tasks.filter((task) => {
199
+ if (adapterBaseTasks.includes(task)) {
200
+ flipTaskFlag(task, `${adapterDir}/pronghorn.json`, true);
201
+ return false;
202
+ } else {
203
+ return true;
204
+ }
205
+ });
206
+ updateAdapterJs(
207
+ tasks,
208
+ `${adapterDir}/adapter-inactive.js`,
209
+ `${adapterDir}/adapter.js`,
210
+ adapterDir
211
+ );
212
+ updatePronghorn(
213
+ tasks,
214
+ `${adapterDir}/pronghorn-inactive.json`,
215
+ `${adapterDir}/pronghorn.json`
216
+ );
217
+ activateTest(
218
+ adapterDir,
219
+ '/test/integration/adapterTestIntegration.js',
220
+ tasks
221
+ );
222
+ activateTest(adapterDir, '/test/unit/adapterTestUnit.js', tasks);
223
+ return 'success';
224
+ } catch (e) {
225
+ console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
226
+ for (let i = 0; i < backupFiles.length; i++) {
227
+ const file = fs.readFileSync(backupFiles[i], 'utf8');
228
+ fs.writeFileSync(filePaths[i], file, 'utf8');
229
+ }
230
+ toDelete.forEach((filePath) => {
231
+ if (fs.existsSync(filePath)) {
232
+ fs.unlinkSync(filePath);
233
+ }
234
+ });
235
+ deleteBackups(adapterDir);
236
+ process.exit(1);
237
+ }
238
+ }
239
+
240
+ //moving from adapter.js to adapter-inactive.js
241
+ function deactivateTasks(adapterDir, tasks) {
242
+ const toDelete = [];
243
+ const backupFiles = [];
244
+ const filePaths = createPaths(adapterDir);
245
+ try {
246
+ //take backup of each file here
247
+ if (!fs.existsSync(`${adapterDir}/temp`)) {
248
+ fs.mkdirSync(`${adapterDir}/temp`);
249
+ }
250
+ filePaths.forEach((filePath) => {
251
+ if (fs.existsSync(filePath)) {
252
+ const index = filePath.split('/').length - 1;
253
+ const backupName = `temp-${filePath.split('/')[index]}`;
254
+ backupFiles.push(`${adapterDir}/temp/${backupName}`);
255
+ fs.copyFileSync(filePath, `${adapterDir}/temp/${backupName}`);
256
+ } else {
257
+ //File doesn't exist before script
258
+ toDelete.push(filePath);
259
+ }
260
+ });
261
+ //filter tasks for blacklisted tasks or IAP tasks
262
+ tasks = tasks.filter((task) => {
263
+ if (blacklistTasks.includes(task)) {
264
+ console.log(`${task} cannot be deactivated.`);
265
+ return false;
266
+ } else if (adapterBaseTasks.includes(task)) {
267
+ flipTaskFlag(task, `${adapterDir}/pronghorn.json`, false);
268
+ return false;
269
+ } else {
270
+ return true;
271
+ }
272
+ });
273
+ updateAdapterJs(
274
+ tasks,
275
+ `${adapterDir}/adapter.js`,
276
+ `${adapterDir}/adapter-inactive.js`,
277
+ adapterDir
278
+ );
279
+ updatePronghorn(
280
+ tasks,
281
+ `${adapterDir}/pronghorn.json`,
282
+ `${adapterDir}/pronghorn-inactive.json`
283
+ );
284
+ deactivateTest(
285
+ adapterDir,
286
+ '/test/integration/adapterTestIntegration.js',
287
+ tasks
288
+ );
289
+ deactivateTest(adapterDir, '/test/unit/adapterTestUnit.js', tasks);
290
+ return 'success';
291
+ } catch (e) {
292
+ console.log(`Error: ${e} ocurred during execution. Rolling back changes.`);
293
+ for (let i = 0; i < backupFiles.length; i++) {
294
+ const file = fs.readFileSync(backupFiles[i], 'utf8');
295
+ fs.writeFileSync(filePaths[i], file, 'utf8');
296
+ }
297
+ toDelete.forEach((filePath) => {
298
+ if (fs.existsSync(filePath)) {
299
+ fs.unlinkSync(filePath);
300
+ }
301
+ });
302
+ deleteBackups(adapterDir);
303
+ process.exit(1);
304
+ }
305
+ }
306
+
307
+ module.exports = {
308
+ activateTasks, deactivateTasks, rollbackChanges, deleteBackups
309
+ };