powerbi-visuals-tools 4.0.4 → 4.0.6

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.
Files changed (50) hide show
  1. package/Changelog.md +8 -0
  2. package/certs/PowerBICustomVisualTest_private.key +28 -0
  3. package/certs/PowerBICustomVisualTest_public.crt +19 -0
  4. package/config.json +35 -1
  5. package/lib/VisualGenerator.js +0 -95
  6. package/package.json +3 -3
  7. package/spec/.jshintrc +5 -0
  8. package/spec/clean-tests.js +31 -0
  9. package/spec/e2e/pbivizCertSpec.js +56 -0
  10. package/spec/e2e/pbivizInfoSpec.js +82 -0
  11. package/spec/e2e/pbivizNewSpec.js +265 -0
  12. package/spec/e2e/pbivizPackageSpec.js +670 -0
  13. package/spec/e2e/pbivizStartSpec.js +380 -0
  14. package/spec/e2e/pbivizWebpackVerSpec.js +102 -0
  15. package/spec/e2e/utils.js +63 -0
  16. package/spec/helpers/FileSystem.js +173 -0
  17. package/spec/jasmine-runner.js +36 -0
  18. package/spec/support/jasmine.json +11 -0
  19. package/templates/visuals/default/capabilities.json +2 -7
  20. package/templates/visuals/default/package.json +2 -2
  21. package/templates/visuals/default/pbiviz.json +1 -1
  22. package/templates/visuals/default/src/settings.ts +54 -3
  23. package/templates/visuals/default/src/visual.ts +14 -17
  24. package/templates/visuals/rhtml/capabilities.json +2 -1
  25. package/templates/visuals/rhtml/package.json +2 -2
  26. package/templates/visuals/rhtml/pbiviz.json +1 -1
  27. package/templates/visuals/rhtml/src/settings.ts +28 -3
  28. package/templates/visuals/rhtml/src/visual.ts +29 -23
  29. package/templates/visuals/rvisual/capabilities.json +2 -1
  30. package/templates/visuals/rvisual/package.json +2 -2
  31. package/templates/visuals/rvisual/pbiviz.json +1 -1
  32. package/templates/visuals/rvisual/src/settings.ts +28 -3
  33. package/templates/visuals/rvisual/src/visual.ts +13 -15
  34. package/templates/visuals/slicer/capabilities.json +2 -1
  35. package/templates/visuals/slicer/package.json +2 -2
  36. package/templates/visuals/slicer/pbiviz.json +1 -1
  37. package/templates/visuals/slicer/src/settings.ts +29 -3
  38. package/templates/visuals/slicer/src/visual.ts +14 -17
  39. package/templates/visuals/table/capabilities.json +2 -1
  40. package/templates/visuals/table/package.json +2 -2
  41. package/templates/visuals/table/pbiviz.json +1 -1
  42. package/templates/visuals/table/src/settings.ts +23 -3
  43. package/templates/visuals/table/src/visual.ts +18 -16
  44. package/.eslintrc.json +0 -313
  45. package/.gitattributes +0 -4
  46. package/.github/workflows/build.yml +0 -32
  47. package/.github/workflows/codeql-analysis.yml +0 -54
  48. package/.snyk +0 -4
  49. package/.vscode/launch.json +0 -74
  50. package/.vscode/settings.json +0 -3
@@ -0,0 +1,380 @@
1
+ /*
2
+ * Power BI Visual CLI
3
+ *
4
+ * Copyright (c) Microsoft Corporation
5
+ * All rights reserved.
6
+ * MIT License
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the ""Software""), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ "use strict";
28
+
29
+ const fs = require('fs-extra');
30
+ const path = require('path');
31
+ const async = require('async');
32
+ const FileSystem = require('../helpers/FileSystem.js');
33
+ const writeMetadata = require("./utils").writeMetadata;
34
+ const download = require("../../lib/utils").download;
35
+ const createFolder = require("../../lib/utils").createFolder;
36
+
37
+ const tempPath = FileSystem.getTempPath();
38
+ const startPath = process.cwd();
39
+
40
+ // these tests can take a bit longer
41
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 180000;
42
+
43
+ let startChecker = (proc) => new Promise((resolve) => {
44
+ proc.stdout.on('data', (data) => {
45
+ let dataStr = (data.toString()).toLowerCase();
46
+ if ((dataStr.indexOf("compiled") !== -1 && dataStr.indexOf("successfully") !== -1) || dataStr.match(/Compiled with\s*(\d)* warnings/) !== null) {
47
+ resolve();
48
+ }
49
+ });
50
+ });
51
+
52
+ let procKiller = (proc, done) => {
53
+ FileSystem.killProcess(proc, 'SIGTERM', (error) => {
54
+ expect(error).toBeNull();
55
+ done();
56
+ });
57
+ };
58
+
59
+ describe("E2E - pbiviz start", () => {
60
+ const visualName = 'visualname';
61
+ const visualPath = path.join(tempPath, visualName);
62
+ const tmpPath = path.join(visualPath, '.tmp');
63
+ const dropPath = path.join(tmpPath, 'drop');
64
+ const assetFiles = ['visual.js', 'visual.css', 'pbiviz.json', 'status'];
65
+
66
+ beforeEach(() => {
67
+ FileSystem.resetTempDirectory();
68
+ process.chdir(tempPath);
69
+ FileSystem.runPbiviz('new', visualName, '--force');
70
+ FileSystem.runCMDCommand('npm i', visualPath, tempPath);
71
+
72
+ writeMetadata(visualPath);
73
+ });
74
+
75
+ afterEach(() => {
76
+ process.chdir(startPath);
77
+ });
78
+
79
+ afterAll(() => {
80
+ process.chdir(startPath);
81
+ FileSystem.deleteTempDirectory();
82
+ });
83
+
84
+ xit("Should throw error if not in the visual root", () => {
85
+ let error;
86
+
87
+ try {
88
+ FileSystem.runPbiviz('start', "-d");
89
+ } catch (e) {
90
+ error = e;
91
+ }
92
+ expect(error).toBeDefined();
93
+ expect(error.status).toBe(1);
94
+ expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command");
95
+ });
96
+
97
+ describe("Build and Server", () => {
98
+ let pbivizProc;
99
+
100
+ beforeEach(() => {
101
+ process.chdir(visualPath);
102
+ pbivizProc = FileSystem.runPbivizAsync("start", "-d");
103
+ });
104
+
105
+ it("Should build visual and generate resources in drop folder", (done) => {
106
+ let visualConfig = fs.readJsonSync(path.join(visualPath, 'pbiviz.json')).visual;
107
+ let visualCapabilities = fs.readJsonSync(path.join(visualPath, 'capabilities.json'));
108
+ startChecker(pbivizProc).then(() => {
109
+ //check files on filesystem
110
+ expect(fs.statSync(dropPath).isDirectory()).toBe(true);
111
+ try {
112
+ assetFiles.forEach(file => {
113
+ let filePath = path.join(dropPath, file);
114
+ expect(fs.statSync(filePath).isFile()).toBe(true);
115
+ });
116
+ } catch (error) {
117
+ expect(error).toBeNull();
118
+ }
119
+ //check metadata
120
+ let pbivizPath = path.join(dropPath, 'pbiviz.json');
121
+ let pbiviz = fs.readJsonSync(pbivizPath);
122
+ //should append "_DEBUG" to guid to avoid collisions
123
+ visualConfig.guid += "_DEBUG";
124
+ expect(pbiviz.visual).toEqual(visualConfig);
125
+ expect(pbiviz.capabilities).toEqual(visualCapabilities);
126
+ expect(pbiviz.content.js).toBeDefined();
127
+ expect(pbiviz.content.css).toBeDefined();
128
+ expect(pbiviz.content.iconBase64).toBeDefined();
129
+ procKiller(pbivizProc, done);
130
+ });
131
+ });
132
+
133
+
134
+ it("Should serve files from drop folder on port 8080", (done) => {
135
+ startChecker(pbivizProc).then(() => {
136
+ async.each(
137
+ assetFiles,
138
+ (file, next) => {
139
+ let errorMessage = `error in request to "${file}" response,`;
140
+ let filePath = path.join(dropPath, file);
141
+ let testFolder = createFolder("./testFolder");
142
+ let testFile = path.join(testFolder, file);
143
+ const options = {
144
+ host: 'localhost',
145
+ hostname: 'localhost',
146
+ port: 8080,
147
+ path: '/assets/' + file,
148
+ method: 'GET',
149
+ rejectUnauthorized: false
150
+ };
151
+
152
+ download(options, testFile)
153
+ .then(() => {
154
+ let downloadedBody = fs.existsSync(testFile) ? fs.readFileSync(testFile).toString() : null;
155
+ let comparisonBody = fs.existsSync(filePath) ? fs.readFileSync(filePath).toString() : null;
156
+ expect(downloadedBody).withContext(`${errorMessage} body`).toBe(comparisonBody);
157
+ next();
158
+ })
159
+ .catch((error) => {
160
+ expect(error).toBeNull();
161
+ next(`request to "${file}" error.`);
162
+ });
163
+ },
164
+ error => {
165
+ if (error) {
166
+ procKiller(pbivizProc, done);
167
+ } else {
168
+ procKiller(pbivizProc, done);
169
+ }
170
+ }
171
+ );
172
+ });
173
+ });
174
+
175
+
176
+ // TODO rewrite this UT because build sequence is different
177
+ xit("Should rebuild files on change and update status", (done) => {
178
+ let statusPath = path.join(dropPath, 'status');
179
+ let lastStatus;
180
+ let tsChangeCount = 0;
181
+ let lessChangeCount = 0;
182
+ let jsonChangeCount = 0;
183
+
184
+ function getStatus() {
185
+ return fs.readFileSync(statusPath);
186
+ }
187
+
188
+ let callbackCalled = false;
189
+ pbivizProc.stdout.on('data', (data) => {
190
+ let dataStr = data.toString();
191
+ if (dataStr.indexOf("Compiled successfully") !== -1 || dataStr.match(/Compiled with\s*(\d)* warnings/) !== null) {
192
+ if (callbackCalled) {
193
+ return;
194
+ }
195
+ callbackCalled = true;
196
+ expect(tsChangeCount).toBe(0);
197
+ expect(lessChangeCount).toBe(0);
198
+ expect(jsonChangeCount).toBe(0);
199
+ lastStatus = getStatus();
200
+
201
+ //trigger ts change
202
+ let tsSrcPath = path.join(visualPath, 'src/visual.ts');
203
+ fs.appendFileSync(tsSrcPath, '// appended to ts file');
204
+ }
205
+
206
+ if (dataStr.indexOf('Visual rebuild completed') !== -1) {
207
+ tsChangeCount++;
208
+ expect(tsChangeCount).toBe(1);
209
+ expect(lessChangeCount).toBe(0);
210
+ expect(jsonChangeCount).toBe(0);
211
+ let status = getStatus();
212
+ expect(status).not.toBe(lastStatus);
213
+ lastStatus = status;
214
+
215
+ //trigger less change
216
+ let lessSrcPath = path.join(visualPath, 'style/visual.less');
217
+ fs.appendFileSync(lessSrcPath, '/* appended to less file */');
218
+ }
219
+
220
+ if (dataStr.indexOf('Less build complete') !== -1) {
221
+ lessChangeCount++;
222
+ expect(tsChangeCount).toBe(1);
223
+ expect(lessChangeCount).toBe(1);
224
+ expect(jsonChangeCount).toBe(0);
225
+ let status = getStatus();
226
+ expect(status).not.toBe(lastStatus);
227
+ lastStatus = status;
228
+
229
+ //trigger json change
230
+ let capabilitiesPath = path.join(visualPath, 'capabilities.json');
231
+ let visualCapabilities = fs.readJsonSync(capabilitiesPath);
232
+ visualCapabilities.dataRoles.pop();
233
+ fs.writeJsonSync(capabilitiesPath, visualCapabilities);
234
+ }
235
+
236
+ if (dataStr.indexOf('JSON build complete') !== -1) {
237
+ jsonChangeCount++;
238
+ expect(tsChangeCount).toBe(1);
239
+ expect(lessChangeCount).toBe(1);
240
+ expect(jsonChangeCount).toBe(1);
241
+ let status = getStatus();
242
+ expect(status).not.toBe(lastStatus);
243
+ lastStatus = status;
244
+
245
+ //the end
246
+ FileSystem.killProcess(pbivizProc, 'SIGTERM', (error) => {
247
+ expect(error).toBeNull();
248
+ done();
249
+ });
250
+ }
251
+ });
252
+ });
253
+ });
254
+
255
+ // custom port wans't implemented in new tools
256
+ xit("Should serve files from drop folder on custom port with -p flag", (done) => {
257
+ process.chdir(visualPath);
258
+ let pbivizProc = FileSystem.runPbivizAsync('start', ['-p', '3333']);
259
+ pbivizProc.stderr.on('data', (data) => {
260
+ if (data.toString().indexOf("DeprecationWarning") === -1) {
261
+ throw new Error(data.toString());
262
+ }
263
+ });
264
+ let callbackCalled = false;
265
+ pbivizProc.stdout.on('data', (data) => {
266
+ let dataStr = data.toString();
267
+
268
+ if (dataStr.indexOf("Compiled successfully") !== -1 || dataStr.match(/Compiled with\s*(\d)* warnings/) !== null) {
269
+ if (callbackCalled) {
270
+ return;
271
+ }
272
+ callbackCalled = true;
273
+ async.each(
274
+ assetFiles,
275
+ (file, next) => {
276
+ let filePath = path.join(dropPath, file);
277
+ request({
278
+ url: 'https://localhost:3333/assets/' + file,
279
+ //allow self signed cert
280
+ strictSSL: false
281
+ }, (error, response, body) => {
282
+ expect(error).toBeNull();
283
+ expect(response.statusCode).toBe(200);
284
+ expect(body).toBe(fs.readFileSync(filePath).toString());
285
+ next();
286
+ });
287
+ },
288
+ error => {
289
+ if (error) { throw error; }
290
+ FileSystem.killProcess(pbivizProc, 'SIGTERM', (error) => {
291
+ expect(error).toBeNull();
292
+ done();
293
+ });
294
+ }
295
+ );
296
+
297
+ }
298
+ });
299
+ });
300
+
301
+ });
302
+
303
+ describe("E2E - pbiviz start for R Visuals", () => {
304
+
305
+ let visualName = 'visualname';
306
+ let visualPath = path.join(tempPath, visualName);
307
+ let dropPath = path.join(visualPath, '.tmp', 'drop');
308
+
309
+ beforeEach(() => {
310
+ FileSystem.resetTempDirectory();
311
+ process.chdir(tempPath);
312
+ FileSystem.runPbiviz('new', visualName, '--template rvisual');
313
+ });
314
+
315
+ afterEach(() => {
316
+ process.chdir(startPath);
317
+ });
318
+
319
+ afterAll(() => {
320
+ process.chdir(startPath);
321
+ FileSystem.deleteTempDirectory();
322
+ });
323
+
324
+ // todo check R visuals build
325
+ xdescribe("Build and Server for R Visuals", () => {
326
+ let pbivizProc;
327
+
328
+ beforeEach(() => {
329
+ process.chdir(visualPath);
330
+ FileSystem.runCMDCommand('npm i', visualPath);
331
+ pbivizProc = FileSystem.runPbivizAsync('start');
332
+ pbivizProc.stderr.on('data', (data) => {
333
+ if (data.toString().indexOf("DeprecationWarning") === -1) {
334
+ throw new Error(data.toString());
335
+ }
336
+ });
337
+ });
338
+
339
+ it("Should rebuild files on change and update status for R Visuals", (done) => {
340
+ let statusPath = path.join(dropPath, 'status');
341
+ let lastStatus;
342
+ let rChangeCount = 0;
343
+
344
+ function getStatus() {
345
+ return fs.readFileSync(statusPath);
346
+ }
347
+
348
+ let callbackCalled = false;
349
+ pbivizProc.stdout.on('data', (data) => {
350
+ let dataStr = data.toString();
351
+ if (dataStr.indexOf("Compiled successfully") !== -1 || dataStr.match(/Compiled with\s*(\d)* warnings/) !== null) {
352
+ if (callbackCalled) {
353
+ return;
354
+ }
355
+ callbackCalled = true;
356
+ expect(rChangeCount).toBe(0);
357
+ lastStatus = getStatus();
358
+
359
+ //trigger r change
360
+ let rScriptPath = path.join(visualPath, 'script.r');
361
+ fs.appendFileSync(rScriptPath, '// appended to R file');
362
+ }
363
+
364
+ if (dataStr.indexOf('RScript build complete') !== -1) {
365
+ rChangeCount++;
366
+ expect(rChangeCount).toBe(1);
367
+ let status = getStatus();
368
+ expect(status).not.toBe(lastStatus);
369
+ lastStatus = status;
370
+
371
+ //the end
372
+ FileSystem.killProcess(pbivizProc, 'SIGTERM', (error) => {
373
+ expect(error).toBeNull();
374
+ done();
375
+ });
376
+ }
377
+ });
378
+ });
379
+ });
380
+ });
@@ -0,0 +1,102 @@
1
+ /*
2
+ * Power BI Visual CLI
3
+ *
4
+ * Copyright (c) Microsoft Corporation
5
+ * All rights reserved.
6
+ * MIT License
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the ""Software""), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ "use strict";
28
+
29
+ const fs = require('fs-extra');
30
+ const path = require('path');
31
+
32
+ const FileSystem = require('../helpers/FileSystem.js');
33
+ const writeMetadata = require("./utils").writeMetadata;
34
+ const semver = require('semver');
35
+
36
+ const tempPath = FileSystem.getTempPath();
37
+ const startPath = process.cwd();
38
+ const visualName = 'visualname';
39
+ const visualPath = path.join(tempPath, visualName);
40
+
41
+ describe("E2E - webpack tools", () => {
42
+ beforeEach(() => {
43
+ FileSystem.resetTempDirectory();
44
+ process.chdir(tempPath);
45
+ FileSystem.runPbiviz('new', visualName, ' -t default --force');
46
+ process.chdir(visualPath);
47
+
48
+ writeMetadata(visualPath);
49
+ });
50
+
51
+ afterEach(() => {
52
+ process.chdir(startPath);
53
+ });
54
+
55
+ afterAll(() => {
56
+ process.chdir(startPath);
57
+ FileSystem.deleteTempDirectory();
58
+ });
59
+
60
+ let removeApi = () => {
61
+ let packageJson = fs.readJsonSync(path.join(visualPath, 'package.json'));
62
+ packageJson.dependencies = {
63
+ "powerbi-visuals-utils-dataviewutils": "2.0.1"
64
+ };
65
+ fs.writeJsonSync(path.join(visualPath, 'package.json'), packageJson);
66
+
67
+ fs.removeSync(path.join(visualPath, "node_modules", "powerbi-visuals-api"));
68
+ };
69
+
70
+ it("Should not add empty dependencies option into visual config", () => {
71
+ FileSystem.runPbiviz('package');
72
+
73
+ let packageJson = fs.readJsonSync(path.join(visualPath, '.tmp/drop/pbiviz.json'));
74
+ expect(packageJson.dependencies).not.toBeDefined();
75
+ });
76
+
77
+ it("Should install the latest powerbi-visual-api if apiVersion is undefined", () => {
78
+ let pbivizJson = fs.readJsonSync(path.join(visualPath, 'pbiviz.json'));
79
+ pbivizJson.apiVersion = null;
80
+ fs.writeJsonSync(path.join(visualPath, 'pbiviz.json'), pbivizJson);
81
+
82
+ removeApi();
83
+ FileSystem.runPbiviz('package');
84
+
85
+ let packageJson = fs.readJsonSync(path.join(visualPath, 'package.json'));
86
+ expect(packageJson.dependencies["powerbi-visuals-api"]).toBeDefined();
87
+ });
88
+
89
+ it("Should install powerbi-visual-api with version from pbiviz.json on 'pbiviz start/package'", () => {
90
+ let pbivizJson = fs.readJsonSync(path.join(visualPath, 'pbiviz.json'));
91
+ removeApi();
92
+ FileSystem.runPbiviz('package');
93
+
94
+ let packageJson = fs.readJsonSync(path.join(visualPath, 'package.json'));
95
+ expect(packageJson.dependencies["powerbi-visuals-api"]).toBeDefined();
96
+ expect(semver.major(pbivizJson.apiVersion))
97
+ .toBe(semver.major(packageJson.dependencies["powerbi-visuals-api"].replace(/\^|\~/, ""))); // eslint-disable-line no-useless-escape
98
+ expect(semver.minor(pbivizJson.apiVersion))
99
+ .toBe(semver.minor(packageJson.dependencies["powerbi-visuals-api"].replace(/\^|\~/, ""))); // eslint-disable-line no-useless-escape
100
+ });
101
+
102
+ });
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Power BI Visual CLI
3
+ *
4
+ * Copyright (c) Microsoft Corporation
5
+ * All rights reserved.
6
+ * MIT License
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the ""Software""), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ "use strict";
28
+
29
+ const path = require("path");
30
+ const fs = require('fs-extra');
31
+
32
+ let readdirSyncRecursive = (baseDir) => {
33
+ let read = (dir) => {
34
+ let results = [];
35
+ let list = fs.readdirSync(dir);
36
+ list.forEach((file) => {
37
+ file = dir + '/' + file;
38
+ let stat = fs.statSync(file);
39
+ if (stat && stat.isDirectory()) {
40
+ /* Recurse into a subdirectory */
41
+ results = results.concat(read(file));
42
+ } else {
43
+ /* Is a file */
44
+ results.push(file.replace(baseDir, ""));
45
+ }
46
+ });
47
+ return results;
48
+ };
49
+ return read(baseDir);
50
+ };
51
+
52
+ let writeMetadata = (visualPath) => {
53
+ let pbivizJSONFile = path.join(visualPath, '/pbiviz.json');
54
+ let pbiviz = fs.readJSONSync(pbivizJSONFile);
55
+ pbiviz.visual.description = "description";
56
+ pbiviz.visual.supportUrl = "supportUrl";
57
+ pbiviz.author.name = "Microsoft";
58
+ pbiviz.author.email = "pbicvsupport";
59
+ fs.writeJSONSync(pbivizJSONFile, pbiviz);
60
+ };
61
+
62
+ module.exports.readdirSyncRecursive = readdirSyncRecursive;
63
+ module.exports.writeMetadata = writeMetadata;