Skip to content

Commit ac00fe9

Browse files
committed
feat: generate xsd
1 parent 1b49dd6 commit ac00fe9

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

pwa/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ yarn-error.log*
4040
next-env.d.ts
4141

4242
data/docs/guides/**/*.mdx
43+
public/schema/metadata/*.xsd

pwa/prebuild.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const sharp = require("sharp");
33
const path = require("path");
44
const fs = require("fs");
5+
const { current } = require("./consts");
56

67
export async function createWallpaper(
78
inputDirectory: string,
@@ -183,5 +184,53 @@ export async function updateAllReferenceLinks(directory: string) {
183184
);
184185
}
185186

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+
186234
updateAllDocFiles(path.join(process.cwd(), "data/docs"));
235+
generateXsd();
187236
//updateAllReferenceLinks(path.join(process.cwd(), "data/docs/reference"));

pwa/public/schema/metadata/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)