powerbi-visuals-tools 6.2.0 → 7.0.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.
Files changed (48) hide show
  1. package/.eslintrc.json +21 -0
  2. package/Changelog.md +5 -0
  3. package/eslint.config.mjs +37 -0
  4. package/package.json +1 -24
  5. package/certs/blank +0 -0
  6. package/lib/CertificateTools.js +0 -262
  7. package/lib/CommandManager.js +0 -75
  8. package/lib/ConsoleWriter.js +0 -188
  9. package/lib/FeatureManager.js +0 -43
  10. package/lib/LintValidator.js +0 -61
  11. package/lib/Package.js +0 -46
  12. package/lib/TemplateFetcher.js +0 -111
  13. package/lib/Visual.js +0 -29
  14. package/lib/VisualGenerator.js +0 -221
  15. package/lib/VisualManager.js +0 -316
  16. package/lib/WebPackWrap.js +0 -274
  17. package/lib/features/APIVersion.js +0 -16
  18. package/lib/features/AdvancedEditMode.js +0 -12
  19. package/lib/features/AllowInteractions.js +0 -12
  20. package/lib/features/AnalyticsPane.js +0 -17
  21. package/lib/features/BaseFeature.js +0 -9
  22. package/lib/features/Bookmarks.js +0 -12
  23. package/lib/features/ColorPalette.js +0 -12
  24. package/lib/features/ConditionalFormatting.js +0 -12
  25. package/lib/features/ContextMenu.js +0 -12
  26. package/lib/features/DrillDown.js +0 -16
  27. package/lib/features/FeatureTypes.js +0 -23
  28. package/lib/features/FetchMoreData.js +0 -22
  29. package/lib/features/FileDownload.js +0 -12
  30. package/lib/features/FormatPane.js +0 -12
  31. package/lib/features/HighContrast.js +0 -12
  32. package/lib/features/HighlightData.js +0 -12
  33. package/lib/features/KeyboardNavigation.js +0 -12
  34. package/lib/features/LandingPage.js +0 -12
  35. package/lib/features/LaunchURL.js +0 -12
  36. package/lib/features/LocalStorage.js +0 -12
  37. package/lib/features/Localizations.js +0 -12
  38. package/lib/features/ModalDialog.js +0 -12
  39. package/lib/features/RenderingEvents.js +0 -13
  40. package/lib/features/SelectionAcrossVisuals.js +0 -12
  41. package/lib/features/SyncSlicer.js +0 -12
  42. package/lib/features/Tooltips.js +0 -12
  43. package/lib/features/TotalSubTotal.js +0 -12
  44. package/lib/features/VisualVersion.js +0 -12
  45. package/lib/features/WarningIcon.js +0 -12
  46. package/lib/features/index.js +0 -28
  47. package/lib/utils.js +0 -43
  48. package/lib/webpack.config.js +0 -148
@@ -1,316 +0,0 @@
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
- "use strict";
27
- import webpack from "webpack";
28
- import WebpackDevServer from "webpack-dev-server";
29
- import childProcess from 'child_process';
30
- import fs from 'fs-extra';
31
- import path from 'path';
32
- import ConsoleWriter from './ConsoleWriter.js';
33
- import VisualGenerator from './VisualGenerator.js';
34
- import { readJsonFromRoot, readJsonFromVisual } from './utils.js';
35
- import WebpackWrap from './WebPackWrap.js';
36
- import Package from './Package.js';
37
- import { Visual } from "./Visual.js";
38
- import { FeatureManager, Status } from "./FeatureManager.js";
39
- import { Severity, Stage } from "./features/FeatureTypes.js";
40
- import TemplateFetcher from "./TemplateFetcher.js";
41
- import { LintValidator } from "./LintValidator.js";
42
- const globalConfig = await readJsonFromRoot('config.json');
43
- const PBIVIZ_FILE = 'pbiviz.json';
44
- /**
45
- * Represents an instance of a visual package based on file path
46
- */
47
- export default class VisualManager {
48
- basePath;
49
- pbivizConfig;
50
- capabilities;
51
- webpackConfig;
52
- visual;
53
- package;
54
- featureManager;
55
- compiler;
56
- webpackDevServer;
57
- constructor(rootPath) {
58
- this.basePath = rootPath;
59
- }
60
- async prepareVisual(pbivizFile = PBIVIZ_FILE) {
61
- this.pbivizConfig = await readJsonFromVisual(pbivizFile, this.basePath);
62
- if (this.pbivizConfig) {
63
- await this.createVisualInstance();
64
- }
65
- else {
66
- ConsoleWriter.error(pbivizFile + ' not found. You must be in the root of a visual project to run this command.');
67
- process.exit(1);
68
- }
69
- return this;
70
- }
71
- async runLintValidation(options) {
72
- try {
73
- const linter = new LintValidator(options);
74
- await linter.runLintValidation();
75
- }
76
- catch (error) {
77
- ConsoleWriter.error("Can't run lint validation.");
78
- if (options.verbose) {
79
- ConsoleWriter.error(error.message);
80
- }
81
- }
82
- }
83
- async createVisualInstance() {
84
- this.capabilities = await readJsonFromVisual("capabilities.json", this.basePath);
85
- this.visual = new Visual(this.capabilities, this.pbivizConfig);
86
- }
87
- async initializeWebpack(webpackOptions) {
88
- const webpackWrap = new WebpackWrap();
89
- this.webpackConfig = await webpackWrap.generateWebpackConfig(this, webpackOptions);
90
- this.compiler = webpack(this.webpackConfig);
91
- return this;
92
- }
93
- generatePackage(verbose = false) {
94
- const callback = (err, stats) => {
95
- this.parseCompilationResults(err, stats);
96
- this.createPackageInstance();
97
- const logs = this.validatePackage();
98
- this.outputResults(logs, verbose);
99
- };
100
- this.compiler.run(callback);
101
- }
102
- /**
103
- * Starts webpack server
104
- */
105
- startWebpackServer(generateDropFiles = false) {
106
- ConsoleWriter.blank();
107
- ConsoleWriter.info('Starting server...');
108
- try {
109
- if (generateDropFiles) {
110
- this.prepareDropFiles();
111
- }
112
- this.webpackDevServer = new WebpackDevServer({
113
- ...this.webpackConfig.devServer,
114
- client: false,
115
- hot: false,
116
- devMiddleware: {
117
- writeToDisk: true
118
- }
119
- }, this.compiler);
120
- (async () => {
121
- await this.webpackDevServer.start();
122
- ConsoleWriter.info(`Server listening on port ${this.webpackConfig.devServer.port}`);
123
- })();
124
- process.on('SIGINT', this.stopServer);
125
- process.on('SIGTERM', this.stopServer);
126
- }
127
- catch (e) {
128
- ConsoleWriter.error(e.message);
129
- process.exit(1);
130
- }
131
- }
132
- /**
133
- * Validates the visual code
134
- */
135
- validateVisual(verbose = false) {
136
- this.featureManager = new FeatureManager();
137
- const { status, logs } = this.featureManager.validate(Stage.PreBuild, this.visual);
138
- this.outputResults(logs, verbose);
139
- if (status === Status.Error) {
140
- process.exit(1);
141
- }
142
- return this;
143
- }
144
- /**
145
- * Validates the visual package
146
- */
147
- validatePackage() {
148
- const featureManager = new FeatureManager();
149
- const { logs } = featureManager.validate(Stage.PostBuild, this.package);
150
- return logs;
151
- }
152
- /**
153
- * Outputs the results of the validation
154
- */
155
- outputResults({ errors, deprecation, warnings, info }, verbose) {
156
- const headerMessage = {
157
- error: `Visual doesn't support some features required for all custom visuals:`,
158
- deprecation: `Some features are going to be required soon, please update the visual:`,
159
- warning: `Visual doesn't support some features recommended for all custom visuals:`,
160
- verboseInfo: `Visual can be improved by adding some features:`,
161
- shortInfo: `Visual can be improved by adding ${info.length} more optional features.`
162
- };
163
- this.outputLogsWithHeadMessage(headerMessage.error, errors, Severity.Error);
164
- this.outputLogsWithHeadMessage(headerMessage.deprecation, deprecation, Severity.Deprecation);
165
- this.outputLogsWithHeadMessage(headerMessage.warning, warnings, Severity.Warning);
166
- const verboseSuggestion = 'Run `pbiviz package` with --verbose flag to see more details.';
167
- const headerInfoMessage = headerMessage[verbose ? "verboseInfo" : "shortInfo"];
168
- const infoLogs = (!info.length || verbose) ? info : [verboseSuggestion];
169
- this.outputLogsWithHeadMessage(headerInfoMessage, infoLogs, Severity.Info);
170
- }
171
- /**
172
- * Displays visual info
173
- */
174
- displayInfo() {
175
- if (this.pbivizConfig) {
176
- ConsoleWriter.infoTable(this.pbivizConfig);
177
- }
178
- else {
179
- ConsoleWriter.error('Unable to load visual info. Please ensure the package is valid.');
180
- }
181
- }
182
- /**
183
- * Creates a new visual
184
- */
185
- static async createVisual(rootPath, visualName, generateOptions) {
186
- ConsoleWriter.info('Creating new visual');
187
- if (generateOptions.force) {
188
- ConsoleWriter.warning('Running with force flag. Existing files will be overwritten');
189
- }
190
- try {
191
- const config = await readJsonFromRoot('config.json');
192
- if (config.visualTemplates[generateOptions.template]) {
193
- new TemplateFetcher(generateOptions.template, visualName, undefined)
194
- .fetch();
195
- return;
196
- }
197
- const newVisualPath = await VisualGenerator.generateVisual(rootPath, visualName, generateOptions);
198
- await VisualManager.installPackages(newVisualPath).then(() => ConsoleWriter.done('Visual creation complete'));
199
- return new VisualManager(newVisualPath);
200
- }
201
- catch (error) {
202
- ConsoleWriter.error(['Unable to create visual.\n', error]);
203
- process.exit(1);
204
- }
205
- }
206
- /**
207
- * Install npm dependencies for visual
208
- */
209
- static installPackages(visualPath) {
210
- return new Promise(function (resolve, reject) {
211
- ConsoleWriter.info('Installing packages...');
212
- childProcess.exec(`npm install`, { cwd: visualPath }, (err) => {
213
- if (err) {
214
- reject(new Error('Package install failed.'));
215
- }
216
- else {
217
- ConsoleWriter.info('Installed packages.');
218
- resolve();
219
- }
220
- });
221
- });
222
- }
223
- doesPBIVIZExists(pbivizFile) {
224
- return fs.existsSync(pbivizFile);
225
- }
226
- prepareDropFiles() {
227
- this.webpackConfig.devServer.setupMiddlewares = (middlewares, devServer) => {
228
- const { headers, publicPath, static: { directory } } = this.webpackConfig.devServer;
229
- const assets = ['visual.js', 'visual.css', 'pbiviz.json'];
230
- const setHeaders = (res) => {
231
- Object.getOwnPropertyNames(headers)
232
- .forEach(property => res.header(property, headers[property]));
233
- };
234
- const readFile = (file, res, name) => {
235
- const assetMiddleware = (req, middlewareRes, next) => {
236
- fs.readFile(file)
237
- .then(content => {
238
- middlewareRes.write(content);
239
- ConsoleWriter.info(`Serving ${name}`);
240
- middlewareRes.end();
241
- })
242
- .catch(err => {
243
- ConsoleWriter.error(`Error serving ${name}: ${err.message}`);
244
- next();
245
- });
246
- };
247
- middlewares.unshift({
248
- name,
249
- path: `${publicPath}/${name}`,
250
- middleware: assetMiddleware
251
- });
252
- res.end();
253
- };
254
- assets.forEach(asset => {
255
- devServer.app.get(`${publicPath}/${asset}`, function (req, res) {
256
- setHeaders(res);
257
- readFile(path.join(directory, asset), res, asset);
258
- });
259
- });
260
- return middlewares;
261
- };
262
- }
263
- async stopServer() {
264
- ConsoleWriter.blank();
265
- ConsoleWriter.info("Stopping server...");
266
- if (this.webpackDevServer) {
267
- await this.webpackDevServer.stop();
268
- this.webpackDevServer = null;
269
- }
270
- }
271
- createPackageInstance() {
272
- const pathToJSContent = path.join((this.pbivizConfig.build ?? globalConfig.build).dropFolder, "visual.js");
273
- const sourceCode = fs.readFileSync(pathToJSContent, "utf8");
274
- this.package = new Package(sourceCode, this.capabilities, this.visual.visualFeatureType);
275
- }
276
- parseCompilationResults(err, stats) {
277
- ConsoleWriter.blank();
278
- if (err) {
279
- ConsoleWriter.error(`Package wasn't created. ${JSON.stringify(err)}`);
280
- }
281
- if (stats?.compilation.errors.length) {
282
- stats.compilation.errors.forEach(error => ConsoleWriter.error(error.message));
283
- ConsoleWriter.error(`Package wasn't created. ${stats.compilation.errors.length} errors found.`);
284
- }
285
- if (!err && !stats?.compilation.errors.length) {
286
- ConsoleWriter.done('Build completed successfully');
287
- }
288
- else {
289
- process.exit(1);
290
- }
291
- }
292
- outputLogsWithHeadMessage(headMessage, logs, severity) {
293
- if (!logs.length) {
294
- return;
295
- }
296
- let outputLog;
297
- switch (severity) {
298
- case Severity.Deprecation:
299
- case Severity.Error:
300
- outputLog = ConsoleWriter.error;
301
- break;
302
- case Severity.Warning:
303
- outputLog = ConsoleWriter.warning;
304
- break;
305
- default:
306
- outputLog = ConsoleWriter.info;
307
- break;
308
- }
309
- if (headMessage) {
310
- outputLog(headMessage);
311
- ConsoleWriter.blank();
312
- }
313
- logs.forEach(error => outputLog(error));
314
- ConsoleWriter.blank();
315
- }
316
- }
@@ -1,274 +0,0 @@
1
- "use strict";
2
- import fs from 'fs-extra';
3
- import os from 'os';
4
- import path from 'path';
5
- import webpack from 'webpack';
6
- import util from 'util';
7
- const exec = util.promisify(processExec);
8
- import { exec as processExec } from 'child_process';
9
- import lodashCloneDeep from 'lodash.clonedeep';
10
- import ExtraWatchWebpackPlugin from 'extra-watch-webpack-plugin';
11
- import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
12
- import { PowerBICustomVisualsWebpackPlugin, LocalizationLoader } from 'powerbi-visuals-webpack-plugin';
13
- import ConsoleWriter from './ConsoleWriter.js';
14
- import { resolveCertificate } from "./CertificateTools.js";
15
- import { readJsonFromRoot, readJsonFromVisual } from './utils.js';
16
- const config = await readJsonFromRoot('config.json');
17
- const npmPackage = await readJsonFromRoot('package.json');
18
- const visualPlugin = "visualPlugin.ts";
19
- const encoding = "utf8";
20
- export default class WebPackWrap {
21
- pbiviz;
22
- webpackConfig;
23
- static async prepareFoldersAndFiles(visualPackage) {
24
- const tmpFolder = path.join(visualPackage.basePath, ".tmp");
25
- const precompileFolder = path.join(visualPackage.basePath, config.build.precompileFolder);
26
- const dropFolder = path.join(visualPackage.basePath, config.build.dropFolder);
27
- const packageDropFolder = path.join(visualPackage.basePath, config.package.dropFolder);
28
- const visualPluginFile = path.join(visualPackage.basePath, config.build.precompileFolder, visualPlugin);
29
- await fs.ensureDir(tmpFolder);
30
- await fs.ensureDir(precompileFolder);
31
- await fs.ensureDir(dropFolder);
32
- await fs.ensureDir(packageDropFolder);
33
- await fs.createFile(visualPluginFile);
34
- }
35
- static loadAPIPackage() {
36
- const apiPath = path.join(process.cwd(), "node_modules", "powerbi-visuals-api");
37
- const doesAPIExist = fs.pathExistsSync(apiPath);
38
- if (!doesAPIExist) {
39
- ConsoleWriter.error(`Can't find powerbi-visuals-api package`);
40
- process.exit(1);
41
- }
42
- return import("file://" + path.join(apiPath, "index.js"));
43
- }
44
- async installAPIpackage() {
45
- const apiVersion = this.pbiviz.apiVersion ? `~${this.pbiviz.apiVersion}` : "latest";
46
- try {
47
- ConsoleWriter.info(`Installing API: ${apiVersion}...`);
48
- const { stdout, stderr } = await exec(`npm install --save powerbi-visuals-api@${apiVersion}`);
49
- if (stdout)
50
- ConsoleWriter.info(stdout);
51
- if (stderr)
52
- ConsoleWriter.warning(stderr);
53
- return true;
54
- }
55
- catch (ex) {
56
- if (ex.message.indexOf("No matching version found for powerbi-visuals-api") !== -1) {
57
- throw new Error(`Error: Invalid API version: ${apiVersion}`);
58
- }
59
- ConsoleWriter.error(`npm install powerbi-visuals-api@${apiVersion} failed`);
60
- return false;
61
- }
62
- }
63
- enableOptimization() {
64
- this.webpackConfig.mode = "production";
65
- this.webpackConfig.optimization = {
66
- concatenateModules: false,
67
- minimize: true
68
- };
69
- }
70
- async configureDevServer(visualPackage, port = 8080) {
71
- const options = await resolveCertificate();
72
- this.webpackConfig.devServer = {
73
- ...this.webpackConfig.devServer,
74
- hot: false,
75
- port,
76
- static: {
77
- directory: path.join(visualPackage.basePath, config.build.dropFolder),
78
- publicPath: config.server.assetsRoute
79
- },
80
- server: {
81
- type: 'https',
82
- options: {
83
- key: options.key,
84
- cert: options.cert,
85
- pfx: options.pfx,
86
- passphrase: options.passphrase
87
- }
88
- }
89
- };
90
- }
91
- configureVisualPlugin(options, tsconfig, visualPackage) {
92
- const visualJSFilePath = tsconfig.compilerOptions.out || tsconfig.compilerOptions.outDir;
93
- this.webpackConfig.output.path = path.join(visualPackage.basePath, config.build.dropFolder);
94
- this.webpackConfig.output.filename = "[name]";
95
- const visualPluginPath = path.join(process.cwd(), config.build.precompileFolder, visualPlugin);
96
- this.webpackConfig.watchOptions.ignored.push(visualPluginPath);
97
- if (tsconfig.compilerOptions.out) {
98
- this.webpackConfig.entry = {
99
- "visual.js": visualJSFilePath
100
- };
101
- }
102
- else {
103
- this.webpackConfig.entry["visual.js"] = [visualPluginPath];
104
- this.webpackConfig.output.library = `${this.pbiviz.visual.guid}${options.devMode ? "_DEBUG" : ""}`;
105
- this.webpackConfig.output.libraryTarget = 'var';
106
- }
107
- }
108
- async getEnvironmentDetails() {
109
- const env = {
110
- nodeVersion: process.versions.node,
111
- osPlatform: await os.platform(),
112
- osVersion: await os.version ?? "undefined",
113
- osReleaseVersion: await os.release(),
114
- toolsVersion: npmPackage.version
115
- };
116
- return env;
117
- }
118
- async configureCustomVisualsWebpackPlugin(visualPackage, options, tsconfig) {
119
- if (options.skipApiCheck) {
120
- ConsoleWriter.warning(`Skipping API check. Tools started with --skipApi flag.`);
121
- }
122
- else {
123
- await this.configureAPIVersion();
124
- }
125
- const api = await WebPackWrap.loadAPIPackage();
126
- const dependenciesPath = typeof this.pbiviz.dependencies === "string" && path.join(process.cwd(), this.pbiviz.dependencies);
127
- let pluginConfiguration = {
128
- ...lodashCloneDeep(visualPackage.pbivizConfig),
129
- apiVersion: api.version,
130
- capabilitiesSchema: api.schemas.capabilities,
131
- pbivizSchema: api.schemas.pbiviz,
132
- stringResourcesSchema: api.schemas.stringResources,
133
- dependenciesSchema: api.schemas.dependencies,
134
- customVisualID: `CustomVisual_${this.pbiviz.visual.guid}`.replace(/[^\w\s]/gi, ''),
135
- devMode: options.devMode,
136
- generatePbiviz: options.generatePbiviz,
137
- generateResources: options.generateResources,
138
- minifyJS: options.minifyJS,
139
- dependencies: fs.existsSync(dependenciesPath) ? this.pbiviz.dependencies : null,
140
- modules: typeof tsconfig.compilerOptions.outDir !== "undefined",
141
- visualSourceLocation: path.posix.relative(config.build.precompileFolder, tsconfig.files[0]).replace(/(\.ts)x|\.ts/, ""),
142
- pluginLocation: path.join(config.build.precompileFolder, "visualPlugin.ts"),
143
- compression: options.compression,
144
- certificationAudit: options.certificationAudit,
145
- certificationFix: options.certificationFix,
146
- };
147
- return pluginConfiguration;
148
- }
149
- async configureAPIVersion() {
150
- //(?<=powerbi-visuals-api@) - positive look-behind to find version installed in visual and get 3 level version.
151
- const regexFullVersion = /(?<=powerbi-visuals-api@)((?:\d+\.?){1,3})/g;
152
- //get only first 2 parts of version
153
- const regexMajorVersion = /\d+(?:\.\d+)?/;
154
- let listResults;
155
- try {
156
- listResults = (await exec('npm list powerbi-visuals-api version')).stdout;
157
- }
158
- catch (error) {
159
- listResults = error.stdout;
160
- }
161
- const installedAPIVersion = listResults.match(regexFullVersion)?.[0] ?? "not found";
162
- const doesAPIExist = fs.pathExistsSync(path.join(process.cwd(), "node_modules", "powerbi-visuals-api"));
163
- // if the powerbi-visual-api package wasn't installed install the powerbi-visual-api,
164
- // with version from apiVersion in pbiviz.json or the latest API, if apiVersion is absent in pbiviz.json
165
- const isAPIConfigured = doesAPIExist && installedAPIVersion && this.pbiviz.apiVersion;
166
- if (!isAPIConfigured || this.pbiviz.apiVersion.match(regexMajorVersion)[0] != installedAPIVersion.match(regexMajorVersion)[0]) {
167
- ConsoleWriter.warning(`installed "powerbi-visuals-api" version - "${installedAPIVersion}", is not match with the version specified in pbviz.json - "${this.pbiviz.apiVersion}".`);
168
- await this.installAPIpackage();
169
- }
170
- }
171
- async appendPlugins(options, visualPackage, tsconfig) {
172
- const pluginConfiguration = await this.configureCustomVisualsWebpackPlugin(visualPackage, options, tsconfig);
173
- let statsFilename = config.build.stats.split("/").pop();
174
- const statsLocation = config.build.stats.split("/").slice(0, -1).join(path.sep);
175
- statsFilename = statsFilename?.split(".").slice(0, -1).join(".");
176
- statsFilename = `${statsFilename}.${options.devMode ? "dev" : "prod"}.html`;
177
- if (options.stats) {
178
- this.webpackConfig.plugins.push(new BundleAnalyzerPlugin({
179
- reportFilename: path.join(statsLocation, statsFilename),
180
- openAnalyzer: false,
181
- analyzerMode: `static`
182
- }));
183
- }
184
- this.webpackConfig.plugins.push(new PowerBICustomVisualsWebpackPlugin(pluginConfiguration), new ExtraWatchWebpackPlugin({
185
- files: this.pbiviz.capabilities
186
- }));
187
- // Only add separate source map files when NOT using inline source maps
188
- if (options.devMode && options.devtool && this.webpackConfig.devServer.port &&
189
- options.devtool !== "inline-source-map") {
190
- this.webpackConfig.plugins.push(new webpack.SourceMapDevToolPlugin({
191
- filename: '[file].map',
192
- publicPath: `https://localhost:${this.webpackConfig.devServer.port}/assets/`
193
- }));
194
- }
195
- }
196
- async configureLoaders({ fast = false, includeAllLocales = false }) {
197
- this.webpackConfig.module.rules.push({
198
- test: /(\.ts)x?$/,
199
- use: [
200
- {
201
- loader: "ts-loader",
202
- options: fast
203
- ? {
204
- transpileOnly: false,
205
- experimentalWatchApi: false
206
- }
207
- : {}
208
- }
209
- ]
210
- });
211
- if (!includeAllLocales) {
212
- this.webpackConfig.module.rules.push({
213
- test: /powerbiGlobalizeLocales\.js$/, // path to file with all locales declared in formattingutils
214
- loader: LocalizationLoader
215
- });
216
- }
217
- }
218
- async prepareWebPackConfig(visualPackage, options, tsconfig) {
219
- this.webpackConfig = Object.assign({}, await import('./webpack.config.js')).default;
220
- // Set webpack mode based on devMode
221
- if (options.devMode) {
222
- this.webpackConfig.mode = "development";
223
- }
224
- if (options.minifyJS) {
225
- this.enableOptimization();
226
- }
227
- if (options.devtool) {
228
- this.webpackConfig.devtool = options.devtool;
229
- }
230
- await this.appendPlugins(options, visualPackage, tsconfig);
231
- await this.configureDevServer(visualPackage, options.devServerPort);
232
- await this.configureVisualPlugin(options, tsconfig, visualPackage);
233
- await this.configureLoaders({
234
- fast: options.fast,
235
- includeAllLocales: options.allLocales
236
- });
237
- return this.webpackConfig;
238
- }
239
- async assemblyExternalJSFiles(visualPackage) {
240
- const externalJSFilesContent = "";
241
- const externalJSFilesPath = path.join(visualPackage.basePath, config.build.precompileFolder, "externalJS.js");
242
- await fs.writeFile(externalJSFilesPath, externalJSFilesContent, {
243
- encoding: encoding
244
- });
245
- return externalJSFilesPath;
246
- }
247
- async generateWebpackConfig(visualPackage, options = {
248
- devMode: false,
249
- generateResources: false,
250
- generatePbiviz: false,
251
- minifyJS: true,
252
- minify: true,
253
- devServerPort: 8080,
254
- fast: false,
255
- compression: 0,
256
- stats: true,
257
- skipApiCheck: false,
258
- allLocales: false,
259
- pbivizFile: 'pbiviz.json',
260
- certificationAudit: false,
261
- certificationFix: false,
262
- }) {
263
- const tsconfig = await readJsonFromVisual('tsconfig.json');
264
- this.pbiviz = await readJsonFromVisual(options.pbivizFile);
265
- const capabilitiesPath = this.pbiviz.capabilities;
266
- visualPackage.pbivizConfig.capabilities = capabilitiesPath;
267
- const dependenciesPath = this.pbiviz.dependencies && path.join(process.cwd(), this.pbiviz.dependencies);
268
- const dependenciesFile = fs.existsSync(dependenciesPath) && JSON.parse(fs.readFileSync(dependenciesPath));
269
- visualPackage.pbivizConfig.dependencies = typeof dependenciesFile === 'object' ? dependenciesFile : {};
270
- await WebPackWrap.prepareFoldersAndFiles(visualPackage);
271
- const webpackConfig = await this.prepareWebPackConfig(visualPackage, options, tsconfig);
272
- return webpackConfig;
273
- }
274
- }
@@ -1,16 +0,0 @@
1
- import { readJsonFromRoot } from "../utils.js";
2
- import { Severity, Stage, VisualFeatureType } from "./FeatureTypes.js";
3
- export default class APIVersion {
4
- static featureName = "Api";
5
- static severity = Severity.Error;
6
- static stage = Stage.PreBuild;
7
- static visualFeatureType = VisualFeatureType.NonSlicer;
8
- static minAPIversion;
9
- static errorMessage;
10
- static async isSupported(visual) {
11
- const globalConfig = await readJsonFromRoot('config.json');
12
- this.minAPIversion = globalConfig.constants.minAPIversion;
13
- this.errorMessage = `API version must be at least ${this.minAPIversion}.`;
14
- return visual.doesAPIVersionMatch(this.minAPIversion);
15
- }
16
- }
@@ -1,12 +0,0 @@
1
- import { Severity, Stage, VisualFeatureType } from "./FeatureTypes.js";
2
- export default class AdvancedEditMode {
3
- static featureName = "Advanced Edit Mode";
4
- static documentationLink = "https://learn.microsoft.com/en-us/power-bi/developer/visuals/advanced-edit-mode";
5
- static severity = Severity.Info;
6
- static stage = Stage.PostBuild;
7
- static visualFeatureType = VisualFeatureType.NonSlicer | VisualFeatureType.Slicer;
8
- static errorMessage = `${this.featureName} - ${this.documentationLink}`;
9
- static isSupported(packageInstance) {
10
- return !packageInstance.isCapabilityEnabled({ advancedEditMode: 0 }); // 0 - Advanced edit mode is disabled
11
- }
12
- }
@@ -1,12 +0,0 @@
1
- import { Severity, Stage, VisualFeatureType } from "./FeatureTypes.js";
2
- export default class AllowInteractions {
3
- static featureName = "Allow Interactions";
4
- static documentationLink = "https://learn.microsoft.com/en-us/power-bi/developer/visuals/visuals-interactions";
5
- static severity = Severity.Warning;
6
- static stage = Stage.PostBuild;
7
- static visualFeatureType = VisualFeatureType.NonSlicer | VisualFeatureType.Slicer;
8
- static errorMessage = `${this.featureName} - ${this.documentationLink}`;
9
- static isSupported(packageInstance) {
10
- return packageInstance.contain('.allowInteractions');
11
- }
12
- }
@@ -1,17 +0,0 @@
1
- import { Severity, Stage, VisualFeatureType } from "./FeatureTypes.js";
2
- export default class AnalyticsPane {
3
- static featureName = "Analytics Pane";
4
- static documentationLink = "https://learn.microsoft.com/en-us/power-bi/developer/visuals/analytics-pane";
5
- static severity = Severity.Info;
6
- static stage = Stage.PostBuild;
7
- static visualFeatureType = VisualFeatureType.NonSlicer | VisualFeatureType.Slicer;
8
- static errorMessage = `${this.featureName} - ${this.documentationLink}`;
9
- static isSupported(packageInstance) {
10
- return (packageInstance.isCapabilityEnabled({
11
- objects: {
12
- objectCategory: 2
13
- }
14
- }) ||
15
- packageInstance.contain("analyticsPane=true"));
16
- }
17
- }
@@ -1,9 +0,0 @@
1
- export default class BaseFeature {
2
- static severity;
3
- static stage;
4
- static visualFeatureType;
5
- static featureName;
6
- static documentationLink;
7
- static errorMessage;
8
- static isSupported() { }
9
- }
@@ -1,12 +0,0 @@
1
- import { Severity, Stage, VisualFeatureType } from "./FeatureTypes.js";
2
- export default class Bookmarks {
3
- static featureName = "Bookmarks";
4
- static documentationLink = "https://learn.microsoft.com/en-us/power-bi/developer/visuals/bookmarks-support";
5
- static severity = Severity.Warning;
6
- static stage = Stage.PostBuild;
7
- static visualFeatureType = VisualFeatureType.Slicer;
8
- static errorMessage = `${this.featureName} - ${this.documentationLink}`;
9
- static isSupported(packageInstance) {
10
- return packageInstance.contain("applySelectionFromFilter") || packageInstance.contain("registerOnSelectCallback");
11
- }
12
- }