Update changes
Dieser Commit ist enthalten in:
@ -3,32 +3,43 @@
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const vm = require('vm')
|
||||
const Database = require('better-sqlite3')
|
||||
|
||||
function parseFrontendHierarchy() {
|
||||
function loadHierarchy() {
|
||||
const sharedPath = path.join(process.cwd(), '..', 'shared', 'skills.js')
|
||||
if (fs.existsSync(sharedPath)) {
|
||||
const sharedModule = require(sharedPath)
|
||||
if (Array.isArray(sharedModule?.SKILL_HIERARCHY)) {
|
||||
return sharedModule.SKILL_HIERARCHY
|
||||
}
|
||||
throw new Error('SKILL_HIERARCHY missing or invalid in shared/skills.js')
|
||||
}
|
||||
|
||||
const tsPath = path.join(process.cwd(), '..', 'frontend', 'src', 'data', 'skillCategories.ts')
|
||||
if (!fs.existsSync(tsPath)) {
|
||||
throw new Error('No skill hierarchy definition found in shared/skills.js or frontend/src/data/skillCategories.ts')
|
||||
}
|
||||
|
||||
const src = fs.readFileSync(tsPath, 'utf8')
|
||||
// Remove interface declarations and LANGUAGE_LEVELS export, keep the array literal
|
||||
let code = src
|
||||
.replace(/export interface[\s\S]*?\n\}/g, '')
|
||||
.replace(/export const LANGUAGE_LEVELS[\s\S]*?\n\n/, '')
|
||||
.replace(/export const SKILL_HIERARCHY:[^=]*=/, 'module.exports =')
|
||||
|
||||
const sandbox = { module: {}, exports: {} }
|
||||
vm.createContext(sandbox)
|
||||
vm.runInContext(code, sandbox)
|
||||
return sandbox.module.exports || sandbox.exports
|
||||
require('vm').runInNewContext(code, sandbox)
|
||||
const hierarchy = sandbox.module?.exports || sandbox.exports
|
||||
if (!Array.isArray(hierarchy)) {
|
||||
throw new Error('Parsed hierarchy is not an array')
|
||||
}
|
||||
return hierarchy
|
||||
}
|
||||
|
||||
function main() {
|
||||
const dbPath = path.join(process.cwd(), 'skillmate.dev.encrypted.db')
|
||||
const db = new Database(dbPath)
|
||||
try {
|
||||
const hierarchy = parseFrontendHierarchy()
|
||||
if (!Array.isArray(hierarchy)) {
|
||||
throw new Error('Parsed hierarchy is not an array')
|
||||
}
|
||||
const hierarchy = loadHierarchy()
|
||||
|
||||
const insert = db.prepare(`
|
||||
INSERT OR IGNORE INTO skills (id, name, category, description, expires_after)
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren