-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated webpack-plugin * Updated changelog * Implemented PAC validation, fixed wrong path to LocalizationLoader, updated template * Fixed tests * updated deprecation log * Migrated to typescript, reworked PAC validation; Updated package command logic * Updated new, info, start commands; Updated all templates to use eslint and satisfy all PAC requirements * updated commander.js, removed lib files, * added lib to ignore * Fixed tests * Fixed naming, Implemented unit tests * Fixed errorMessage * test the files in repo * test workspace * fix path to file * Attempt to find out the correct path to files * Attempt to find out the correct path to files #2 * New way to build path to file using new URL * Try to import file as json * Updated import in pbivizNew * Fixed one import of config.json * Fixed name of the folder * Removed wrong pushed files * Reverted new way for building path to root files * Decreased node version in build pipeline * Decreased node version to 12x in build pipeline * added missing @typescript-eslint/parser * Updated actions/checkout * Deleted redundant part of path to config * Fixed path in case of Linux * Fixed case sensitive test, removed Math.random * Removed imports with type assertion * Fixed options in start command * Updated packages, removed redundant changes, updated changelog * Fixed package-lock file and basic commands * Fixed feature types, resolved review comments * Changed way to compare objects in Package instance * removed redundant changes * Removed source from BaseFeature * Declared errorMessage as getter * Updated features' types * Changed way to chose the visual type * Updated package.json --------- Co-authored-by: AleksSavelev <[email protected]>
- Loading branch information
1 parent
3151ab4
commit 29075f2
Showing
45 changed files
with
893 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
node_modules | ||
lib | ||
*.log | ||
/lib | ||
spec/.tmp | ||
/certs | ||
/testGround |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,4 +97,4 @@ pbiviz | |
CommandManager.package(options, rootPath); | ||
}); | ||
|
||
program.parse(process.argv); | ||
program.parse(process.argv); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Power BI Visual CLI | ||
* | ||
* Copyright (c) Microsoft Corporation | ||
* All rights reserved. | ||
* MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the ""Software""), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
import * as features from '../../lib/features/index.js'; | ||
import Package from '../../lib/Package.js'; | ||
import { Stage, VisualFeatureType } from '../../lib/features/FeatureTypes.js'; | ||
import { readJsonFromRoot } from '../../lib/utils.js'; | ||
|
||
const config = readJsonFromRoot('config.json'); | ||
|
||
describe("Features", () => { | ||
describe("Visual", () => { | ||
const { APIVersion, ESLint, VisualVersion } = features; | ||
it("Should support API Version", () => { | ||
const Visual = { | ||
doesAPIVersionMatch: (minVersion) => { | ||
expect(minVersion).toBe(config.constants.minAPIversion); | ||
return true; | ||
} | ||
} | ||
expect(APIVersion.isSupported(Visual)).toBeTrue; | ||
}); | ||
|
||
it("Should support ESLint", () => { | ||
const Visual = { | ||
doesESLlintSupported: () => true | ||
} | ||
expect(ESLint.isSupported(Visual)).toBeTrue; | ||
}); | ||
|
||
it("Should support Version", () => { | ||
const Visual = { | ||
isVisualVersionValid: (versionLength) => { | ||
expect(versionLength).toBe(4); | ||
return true; | ||
} | ||
} | ||
expect(VisualVersion.isSupported(Visual)).toBeTrue; | ||
}); | ||
}); | ||
|
||
describe("Package", () => { | ||
const featuresArray = Object.keys(features).filter(key => features[key].stage === Stage.PostBuild).map(key => features[key]); | ||
|
||
it("Should support features with correct sources", () => { | ||
const sourceCode = `.allowInteractions, .applySelectionFromFilter or .registerOnSelectCallback, .colorPalette, | ||
.createDataViewWildcardSelector, .showContextMenu, .downloadService and .exportVisualsContent, | ||
getFormattingModel, .isHighContrast, .launchUrl, .createLocalizationManager, .storageService, .openModalDialog, | ||
.eventService and .renderingStarted and .renderingFinished, tooltipService, .displayWarningIcon` | ||
const capabilities = { | ||
advancedEditMode: 1, | ||
supportsHighlight: true, | ||
supportsKeyboardFocus: true, | ||
supportsLandingPage: true, | ||
supportsMultiVisualSelection: true, | ||
supportsSynchronizingFilterState: true, | ||
subtotals: true, | ||
tooltips: {}, | ||
objects: { | ||
objectCategory: 2 | ||
}, | ||
drilldown: { | ||
roles: [] | ||
}, | ||
dataViewMappings: [ | ||
{ | ||
table: { | ||
rows: { | ||
dataReductionAlgorithm: {} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
const correctPackage = new Package(sourceCode, capabilities, VisualFeatureType.All); | ||
|
||
featuresArray.forEach(feature => { | ||
expect(feature.isSupported(correctPackage)).toBeTrue; | ||
}) | ||
}); | ||
|
||
it("Should not support features with empty sources", () => { | ||
const emptyPackage = new Package('', {}, VisualFeatureType.All); | ||
|
||
featuresArray.forEach(feature => { | ||
expect(feature.isSupported(emptyPackage)).toBeFalse; | ||
}) | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Severity, Stage } from "./features/FeatureTypes.js"; | ||
import * as features from "./features/index.js"; | ||
import { Visual } from "./Visual.js"; | ||
import Package from "./Package.js"; | ||
|
||
export enum Status { | ||
Success, | ||
Error | ||
} | ||
export interface ValidationStats { | ||
status: Status, | ||
logs: Logs | ||
} | ||
|
||
export interface Logs { | ||
errors: string[], | ||
warnings: string[], | ||
info: string[], | ||
deprecation: string[] | ||
} | ||
|
||
export class FeatureManager { | ||
public features = Object.keys(features).map(key => features[key]); | ||
|
||
public validate(stage: Stage, sourceInstance: Visual | Package): ValidationStats { | ||
const result: ValidationStats = { | ||
status: Status.Success, | ||
logs: { | ||
errors: [], | ||
warnings: [], | ||
info: [], | ||
deprecation: [] | ||
} | ||
} | ||
this.features | ||
.filter(feature => feature.stage == stage) | ||
.filter(feature => feature.visualFeatureType & sourceInstance.visualFeatureType) | ||
.filter(feature => !feature.isSupported(sourceInstance)) | ||
.forEach(({ errorMessage, severity }) => { | ||
switch(severity) { | ||
case Severity.Error: | ||
result.status = Status.Error; | ||
result.logs.errors.push(errorMessage); | ||
break; | ||
case Severity.Warning: | ||
result.logs.warnings.push(errorMessage); | ||
break; | ||
case Severity.Info: | ||
result.logs.info.push(errorMessage); | ||
break; | ||
case Severity.Deprecation: | ||
result.logs.deprecation.push(errorMessage); | ||
break; | ||
} | ||
}); | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Power BI Visual CLI | ||
* | ||
* Copyright (c) Microsoft Corporation | ||
* All rights reserved. | ||
* MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the ""Software""), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
import { VisualFeatureType } from "./features/FeatureTypes.js"; | ||
import isMatch from "lodash.ismatch"; | ||
|
||
/** | ||
* Represents an instance of a visual package based on file path | ||
*/ | ||
export default class Package { | ||
private sourceCode: string; | ||
private capabilities: object; | ||
public visualFeatureType: VisualFeatureType; | ||
|
||
constructor(sourceCode: string, capabilities: object, visualFeatureType: VisualFeatureType) { | ||
this.sourceCode = sourceCode; | ||
this.capabilities = capabilities; | ||
this.visualFeatureType = visualFeatureType; | ||
} | ||
|
||
public contain(keyword: string) { | ||
return this.sourceCode.includes(keyword); | ||
} | ||
|
||
public isCapabilityEnabled(expectedObject: object) { | ||
return isMatch(this.capabilities, expectedObject); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { compareVersions } from "compare-versions"; | ||
import { VisualFeatureType } from "./features/FeatureTypes.js"; | ||
|
||
export class Visual { | ||
public visualFeatureType: VisualFeatureType; | ||
private capabilities; | ||
private config; | ||
private packageJSON; | ||
private visualVersion: string; | ||
|
||
constructor(capabilities, config, packageJson) { | ||
this.capabilities = capabilities; | ||
this.config = config; | ||
this.visualFeatureType = this.getVisualFeatureType(); | ||
this.packageJSON = packageJson; | ||
this.visualVersion = config.visual.version; | ||
} | ||
|
||
public doesAPIVersionMatch(minAPIversion: string) { | ||
return compareVersions(this.config.apiVersion ?? minAPIversion, minAPIversion) !== -1 | ||
} | ||
|
||
public doesESLlintSupported() { | ||
return Object.entries(this.packageJSON.scripts).some(([, value]) => (<string>value).includes("eslint")) | ||
} | ||
|
||
public isVisualVersionValid(length: number) { | ||
return this.visualVersion.split(".").length === length | ||
} | ||
|
||
private getVisualFeatureType() { | ||
const isMatrixSupported = this.capabilities?.dataViewMappings?.some(dataView => dataView.matrix) | ||
const isSlicer = Boolean(this.capabilities?.objects?.general?.properties?.filter?.type?.filter) | ||
let type = isSlicer ? VisualFeatureType.Slicer : VisualFeatureType.NonSlicer; | ||
if (isMatrixSupported) { | ||
type = type | VisualFeatureType.Matrix; | ||
} | ||
return type; | ||
} | ||
} |
Oops, something went wrong.