@itentialopensource/adapter-mockdevice 2.1.4 → 2.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.
- package/AUTH.md +2 -2
- package/ENHANCE.md +3 -3
- package/README.md +8 -8
- package/TAB2.md +3 -3
- package/coverage/adapter-mockdevice/adapter.js.html +1612 -0
- package/coverage/adapter-mockdevice/index.html +116 -0
- package/coverage/adapter-mockdevice/utils/argParser.js.html +217 -0
- package/coverage/adapter-mockdevice/utils/index.html +131 -0
- package/coverage/adapter-mockdevice/utils/logger.js.html +163 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/package.json +35 -38
- package/utils/argParser.js +44 -0
- package/utils/logger.js +26 -0
- package/utils/artifactize.js +0 -146
- package/utils/packModificationScript.js +0 -35
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
var addSorting = (function() {
|
|
3
|
+
'use strict';
|
|
4
|
+
var cols,
|
|
5
|
+
currentSort = {
|
|
6
|
+
index: 0,
|
|
7
|
+
desc: false
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// returns the summary table element
|
|
11
|
+
function getTable() {
|
|
12
|
+
return document.querySelector('.coverage-summary');
|
|
13
|
+
}
|
|
14
|
+
// returns the thead element of the summary table
|
|
15
|
+
function getTableHeader() {
|
|
16
|
+
return getTable().querySelector('thead tr');
|
|
17
|
+
}
|
|
18
|
+
// returns the tbody element of the summary table
|
|
19
|
+
function getTableBody() {
|
|
20
|
+
return getTable().querySelector('tbody');
|
|
21
|
+
}
|
|
22
|
+
// returns the th element for nth column
|
|
23
|
+
function getNthColumn(n) {
|
|
24
|
+
return getTableHeader().querySelectorAll('th')[n];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function onFilterInput() {
|
|
28
|
+
const searchValue = document.getElementById('fileSearch').value;
|
|
29
|
+
const rows = document.getElementsByTagName('tbody')[0].children;
|
|
30
|
+
for (let i = 0; i < rows.length; i++) {
|
|
31
|
+
const row = rows[i];
|
|
32
|
+
if (
|
|
33
|
+
row.textContent
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.includes(searchValue.toLowerCase())
|
|
36
|
+
) {
|
|
37
|
+
row.style.display = '';
|
|
38
|
+
} else {
|
|
39
|
+
row.style.display = 'none';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// loads the search box
|
|
45
|
+
function addSearchBox() {
|
|
46
|
+
var template = document.getElementById('filterTemplate');
|
|
47
|
+
var templateClone = template.content.cloneNode(true);
|
|
48
|
+
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
|
49
|
+
template.parentElement.appendChild(templateClone);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// loads all columns
|
|
53
|
+
function loadColumns() {
|
|
54
|
+
var colNodes = getTableHeader().querySelectorAll('th'),
|
|
55
|
+
colNode,
|
|
56
|
+
cols = [],
|
|
57
|
+
col,
|
|
58
|
+
i;
|
|
59
|
+
|
|
60
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
|
61
|
+
colNode = colNodes[i];
|
|
62
|
+
col = {
|
|
63
|
+
key: colNode.getAttribute('data-col'),
|
|
64
|
+
sortable: !colNode.getAttribute('data-nosort'),
|
|
65
|
+
type: colNode.getAttribute('data-type') || 'string'
|
|
66
|
+
};
|
|
67
|
+
cols.push(col);
|
|
68
|
+
if (col.sortable) {
|
|
69
|
+
col.defaultDescSort = col.type === 'number';
|
|
70
|
+
colNode.innerHTML =
|
|
71
|
+
colNode.innerHTML + '<span class="sorter"></span>';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return cols;
|
|
75
|
+
}
|
|
76
|
+
// attaches a data attribute to every tr element with an object
|
|
77
|
+
// of data values keyed by column name
|
|
78
|
+
function loadRowData(tableRow) {
|
|
79
|
+
var tableCols = tableRow.querySelectorAll('td'),
|
|
80
|
+
colNode,
|
|
81
|
+
col,
|
|
82
|
+
data = {},
|
|
83
|
+
i,
|
|
84
|
+
val;
|
|
85
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
|
86
|
+
colNode = tableCols[i];
|
|
87
|
+
col = cols[i];
|
|
88
|
+
val = colNode.getAttribute('data-value');
|
|
89
|
+
if (col.type === 'number') {
|
|
90
|
+
val = Number(val);
|
|
91
|
+
}
|
|
92
|
+
data[col.key] = val;
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
// loads all row data
|
|
97
|
+
function loadData() {
|
|
98
|
+
var rows = getTableBody().querySelectorAll('tr'),
|
|
99
|
+
i;
|
|
100
|
+
|
|
101
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
102
|
+
rows[i].data = loadRowData(rows[i]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// sorts the table using the data for the ith column
|
|
106
|
+
function sortByIndex(index, desc) {
|
|
107
|
+
var key = cols[index].key,
|
|
108
|
+
sorter = function(a, b) {
|
|
109
|
+
a = a.data[key];
|
|
110
|
+
b = b.data[key];
|
|
111
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
112
|
+
},
|
|
113
|
+
finalSorter = sorter,
|
|
114
|
+
tableBody = document.querySelector('.coverage-summary tbody'),
|
|
115
|
+
rowNodes = tableBody.querySelectorAll('tr'),
|
|
116
|
+
rows = [],
|
|
117
|
+
i;
|
|
118
|
+
|
|
119
|
+
if (desc) {
|
|
120
|
+
finalSorter = function(a, b) {
|
|
121
|
+
return -1 * sorter(a, b);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
|
126
|
+
rows.push(rowNodes[i]);
|
|
127
|
+
tableBody.removeChild(rowNodes[i]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
rows.sort(finalSorter);
|
|
131
|
+
|
|
132
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
133
|
+
tableBody.appendChild(rows[i]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// removes sort indicators for current column being sorted
|
|
137
|
+
function removeSortIndicators() {
|
|
138
|
+
var col = getNthColumn(currentSort.index),
|
|
139
|
+
cls = col.className;
|
|
140
|
+
|
|
141
|
+
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
142
|
+
col.className = cls;
|
|
143
|
+
}
|
|
144
|
+
// adds sort indicators for current column being sorted
|
|
145
|
+
function addSortIndicators() {
|
|
146
|
+
getNthColumn(currentSort.index).className += currentSort.desc
|
|
147
|
+
? ' sorted-desc'
|
|
148
|
+
: ' sorted';
|
|
149
|
+
}
|
|
150
|
+
// adds event listeners for all sorter widgets
|
|
151
|
+
function enableUI() {
|
|
152
|
+
var i,
|
|
153
|
+
el,
|
|
154
|
+
ithSorter = function ithSorter(i) {
|
|
155
|
+
var col = cols[i];
|
|
156
|
+
|
|
157
|
+
return function() {
|
|
158
|
+
var desc = col.defaultDescSort;
|
|
159
|
+
|
|
160
|
+
if (currentSort.index === i) {
|
|
161
|
+
desc = !currentSort.desc;
|
|
162
|
+
}
|
|
163
|
+
sortByIndex(i, desc);
|
|
164
|
+
removeSortIndicators();
|
|
165
|
+
currentSort.index = i;
|
|
166
|
+
currentSort.desc = desc;
|
|
167
|
+
addSortIndicators();
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
for (i = 0; i < cols.length; i += 1) {
|
|
171
|
+
if (cols[i].sortable) {
|
|
172
|
+
// add the click event handler on the th so users
|
|
173
|
+
// dont have to click on those tiny arrows
|
|
174
|
+
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
|
175
|
+
if (el.addEventListener) {
|
|
176
|
+
el.addEventListener('click', ithSorter(i));
|
|
177
|
+
} else {
|
|
178
|
+
el.attachEvent('onclick', ithSorter(i));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// adds sorting functionality to the UI
|
|
184
|
+
return function() {
|
|
185
|
+
if (!getTable()) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
cols = loadColumns();
|
|
189
|
+
loadData();
|
|
190
|
+
addSearchBox();
|
|
191
|
+
addSortIndicators();
|
|
192
|
+
enableUI();
|
|
193
|
+
};
|
|
194
|
+
})();
|
|
195
|
+
|
|
196
|
+
window.addEventListener('load', addSorting);
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itentialopensource/adapter-mockdevice",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "mock implementation of device broker",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
+
"wizardVersion": "2.44.7",
|
|
7
|
+
"engineVersion": "1.69.14",
|
|
6
8
|
"repository": {
|
|
7
9
|
"type": "git",
|
|
8
10
|
"url": "git@gitlab.com:itentialopensource/adapters/adapter-mockdevice.git"
|
|
@@ -15,7 +17,6 @@
|
|
|
15
17
|
"npm": ">=7.18.1 <8.0.0"
|
|
16
18
|
},
|
|
17
19
|
"scripts": {
|
|
18
|
-
"artifactize": "npm i && node utils/packModificationScript.js",
|
|
19
20
|
"preinstall": "node utils/setup.js",
|
|
20
21
|
"deinstall": "node utils/removeHooks.js",
|
|
21
22
|
"lint": "node --max_old_space_size=4096 ./node_modules/eslint/bin/eslint.js . --ext .json --ext .js",
|
|
@@ -29,56 +30,52 @@
|
|
|
29
30
|
},
|
|
30
31
|
"keywords": [
|
|
31
32
|
"Itential",
|
|
32
|
-
"
|
|
33
|
+
"Itential Platform",
|
|
33
34
|
"Automation",
|
|
34
35
|
"Integration",
|
|
35
|
-
"App-Artifacts",
|
|
36
36
|
"Adapter",
|
|
37
37
|
"mockdevice",
|
|
38
38
|
"Pre-Release"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"ajv": "
|
|
42
|
-
"axios": "
|
|
43
|
-
"esprima": "
|
|
44
|
-
"fs-extra": "
|
|
45
|
-
"readline-sync": "
|
|
46
|
-
"
|
|
41
|
+
"ajv": "8.17.1",
|
|
42
|
+
"axios": "1.9.0",
|
|
43
|
+
"esprima": "4.0.1",
|
|
44
|
+
"fs-extra": "11.3.0",
|
|
45
|
+
"readline-sync": "1.4.10",
|
|
46
|
+
"mocha": "10.8.2",
|
|
47
|
+
"semver": "7.7.2",
|
|
48
|
+
"winston": "3.17.0"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
49
|
-
"chai": "
|
|
50
|
-
"eslint": "
|
|
51
|
-
"eslint-config-airbnb-base": "
|
|
52
|
-
"eslint-plugin-import": "
|
|
53
|
-
"eslint-plugin-json": "
|
|
54
|
-
"eslint-config-airbnb": "
|
|
55
|
-
"eslint-config-prettier": "
|
|
56
|
-
"eslint-plugin-jsdoc": "
|
|
57
|
-
"eslint-plugin-mocha": "
|
|
58
|
-
"eslint-plugin-node": "
|
|
59
|
-
"eslint-plugin-prettier": "
|
|
60
|
-
"eslint-plugin-yaml": "
|
|
61
|
-
"husky": "
|
|
62
|
-
"jsdoc": "
|
|
63
|
-
"lint-staged": "
|
|
64
|
-
"minami": "
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"prettier": "
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"testdouble": "^3.18.0",
|
|
73
|
-
"winston": "^3.14.2"
|
|
51
|
+
"chai": "4.5.0",
|
|
52
|
+
"eslint": "8.57.0",
|
|
53
|
+
"eslint-config-airbnb-base": "15.0.0",
|
|
54
|
+
"eslint-plugin-import": "2.31.0",
|
|
55
|
+
"eslint-plugin-json": "3.1.0",
|
|
56
|
+
"eslint-config-airbnb": "19.0.4",
|
|
57
|
+
"eslint-config-prettier": "8.1.0",
|
|
58
|
+
"eslint-plugin-jsdoc": "50.2.4",
|
|
59
|
+
"eslint-plugin-mocha": "8.1.0",
|
|
60
|
+
"eslint-plugin-node": "11.1.0",
|
|
61
|
+
"eslint-plugin-prettier": "3.3.1",
|
|
62
|
+
"eslint-plugin-yaml": "0.4.1",
|
|
63
|
+
"husky": "4.3.8",
|
|
64
|
+
"jsdoc": "4.0.2",
|
|
65
|
+
"lint-staged": "10.5.4",
|
|
66
|
+
"minami": "1.2.3",
|
|
67
|
+
"mochawesome": "7.1.3",
|
|
68
|
+
"nyc": "15.1.0",
|
|
69
|
+
"prettier": "2.2.1",
|
|
70
|
+
"prettier-plugin-package": "1.3.0",
|
|
71
|
+
"pretty-quick": "3.1.0",
|
|
72
|
+
"shellcheck": "1.0.0",
|
|
73
|
+
"testdouble": "3.18.0"
|
|
74
74
|
},
|
|
75
75
|
"lint-staged": {
|
|
76
76
|
"*.{js,json,jsx,yaml,yml,md}": [
|
|
77
77
|
"./node_modules/.bin/eslint --fix"
|
|
78
78
|
]
|
|
79
79
|
},
|
|
80
|
-
"resolutions": {
|
|
81
|
-
"minimist": "^1.2.8"
|
|
82
|
-
},
|
|
83
80
|
"private": false
|
|
84
81
|
}
|
|
@@ -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;
|
package/utils/artifactize.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* @copyright Itential, LLC 2019 */
|
|
3
|
-
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const fs = require('fs-extra');
|
|
6
|
-
|
|
7
|
-
async function createBundle(adapterOldDir) {
|
|
8
|
-
// set directories
|
|
9
|
-
const artifactDir = path.join(adapterOldDir, '../artifactTemp');
|
|
10
|
-
const workflowsDir = path.join(adapterOldDir, 'workflows');
|
|
11
|
-
|
|
12
|
-
// read adapter's package and set names
|
|
13
|
-
const adapterPackage = fs.readJSONSync(path.join(adapterOldDir, 'package.json'));
|
|
14
|
-
const originalName = adapterPackage.name.substring(adapterPackage.name.lastIndexOf('/') + 1);
|
|
15
|
-
const shortenedName = originalName.replace('adapter-', '');
|
|
16
|
-
const artifactName = originalName.replace('adapter', 'bundled-adapter');
|
|
17
|
-
|
|
18
|
-
const adapterNewDir = path.join(artifactDir, 'bundles', 'adapters', originalName);
|
|
19
|
-
fs.ensureDirSync(adapterNewDir);
|
|
20
|
-
|
|
21
|
-
const ops = [];
|
|
22
|
-
|
|
23
|
-
// copy old adapterDir to bundled hierarchy location
|
|
24
|
-
ops.push(() => fs.copySync(adapterOldDir, adapterNewDir));
|
|
25
|
-
|
|
26
|
-
// copy readme
|
|
27
|
-
ops.push(() => fs.copySync(path.join(adapterOldDir, 'README.md'), path.join(artifactDir, 'README.md')));
|
|
28
|
-
|
|
29
|
-
// copy changelog
|
|
30
|
-
if (fs.existsSync(path.join(adapterOldDir, 'CHANGELOG.md'))) {
|
|
31
|
-
ops.push(() => fs.copySync(path.join(adapterOldDir, 'CHANGELOG.md'), path.join(artifactDir, 'CHANGELOG.md')));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// copy license
|
|
35
|
-
if (fs.existsSync(path.join(adapterOldDir, 'LICENSE'))) {
|
|
36
|
-
ops.push(() => fs.copySync(path.join(adapterOldDir, 'LICENSE'), path.join(artifactDir, 'LICENSE')));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// create package
|
|
40
|
-
const artifactPackage = {
|
|
41
|
-
name: artifactName,
|
|
42
|
-
version: adapterPackage.version,
|
|
43
|
-
description: `A bundled version of the ${originalName} to be used in adapter-artifacts for easy installation`,
|
|
44
|
-
scripts: {
|
|
45
|
-
test: 'echo "Error: no test specified" && exit 1',
|
|
46
|
-
deploy: 'npm publish --registry=http://registry.npmjs.org'
|
|
47
|
-
},
|
|
48
|
-
keywords: [
|
|
49
|
-
'IAP',
|
|
50
|
-
'artifacts',
|
|
51
|
-
'Itential',
|
|
52
|
-
'Pronghorn',
|
|
53
|
-
'Adapter',
|
|
54
|
-
'Adapter-Artifacts',
|
|
55
|
-
shortenedName
|
|
56
|
-
],
|
|
57
|
-
author: 'Itential Artifacts',
|
|
58
|
-
license: 'Apache-2.0',
|
|
59
|
-
repository: adapterPackage.repository,
|
|
60
|
-
private: false,
|
|
61
|
-
devDependencies: {
|
|
62
|
-
r2: '^2.0.1',
|
|
63
|
-
ajv: '6.10.0',
|
|
64
|
-
'better-ajv-errors': '^0.6.1',
|
|
65
|
-
'fs-extra': '^7.0.1'
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
ops.push(() => fs.writeJSONSync(path.join(artifactDir, 'package.json'), artifactPackage, { spaces: 2 }));
|
|
70
|
-
|
|
71
|
-
// create manifest
|
|
72
|
-
const manifest = {
|
|
73
|
-
bundleName: originalName,
|
|
74
|
-
version: adapterPackage.version,
|
|
75
|
-
fingerprint: 'Some verifiable token',
|
|
76
|
-
createdEpoch: '1554836984020',
|
|
77
|
-
artifacts: [
|
|
78
|
-
{
|
|
79
|
-
id: `${shortenedName}-adapter`,
|
|
80
|
-
name: `${shortenedName}-adapter`,
|
|
81
|
-
type: 'adapter',
|
|
82
|
-
location: `/bundles/adapters/${originalName}`,
|
|
83
|
-
description: artifactPackage.description,
|
|
84
|
-
properties: {
|
|
85
|
-
entryPoint: false
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// add workflows into artifact
|
|
92
|
-
if (fs.existsSync(workflowsDir)) {
|
|
93
|
-
const workflowFileNames = fs.readdirSync(workflowsDir);
|
|
94
|
-
|
|
95
|
-
// if folder isnt empty and only file is not readme
|
|
96
|
-
if (workflowFileNames.length !== 0 && (!(workflowFileNames.length === 1 && workflowFileNames[0].split('.')[1] === 'md'))) {
|
|
97
|
-
// add workflows to correct location in bundle
|
|
98
|
-
ops.push(() => fs.copySync(workflowsDir, path.join(artifactDir, 'bundles', 'workflows')));
|
|
99
|
-
|
|
100
|
-
// add workflows to manifest
|
|
101
|
-
workflowFileNames.forEach((filename) => {
|
|
102
|
-
const [filenameNoExt, ext] = filename.split('.');
|
|
103
|
-
if (ext === 'json') {
|
|
104
|
-
manifest.artifacts.push({
|
|
105
|
-
id: `workflow-${filenameNoExt}`,
|
|
106
|
-
name: filenameNoExt,
|
|
107
|
-
type: 'workflow',
|
|
108
|
-
location: `/bundles/workflows/${filename}`,
|
|
109
|
-
description: 'Main entry point to artifact',
|
|
110
|
-
properties: {
|
|
111
|
-
entryPoint: false
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
ops.push(() => fs.writeJSONSync(path.join(artifactDir, 'manifest.json'), manifest, { spaces: 2 }));
|
|
120
|
-
|
|
121
|
-
// Run the commands in parallel
|
|
122
|
-
try {
|
|
123
|
-
await Promise.all(ops.map(async (op) => op()));
|
|
124
|
-
} catch (e) {
|
|
125
|
-
throw new Error(e);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const pathObj = {
|
|
129
|
-
bundlePath: artifactDir,
|
|
130
|
-
bundledAdapterPath: path.join(artifactDir, 'bundles', 'adapters', originalName)
|
|
131
|
-
};
|
|
132
|
-
return pathObj;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function artifactize(entryPathToAdapter) {
|
|
136
|
-
const truePath = path.resolve(entryPathToAdapter);
|
|
137
|
-
const packagePath = path.join(truePath, 'package');
|
|
138
|
-
// remove adapter from package and move bundle in
|
|
139
|
-
const pathObj = await createBundle(packagePath);
|
|
140
|
-
const { bundlePath } = pathObj;
|
|
141
|
-
fs.removeSync(packagePath);
|
|
142
|
-
fs.moveSync(bundlePath, packagePath);
|
|
143
|
-
return 'Bundle successfully created and old folder system removed';
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
module.exports = { createBundle, artifactize };
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
});
|