-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui5-la): new script for schema update (#697)
* 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
1 parent
e1b3cd3
commit 6d8f0d9
Showing
7 changed files
with
1,217 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/vscode-ui5-language-assistant/scripts/manifest/run-update.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}); | ||
} |
Oops, something went wrong.