powerbi-visuals-tools 3.3.2 → 3.4.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.
Files changed (122) hide show
  1. package/.vscode/launch.json +52 -0
  2. package/Changelog.md +105 -16
  3. package/bin/pbiviz-new.js +3 -12
  4. package/bin/pbiviz-package.js +12 -8
  5. package/bin/pbiviz-start.js +25 -51
  6. package/bin/pbiviz.js +0 -1
  7. package/config.json +1 -1
  8. package/lib/CertificateTools.js +6 -8
  9. package/lib/TemplateFetcher.js +7 -29
  10. package/lib/VisualGenerator.js +5 -94
  11. package/lib/WebPackWrap.js +69 -75
  12. package/lib/utils.js +26 -0
  13. package/lib/webpack.config.js +9 -6
  14. package/package.json +14 -16
  15. package/templates/visuals/default/package.json +2 -2
  16. package/templates/visuals/rhtml/package.json +1 -1
  17. package/templates/visuals/rvisual/package.json +1 -1
  18. package/templates/visuals/slicer/package.json +2 -2
  19. package/templates/visuals/table/package.json +2 -2
  20. package/bin/pbiviz-update.js +0 -128
  21. package/lib/LessCompiler.js +0 -86
  22. package/lib/TypescriptCompiler.js +0 -243
  23. package/templates/visuals/.api/v1.0.0/PowerBI-visuals.d.ts +0 -1139
  24. package/templates/visuals/.api/v1.0.0/schema.capabilities.json +0 -758
  25. package/templates/visuals/.api/v1.0.0/schema.pbiviz.json +0 -95
  26. package/templates/visuals/.api/v1.1.0/PowerBI-visuals.d.ts +0 -1179
  27. package/templates/visuals/.api/v1.1.0/schema.capabilities.json +0 -828
  28. package/templates/visuals/.api/v1.1.0/schema.pbiviz.json +0 -95
  29. package/templates/visuals/.api/v1.10.0/PowerBI-visuals.d.ts +0 -1406
  30. package/templates/visuals/.api/v1.10.0/schema.capabilities.json +0 -1143
  31. package/templates/visuals/.api/v1.10.0/schema.dependencies.json +0 -38
  32. package/templates/visuals/.api/v1.10.0/schema.pbiviz.json +0 -103
  33. package/templates/visuals/.api/v1.10.0/schema.stringResources.json +0 -67
  34. package/templates/visuals/.api/v1.11.0/PowerBI-visuals.d.ts +0 -1406
  35. package/templates/visuals/.api/v1.11.0/schema.capabilities.json +0 -1143
  36. package/templates/visuals/.api/v1.11.0/schema.dependencies.json +0 -38
  37. package/templates/visuals/.api/v1.11.0/schema.pbiviz.json +0 -103
  38. package/templates/visuals/.api/v1.11.0/schema.stringResources.json +0 -67
  39. package/templates/visuals/.api/v1.12.0/PowerBI-visuals.d.ts +0 -1408
  40. package/templates/visuals/.api/v1.12.0/schema.capabilities.json +0 -1173
  41. package/templates/visuals/.api/v1.12.0/schema.dependencies.json +0 -38
  42. package/templates/visuals/.api/v1.12.0/schema.pbiviz.json +0 -103
  43. package/templates/visuals/.api/v1.12.0/schema.stringResources.json +0 -67
  44. package/templates/visuals/.api/v1.13.0/PowerBI-visuals.d.ts +0 -1450
  45. package/templates/visuals/.api/v1.13.0/schema.capabilities.json +0 -1181
  46. package/templates/visuals/.api/v1.13.0/schema.dependencies.json +0 -38
  47. package/templates/visuals/.api/v1.13.0/schema.pbiviz.json +0 -103
  48. package/templates/visuals/.api/v1.13.0/schema.stringResources.json +0 -67
  49. package/templates/visuals/.api/v1.2.0/PowerBI-visuals.d.ts +0 -1188
  50. package/templates/visuals/.api/v1.2.0/schema.capabilities.json +0 -951
  51. package/templates/visuals/.api/v1.2.0/schema.dependencies.json +0 -38
  52. package/templates/visuals/.api/v1.2.0/schema.pbiviz.json +0 -99
  53. package/templates/visuals/.api/v1.3.0/PowerBI-visuals.d.ts +0 -1293
  54. package/templates/visuals/.api/v1.3.0/schema.capabilities.json +0 -951
  55. package/templates/visuals/.api/v1.3.0/schema.dependencies.json +0 -38
  56. package/templates/visuals/.api/v1.3.0/schema.pbiviz.json +0 -95
  57. package/templates/visuals/.api/v1.4.0/PowerBI-visuals.d.ts +0 -1282
  58. package/templates/visuals/.api/v1.4.0/schema.capabilities.json +0 -951
  59. package/templates/visuals/.api/v1.4.0/schema.dependencies.json +0 -38
  60. package/templates/visuals/.api/v1.4.0/schema.pbiviz.json +0 -95
  61. package/templates/visuals/.api/v1.5.0/PowerBI-visuals.d.ts +0 -1205
  62. package/templates/visuals/.api/v1.5.0/schema.capabilities.json +0 -987
  63. package/templates/visuals/.api/v1.5.0/schema.dependencies.json +0 -38
  64. package/templates/visuals/.api/v1.5.0/schema.pbiviz.json +0 -95
  65. package/templates/visuals/.api/v1.6.0/PowerBI-visuals.d.ts +0 -1297
  66. package/templates/visuals/.api/v1.6.0/schema.capabilities.json +0 -1007
  67. package/templates/visuals/.api/v1.6.0/schema.dependencies.json +0 -38
  68. package/templates/visuals/.api/v1.6.0/schema.pbiviz.json +0 -103
  69. package/templates/visuals/.api/v1.6.0/schema.stringResources.json +0 -67
  70. package/templates/visuals/.api/v1.7.0/PowerBI-visuals.d.ts +0 -1381
  71. package/templates/visuals/.api/v1.7.0/schema.capabilities.json +0 -1007
  72. package/templates/visuals/.api/v1.7.0/schema.dependencies.json +0 -38
  73. package/templates/visuals/.api/v1.7.0/schema.pbiviz.json +0 -103
  74. package/templates/visuals/.api/v1.7.0/schema.stringResources.json +0 -67
  75. package/templates/visuals/.api/v1.8.0/PowerBI-visuals.d.ts +0 -1389
  76. package/templates/visuals/.api/v1.8.0/schema.capabilities.json +0 -1131
  77. package/templates/visuals/.api/v1.8.0/schema.dependencies.json +0 -38
  78. package/templates/visuals/.api/v1.8.0/schema.pbiviz.json +0 -103
  79. package/templates/visuals/.api/v1.8.0/schema.stringResources.json +0 -67
  80. package/templates/visuals/.api/v1.9.0/PowerBI-visuals.d.ts +0 -1391
  81. package/templates/visuals/.api/v1.9.0/schema.capabilities.json +0 -1131
  82. package/templates/visuals/.api/v1.9.0/schema.dependencies.json +0 -38
  83. package/templates/visuals/.api/v1.9.0/schema.pbiviz.json +0 -103
  84. package/templates/visuals/.api/v1.9.0/schema.stringResources.json +0 -67
  85. package/templates/visuals/.api/v2.0.0/PowerBI-visuals.d.ts +0 -1417
  86. package/templates/visuals/.api/v2.0.0/schema.capabilities.json +0 -1177
  87. package/templates/visuals/.api/v2.0.0/schema.dependencies.json +0 -38
  88. package/templates/visuals/.api/v2.0.0/schema.pbiviz.json +0 -103
  89. package/templates/visuals/.api/v2.0.0/schema.stringResources.json +0 -67
  90. package/templates/visuals/.api/v2.1.0/PowerBI-visuals.d.ts +0 -1417
  91. package/templates/visuals/.api/v2.1.0/schema.capabilities.json +0 -1177
  92. package/templates/visuals/.api/v2.1.0/schema.dependencies.json +0 -38
  93. package/templates/visuals/.api/v2.1.0/schema.pbiviz.json +0 -103
  94. package/templates/visuals/.api/v2.1.0/schema.stringResources.json +0 -67
  95. package/templates/visuals/.api/v2.2.0/PowerBI-visuals.d.ts +0 -1423
  96. package/templates/visuals/.api/v2.2.0/schema.capabilities.json +0 -1189
  97. package/templates/visuals/.api/v2.2.0/schema.dependencies.json +0 -38
  98. package/templates/visuals/.api/v2.2.0/schema.pbiviz.json +0 -103
  99. package/templates/visuals/.api/v2.2.0/schema.stringResources.json +0 -67
  100. package/templates/visuals/.api/v2.3.0/PowerBI-visuals.d.ts +0 -1480
  101. package/templates/visuals/.api/v2.3.0/schema.capabilities.json +0 -1193
  102. package/templates/visuals/.api/v2.3.0/schema.dependencies.json +0 -38
  103. package/templates/visuals/.api/v2.3.0/schema.pbiviz.json +0 -103
  104. package/templates/visuals/.api/v2.3.0/schema.stringResources.json +0 -67
  105. package/templates/visuals/.api/v2.5.0/PowerBI-visuals.d.ts +0 -1483
  106. package/templates/visuals/.api/v2.5.0/schema.capabilities.json +0 -1197
  107. package/templates/visuals/.api/v2.5.0/schema.dependencies.json +0 -38
  108. package/templates/visuals/.api/v2.5.0/schema.pbiviz.json +0 -103
  109. package/templates/visuals/.api/v2.5.0/schema.stringResources.json +0 -67
  110. package/templates/visuals/.api/v2.6.0/PowerBI-visuals.d.ts +0 -1485
  111. package/templates/visuals/.api/v2.6.0/schema.capabilities.json +0 -1323
  112. package/templates/visuals/.api/v2.6.0/schema.dependencies.json +0 -38
  113. package/templates/visuals/.api/v2.6.0/schema.pbiviz.json +0 -103
  114. package/templates/visuals/.api/v2.6.0/schema.stringResources.json +0 -67
  115. package/templates/visuals/default1/assets/icon.png +0 -0
  116. package/templates/visuals/default1/capabilities.json +0 -84
  117. package/templates/visuals/default1/package.json +0 -6
  118. package/templates/visuals/default1/pbiviz.json +0 -3
  119. package/templates/visuals/default1/src/settings.ts +0 -32
  120. package/templates/visuals/default1/src/visual.ts +0 -71
  121. package/templates/visuals/default1/style/visual.less +0 -9
  122. package/templates/visuals/default1/tsconfig.json +0 -16
@@ -2,23 +2,23 @@ const fs = require('fs-extra');
2
2
  const path = require('path');
3
3
  const config = require('../config.json');
4
4
  const JSZip = require('jszip');
5
- const request = require('request');
6
5
  const VisualGenerator = require("./VisualGenerator");
7
6
  const { exec } = require('child_process');
8
- let ConsoleWriter = require('../lib/ConsoleWriter');
7
+ const ConsoleWriter = require('../lib/ConsoleWriter');
8
+ const download = require('./utils').download;
9
+ const createFolder = require('./utils').createFolder;
9
10
 
10
11
  class TemplateFetcher {
11
12
  constructor({ templateName, visualName, apiVersion }) {
12
13
  this.templateName = templateName;
13
14
  this.visualName = visualName;
14
- this.folderName = `powerbi-visuals-${this.visualName}`;
15
+ this.folderName = `${this.visualName}`;
15
16
  this.apiVersion = apiVersion;
16
- console.log();
17
17
  }
18
18
 
19
19
  fetch() {
20
- this.createFolder()
21
- .then(this.download.bind(this))
20
+ let folder = createFolder.call(this, this.folderName);
21
+ download.call(this, config.visualTemplates[this.templateName], path.join(folder, "template.zip"))
22
22
  .then(this.extractFiles.bind(this))
23
23
  .then(this.removeZipFile.bind(this))
24
24
  .then(this.setVisualGUID.bind(this))
@@ -27,28 +27,6 @@ class TemplateFetcher {
27
27
  .then(this.showNextSteps.bind(this));
28
28
  }
29
29
 
30
- async createFolder() {
31
- let folder = path.join("./", this.folderName);
32
- await fs.ensureDir(folder);
33
- return folder;
34
- }
35
-
36
- download(folder) {
37
- return new Promise((resolve) => {
38
- const templateUrl = config.visualTemplates[this.templateName];
39
- const fileName = path.join(folder, "template.zip");
40
- const fileStream = fs.createWriteStream(`.${path.sep}${fileName}`);
41
-
42
- request.get(templateUrl, (err) => {
43
- if (err) {
44
- reject(err);
45
- }
46
- })
47
- .pipe(fileStream)
48
- .on("close", () => resolve(fileStream));
49
- });
50
- }
51
-
52
30
  async removeZipFile() {
53
31
  const folder = path.join("./", this.folderName);
54
32
  const fileName = path.join(folder, "template.zip");
@@ -64,7 +42,7 @@ class TemplateFetcher {
64
42
  const buffer = await fs.readFile(filePath);
65
43
  const zip = await JSZip.loadAsync(buffer);
66
44
 
67
- const filesList = Object.keys(zip.files);
45
+ const filesList = Object.keys(zip.files);
68
46
  for (const filename of filesList) {
69
47
  if (filename[filename.length - 1] === "/") {
70
48
  // generate folders for exclude parent folder
@@ -29,12 +29,14 @@
29
29
  const fs = require('fs-extra');
30
30
  const path = require('path');
31
31
  const uuid = require('uuid');
32
+ const compareVersions = require("compare-versions");
32
33
  const config = require('../config.json');
33
34
  const lodashDefaults = require('lodash.defaults');
34
35
  const template = require('../templates/pbiviz-json-template');
35
36
 
36
37
  const VISUAL_TEMPLATES_PATH = path.join(__dirname, '..', config.templates.visuals);
37
38
  const API_VERSION = config.generate.apiVersion;
39
+ const minAPIversion = config.constants.minAPIversion;
38
40
 
39
41
  /**
40
42
  * Generates the data for the visual
@@ -248,8 +250,8 @@ class VisualGenerator {
248
250
  static generate(targetPath, visualName, options) {
249
251
  return new Promise((resolve, reject) => {
250
252
  let buildOptions = lodashDefaults(options, defaultOptions);
251
- if (!buildOptions.apiVersion || parseFloat(buildOptions.apiVersion) < parseFloat('3.2.0')) {
252
- return reject(new Error(`Can not generate a visual with an API below than '3.2.0', current API is '${buildOptions.apiVersion}'.`));
253
+ if (!buildOptions.apiVersion || compareVersions.compare(buildOptions.apiVersion, minAPIversion, "<")) {
254
+ return reject(new Error(`Can not generate a visual with an API below than ${minAPIversion}, current API is '${buildOptions.apiVersion}'.`));
253
255
  }
254
256
  let visualOptions = generateVisualOptions(visualName, buildOptions.apiVersion);
255
257
  const validationResult = VisualGenerator.checkVisualName(visualOptions.name);
@@ -270,19 +272,10 @@ class VisualGenerator {
270
272
  if (!err && buildOptions.force) {
271
273
  fs.removeSync(visualPath);
272
274
  }
273
-
274
275
  copyVisualTemplate(visualPath, buildOptions.template);
275
276
  generateSettings(visualPath);
276
277
  createPbiVizJson(visualPath, visualOptions, options.template);
277
- if (options.template === "default1") {
278
- // only for old template
279
- VisualGenerator.updateApi(visualPath, visualOptions.apiVersion)
280
- .then(() => VisualGenerator.setApiVersion(visualPath, visualOptions.apiVersion))
281
- .then(() => resolve(visualPath))
282
- .catch(reject);
283
- } else {
284
- resolve(visualPath);
285
- }
278
+ resolve(visualPath);
286
279
  } catch (e) {
287
280
  reject(e);
288
281
  }
@@ -297,88 +290,6 @@ class VisualGenerator {
297
290
  return uuid.v4().replace(/-/g, '').toUpperCase();
298
291
  }
299
292
 
300
- /**
301
- * Copies the api folder for the specified api version
302
- *
303
- * @param {string} targetPath - file path of the root of the visual package
304
- * @param {string} apiVersion - api version to update
305
- */
306
- static updateApi(targetPath, apiVersion) {
307
- return new Promise((resolve, reject) => {
308
- if (parseFloat(apiVersion) <= parseFloat('2.6.0')) {
309
- let version = 'v' + apiVersion;
310
- let apiSourcePath = path.join(VISUAL_TEMPLATES_PATH, '.api', version);
311
- let apiTargetPath = path.join(targetPath, '.api', version);
312
-
313
- if (!VisualGenerator.checkApiVersion(apiVersion)) {
314
- return reject(new Error('Invalid API version: ' + apiVersion));
315
- }
316
-
317
- fs.ensureDirSync(apiTargetPath);
318
- fs.removeSync(apiTargetPath);
319
- fs.ensureDirSync(apiTargetPath);
320
- fs.copySync(apiSourcePath, apiTargetPath);
321
- resolve();
322
- }
323
- resolve();
324
- });
325
- }
326
-
327
- /**
328
- * Sets the api version for a visual (tsconfig.json, pbiviz.json, .vscode/settings.json)
329
- *
330
- * @param {string} targetPath - file path of the root of the visual package
331
- * @param {string} apiVersion - api version to set
332
- */
333
- static setApiVersion(targetPath, apiVersion) {
334
- let pbivizPath = path.join(targetPath, 'pbiviz.json');
335
- let tsConfigPath = path.join(targetPath, 'tsconfig.json');
336
- let vsCodeSettingsPath = path.join(targetPath, '.vscode', 'settings.json');
337
-
338
- //set version in pbiviz.json
339
- let pbiviz = fs.readJsonSync(pbivizPath);
340
- pbiviz.apiVersion = apiVersion;
341
- fs.writeJsonSync(pbivizPath, pbiviz);
342
-
343
- //set correct version d.ts file in tsconfig.json
344
- let tsConfig = fs.readJsonSync(tsConfigPath);
345
- let typeDefIndex = tsConfig.files.findIndex(i => i.match(/.api\/.+\/PowerBI-visuals.d.ts$/));
346
- tsConfig.files[typeDefIndex] = `.api/v${apiVersion}/PowerBI-visuals.d.ts`;
347
- fs.writeJsonSync(tsConfigPath, tsConfig);
348
-
349
- //set correct version schemas in .vscode/settings.json
350
- let vsCodeSettings = fs.readJsonSync(vsCodeSettingsPath);
351
- vsCodeSettings['json.schemas'].forEach((item, idx) => {
352
- if (item.url.match(/.api\/.+\/schema.pbiviz.json$/)) {
353
- vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.pbiviz.json`;
354
- } else if (item.url.match(/.api\/.+\/schema.capabilities.json$/)) {
355
- vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.capabilities.json`;
356
- } else if (item.url.match(/.api\/.+\/schema.dependencies.json$/)) {
357
- vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.dependencies.json`;
358
- }
359
- });
360
- fs.writeJsonSync(vsCodeSettingsPath, vsCodeSettings);
361
- }
362
-
363
- /**
364
- * Checks an if a specified API version is valid
365
- *
366
- * @param {string} apiVersion - api version to set
367
- * @returns {boolean} - is this version valid
368
- */
369
- static checkApiVersion(apiVersion) {
370
- let apiSourcePath = path.join(VISUAL_TEMPLATES_PATH, '.api', 'v' + apiVersion);
371
- try {
372
- fs.accessSync(apiSourcePath);
373
- } catch (e) {
374
- if (e && e.code && e.code === 'ENOENT') {
375
- return false;
376
- }
377
- throw e;
378
- }
379
- return true;
380
- }
381
-
382
293
  /**
383
294
  * Check visual name
384
295
  * Using https://github.com/mathiasbynens/mothereff.in/tree/master/js-properties
@@ -1,22 +1,21 @@
1
1
  "use strict";
2
2
 
3
3
  const fs = require('fs-extra');
4
+ const os = require('os');
4
5
  const path = require('path');
5
6
  const webpack = require('webpack');
6
7
  const config = require('../config.json');
7
8
  const PowerBICustomVisualsWebpackPlugin = require('powerbi-visuals-webpack-plugin');
8
- const TypescriptCompiler = require('../lib/TypescriptCompiler');
9
- const LessCompiler = require('../lib/LessCompiler');
10
9
  const encoding = "utf8";
11
10
  const ConsoleWriter = require('../lib/ConsoleWriter');
12
11
  const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin');
13
12
  const Visualizer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
14
- const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
15
13
  const util = require('util');
16
14
  const exec = util.promisify(require('child_process').exec);
17
15
  const CertificateTools = require("../lib/CertificateTools");
18
16
  const visualPlugin = "visualPlugin.ts";
19
17
  const lodashCloneDeep = require('lodash.clonedeep');
18
+ const npmPackage = require('../package.json');
20
19
 
21
20
  class WebPackGenerator {
22
21
 
@@ -77,15 +76,21 @@ class WebPackGenerator {
77
76
 
78
77
  this.webpackConfig.devServer = {
79
78
  ...this.webpackConfig.devServer,
79
+ hot: false,
80
80
  port: port || config.server.port,
81
- contentBase: path.join(visualPackage.basePath, config.build.dropFolder),
82
- https: {
83
- key: options.key,
84
- cert: options.cert,
85
- pfx: options.pfx,
86
- passphrase: options.passphrase
81
+ static: {
82
+ directory: path.join(visualPackage.basePath, config.build.dropFolder),
83
+ publicPath: config.server.assetsRoute
87
84
  },
88
- publicPath: config.server.assetsRoute
85
+ server: {
86
+ type: 'https',
87
+ options: {
88
+ key: options.key,
89
+ cert: options.cert,
90
+ pfx: options.pfx,
91
+ passphrase: options.passphrase
92
+ }
93
+ }
89
94
  };
90
95
  }
91
96
 
@@ -108,35 +113,45 @@ class WebPackGenerator {
108
113
  }
109
114
  }
110
115
 
116
+ async getEnvironmentDetails() {
117
+ let env = {};
118
+ env.nodeVersion = process.versions.node;
119
+ env.osPlatform = await os.platform();
120
+ env.osVersion = await os.version ? os.version() : "undefined";
121
+ env.osReleaseVersion = await os.release();
122
+ env.toolsVersion = npmPackage.version;
123
+ return env;
124
+ }
125
+
111
126
  async configureCustomVisualsWebpackPlugin(visualPackage, options, tsconfig) {
112
127
  let pluginConfiguration = lodashCloneDeep(visualPackage.config);
113
-
114
- if (tsconfig.compilerOptions.outDir) {
115
- let apiVersionInstalled;
116
- try {
117
- apiVersionInstalled = (await exec('npm list powerbi-visuals-api version')).stdout.split("\n")[1].split("@")[1].trim();
118
- } catch (err) {
119
- ConsoleWriter.warn(`"powerbi-visuals-api" is not installed`);
120
- }
121
- // if the powerbi-visual-api package wasn't installed
122
- // install the powerbi-visual-api, with version from apiVersion in pbiviz.json
123
- // or the latest version the API if apiVersion is absent in pbiviz.json
124
- if (!apiVersionInstalled || (typeof this.pbiviz.apiVersion !== "undefined" && this.pbiviz.apiVersion != apiVersionInstalled)) {
125
- await this.installAPIpackage();
126
- }
127
- let api = WebPackGenerator.loadAPIPackage(visualPackage);
128
- pluginConfiguration.apiVersion = api.version;
129
- pluginConfiguration.capabilitiesSchema = api.schemas.capabilities;
130
- pluginConfiguration.pbivizSchema = api.schemas.pbiviz;
131
- pluginConfiguration.stringResourcesSchema = api.schemas.stringResources;
132
- pluginConfiguration.dependenciesSchema = api.schemas.dependencies;
133
- } else {
134
- pluginConfiguration.schemaLocation = path.join(process.cwd(), '.api', 'v' + this.pbiviz.apiVersion);
135
- pluginConfiguration.externalJS = [path.join(visualPackage.basePath, config.build.precompileFolder, "externalJS.js")];
136
- pluginConfiguration.cssStyles = path.join(visualPackage.basePath, config.build.dropFolder, config.build.css);
137
- pluginConfiguration.generatePlugin = false;
128
+ //(?=\D*$) - positive look-ahead to find last version symbols and exclude any non-digit symbols after the version.
129
+ let regexFullVersion = /(?:\d+\.?){1,3}(?=\D*$)/;
130
+ let regexMinorVersion = /\d+(?:\.\d+)?/;
131
+ let apiVersionInstalled;
132
+ try {
133
+ apiVersionInstalled = (await exec('npm list powerbi-visuals-api version')).stdout.match(regexFullVersion)[0];
134
+ } catch (err) {
135
+ ConsoleWriter.warn(`"powerbi-visuals-api" is not installed`);
136
+ }
137
+ // if the powerbi-visual-api package wasn't installed
138
+ // install the powerbi-visual-api, with version from apiVersion in pbiviz.json
139
+ // or the latest API, if apiVersion is absent in pbiviz.json
140
+ if (!apiVersionInstalled || (typeof this.pbiviz.apiVersion !== "undefined" && this.pbiviz.apiVersion.match(regexMinorVersion)[0] != apiVersionInstalled.match(regexMinorVersion)[0])) {
141
+ ConsoleWriter.warn(`installed "powerbi-visuals-api" version - "${apiVersionInstalled}", is not match with the version specified in pbviz.json - "${this.pbiviz.apiVersion}".`);
142
+ await this.installAPIpackage();
138
143
  }
139
144
 
145
+ pluginConfiguration.env = await this.getEnvironmentDetails();
146
+
147
+ let api = WebPackGenerator.loadAPIPackage(visualPackage);
148
+ pluginConfiguration.apiVersion = api.version;
149
+ pluginConfiguration.capabilitiesSchema = api.schemas.capabilities;
150
+ pluginConfiguration.pbivizSchema = api.schemas.pbiviz;
151
+ pluginConfiguration.stringResourcesSchema = api.schemas.stringResources;
152
+ pluginConfiguration.dependenciesSchema = api.schemas.dependencies;
153
+
154
+
140
155
  pluginConfiguration.customVisualID = `CustomVisual_${this.pbiviz.visual.guid}`.replace(/[^\w\s]/gi, '');
141
156
  pluginConfiguration.devMode = (typeof options.devMode === "undefined") ? true : options.devMode;
142
157
  pluginConfiguration.generatePbiviz = options.generatePbiviz;
@@ -169,13 +184,21 @@ class WebPackGenerator {
169
184
  new ExtraWatchWebpackPlugin({
170
185
  files: [visualPackage.buildPath(this.pbiviz.capabilities)]
171
186
  }),
172
- new FriendlyErrorsWebpackPlugin(),
173
187
  new webpack.ProvidePlugin({
174
188
  window: 'realWindow',
175
189
  define: 'fakeDefine',
176
190
  powerbi: 'globalPowerbi'
177
191
  })
178
192
  );
193
+
194
+ if (options.devtool === "source-map" && this.webpackConfig.devServer.port) {
195
+ this.webpackConfig.plugins.push(
196
+ new webpack.SourceMapDevToolPlugin({
197
+ filename: '[file].map',
198
+ publicPath: `https://localhost:${this.webpackConfig.devServer.port}/assets/`
199
+ })
200
+ );
201
+ }
179
202
  }
180
203
 
181
204
  setTarget({
@@ -252,13 +275,17 @@ class WebPackGenerator {
252
275
  if (options.minifyJS) {
253
276
  this.enableOptimization();
254
277
  }
278
+
279
+ if (options.devtool) {
280
+ this.webpackConfig.devtool = options.devtool;
281
+ }
282
+
255
283
  await this.appendPlugins(options, visualPackage, tsconfig);
256
284
  await this.configureDevServer(visualPackage, options.devServerPort);
257
285
  await this.configureVisualPlugin(options, tsconfig, visualPackage);
258
286
  this.setTarget({
259
287
  target: options.target,
260
- fast: options.fast,
261
- oldProject: options.oldProject
288
+ fast: options.fast
262
289
  });
263
290
 
264
291
  return this.webpackConfig;
@@ -285,8 +312,7 @@ class WebPackGenerator {
285
312
  target: "es5",
286
313
  devServerPort: 8080,
287
314
  fast: false,
288
- compression: 0,
289
- oldProject: false
315
+ compression: 0
290
316
  }) {
291
317
  const tsconfigPath = visualPackage.buildPath('tsconfig.json');
292
318
  const tsconfig = require(tsconfigPath);
@@ -303,41 +329,9 @@ class WebPackGenerator {
303
329
 
304
330
  await WebPackGenerator.prepareFoldersAndFiles(visualPackage);
305
331
 
306
- let webpackConfig;
307
- // new style
308
- let oldProject;
309
- if (tsconfig.compilerOptions.outDir) {
310
- options.oldProject = false;
311
- oldProject = false;
312
- // check apiVersion in package.json and installed version
313
- webpackConfig = await this.prepareWebPackConfig(visualPackage, options, tsconfig);
314
- // old style
315
- } else {
316
- options.oldProject = true;
317
- oldProject = true;
318
- ConsoleWriter.warn("For better development experience, we strongly recommend converting the visual to es2015 modules");
319
- ConsoleWriter.warn("https://microsoft.github.io/PowerBI-visuals/docs/latest/how-to-guide/migrating-to-powerbi-visuals-tools-3-0");
320
- let pluginDropPath = await TypescriptCompiler
321
- .createPlugin(
322
- visualPackage,
323
- `${this.pbiviz.visual.guid}${options.devMode ? "_DEBUG" : ""}`
324
- );
325
- tsconfig.files.push(pluginDropPath);
326
-
327
- await TypescriptCompiler.runWatcher(tsconfig.files, tsconfig.compilerOptions, !options.devMode, visualPackage);
328
- await TypescriptCompiler.concatExternalJS(visualPackage);
329
- await this.assemblyExternalJSFiles(visualPackage, options.minifyJS, tsconfig.compilerOptions.out);
330
- await TypescriptCompiler.appendExportPowerBINameSpace(visualPackage, tsconfig.compilerOptions);
331
- await TypescriptCompiler.injectGlobalizeNameSpace(visualPackage, tsconfig.compilerOptions);
332
- await LessCompiler.build(visualPackage, options);
333
- // eslint-disable-next-line require-atomic-updates
334
- options.target = "es6"; // disable babel for old projects
335
- webpackConfig = await this.prepareWebPackConfig(visualPackage, options, tsconfig);
336
- }
337
- return {
338
- webpackConfig,
339
- oldProject
340
- };
332
+ let webpackConfig = await this.prepareWebPackConfig(visualPackage, options, tsconfig);
333
+
334
+ return { webpackConfig };
341
335
  }
342
336
  }
343
337
 
package/lib/utils.js ADDED
@@ -0,0 +1,26 @@
1
+ const fs = require('fs-extra');
2
+ let https = require("https");
3
+ let path = require("path");
4
+
5
+ function download(url, pathToFile) {
6
+ return new Promise((resolve, reject) => {
7
+ const fileStream = fs.createWriteStream(pathToFile);
8
+ https.get(url, (res) => {
9
+ res.pipe(fileStream);
10
+ fileStream.on('close', () => resolve(fileStream));
11
+ res.on('error', (error) => reject(error));
12
+ })
13
+ .on('error', (error) => reject(error));
14
+ });
15
+ }
16
+
17
+ function createFolder(folderName) {
18
+ let folder = path.join("./", folderName);
19
+ fs.ensureDirSync(folder);
20
+ return folder;
21
+ }
22
+
23
+ module.exports = {
24
+ download,
25
+ createFolder
26
+ };
@@ -9,7 +9,7 @@ module.exports = {
9
9
  'visual.js': ['./src/visual.ts']
10
10
  },
11
11
  target: 'web',
12
- devtool: 'source-map',
12
+ devtool: false,
13
13
  mode: "production",
14
14
  optimization: {
15
15
  minimizer: [
@@ -50,7 +50,9 @@ module.exports = {
50
50
  {
51
51
  loader: require.resolve('less-loader'),
52
52
  options: {
53
- paths: [path.resolve(__dirname, "..", 'node_modules')]
53
+ lessOptions: {
54
+ paths: [path.resolve(__dirname, "..", 'node_modules')]
55
+ }
54
56
  }
55
57
  }
56
58
  ]
@@ -112,13 +114,14 @@ module.exports = {
112
114
  filename: "[name]"
113
115
  },
114
116
  devServer: {
115
- disableHostCheck: true,
116
- contentBase: null,
117
+ allowedHosts: "all",
118
+ static: {
119
+ directory: null
120
+ },
117
121
  compress: true,
118
122
  port: 8080,
119
123
  hot: false,
120
- inline: false,
121
- https: true,
124
+ server: 'https',
122
125
  headers: {
123
126
  "access-control-allow-origin": "*",
124
127
  "cache-control": "public, max-age=0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powerbi-visuals-tools",
3
- "version": "3.3.2",
3
+ "version": "3.4.3",
4
4
  "description": "Command line tool for creating and publishing visuals for Power BI",
5
5
  "main": "./lib/VisualPackage.js",
6
6
  "scripts": {
@@ -34,58 +34,56 @@
34
34
  "assert": "^2.0.0",
35
35
  "async": "3.2.0",
36
36
  "babel-loader": "^8.1.0",
37
- "base64-inline-loader": "^1.1.1",
37
+ "base64-inline-loader": "^2.0.1",
38
38
  "browserify-zlib": "^0.2.0",
39
39
  "buffer": "^6.0.3",
40
40
  "chalk": "3.0.0",
41
41
  "commander": "4.1.1",
42
+ "compare-versions": "^3.6.0",
42
43
  "connect": "3.7.0",
43
44
  "console-browserify": "^1.2.0",
44
45
  "constants-browserify": "^1.0.0",
45
- "core-js": "3.6.4",
46
+ "core-js": "^3.18.1",
46
47
  "crypto-browserify": "^3.12.0",
47
- "css-loader": "^5.2.4",
48
- "domain-browser": "^4.19.0",
48
+ "css-loader": "^5.2.7",
49
+ "domain-browser": "^4.22.0",
49
50
  "events": "^3.3.0",
50
51
  "extra-watch-webpack-plugin": "^1.0.3",
51
- "friendly-errors-webpack-plugin": "^1.7.0",
52
52
  "fs-extra": "^9.1.0",
53
53
  "https-browserify": "^1.0.0",
54
54
  "json-loader": "0.5.7",
55
- "jszip": "3.2.2",
55
+ "jszip": "^3.7.1",
56
56
  "less": "^3.11.1",
57
- "less-loader": "^5.0.0",
57
+ "less-loader": "^10.0.1",
58
58
  "lodash.clonedeep": "4.5.0",
59
59
  "lodash.defaults": "4.2.0",
60
60
  "lodash.isequal": "4.5.0",
61
61
  "mini-css-extract-plugin": "^1.4.0",
62
62
  "os-browserify": "^0.3.0",
63
63
  "path-browserify": "^1.0.1",
64
- "powerbi-visuals-webpack-plugin": "^2.3.1",
64
+ "powerbi-visuals-webpack-plugin": "^3.0.0",
65
65
  "process": "^0.11.10",
66
66
  "punycode": "^2.1.1",
67
67
  "querystring-es3": "^0.2.1",
68
68
  "readable-stream": "^3.6.0",
69
- "request": "^2.88.2",
70
69
  "serve-static": "1.14.1",
71
- "source-map-concat": "1.0.1",
72
70
  "stream-browserify": "^3.0.0",
73
71
  "stream-http": "^3.2.0",
74
72
  "string_decoder": "^1.3.0",
75
73
  "timers-browserify": "^2.0.12",
76
- "ts-loader": "6.2.2",
74
+ "ts-loader": "^9.2.5",
77
75
  "tty-browserify": "0.0.1",
78
- "typescript": "3.8.3",
76
+ "typescript": "^4.4.3",
79
77
  "url": "^0.11.0",
80
78
  "util": "^0.12.3",
81
79
  "uuid": "7.0.2",
82
80
  "vm-browserify": "^1.1.2",
83
- "webpack": "^5.38.1",
81
+ "webpack": "^5.51.1",
84
82
  "webpack-bundle-analyzer": "4.4.2",
85
- "webpack-dev-server": "^3.11.2"
83
+ "webpack-dev-server": "^4.1.0"
86
84
  },
87
85
  "devDependencies": {
88
- "eslint": "6.8.0",
86
+ "eslint": "^7.31.0",
89
87
  "jasmine": "3.5.0",
90
88
  "jasmine-spec-reporter": "5.0.1",
91
89
  "semver": "7.1.3",
@@ -18,8 +18,8 @@
18
18
  "@types/d3": "5.7.2",
19
19
  "d3": "5.12.0",
20
20
  "powerbi-visuals-utils-dataviewutils": "2.2.1",
21
- "powerbi-visuals-api": "~3.8.2",
22
- "core-js": "3.2.1"
21
+ "powerbi-visuals-api": "~3.8.0",
22
+ "core-js": "^3.18.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "ts-loader": "6.1.0",
@@ -4,7 +4,7 @@
4
4
  "powerbi-visuals-utils-dataviewutils": "^2.2.1"
5
5
  },
6
6
  "devDependencies": {
7
- "powerbi-visuals-api": "~3.8.2",
7
+ "powerbi-visuals-api": "~3.8.0",
8
8
  "ts-loader": "6.1.0",
9
9
  "tslint": "^5.18.0",
10
10
  "tslint-microsoft-contrib": "^6.2.0",
@@ -4,7 +4,7 @@
4
4
  "powerbi-visuals-utils-dataviewutils": "^2.2.1"
5
5
  },
6
6
  "devDependencies": {
7
- "powerbi-visuals-api": "~3.8.2",
7
+ "powerbi-visuals-api": "~3.8.0",
8
8
  "tslint": "^5.18.0",
9
9
  "tslint-microsoft-contrib": "^6.2.0",
10
10
  "typescript": "3.6.3"
@@ -9,14 +9,14 @@
9
9
  "dependencies": {
10
10
  "d3": "5.10.0",
11
11
  "powerbi-visuals-utils-dataviewutils": "^2.2.1",
12
- "core-js": "3.2.1"
12
+ "core-js": "3.18.1"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@babel/polyfill": "^7.4.4",
16
16
  "@babel/runtime": "^7.5.5",
17
17
  "@babel/runtime-corejs2": "^7.5.5",
18
18
  "@types/d3": "5.7.2",
19
- "powerbi-visuals-api": "~3.8.2",
19
+ "powerbi-visuals-api": "~3.8.0",
20
20
  "tslint": "^5.18.0",
21
21
  "tslint-microsoft-contrib": "^6.2.0",
22
22
  "typescript": "3.6.3"
@@ -9,10 +9,10 @@
9
9
  "dependencies": {
10
10
  "d3": "5.10.0",
11
11
  "powerbi-visuals-utils-dataviewutils": "^2.2.1",
12
- "core-js": "3.2.1"
12
+ "core-js": "^3.18.1"
13
13
  },
14
14
  "devDependencies": {
15
- "powerbi-visuals-api": "~3.8.2",
15
+ "powerbi-visuals-api": "~3.8.0",
16
16
  "@babel/polyfill": "^7.4.4",
17
17
  "@babel/runtime": "^7.5.5",
18
18
  "@babel/runtime-corejs2": "^7.5.5",