diff --git a/buildWeb.js b/buildWeb.js new file mode 100644 index 0000000..6e2178c --- /dev/null +++ b/buildWeb.js @@ -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}`); + } +}); + diff --git a/justfile b/justfile index 3e2263b..919d234 100644 --- a/justfile +++ b/justfile @@ -1,2 +1,2 @@ compile: - npm run build \ No newline at end of file + npm run build-web \ No newline at end of file diff --git a/modules.tsp b/modules.tsp index 62f0247..d0b19f3 100644 --- a/modules.tsp +++ b/modules.tsp @@ -3,7 +3,7 @@ using TypeSpec.JsonSchema; alias module = rpmOstreeModule | fontsModule; -@jsonSchema() +@jsonSchema("/modules/rpm-ostree.json") model rpmOstreeModule { type: "rpm-ostree", repos: Array, @@ -11,7 +11,7 @@ model rpmOstreeModule { remove: Array, } -@jsonSchema() +@jsonSchema("/modules/fonts.json") model fontsModule { type: "fonts", fonts: { diff --git a/package.json b/package.json index 46645b9..1a0dad1 100644 --- a/package.json +++ b/package.json @@ -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" } }