feat: add preprocess script for web output that corrects file paths

This commit is contained in:
xyny 2024-05-13 19:53:07 +03:00
parent 6307b2d6b6
commit 0012640261
4 changed files with 26 additions and 4 deletions

22
buildWeb.js Normal file
View file

@ -0,0 +1,22 @@
import fs from "node:fs";
import path from "node:path";
const sourceDir = './tsp-output/@typespec/json-schema';
const buildDir = './dist';
console.log("Building final web output into " + buildDir);
fs.existsSync(buildDir) && fs.rmSync(buildDir, { recursive: true });
fs.mkdirSync(buildDir)
fs.mkdirSync(`${buildDir}/modules`);
fs.copyFileSync('./_headers', `${buildDir}/_headers`);
fs.readdirSync(sourceDir).forEach((file) => {
if (file.endsWith('.json')) {
const filePath = path.join(sourceDir, file);
const { $id } = JSON.parse(fs.readFileSync(filePath));
fs.copyFileSync(filePath, `${buildDir}/${$id}`);
}
});

View file

@ -1,2 +1,2 @@
compile:
npm run build
npm run build-web

View file

@ -3,7 +3,7 @@ using TypeSpec.JsonSchema;
alias module = rpmOstreeModule | fontsModule;
@jsonSchema()
@jsonSchema("/modules/rpm-ostree.json")
model rpmOstreeModule {
type: "rpm-ostree",
repos: Array<string>,
@ -11,7 +11,7 @@ model rpmOstreeModule {
remove: Array<string>,
}
@jsonSchema()
@jsonSchema("/modules/fonts.json")
model fontsModule {
type: "fonts",
fonts: {

View file

@ -9,6 +9,6 @@
"private": true,
"scripts": {
"build": "rm -rf ./tsp-output && npx tsp compile .",
"build-web": "npm run build && cp -r ./tsp-output/@typespec/json-schema ./dist && cp ./_headers ./dist"
"build-web": "npm run build && node ./buildWeb.js"
}
}