@elisra-devops/docgen-skins 0.3.3

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.
@@ -0,0 +1,5 @@
1
+ sonar.sources=src
2
+ sonar.language=typescript
3
+ # sonar.javascript.lcov.reportPaths=coverage\SonarQube.xml
4
+ # sonar.typescript.lcov.reportPaths=coverage\SonarQube.xml
5
+ sonar.coverageReportPaths=coverage/SonarQube.xml
@@ -0,0 +1,21 @@
1
+ name: "🚀 ci"
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ build_and_test:
7
+ name: 🚀 build and test
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: 📚 checkout
11
+ uses: actions/checkout@v2
12
+ - name: 🟢 node
13
+ uses: actions/setup-node@v2
14
+ with:
15
+ node-version: 14
16
+ registry-url: https://registry.npmjs.org
17
+ - run: npm install
18
+ - run: npm run build
19
+ env:
20
+ ORG_URL: ${{secrets.AZDO_ORG_URL}}
21
+ PAT: ${{secrets.AZDO_PAT}}
@@ -0,0 +1,31 @@
1
+ name: "🚀 publish"
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ release:
10
+ name: 🚀 publish
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: 📚 checkout
14
+ uses: actions/checkout@v2
15
+ - name: 🟢 node
16
+ uses: actions/setup-node@v2
17
+ with:
18
+ node-version: 14
19
+ registry-url: https://registry.npmjs.org
20
+ - run: npm install
21
+ - run: npm run build
22
+ - name: "Automated Version Bump"
23
+ uses: "phips28/gh-action-bump-version@master"
24
+ env:
25
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26
+ with:
27
+ commit-message: "CI: bumps version to {{version}} [skip ci]"
28
+ - name: 🚀 publish
29
+ run: npm publish --access public
30
+ env:
31
+ NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
package/Readme.md ADDED
@@ -0,0 +1,6 @@
1
+ # Skins for Docgen JSON
2
+
3
+ Can be outputed in various types:
4
+
5
+ - JSON - default
6
+ - HTML
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@elisra-devops/docgen-skins",
3
+ "version": "0.3.3",
4
+ "description": "Can be outputed in various types:",
5
+ "main": "./bin/index.js",
6
+ "types": "./bin/index.d.ts",
7
+ "scripts": {
8
+ "start": "node ./bin/server.js",
9
+ "build": "tsc",
10
+ "test": "jest --coverage --runInBand --forceExit"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": ""
15
+ },
16
+ "author": "",
17
+ "license": "ISC",
18
+ "dependencies": {
19
+ "@types/node": "^14.0.5",
20
+ "moment": "^2.26.0",
21
+ "string-strip-html": "^4.5.1",
22
+ "winston": "^3.2.1"
23
+ },
24
+ "devDependencies": {
25
+ "@types/babel__traverse": "^7.20.2",
26
+ "@types/jest": "^25.2.3",
27
+ "jest": "^25.5.4",
28
+ "jest-junit": "^10.0.0",
29
+ "ts-jest": "^25.5.1",
30
+ "typescript": "^5.2.2"
31
+ },
32
+ "jest": {
33
+ "testEnvironment": "node",
34
+ "preset": "ts-jest",
35
+ "testPathIgnorePatterns": [
36
+ "/bin/"
37
+ ],
38
+ "reporters": [
39
+ "default",
40
+ "jest-junit"
41
+ ]
42
+ },
43
+ "jest-junit": {
44
+ "output": "./junit.xml"
45
+ }
46
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "templatePath": "C:\\test\\test.dotx",
3
+ "contentControls": [
4
+ {
5
+ "title": "system-capabilities",
6
+ "wordObjects": [
7
+ {
8
+ "type": "table",
9
+ "rows": [
10
+ {
11
+ "cells": [
12
+ {
13
+ "attachments": {
14
+ "type": "picture",
15
+ "Path": "C:\\docgen\\documents\\181020205911\\downloads\\4b63f630-d0b4-4ab8-8d60-46df23b322c9\\gif 2.PNG"
16
+ }
17
+ }
18
+ ]
19
+ }
20
+ ]
21
+ }
22
+ ]
23
+ }
24
+ ]
25
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "templatePath": "C:\\dev\\test.dotx",
3
+ "contentControls": [
4
+ {
5
+ "title": "test",
6
+ "wordObjects": [
7
+ {
8
+ "type": "paragraph",
9
+ "runs": [
10
+ {
11
+ "text": "Test!",
12
+ "isBold": true,
13
+ "IsItalic": true,
14
+ "IsUnderline": true,
15
+ "Size": 9,
16
+ "Uri": "http://......",
17
+ "Font": "Arial",
18
+ "InsertLineBreak": true,
19
+ "InsertSpace": true
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "type": "table",
25
+ "Rows": [
26
+ {
27
+ "Cells": [
28
+ {
29
+ "Paragraphs": [
30
+ {
31
+ "Runs": [
32
+ {
33
+ "text": "Test!",
34
+ "isBold": true,
35
+ "IsItalic": true,
36
+ "IsUnderline": true,
37
+ "Size": 9,
38
+ "Uri": "http://......",
39
+ "Font": "Arial",
40
+ "InsertLineBreak": true,
41
+ "InsertSpace": true
42
+ }
43
+ ]
44
+ }
45
+ ]
46
+ }
47
+ ]
48
+ }
49
+ ]
50
+ },
51
+ {
52
+ "type": "file",
53
+ "Path": "c:\\temp\\...."
54
+ },
55
+ {
56
+ "type": "picture",
57
+ "Path": "c:\\temp\\...."
58
+ },
59
+ {
60
+ "type": "html",
61
+ "Html": "<html></html>"
62
+ }
63
+ ]
64
+ }
65
+ ]
66
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "type": "paragraph",
3
+ "runs": [
4
+ {
5
+ "text": "Test!",
6
+ "isBold": true,
7
+ "IsItalic": true,
8
+ "IsUnderline": true,
9
+ "Size": 9,
10
+ "Uri": "http://......",
11
+ "Font": "Arial",
12
+ "InsertLineBreak": true,
13
+ "InsertSpace": true
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "type": "table",
3
+ "Rows": [
4
+ {
5
+ "Cells": [
6
+ {
7
+ "Paragraphs": [
8
+ {
9
+ "Runs": [
10
+ //for every new property we need a new run
11
+ {
12
+ "text": "Test!",
13
+ "isBold": true,
14
+ "IsItalic": true,
15
+ "IsUnderline": true,
16
+ "Size": 9,
17
+ "Uri": "http://......",
18
+ "Font": "Arial",
19
+ "InsertLineBreak": true,
20
+ "InsertSpace": true
21
+ }
22
+ ]
23
+ }
24
+ ]
25
+ }
26
+ ]
27
+ }
28
+ ]
29
+ }
package/src/index.ts ADDED
@@ -0,0 +1,401 @@
1
+ import {
2
+ DocumentSkin,
3
+ WIQueryResults,
4
+ WIData,
5
+ WIProperty,
6
+ StyleOptions,
7
+ } from "./models/json/wordJsonModels";
8
+ import logger from "./services/logger";
9
+ import JSONTable from "./models/json/table/JSONTable";
10
+ import JSONParagraph from "./models/json/paragraph/JSONParagraph";
11
+ import JSONHeaderParagraph from "./models/json/paragraph/JSONTestSuiteHeaderParagraph";
12
+ import JSONRichTextParagraph from "./models/json/paragraph/JSONRichTextParagraph";
13
+ import {
14
+ DescriptionandProcedureStyle
15
+ } from "./models/json/default";
16
+
17
+ export default class Skins {
18
+ SKIN_TYPE_TABLE = "table";
19
+ SKIN_TYPE_PARAGRAPH = "paragraph";
20
+ SKIN_TYPE_TEST_PLAN = "test-plan";
21
+
22
+ documentSkin: DocumentSkin = {
23
+ templatePath: "",
24
+ contentControls: [],
25
+ };
26
+
27
+ skinFormat: string = "json";
28
+
29
+ constructor(skinFormat: string = "json", templatePath: string) {
30
+ this.documentSkin.templatePath = templatePath;
31
+ this.skinFormat = skinFormat;
32
+ }
33
+
34
+ async addNewContentToDocumentSkin(
35
+ contetnControlTitle: string,
36
+ skinType: string,
37
+ data: any,
38
+ styles: StyleOptions,
39
+ headingLvl: number = 0,
40
+ includeAttachments: boolean = true
41
+ ): Promise<any> {
42
+ try {
43
+ let populatedSkin;
44
+
45
+ switch (skinType) {
46
+ case this.SKIN_TYPE_TABLE:
47
+ populatedSkin = this.generateQueryBasedTable(
48
+ data,
49
+ styles,
50
+ headingLvl
51
+ );
52
+ if (populatedSkin === false) {
53
+ logger.error(
54
+ `Could not generate table for content control :${contetnControlTitle}`
55
+ );
56
+ return false;
57
+ }
58
+ break;
59
+ case this.SKIN_TYPE_PARAGRAPH:
60
+ populatedSkin = this.generateQueryBasedParagraphs(
61
+ data,
62
+ styles,
63
+ headingLvl
64
+ );
65
+ if (populatedSkin === false) {
66
+ logger.error(
67
+ `Could not generate paragraph for content control :${contetnControlTitle}`
68
+ );
69
+ return false;
70
+ }
71
+ break;
72
+ case this.SKIN_TYPE_TEST_PLAN:
73
+ populatedSkin = this.generateTestBasedSkin(
74
+ data,
75
+ styles,
76
+ headingLvl,
77
+ includeAttachments
78
+ );
79
+ if (populatedSkin === false) {
80
+ logger.error(
81
+ `Could not generate test skin for content control :${contetnControlTitle}`
82
+ );
83
+ return false;
84
+ }
85
+ break;
86
+ default:
87
+ logger.error(
88
+ `Unknown skinType : ${skinType} - not appended to document skin`
89
+ );
90
+ return false;
91
+ }
92
+
93
+ return populatedSkin;
94
+
95
+ // await this.validateAndAppendContentControl(
96
+ // contetnControlTitle,
97
+ // populatedSkin
98
+ // );
99
+ } catch (error) {
100
+ logger.error(
101
+ `Fatal error happened when generate skin for : ${contetnControlTitle}`
102
+ );
103
+ return false;
104
+ }
105
+ } //addNewContentToDocumentSkin
106
+
107
+ // iterates on content controls array:
108
+ // if finds return true else creates content control and returns true
109
+ // on error returns false
110
+ async validateAndAppendContentControl(
111
+ contetnControlTitle: string,
112
+ populatedSkin: any
113
+ ): Promise<boolean> {
114
+ try {
115
+ let isContetnControlExists: boolean[] = await Promise.all(
116
+ this.documentSkin.contentControls.map((contentControl, i) => {
117
+ if (contentControl.title === contetnControlTitle) {
118
+ logger.debug(`Content control - ${contetnControlTitle} found on index ${i}
119
+ populating with: ${contetnControlTitle}`);
120
+ this.documentSkin.contentControls[i].wordObjects = [
121
+ ...this.documentSkin.contentControls[i].wordObjects,
122
+ ...populatedSkin,
123
+ ];
124
+ return true;
125
+ }
126
+ return false;
127
+ }) //.map
128
+ ); //Promise.all
129
+
130
+ if (!isContetnControlExists.includes(true)) {
131
+ let contentControlToAppend = {
132
+ title: contetnControlTitle,
133
+ wordObjects: populatedSkin,
134
+ };
135
+
136
+ logger.debug(`Content control - ${contetnControlTitle} not found
137
+ appending to document title:
138
+ ${JSON.stringify(contetnControlTitle)}`);
139
+ this.documentSkin.contentControls.unshift(contentControlToAppend);
140
+ }
141
+ logger.info(
142
+ `Appended new content control document: ${contetnControlTitle}`
143
+ );
144
+ return true;
145
+ } catch (error) {
146
+ logger.error(`Error validating and appending to content control`);
147
+ console.log(error);
148
+ }
149
+ } //validateAndAppendContentControl
150
+
151
+ //parses data to the class skin format and returns the parsed data
152
+ //returns false if supplied an invalid type or error occurd during parsing
153
+ generateQueryBasedTable(
154
+ data: WIQueryResults,
155
+ styles: StyleOptions,
156
+ headingLvl: number = 0
157
+ ) {
158
+ logger.debug(`Generating table as ${this.skinFormat}`);
159
+
160
+ switch (this.skinFormat) {
161
+ case "json":
162
+ let tableSkin = new JSONTable(data, styles, headingLvl);
163
+ return [tableSkin.getJSONTable()];
164
+ case "html":
165
+ logger.info(`Generating html table!`);
166
+ break;
167
+ default:
168
+ return false;
169
+ } //switch
170
+ } //generateTable
171
+
172
+ generateQueryBasedParagraphs(
173
+ data: any,
174
+ styles: StyleOptions,
175
+ headingLvl: number = 0
176
+ ) {
177
+ logger.debug(`Generating paragraph as ${this.skinFormat}`);
178
+
179
+ switch (this.skinFormat) {
180
+ case "json":
181
+ let paragraphs: any[] = [];
182
+ data.forEach((wi: WIData) => {
183
+ wi.fields.forEach((field: WIProperty) => {
184
+ //Description and Test Description are handled in richText handler
185
+ if (
186
+ field.name === "Description: " ||
187
+ field.name === "Test Description:"
188
+ ) {
189
+ let paragraphSkin = new JSONRichTextParagraph(
190
+ field,
191
+ styles,
192
+ wi.Source,
193
+ headingLvl + wi.level
194
+ );
195
+ paragraphs.push(paragraphSkin.getJSONRichTextParagraph());
196
+ }
197
+
198
+ //making sure ID is not printed
199
+ //excluding Description and Test Description are handled in richText handler
200
+ if (
201
+ field.name !== "ID" &&
202
+ field.name !== "Description: " &&
203
+ field.name !== "Test Description:"
204
+ ) {
205
+ let paragraphSkin = new JSONParagraph(
206
+ field,
207
+ styles,
208
+ wi.Source,
209
+ headingLvl + wi.level
210
+ );
211
+ paragraphs.push(paragraphSkin.getJSONParagraph());
212
+ }
213
+ });
214
+ });
215
+ return paragraphs;
216
+ case "html":
217
+ logger.info(`Generating html paragraphs!`);
218
+ break;
219
+ default:
220
+ return false;
221
+ } //switch
222
+ } //generateParagraph
223
+
224
+ generateTestBasedSkin(
225
+ data: any,
226
+ styles: StyleOptions,
227
+ headingLvl: number = 0,
228
+ includeAttachments: boolean = true
229
+ ) {
230
+ logger.debug(`Generating testSkin as ${this.skinFormat}`);
231
+ switch (this.skinFormat) {
232
+ case "json":
233
+ let testSkin: any[] = [];
234
+ //create suite Header pragraph
235
+ data.forEach((testSuite: any) => {
236
+ let SuiteStyles = {
237
+ isBold: true,
238
+ IsItalic: false,
239
+ IsUnderline: false,
240
+ Size: 16,
241
+ Uri: null,
242
+ Font: "Arial",
243
+ InsertLineBreak: false,
244
+ InsertSpace: true,
245
+ };
246
+ let testSuiteParagraphSkin = new JSONHeaderParagraph(
247
+ testSuite.suiteSkinData.fields,
248
+ SuiteStyles,
249
+ testSuite.suiteSkinData.id || 0,
250
+ testSuite.suiteSkinData.level
251
+ ? headingLvl + testSuite.suiteSkinData.level
252
+ : headingLvl
253
+ ? headingLvl
254
+ : 1
255
+ );
256
+ testSkin.push(testSuiteParagraphSkin.getJSONParagraph());
257
+
258
+ testSuite.testCases.forEach((testcase) => {
259
+ //create testcase Header paragraph
260
+ let testCaseHeaderFields = [
261
+ testcase.testCaseHeaderSkinData.fields[0],
262
+ testcase.testCaseHeaderSkinData.fields[1],
263
+ ];
264
+ let TestCaseStyles = {
265
+ isBold: true,
266
+ IsItalic: false,
267
+ IsUnderline: false,
268
+ Size: 14,
269
+ Uri: null,
270
+ Font: "Arial",
271
+ InsertLineBreak: false,
272
+ InsertSpace: true,
273
+ };
274
+ let testCaseParagraphSkin = new JSONHeaderParagraph(
275
+ testCaseHeaderFields,
276
+ TestCaseStyles,
277
+ testcase.id || 0,
278
+ testcase.testCaseHeaderSkinData.level
279
+ ? headingLvl + testcase.testCaseHeaderSkinData.level
280
+ : headingLvl
281
+ ? headingLvl
282
+ : 1
283
+ );
284
+ testSkin.push(testCaseParagraphSkin.getJSONParagraph());
285
+
286
+ let testDescriptionTitleParagraph = new JSONParagraph(
287
+ { name: "Title", value: "Test Description:" },
288
+ DescriptionandProcedureStyle,
289
+ testcase.id || 0,
290
+ 0
291
+ );
292
+ testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
293
+ let testDescriptionParagraph = new JSONRichTextParagraph(
294
+ testcase.testCaseHeaderSkinData.fields[2],
295
+ styles,
296
+ testcase.id || 0,
297
+ 0
298
+ );
299
+ let richTextSkin: any[] =
300
+ testDescriptionParagraph.getJSONRichTextParagraph();
301
+ testSkin = [...testSkin, ...richTextSkin];
302
+
303
+ if (testcase.testCaseRequirements) {
304
+ if (
305
+ testcase.testCaseRequirements.length > 0
306
+ ) {
307
+
308
+ let testDescriptionTitleParagraph = new JSONParagraph(
309
+ { name: "Title", value: "Covered Requirements:" },
310
+ DescriptionandProcedureStyle,
311
+ testcase.id || 0,
312
+ 0
313
+ );
314
+ testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
315
+ //create test steps table
316
+ let tableSkin = new JSONTable(
317
+ testcase.testCaseRequirements,
318
+ styles,
319
+ headingLvl
320
+ );
321
+
322
+ let populatedTableSkin = tableSkin.getJSONTable();
323
+
324
+ testSkin.push(populatedTableSkin);
325
+ }
326
+ }
327
+
328
+ try {
329
+ if (testcase.testCaseStepsSkinData.length > 0) {
330
+ let testProcedureTitleParagraph = new JSONParagraph(
331
+ { name: "Title", value: "Test Procedure:" },
332
+ DescriptionandProcedureStyle,
333
+ testcase.id || 0,
334
+ 0
335
+ );
336
+ let TableContentStyles = {
337
+ isBold: false,
338
+ IsItalic: false,
339
+ IsUnderline: false,
340
+ Size: 12,
341
+ Uri: null,
342
+ Font: "Arial",
343
+ InsertLineBreak: false,
344
+ InsertSpace: true,
345
+ };
346
+ testSkin.push(testProcedureTitleParagraph.getJSONParagraph());
347
+ //create test steps table
348
+ let tableSkin = new JSONTable(
349
+ testcase.testCaseStepsSkinData,
350
+ TableContentStyles,
351
+ headingLvl
352
+ );
353
+ let populatedTableSkin = tableSkin.getJSONTable();
354
+ testSkin.push(populatedTableSkin);
355
+ }
356
+ } catch (error) {
357
+ logger.warn(
358
+ `For suite id : ${testSuite.suiteSkinData.fields[0].value} , the testCaseStepsSkinData is not defined for ${testcase.testCaseHeaderSkinData.fields[0].value} `
359
+ );
360
+ }
361
+
362
+ //attachments table
363
+ if (testcase.testCaseAttachments) {
364
+ if (
365
+ testcase.testCaseAttachments.length > 0 &&
366
+ includeAttachments == true
367
+ ) {
368
+
369
+ let testDescriptionTitleParagraph = new JSONParagraph(
370
+ { name: "Title", value: "Test Case Attachments:" },
371
+ styles,
372
+ testcase.id || 0,
373
+ 0
374
+ );
375
+ testSkin.push(testDescriptionTitleParagraph.getJSONParagraph());
376
+ //create test steps table
377
+ let tableSkin = new JSONTable(
378
+ testcase.testCaseAttachments,
379
+ styles,
380
+ headingLvl
381
+ );
382
+ let populatedTableSkin = tableSkin.getJSONTable();
383
+ testSkin.push(populatedTableSkin);
384
+ }
385
+ }
386
+ });
387
+ });
388
+ return testSkin;
389
+ break;
390
+ case "html":
391
+ logger.info(`Generating html test data!`);
392
+ break;
393
+ default:
394
+ return false;
395
+ } //switch
396
+ } //generateTestBasedSkin
397
+
398
+ getDocumentSkin(): DocumentSkin {
399
+ return this.documentSkin;
400
+ } //getDocumentSkin
401
+ }