@beauraines/node-helpers 5.0.0 → 5.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/CHANGELOG.md +14 -0
- package/eslint.config.mjs +1 -0
- package/index.js +4 -2
- package/package.json +1 -1
- package/src/ado.js +1 -1
- package/src/cli-arguments.js +78 -0
- package/src/credentials.js +0 -1
- package/src/database.js +0 -1
- package/src/database.test.js +0 -1
- package/src/helpers.js +13 -2
- package/src/helpers.test.js +7 -0
- package/src/jira.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.2.0](https://github.com/beauraines/node-helpers/compare/v5.1.0...v5.2.0) (2024-10-19)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **helper:** convert unix timestamp to date ([d885b45](https://github.com/beauraines/node-helpers/commit/d885b45abf182ae9bb8e210f129735d672ee766a))
|
|
11
|
+
|
|
12
|
+
## [5.1.0](https://github.com/beauraines/node-helpers/compare/v5.0.0...v5.1.0) (2024-10-16)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* adds cli argument module ([#155](https://github.com/beauraines/node-helpers/issues/155)) ([b7943b6](https://github.com/beauraines/node-helpers/commit/b7943b6cf55a221ecc1a55afec2ab9505ed88347))
|
|
18
|
+
|
|
5
19
|
## [5.0.0](https://github.com/beauraines/node-helpers/compare/v4.3.0...v5.0.0) (2024-10-14)
|
|
6
20
|
|
|
7
21
|
|
package/eslint.config.mjs
CHANGED
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
const ado = require("./src/ado");
|
|
3
3
|
const AzureStorage = require("./src/azure")
|
|
4
|
+
const cliArguments = require('./src/cli-arguments.js');
|
|
4
5
|
const config = require('./src/config.js')
|
|
5
6
|
const credentials = require("./src/credentials.js");
|
|
6
7
|
const database = require("./src/database");
|
|
@@ -8,12 +9,13 @@ const helpers = require("./src/helpers");
|
|
|
8
9
|
const jira = require("./src/jira");
|
|
9
10
|
|
|
10
11
|
module.exports = {
|
|
12
|
+
ado,
|
|
11
13
|
AzureStorage,
|
|
14
|
+
cliArguments,
|
|
12
15
|
config,
|
|
13
16
|
credentials,
|
|
14
17
|
database,
|
|
15
18
|
helpers,
|
|
16
|
-
jira
|
|
17
|
-
ado
|
|
19
|
+
jira
|
|
18
20
|
}
|
|
19
21
|
|
package/package.json
CHANGED
package/src/ado.js
CHANGED
|
@@ -82,7 +82,7 @@ async function getDistinctParentWorkItems(workItemAPI, ids) {
|
|
|
82
82
|
async function callRestApi(url, username, token) {
|
|
83
83
|
// console.log(url) // Only display this in verbose mode
|
|
84
84
|
// Bearer token format for ADO
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
let bearerToken = Buffer.from(`${username}:${token}`).toString('base64');
|
|
87
87
|
|
|
88
88
|
let response;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses command-line parameters and returns an array of the parameters. This is really getting the
|
|
3
|
+
* "arguments" passed from the command-line, but there is no additional parsing or formatting, so
|
|
4
|
+
* this is best suited to just parameters. You could handle each element in the array yourself for
|
|
5
|
+
* involved processing
|
|
6
|
+
*
|
|
7
|
+
* `node script.js beau 42`
|
|
8
|
+
*
|
|
9
|
+
* returns
|
|
10
|
+
* `[ 'beau', '42' ]`
|
|
11
|
+
*
|
|
12
|
+
* *
|
|
13
|
+
* @returns Array
|
|
14
|
+
*/
|
|
15
|
+
const getParameters = () => {
|
|
16
|
+
// process.argv is an array where:
|
|
17
|
+
// - The first element is the path to the Node.js executable (e.g., '/usr/local/bin/node')
|
|
18
|
+
// - The second element is the path to the script file (e.g., '/path/to/script.js')
|
|
19
|
+
// - The subsequent elements are the command-line arguments
|
|
20
|
+
|
|
21
|
+
// Get the arguments starting from the third element
|
|
22
|
+
const args = process.argv.slice(2).length > 0 ? process.argv.slice(2) : []
|
|
23
|
+
return args
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Parses named command-line arguments. This only supports long-named arguments prefixed with a `--`.
|
|
28
|
+
* Short arguments .e.g. `-d` are not supported. The value can either be space separated or with an
|
|
29
|
+
* equals sign
|
|
30
|
+
*
|
|
31
|
+
* `node name-arguments.js --age=42 --name=Beau`
|
|
32
|
+
*
|
|
33
|
+
* Using this function this will return
|
|
34
|
+
*
|
|
35
|
+
* { age: '42', name: 'Beau' }
|
|
36
|
+
*
|
|
37
|
+
*
|
|
38
|
+
* @returns Object
|
|
39
|
+
*/
|
|
40
|
+
const getNamedArguments = () => {
|
|
41
|
+
const args = {};
|
|
42
|
+
|
|
43
|
+
const argv =process.argv;
|
|
44
|
+
// Start from index 2 to skip the node executable and script file paths
|
|
45
|
+
for (let i = 2; i < argv.length; i++) {
|
|
46
|
+
let arg = argv[i];
|
|
47
|
+
|
|
48
|
+
if (arg.startsWith('--')) {
|
|
49
|
+
// Remove the leading --
|
|
50
|
+
arg = arg.slice(2);
|
|
51
|
+
|
|
52
|
+
// Handle --key=value
|
|
53
|
+
if (arg.includes('=')) {
|
|
54
|
+
const [key, value] = arg.split('=');
|
|
55
|
+
args[key] = value;
|
|
56
|
+
} else {
|
|
57
|
+
// Handle --key value
|
|
58
|
+
const key = arg;
|
|
59
|
+
const value = argv[i + 1];
|
|
60
|
+
|
|
61
|
+
if (!value || value.startsWith('--')) {
|
|
62
|
+
args[key] = true; // For flags without values
|
|
63
|
+
} else {
|
|
64
|
+
args[key] = value;
|
|
65
|
+
i++; // Skip the next item as it's the value for this key
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return args;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
module.exports = {
|
|
76
|
+
getNamedArguments,
|
|
77
|
+
getParameters
|
|
78
|
+
}
|
package/src/credentials.js
CHANGED
package/src/database.js
CHANGED
package/src/database.test.js
CHANGED
package/src/helpers.js
CHANGED
|
@@ -114,6 +114,16 @@ function getEpochMillis() {
|
|
|
114
114
|
return Date.now()
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Coverts a unix timestamp to an ISO-8601 date string.
|
|
119
|
+
*
|
|
120
|
+
* @param {number} timestamp A unix timestamp
|
|
121
|
+
* @returns String ISO-8601 formatted date
|
|
122
|
+
*/
|
|
123
|
+
function unixTimestampToDate(timestamp) {
|
|
124
|
+
return (new Date(timestamp * 1000)).toISOString()
|
|
125
|
+
}
|
|
126
|
+
|
|
117
127
|
|
|
118
128
|
|
|
119
129
|
/**
|
|
@@ -192,11 +202,11 @@ async function streamToBuffer(readableStream) {
|
|
|
192
202
|
return new Promise((resolve, reject) => {
|
|
193
203
|
const chunks = [];
|
|
194
204
|
readableStream.on("data", (data) => {
|
|
195
|
-
|
|
205
|
+
|
|
196
206
|
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
|
|
197
207
|
});
|
|
198
208
|
readableStream.on("end", () => {
|
|
199
|
-
|
|
209
|
+
|
|
200
210
|
resolve(Buffer.concat(chunks));
|
|
201
211
|
});
|
|
202
212
|
readableStream.on("error", reject);
|
|
@@ -223,5 +233,6 @@ module.exports = {
|
|
|
223
233
|
toTitleCase,
|
|
224
234
|
toUpperSnakeCase,
|
|
225
235
|
unixTimestamp,
|
|
236
|
+
unixTimestampToDate,
|
|
226
237
|
writeFile
|
|
227
238
|
}
|
package/src/helpers.test.js
CHANGED
|
@@ -38,5 +38,12 @@ describe('helpers',()=> {
|
|
|
38
38
|
})
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
+
it('should return the correct date-time for a timestamp',() =>{
|
|
42
|
+
const timestamp = 1729396788;
|
|
43
|
+
const expectedOutput = '2024-10-20T03:59:48.000Z';
|
|
44
|
+
const convertedDate = helper.unixTimestampToDate(timestamp);
|
|
45
|
+
expect(convertedDate).toBe(expectedOutput);
|
|
46
|
+
})
|
|
47
|
+
|
|
41
48
|
})
|
|
42
49
|
|
package/src/jira.js
CHANGED