Skip to content

Commit

Permalink
fix(ui5-la): new script for schema update (#697)
Browse files Browse the repository at this point in the history
* fix(ui5-la): new script for schema update

* fix: changeset

* fix: update adaptive-card file

* fix: review comments

* fix: update tsconfig

* fix: change from http to https

* fix: remove counting unit test for scripts

* fix: jest config

* fix: add exclusion list

* fix: script exclusion

* fix: add script folder for cpd exclusions
  • Loading branch information
Jimmy-Joseph19 authored Mar 14, 2024
1 parent e1b3cd3 commit 6d8f0d9
Show file tree
Hide file tree
Showing 7 changed files with 1,217 additions and 247 deletions.
6 changes: 6 additions & 0 deletions .changeset/metal-socks-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
---

New script for updating manifest schema and updated manifest schema
7 changes: 5 additions & 2 deletions packages/vscode-ui5-language-assistant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@
"test:unit": "jest --ci --forceExit --detectOpenHandles --maxWorkers=1 --coverage=false",
"coverage:unit": "jest --ci --forceExit --detectOpenHandles --maxWorkers=1 --coverage=true",
"bundle": "node esbuild.js",
"package": "node ./scripts/package-vsix"
"package": "node ./scripts/package-vsix",
"update:schema": "ts-node --project tsconfig.cli.json scripts/manifest/run-update.ts"
},
"dependencies": {
"@ui5-language-assistant/language-server": "4.0.44",
Expand All @@ -170,6 +171,8 @@
"vsce": "1.83.0",
"vscode-languageserver": "8.0.2",
"vscode-test": "1.6.1",
"@ui5-language-assistant/test-framework": "4.0.12"
"@ui5-language-assistant/test-framework": "4.0.12",
"axios": "1.6.1",
"ts-node": "8.5.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import axios from "axios";
import fs from "fs/promises";
import { join } from "path";
import prettier from "prettier";

export const BASE_PATH = join(process.cwd(), "src", "manifest");
export const MANIFEST_SCHEMA_LOCATION = join(BASE_PATH, "schema.json");
export const ADAPTIVE_CARD_LOCATION = join(BASE_PATH, "adaptive-card.json");
export const MANIFEST_SCHEMA_URI =
"https://raw.githubusercontent.com/SAP/ui5-manifest/master/schema.json";
export const ADAPTIVE_CARD_URI =
"https://adaptivecards.io/schemas/adaptive-card.json";

// eslint-disable-next-line no-console
updateManifestResources().catch(console.error);

async function updateManifestResources() {
await updateManifestSchama();
await updateAdaptiveCard();
}

/**
* Fetch data from ADAPTIVE_CARD_URI and updates the adaptive-card.json
*/
async function updateAdaptiveCard() {
const content = await axiosGetRequest(ADAPTIVE_CARD_URI);
const prettifiedContent = prettifyFileContent(ADAPTIVE_CARD_URI, content);
if (prettifiedContent) {
await fs.writeFile(ADAPTIVE_CARD_LOCATION, prettifiedContent, "utf8");
}
}

/**
* Fetch data from MANIFEST_SCHEMA_URI and updates the schema.json
*/
async function updateManifestSchama() {
const content = await axiosGetRequest(MANIFEST_SCHEMA_URI);
const finalString = content.replace(
/"(https:\/\/adaptivecards\.io[^"]*)"/,
`"/manifest/adaptive-card.json"`
);
const prettifiedContent = prettifyFileContent(
MANIFEST_SCHEMA_URI,
finalString
);
if (prettifiedContent) {
await fs.writeFile(MANIFEST_SCHEMA_LOCATION, prettifiedContent, "utf8");
}
}

async function axiosGetRequest(uri: string): Promise<string> {
const response = await axios.get(uri, {
responseType: "json",
});
return JSON.stringify(response.data, null, 2);
}

function prettifyFileContent(filepath: string, content: string): string {
return prettier.format(content, {
tabWidth: 2,
filepath,
parser: "json",
});
}
Loading

0 comments on commit 6d8f0d9

Please sign in to comment.