feat: fetch module schemas from blue-build/modules (#2)
This commit is contained in:
parent
f2636974fd
commit
25c0e5af8a
10 changed files with 41 additions and 55 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
tsp-output/*
|
||||
node_modules/*
|
||||
dist/*
|
||||
dist/*
|
||||
src-tsp/modules/*
|
||||
31
fetchModuleSchemas.js
Normal file
31
fetchModuleSchemas.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { parse } from 'yaml'
|
||||
import { pascalCase } from "change-case";
|
||||
import fs from "node:fs"
|
||||
|
||||
const modulesDir = "./src-tsp/modules"
|
||||
|
||||
const res = await fetch("https://raw.githubusercontent.com/blue-build/modules/113-feat-create-json-schemas-for-module-configuration/modules.json")
|
||||
const modules = await res.json()
|
||||
|
||||
let moduleImports = []
|
||||
let moduleModels = []
|
||||
|
||||
fs.existsSync(modulesDir) && fs.rmSync(modulesDir, { recursive: true });
|
||||
fs.mkdirSync(modulesDir)
|
||||
|
||||
for (const module of modules) {
|
||||
const res = await fetch(module)
|
||||
const moduleYml = parse(await res.text())
|
||||
if (moduleYml.typespec) {
|
||||
const res = await fetch(moduleYml.typespec)
|
||||
fs.writeFileSync(`${modulesDir}/${moduleYml.name}.tsp`, await res.text())
|
||||
|
||||
moduleImports.push(`${moduleYml.name}.tsp`)
|
||||
moduleModels.push(`${pascalCase(moduleYml.name)}`)
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${modulesDir}/index.tsp`,
|
||||
moduleImports.map(m => `import "./${m}";`).join("\n") + `
|
||||
alias Module = ${moduleModels.map(m => `${m}Module`).join(" | ")};`
|
||||
)
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -9,7 +9,9 @@
|
|||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@typespec/compiler": "latest",
|
||||
"@typespec/json-schema": "^0.56.0"
|
||||
"@typespec/json-schema": "^0.56.0",
|
||||
"change-case": "^5.4.4",
|
||||
"yaml": "^2.4.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@
|
|||
"type": "module",
|
||||
"dependencies": {
|
||||
"@typespec/compiler": "latest",
|
||||
"@typespec/json-schema": "^0.56.0"
|
||||
"@typespec/json-schema": "^0.56.0",
|
||||
"change-case": "^5.4.4",
|
||||
"yaml": "^2.4.2"
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "rm -rf ./tsp-output && npx tsp compile ./src-tsp",
|
||||
"build": "node ./fetchModuleSchemas.js && rm -rf ./tsp-output && npx tsp compile ./src-tsp",
|
||||
"build-web": "npm run build && node ./buildWeb.js"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import "@typespec/json-schema";
|
||||
import "./modules.tsp";
|
||||
import "./modules/index.tsp";
|
||||
|
||||
using TypeSpec.JsonSchema;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
import "./modules/akmods.tsp";
|
||||
import "./modules/bling.tsp";
|
||||
import "./modules/fonts.tsp";
|
||||
import "./modules/rpm-ostree.tsp";
|
||||
|
||||
alias Module =
|
||||
akmodsModule |
|
||||
blingModule |
|
||||
fontsModule |
|
||||
rpmOstreeModule
|
||||
;
|
||||
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
import "@typespec/json-schema";
|
||||
using TypeSpec.JsonSchema;
|
||||
|
||||
@jsonSchema("/modules/akmods.json")
|
||||
model akmodsModule {
|
||||
type: "akmods",
|
||||
base: "main" | "asus" | "fsync" | "surface",
|
||||
install: Array<string>
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import "@typespec/json-schema";
|
||||
using TypeSpec.JsonSchema;
|
||||
|
||||
@jsonSchema("/modules/bling.json")
|
||||
model blingModule {
|
||||
type: "bling",
|
||||
install: "ublue-update" | "1password" | "dconf-update-service" | "gnome-vrr" | "laptop" | "flatpaksync"
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import "@typespec/json-schema";
|
||||
using TypeSpec.JsonSchema;
|
||||
|
||||
@jsonSchema("/modules/fonts.json")
|
||||
model fontsModule {
|
||||
type: "fonts",
|
||||
fonts: {
|
||||
"nerd-fonts": Array<string>,
|
||||
"google-fonts": Array<string>
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
import "@typespec/json-schema";
|
||||
using TypeSpec.JsonSchema;
|
||||
|
||||
@jsonSchema("/modules/rpm-ostree.json")
|
||||
model rpmOstreeModule {
|
||||
type: "rpm-ostree",
|
||||
repos: Array<string>,
|
||||
install: Array<string>,
|
||||
remove: Array<string>,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue