diff --git a/bin/pbiviz.js b/bin/pbiviz.js index 45f14dd0..c624e43a 100755 --- a/bin/pbiviz.js +++ b/bin/pbiviz.js @@ -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) @@ -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 ', "Path to pbiviz.json file (useful for debugging)", pbivizFile) .action(async (options) => { CommandManager.start(options, rootPath); }); @@ -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 ', "Path to pbiviz.json file (useful for debugging)", pbivizFile) .addOption(new Option('-c, --compression ', "Enables compression of visual package") .choices(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']) .default('6') diff --git a/spec/e2e/pbivizPackageSpec.js b/spec/e2e/pbivizPackageSpec.js index 619c9950..8dad071b 100644 --- a/spec/e2e/pbivizPackageSpec.js +++ b/spec/e2e/pbivizPackageSpec.js @@ -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) { diff --git a/spec/e2e/pbivizStartSpec.js b/spec/e2e/pbivizStartSpec.js index cc956639..dabb7528 100644 --- a/spec/e2e/pbivizStartSpec.js +++ b/spec/e2e/pbivizStartSpec.js @@ -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) => { diff --git a/src/CommandManager.ts b/src/CommandManager.ts index b47c6402..61d263a1 100644 --- a/src/CommandManager.ts +++ b/src/CommandManager.ts @@ -10,6 +10,7 @@ interface StartOptions { drop: boolean; skipApi: boolean; allLocales: boolean; + pbivizFile: string; } interface PackageOptions { @@ -21,6 +22,7 @@ interface PackageOptions { skipApi: boolean; allLocales: boolean; verbose: boolean; + pbivizFile: string; } interface NewOptions { @@ -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) @@ -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)) diff --git a/src/VisualManager.ts b/src/VisualManager.ts index d44efc7e..68b8df36 100644 --- a/src/VisualManager.ts +++ b/src/VisualManager.ts @@ -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; @@ -223,8 +223,8 @@ export default class VisualManager { }); } - private doesPBIVIZExists() { - return fs.existsSync(PBIVIZ_FILE); + private doesPBIVIZExists(pbivizFile) { + return fs.existsSync(pbivizFile); } private prepareDropFiles() { diff --git a/src/WebPackWrap.ts b/src/WebPackWrap.ts index 18706769..af956c93 100644 --- a/src/WebPackWrap.ts +++ b/src/WebPackWrap.ts @@ -34,6 +34,7 @@ export interface WebpackOptions { fast?: boolean; skipApiCheck?: boolean; allLocales?: boolean; + pbivizFile?: string; } export default class WebPackWrap { @@ -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;