Skip to content

Commit

Permalink
Added pbiviz-flag to change the pbiviz path (#495)
Browse files Browse the repository at this point in the history
* Implemented flag to change the pbiviz path

* Changed flag name to pbiviz-file
  • Loading branch information
YuliaStrun authored Nov 29, 2023
1 parent a124dd1 commit 76e4677
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
3 changes: 3 additions & 0 deletions bin/pbiviz.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { program, Option } from 'commander';

const npmPackage = readJsonFromRoot('package.json');
const rootPath = process.cwd();
const pbivizFile = 'pbiviz.json';

const pbiviz = program
.version(npmPackage.version)
Expand Down Expand Up @@ -76,6 +77,7 @@ pbiviz
.option('--no-stats', "Doesn't generate statistics files")
.option('--skip-api', "Skips powerbi-visuals-api verifying")
.option('-l, --all-locales', "Keeps all locale files in the package. By default only used inside stringResources folder locales are included.")
.option('-p, --pbiviz-file <pbiviz-file>', "Path to pbiviz.json file (useful for debugging)", pbivizFile)
.action(async (options) => {
CommandManager.start(options, rootPath);
});
Expand All @@ -90,6 +92,7 @@ pbiviz
.option('--skip-api', "Skips powerbi-visuals-api verifying")
.option('-l, --all-locales', "Keeps all locale files in the package. By default only used inside stringResources folder locales are included.")
.option('-v, --verbose', "Enables verbose logging")
.option('-p, --pbiviz-file <pbiviz-file>', "Path to pbiviz.json file (useful for debugging)", pbivizFile)
.addOption(new Option('-c, --compression <compressionLevel>', "Enables compression of visual package")
.choices(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
.default('6')
Expand Down
14 changes: 14 additions & 0 deletions spec/e2e/pbivizPackageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,20 @@ describe("E2E - pbiviz package", () => {
expect(error).not.toBeNull();
}
});

fit("Should throw error if wrong file speciefied with --pbiviz-file flag", () => {
const pbivizFile = 'testFile.json';
let error;

try {
FileSystem.runPbiviz('package', undefined, `--pbiviz-file ${pbivizFile}`);
} catch (e) {
error = e
}
expect(error).toBeDefined();
expect(error.status).toBe(1);
expect(error.message).toContain("You must be in the root of a visual project to run this command.");
});
});

function mkDirPromise(path) {
Expand Down
13 changes: 13 additions & 0 deletions spec/e2e/pbivizStartSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ describe("E2E - pbiviz start", () => {
});
});

fit("Should throw error if wrong file speciefied with --pbiviz-file flag", () => {
const pbivizFile = 'testFile.json';
let error;

try {
FileSystem.runPbiviz('start', undefined, `--pbiviz-file ${pbivizFile}`);
} catch (e) {
error = e
}
expect(error).toBeDefined();
expect(error.status).toBe(1);
expect(error.message).toContain("You must be in the root of a visual project to run this command.");
});

// TODO rewrite this UT because build sequence is different
xit("Should rebuild files on change and update status", (done) => {
Expand Down
12 changes: 8 additions & 4 deletions src/CommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface StartOptions {
drop: boolean;
skipApi: boolean;
allLocales: boolean;
pbivizFile: string;
}

interface PackageOptions {
Expand All @@ -21,6 +22,7 @@ interface PackageOptions {
skipApi: boolean;
allLocales: boolean;
verbose: boolean;
pbivizFile: string;
}

interface NewOptions {
Expand All @@ -41,11 +43,12 @@ export default class CommandManager {
devServerPort: options.port,
stats: options.stats,
skipApiCheck: options.skipApi,
allLocales: options.allLocales
allLocales: options.allLocales,
pbivizFile: options.pbivizFile,
}
const visualManager = new VisualManager(rootPath)
await visualManager
.prepareVisual()
.prepareVisual(options.pbivizFile)
.validateVisual()
.initializeWebpack(webpackOptions)
visualManager.startWebpackServer(options.drop)
Expand All @@ -66,10 +69,11 @@ export default class CommandManager {
compression: options.compression,
stats: options.stats,
skipApiCheck: options.skipApi,
allLocales: options.allLocales
allLocales: options.allLocales,
pbivizFile: options.pbivizFile,
}
new VisualManager(rootPath)
.prepareVisual()
.prepareVisual(options.pbivizFile)
.validateVisual(options.verbose)
.initializeWebpack(webpackOptions)
.then(visualManager => visualManager.generatePackage(options.verbose))
Expand Down
12 changes: 6 additions & 6 deletions src/VisualManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export default class VisualManager {
this.basePath = rootPath;
}

public prepareVisual() {
if (this.doesPBIVIZExists()) {
this.pbivizConfig = readJsonFromVisual(PBIVIZ_FILE, this.basePath);
public prepareVisual(pbivizFile: string = PBIVIZ_FILE) {
if (this.doesPBIVIZExists(pbivizFile)) {
this.pbivizConfig = readJsonFromVisual(pbivizFile, this.basePath);
this.createVisualInstance();
} else {
ConsoleWriter.error(PBIVIZ_FILE + ' not found. You must be in the root of a visual project to run this command.')
ConsoleWriter.error(pbivizFile + ' not found. You must be in the root of a visual project to run this command.')
process.exit(1);
}
return this;
Expand Down Expand Up @@ -223,8 +223,8 @@ export default class VisualManager {
});
}

private doesPBIVIZExists() {
return fs.existsSync(PBIVIZ_FILE);
private doesPBIVIZExists(pbivizFile) {
return fs.existsSync(pbivizFile);
}

private prepareDropFiles() {
Expand Down
6 changes: 4 additions & 2 deletions src/WebPackWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface WebpackOptions {
fast?: boolean;
skipApiCheck?: boolean;
allLocales?: boolean;
pbivizFile?: string;
}

export default class WebPackWrap {
Expand Down Expand Up @@ -297,10 +298,11 @@ export default class WebPackWrap {
compression: 0,
stats: true,
skipApiCheck: false,
allLocales: false
allLocales: false,
pbivizFile: 'pbiviz.json',
}) {
const tsconfig = readJsonFromVisual('tsconfig.json');
this.pbiviz = readJsonFromVisual('pbiviz.json');
this.pbiviz = readJsonFromVisual(options.pbivizFile);

const capabilitiesPath = this.pbiviz.capabilities;
visualPackage.pbivizConfig.capabilities = capabilitiesPath;
Expand Down

0 comments on commit 76e4677

Please sign in to comment.