packages/ flattens into: backends/ server protocol adapters (mizan-django, mizan-ts) frontends/ client kernel + framework adapters (mizan-base, mizan-react, mizan-vue, mizan-svelte) workers/ runtime workers (mizan-ssr) cores/ shared language-level primitives (empty for now; mizan-python forthcoming) The frontend kernel (was packages/mizan-runtime, now frontends/mizan-base) is renamed to reflect its role — it's the shared base that frontend adapters depend on directly. Reflects the substrate position that per-framework adapters wrap a single shared kernel; codegen targets the adapter, not the raw kernel. Path updates landed in: Makefile, two Gitea workflows, Dockerfile.test, four example/harness config files, .claude/settings.local.json, four docs (CLAUDE/ISSUES/ROADMAP/AFI_ARCHITECTURE), four codegen templates (stage1 + react/vue/svelte adapters), and three package.jsons (the mizan-base rename plus mizan-vue/svelte peerDeps). Generated files under examples/django-react-site/harness/src/api/ still reference @mizan/runtime — left as-is; they're regenerated artifacts and the harness is non-functional pending the React wrapper-layer codegen. Also folded in a pre-existing fix: the Gitea workflows had working-directory: react / django pointing at a layout that predates packages/, never updated. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
89 lines
2.3 KiB
JavaScript
89 lines
2.3 KiB
JavaScript
/**
|
|
* Schema Fetching
|
|
*
|
|
* Fetches mizan and channels schemas from Django management commands.
|
|
*/
|
|
|
|
import { spawn } from 'child_process'
|
|
import path from 'path'
|
|
|
|
/**
|
|
* Run a Django management command and parse JSON output.
|
|
*/
|
|
function runDjangoCommand(source, cwd, command) {
|
|
const managePath = path.resolve(cwd, source.django.managePath)
|
|
const manageDir = path.dirname(managePath)
|
|
|
|
let cmd, args
|
|
if (source.django.command) {
|
|
cmd = source.django.command[0]
|
|
args = [...source.django.command.slice(1), 'manage.py', command, '--indent', '0']
|
|
} else {
|
|
const python = source.django.python || 'python'
|
|
cmd = python
|
|
args = [managePath, command, '--indent', '0']
|
|
}
|
|
|
|
const env = source.django.env
|
|
? { ...process.env, ...source.django.env }
|
|
: undefined
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const proc = spawn(cmd, args, {
|
|
cwd: manageDir,
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
shell: process.platform === 'win32',
|
|
env,
|
|
})
|
|
|
|
let stdout = ''
|
|
let stderr = ''
|
|
|
|
proc.stdout.on('data', (data) => { stdout += data.toString() })
|
|
proc.stderr.on('data', (data) => { stderr += data.toString() })
|
|
|
|
proc.on('close', (code) => {
|
|
if (code !== 0) {
|
|
reject(new Error(`Django command failed (exit ${code}):\n${stderr}`))
|
|
return
|
|
}
|
|
|
|
const jsonStart = stdout.indexOf('{')
|
|
if (jsonStart === -1) {
|
|
reject(new Error(`No JSON found in Django output:\n${stdout}\n${stderr}`))
|
|
return
|
|
}
|
|
|
|
try {
|
|
resolve(JSON.parse(stdout.slice(jsonStart)))
|
|
} catch (err) {
|
|
reject(new Error(`Failed to parse JSON from Django:\n${err.message}\n${stdout}`))
|
|
}
|
|
})
|
|
|
|
proc.on('error', (err) => {
|
|
reject(new Error(`Failed to spawn Django command: ${err.message}`))
|
|
})
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Fetch channels schema from Django.
|
|
*/
|
|
export async function fetchChannelsSchema(source, cwd) {
|
|
if (!source.django) {
|
|
throw new Error('Channels schema export requires django source configuration')
|
|
}
|
|
return runDjangoCommand(source, cwd, 'export_channels_schema')
|
|
}
|
|
|
|
/**
|
|
* Fetch mizan schema from Django.
|
|
*/
|
|
export async function fetchMizanSchema(source, cwd) {
|
|
if (!source.django) {
|
|
throw new Error('mizan schema export requires django source configuration')
|
|
}
|
|
return runDjangoCommand(source, cwd, 'export_mizan_schema')
|
|
}
|