|
2 | 2 | const sharp = require("sharp");
|
3 | 3 | const path = require("path");
|
4 | 4 | const fs = require("fs");
|
| 5 | +const { current } = require("./consts"); |
5 | 6 |
|
6 | 7 | export async function createWallpaper(
|
7 | 8 | inputDirectory: string,
|
@@ -183,5 +184,53 @@ export async function updateAllReferenceLinks(directory: string) {
|
183 | 184 | );
|
184 | 185 | }
|
185 | 186 |
|
| 187 | +const checkStatus = (response: any) => { |
| 188 | + if (response.ok) { |
| 189 | + return response; |
| 190 | + } |
| 191 | + |
| 192 | + throw new Error( |
| 193 | + `HTTP Error Response: ${response.status} ${response.statusText}` |
| 194 | + ); |
| 195 | +}; |
| 196 | + |
| 197 | +async function generateXsd() { |
| 198 | + try { |
| 199 | + const xsdMetadataPath = "public/schema/metadata"; |
| 200 | + const resResources = await fetch( |
| 201 | + `https://github.com/api-platform/core/raw/${current}/src/Metadata/Extractor/schema/resources.xsd` |
| 202 | + ); |
| 203 | + const resProperties = await fetch( |
| 204 | + `https://github.com/api-platform/core/raw/${current}/src/Metadata/Extractor/schema/properties.xsd` |
| 205 | + ); |
| 206 | + const xsd = await fetch( |
| 207 | + `https://github.com/api-platform/core/raw/2.7/src/Core/Metadata/schema/metadata.xsd` |
| 208 | + ); |
| 209 | + checkStatus(resProperties); |
| 210 | + checkStatus(resResources); |
| 211 | + checkStatus(xsd); |
| 212 | + |
| 213 | + fs.writeFileSync( |
| 214 | + path.resolve(__dirname, `./${xsdMetadataPath}/resources-3.0.xsd`), |
| 215 | + await resResources.text() |
| 216 | + ); |
| 217 | + fs.writeFileSync( |
| 218 | + path.resolve(__dirname, `./${xsdMetadataPath}/properties-3.0.xsd`), |
| 219 | + await resProperties.text() |
| 220 | + ); |
| 221 | + fs.writeFileSync( |
| 222 | + path.resolve(__dirname, `./${xsdMetadataPath}//metadata-2.0.xsd`), |
| 223 | + await xsd.text() |
| 224 | + ); |
| 225 | + } catch (error) { |
| 226 | + console.warn( |
| 227 | + "\x1b[31m", |
| 228 | + `Failed to retrieve metadata XSD files: ${error}`, |
| 229 | + "\x1b[37m" |
| 230 | + ); |
| 231 | + } |
| 232 | +} |
| 233 | + |
186 | 234 | updateAllDocFiles(path.join(process.cwd(), "data/docs"));
|
| 235 | +generateXsd(); |
187 | 236 | //updateAllReferenceLinks(path.join(process.cwd(), "data/docs/reference"));
|
0 commit comments