@beauraines/node-helpers 5.0.0 → 5.1.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 +7 -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 +2 -2
- package/src/jira.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.1.0](https://github.com/beauraines/node-helpers/compare/v5.0.0...v5.1.0) (2024-10-16)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* adds cli argument module ([#155](https://github.com/beauraines/node-helpers/issues/155)) ([b7943b6](https://github.com/beauraines/node-helpers/commit/b7943b6cf55a221ecc1a55afec2ab9505ed88347))
|
|
11
|
+
|
|
5
12
|
## [5.0.0](https://github.com/beauraines/node-helpers/compare/v4.3.0...v5.0.0) (2024-10-14)
|
|
6
13
|
|
|
7
14
|
|
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
|
@@ -192,11 +192,11 @@ async function streamToBuffer(readableStream) {
|
|
|
192
192
|
return new Promise((resolve, reject) => {
|
|
193
193
|
const chunks = [];
|
|
194
194
|
readableStream.on("data", (data) => {
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
|
|
197
197
|
});
|
|
198
198
|
readableStream.on("end", () => {
|
|
199
|
-
|
|
199
|
+
|
|
200
200
|
resolve(Buffer.concat(chunks));
|
|
201
201
|
});
|
|
202
202
|
readableStream.on("error", reject);
|
package/src/jira.js
CHANGED