Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected async updateSchemas(): Promise {
const allConfigs = [...this.jsonSchemaStore.getJsonSchemaConfigurations()];
const config = this.preferences['json.schemas'];
if (config instanceof Array) {
allConfigs.push(...config);
}
const registry: { [pattern: string]: string[] } = {};
for (const s of allConfigs) {
if (s.fileMatch) {
for (let fileMatch of s.fileMatch) {
if (fileMatch.charAt(0) !== '/' && !fileMatch.match(/\w+:/)) {
fileMatch = '/' + fileMatch;
}
registry[fileMatch] = [s.url];
}
}
}
const client = await this.languageClient;
await client.onReady();
vsCodeSettings['json.schemas'].forEach((item, idx) => {
if (item.url.match(/.api\/.+\/schema.pbiviz.json$/)) {
vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.pbiviz.json`;
} else if (item.url.match(/.api\/.+\/schema.capabilities.json$/)) {
vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.capabilities.json`;
} else if (item.url.match(/.api\/.+\/schema.dependencies.json$/)) {
vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.dependencies.json`;
}
});
fs.writeJsonSync(vsCodeSettingsPath, vsCodeSettings);
let stat = fs.statSync(path.join(visualPath, '.api', 'v1.0.0'));
expect(stat.isDirectory()).toBe(true);
//pbiviz version number should've been updated
let pbivizJson = fs.readJsonSync(path.join(visualPath, 'pbiviz.json'));
expect(pbivizJson.apiVersion).toBe('1.0.0');
//tsconfig should've been updated
let tsConfig = fs.readJsonSync(path.join(visualPath, 'tsconfig.json'));
let typeDefIndex = lodashFindIndex(tsConfig.files, i => i.match(/.api\/.+\/PowerBI-visuals.d.ts$/));
expect(tsConfig.files[typeDefIndex]).toBe('.api/v1.0.0/PowerBI-visuals.d.ts');
//.vscode/settings.json should've been set to the correct schemas
let vsCodeSettings = fs.readJsonSync(path.join(visualPath, '.vscode', 'settings.json'));
let vsCodeMatches = 0;
vsCodeSettings['json.schemas'].forEach((item, idx) => {
if (item.url.indexOf("schema.pbiviz.json") > -1) {
expect(vsCodeSettings['json.schemas'][idx].url).toBe('./node_modules/powerbi-visuals-api/schema.pbiviz.json');
vsCodeMatches++;
} else if (item.url.indexOf("schema.capabilities.json") > -1) {
expect(vsCodeSettings['json.schemas'][idx].url).toBe('./node_modules/powerbi-visuals-api/schema.capabilities.json');
vsCodeMatches++;
}
});
expect(vsCodeMatches).toBe(2);
});
let vsCodeSettingsPath = path.join(targetPath, '.vscode', 'settings.json');
//set version in pbiviz.json
let pbiviz = fs.readJsonSync(pbivizPath);
pbiviz.apiVersion = apiVersion;
fs.writeJsonSync(pbivizPath, pbiviz);
//set correct version d.ts file in tsconfig.json
let tsConfig = fs.readJsonSync(tsConfigPath);
let typeDefIndex = lodashFindIndex(tsConfig.files, i => i.match(/.api\/.+\/PowerBI-visuals.d.ts$/));
tsConfig.files[typeDefIndex] = `.api/v${apiVersion}/PowerBI-visuals.d.ts`;
fs.writeJsonSync(tsConfigPath, tsConfig);
//set correct version schemas in .vscode/settings.json
let vsCodeSettings = fs.readJsonSync(vsCodeSettingsPath);
vsCodeSettings['json.schemas'].forEach((item, idx) => {
if (item.url.match(/.api\/.+\/schema.pbiviz.json$/)) {
vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.pbiviz.json`;
} else if (item.url.match(/.api\/.+\/schema.capabilities.json$/)) {
vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.capabilities.json`;
} else if (item.url.match(/.api\/.+\/schema.dependencies.json$/)) {
vsCodeSettings['json.schemas'][idx].url = `./.api/v${apiVersion}/schema.dependencies.json`;
}
});
fs.writeJsonSync(vsCodeSettingsPath, vsCodeSettings);
}
vsCodeSettings['json.schemas'].forEach((item, idx) => {
if (item.url.indexOf("schema.pbiviz.json") > -1) {
expect(vsCodeSettings['json.schemas'][idx].url).toBe('./node_modules/powerbi-visuals-api/schema.pbiviz.json');
vsCodeMatches++;
} else if (item.url.indexOf("schema.capabilities.json") > -1) {
expect(vsCodeSettings['json.schemas'][idx].url).toBe('./node_modules/powerbi-visuals-api/schema.capabilities.json');
vsCodeMatches++;
}
});
expect(vsCodeMatches).toBe(2);