Skip to content

Allow using flag for lxr.json path #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"devDependencies": {
"@leanix/import-sort-style": "^1.0.6",
"@types/commander": "^2.12.2",
"@types/ejs": "^3.0.5",
"@types/inquirer": "^7.3.1",
"@types/jest": "^26.0.15",
Expand Down
10 changes: 6 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ program
program
.command('start')
.description('Start developing and testing your report')
.action(() => {
new DevStarter().start().catch(handleError);
.option('-c, --config <path>', 'Path to lxr.json config', 'lxr.json')
.action(async (options: { config?: string }) => {
new DevStarter().start(options.config).catch(handleError);
});

program
Expand Down Expand Up @@ -62,16 +63,17 @@ would need to configured in a way that it writes the report artefacts to the
program
.command('upload')
.description('Uploads the report to the configured workspace')
.option('-c, --config <path>', 'Path to lxr.json config', 'lxr.json')
.on('--help', () => {
console.log(`
Before uploading, the report will be built – see "lxr help build" for details.

The report will be uploaded to the workspace associated with the "apitoken" on
the "host" given in lxr.json.`);
})
.action(async () => {
.action(async (options: { config?: string }) => {
const cliConfig = loadCliConfig();
const lxrConfig = loadLxrConfig();
const lxrConfig = loadLxrConfig(options.config);
const url = `https://${lxrConfig.host}/services/pathfinder/v1/reports/upload`;

const builder = new Builder(console);
Expand Down
4 changes: 2 additions & 2 deletions src/dev-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ interface DevServerStartResult {
}

export class DevStarter {
public start(): Promise<void> {
const config = loadLxrConfig();
public async start(configPath?: string): Promise<void> {
const config = loadLxrConfig(configPath);
return this.getAccessToken(config)
.then((accessToken) => this.startLocalServer(config, accessToken))
.then((result) => {
Expand Down
34 changes: 33 additions & 1 deletion src/file.helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { loadCliConfig } from './file.helpers';
import * as fs from 'fs';
import { resolve } from 'path';
import { loadCliConfig, loadLxrConfig } from './file.helpers';
import { PackageJson } from './interfaces';

describe('File Helpers', () => {
Expand Down Expand Up @@ -36,4 +38,34 @@ describe('File Helpers', () => {
});
});
});

describe('loadLxrConfig()', () => {
const rootDir = resolve(__dirname, '..');
let cwdSpy: jest.SpyInstance, readFileSyncSpy: jest.SpyInstance;

beforeEach(() => {
cwdSpy = jest.spyOn(process, 'cwd');
readFileSyncSpy = jest.spyOn(fs, 'readFileSync').mockImplementation();

cwdSpy.mockReturnValue(rootDir);
readFileSyncSpy.mockReturnValue(Buffer.from('{}'));
});

afterEach(() => {
cwdSpy.mockRestore();
readFileSyncSpy.mockRestore();
});

it('loads lxr.json from default location', () => {
loadLxrConfig();

expect(fs.readFileSync).toHaveBeenCalledWith(resolve(rootDir, 'lxr.json'));
});

it('loads lxr.json from given location', () => {
loadLxrConfig('./config/lxr.json');

expect(fs.readFileSync).toHaveBeenCalledWith(resolve(rootDir, './config/lxr.json'));
});
});
});
4 changes: 2 additions & 2 deletions src/file.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function readJsonFile<T>(path: string): T {
return JSON.parse(buffer.toString('utf-8'));
}

export function loadLxrConfig(): LxrConfig {
const lxrConfigPath = getProjectDirectoryPath('lxr.json');
export function loadLxrConfig(configPath = 'lxr.json'): LxrConfig {
const lxrConfigPath = getProjectDirectoryPath(configPath);
return readJsonFile(lxrConfigPath);
}

Expand Down