orc-scripts 4.0.4 → 4.0.7
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/package.json +1 -1
- package/src/scripts/generateApi.js +66 -39
- package/src/scripts/generateWindowsZone.js +101 -0
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ const lodash = require("lodash");
|
|
|
5
5
|
const occUrl = process.env.OccUrl;
|
|
6
6
|
const occToken = process.env.OccToken;
|
|
7
7
|
let outputFile = "";
|
|
8
|
+
let requestsFile = "";
|
|
8
9
|
|
|
9
10
|
if (process.argv.includes("--outputFile")) {
|
|
10
11
|
outputFile = process.argv[process.argv.indexOf("--outputFile") + 1];
|
|
@@ -14,6 +15,10 @@ if (!outputFile) {
|
|
|
14
15
|
throw new Error("Missing --outputFile 'file' argument.");
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
if (process.argv.includes("--requestsFile")) {
|
|
19
|
+
requestsFile = process.argv[process.argv.indexOf("--requestsFile") + 1];
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
if (!occToken) {
|
|
18
23
|
throw new Error(
|
|
19
24
|
"Missing OccToken environment variable. This environment variable needs to contains the authentication token used to access the OCC platform specified in OccUrl.",
|
|
@@ -40,7 +45,7 @@ function isVerbAllowed(verb) {
|
|
|
40
45
|
return lowerCaseVerb === "get" || lowerCaseVerb === "post" || lowerCaseVerb === "put" || lowerCaseVerb === "delete";
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
function generateOperationsFromPath(url, pathData) {
|
|
48
|
+
function generateOperationsFromPath(url, pathData, desiredRequests) {
|
|
44
49
|
const operations = [];
|
|
45
50
|
|
|
46
51
|
for (const verb of Object.getOwnPropertyNames(pathData)) {
|
|
@@ -50,8 +55,15 @@ function generateOperationsFromPath(url, pathData) {
|
|
|
50
55
|
|
|
51
56
|
const operation = pathData[verb];
|
|
52
57
|
|
|
58
|
+
const operationName = extractRequestNameFromOperation(operation);
|
|
59
|
+
|
|
60
|
+
const shouldAddOperation = desiredRequests == null || desiredRequests.includes(operationName.toLowerCase());
|
|
61
|
+
if( !shouldAddOperation ){
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
53
65
|
operations.push({
|
|
54
|
-
name:
|
|
66
|
+
name: operationName,
|
|
55
67
|
url: url,
|
|
56
68
|
verb: verb.toUpperCase(),
|
|
57
69
|
hasQueryString: operation.parameters.filter(p => p.in === "query").length > 0,
|
|
@@ -102,51 +114,66 @@ function generateImports() {
|
|
|
102
114
|
return 'import { buildUrl } from "../utils/buildUrl";\n\n';
|
|
103
115
|
}
|
|
104
116
|
|
|
105
|
-
|
|
106
|
-
.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (resp.statusCode !== 200) {
|
|
111
|
-
error = new Error(`Request Failed. Status Code: ${resp.statusCode}`);
|
|
112
|
-
}
|
|
113
|
-
if (error) {
|
|
114
|
-
console.error(error.message);
|
|
115
|
-
// Consume response data to free up memory
|
|
116
|
-
resp.resume();
|
|
117
|
-
return;
|
|
117
|
+
if (requestsFile) {
|
|
118
|
+
fs.readFile(requestsFile, 'utf-8', (err, data) => {
|
|
119
|
+
if (err) {
|
|
120
|
+
return console.error(err);
|
|
118
121
|
}
|
|
122
|
+
const desiredRequests = data.split("\n").map(d => d.trim().toLowerCase());
|
|
123
|
+
generate(desiredRequests);
|
|
124
|
+
})
|
|
125
|
+
}else {
|
|
126
|
+
generate(null);
|
|
127
|
+
}
|
|
119
128
|
|
|
120
|
-
// A chunk of data has been received.
|
|
121
|
-
resp.on("data", chunk => {
|
|
122
|
-
data += chunk;
|
|
123
|
-
});
|
|
124
129
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let
|
|
130
|
+
function generate(desiredRequests) {
|
|
131
|
+
https
|
|
132
|
+
.get(occUrl, { headers: { "X-AUTH": occToken } }, resp => {
|
|
133
|
+
let data = "";
|
|
134
|
+
let error = "";
|
|
130
135
|
|
|
131
|
-
|
|
132
|
-
|
|
136
|
+
if (resp.statusCode !== 200) {
|
|
137
|
+
error = new Error(`Request Failed. Status Code: ${resp.statusCode}`);
|
|
138
|
+
}
|
|
139
|
+
if (error) {
|
|
140
|
+
console.error(error.message);
|
|
141
|
+
// Consume response data to free up memory
|
|
142
|
+
resp.resume();
|
|
143
|
+
return;
|
|
133
144
|
}
|
|
134
145
|
|
|
135
|
-
|
|
136
|
-
|
|
146
|
+
// A chunk of data has been received.
|
|
147
|
+
resp.on("data", chunk => {
|
|
148
|
+
data += chunk;
|
|
149
|
+
});
|
|
137
150
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
// The whole response has been received. Print out the result.
|
|
152
|
+
resp.on("end", () => {
|
|
153
|
+
const swaggerMetaData = JSON.parse(data);
|
|
154
|
+
const paths = swaggerMetaData.paths;
|
|
155
|
+
let operations = [];
|
|
156
|
+
|
|
157
|
+
for (const url of Object.getOwnPropertyNames(paths)) {
|
|
158
|
+
operations = operations.concat(generateOperationsFromPath(url, paths[url], desiredRequests));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let helperData = "/* istanbul ignore file */\n\n";
|
|
162
|
+
helperData += generateImports();
|
|
141
163
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return console.error(err);
|
|
164
|
+
for (const op of lodash.sortBy(operations, [o => o.name])) {
|
|
165
|
+
helperData += generateOperation(op);
|
|
145
166
|
}
|
|
146
|
-
|
|
167
|
+
|
|
168
|
+
fs.writeFile(outputFile, helperData, function (err) {
|
|
169
|
+
if (err) {
|
|
170
|
+
return console.error(err);
|
|
171
|
+
}
|
|
172
|
+
console.log(`File '${outputFile}' has been created`);
|
|
173
|
+
});
|
|
147
174
|
});
|
|
175
|
+
})
|
|
176
|
+
.on("error", err => {
|
|
177
|
+
console.log("Error: " + err.message);
|
|
148
178
|
});
|
|
149
|
-
|
|
150
|
-
.on("error", err => {
|
|
151
|
-
console.log("Error: " + err.message);
|
|
152
|
-
});
|
|
179
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const https = require("https");
|
|
3
|
+
const jsdom = require("jsdom");
|
|
4
|
+
|
|
5
|
+
let outputFile = "";
|
|
6
|
+
let windowsZonesUrl = "";
|
|
7
|
+
|
|
8
|
+
if (process.argv.includes("--outputFile")) {
|
|
9
|
+
outputFile = process.argv[process.argv.indexOf("--outputFile") + 1];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!outputFile) {
|
|
13
|
+
throw new Error("Missing --outputFile 'file' argument.");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (process.argv.includes("--windowsZonesUrl")) {
|
|
17
|
+
windowsZonesUrl = process.argv[process.argv.indexOf("--windowsZonesUrl") + 1];
|
|
18
|
+
} else {
|
|
19
|
+
windowsZonesUrl =
|
|
20
|
+
"https://raw.githubusercontent.com/unicode-org/cldr/refs/heads/main/common/supplemental/windowsZones.xml";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
downloadUrl();
|
|
24
|
+
|
|
25
|
+
function extractTimeZones(timeZones) {
|
|
26
|
+
const result = {
|
|
27
|
+
ianaToWindows: {},
|
|
28
|
+
windowsToIana: {},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const dom = new jsdom.JSDOM(timeZones);
|
|
32
|
+
const parser = new dom.window.DOMParser();
|
|
33
|
+
|
|
34
|
+
const xmlDoc = parser.parseFromString(timeZones, "application/xml");
|
|
35
|
+
const mapZones = xmlDoc.getElementsByTagName("mapZone");
|
|
36
|
+
|
|
37
|
+
for (let zone of mapZones) {
|
|
38
|
+
const key = zone.getAttribute("other");
|
|
39
|
+
const type = zone.getAttribute("type");
|
|
40
|
+
|
|
41
|
+
if (!result.windowsToIana[key]) {
|
|
42
|
+
result.windowsToIana[key] = [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const types = type.split(" ");
|
|
46
|
+
|
|
47
|
+
for (let t of types) {
|
|
48
|
+
if (!result.windowsToIana[key].includes(t)) {
|
|
49
|
+
result.windowsToIana[key].push(t);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!result.ianaToWindows[t]) {
|
|
53
|
+
result.ianaToWindows[t] = [];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!result.ianaToWindows[t].includes(key)) {
|
|
57
|
+
result.ianaToWindows[t].push(key);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function downloadUrl() {
|
|
66
|
+
https
|
|
67
|
+
.get(windowsZonesUrl, {}, resp => {
|
|
68
|
+
let data = "";
|
|
69
|
+
let error = "";
|
|
70
|
+
|
|
71
|
+
if (resp.statusCode !== 200) {
|
|
72
|
+
error = new Error(`Request Failed. Status Code: ${resp.statusCode}`);
|
|
73
|
+
}
|
|
74
|
+
if (error) {
|
|
75
|
+
console.error(error.message);
|
|
76
|
+
// Consume response data to free up memory
|
|
77
|
+
resp.resume();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// A chunk of data has been received.
|
|
82
|
+
resp.on("data", chunk => {
|
|
83
|
+
data += chunk;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// The whole response has been received. Print out the result.
|
|
87
|
+
resp.on("end", () => {
|
|
88
|
+
const result = extractTimeZones(data);
|
|
89
|
+
|
|
90
|
+
fs.writeFile(outputFile, JSON.stringify(result, null, 2), function (err) {
|
|
91
|
+
if (err) {
|
|
92
|
+
return console.error(err);
|
|
93
|
+
}
|
|
94
|
+
console.log(`File '${outputFile}' has been created`);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
})
|
|
98
|
+
.on("error", err => {
|
|
99
|
+
console.log("Error: " + err.message);
|
|
100
|
+
});
|
|
101
|
+
}
|