This commit is contained in:
Joshua Bemenderfer
2025-09-08 16:24:38 -04:00
parent 70200a4091
commit 9d9757e868
79 changed files with 11705 additions and 3554 deletions

View File

@@ -1,15 +1,16 @@
import fs from 'node:fs/promises'
import { useDocument } from '@terrace-lang/js'
import { createFileReader } from '@terrace-lang/js/readers/node-readline'
import { useDocument } from '../packages/js/dist/esm/index.js'
import { createFileReader } from '../packages/js/dist/esm/readers/node-readline.js'
function useHelpers({ next, level, head, tail }) {
// NOTE: The children() iterator now works correctly with file readers after fixing the parser
async function kvObject(handleValue) {
function useHelpers() {
async function kvObject(parentNode, handleValue) {
const object = {}
const rootLevel = level()
while (await next(rootLevel)) {
if (!head()) continue
object[head()] = handleValue ? await handleValue(level()) : tail().trim()
for await (const child of parentNode.children()) {
if (!child.head) continue
object[child.head] = handleValue ? await handleValue(child) : child.tail.trim()
}
return object
}
@@ -18,48 +19,46 @@ function useHelpers({ next, level, head, tail }) {
}
async function buildPackage() {
const { next, level, head, tail, match } = useDocument(createFileReader('./repo/package.tce'))
const { kvObject } = useHelpers({ next, level, head, tail })
const doc = useDocument(createFileReader('./repo/package.tce'))
const { kvObject } = useHelpers()
const pkg = {}
while (await next()) {
if (match('name')) pkg.name = tail().trim()
if (match('version')) pkg.version = tail().trim()
if (match('license')) pkg.license = tail().trim()
if (match('type')) pkg.type = tail().trim()
if (match('private')) pkg.private = tail().trim() === 'true'
for await (const node of doc) {
if (node.is('name')) pkg.name = node.tail.trim()
if (node.is('version')) pkg.version = node.tail.trim()
if (node.is('license')) pkg.license = node.tail.trim()
if (node.is('type')) pkg.type = node.tail.trim()
if (node.is('private')) pkg.private = node.tail.trim() === 'true'
if (match('scripts')) pkg.scripts = await kvObject()
if (match('devDependencies')) pkg.devDependencies = await kvObject()
if (node.is('scripts')) pkg.scripts = await kvObject(node)
if (node.is('devDependencies')) pkg.devDependencies = await kvObject(node)
}
await fs.writeFile('./package.json', JSON.stringify(pkg, null, ' '))
}
async function buildTurbo() {
const { next, level, head, tail, match } = useDocument(createFileReader('./repo/turbo.tce'))
const { kvObject } = useHelpers({ next, level, head, tail })
const doc = useDocument(createFileReader('./repo/turbo.tce'), ' ')
const { kvObject } = useHelpers()
const turbo = {}
while (await next()) {
if (match('#schema')) turbo['$schema'] = tail().trim()
if (match('pipeline')) turbo.pipeline = await (async () => {
for await (const node of doc) {
if (node.is('#schema')) turbo['$schema'] = node.tail.trim()
if (node.is('pipeline')) {
const pipeline = {}
const rootLevel = level()
while (await next(rootLevel)) {
if (!head()) continue
for await (const pipelineNode of node.children()) {
if (!pipelineNode.head) continue
const entry = pipeline[head()] = {}
const pipelineLevel = level()
while(await next(pipelineLevel)) {
if (match('dependsOn')) entry.dependsOn = tail().trim().split(' ')
if (match('outputs')) entry.outputs = tail().trim().split(' ')
const entry = pipeline[pipelineNode.head] = {}
for await (const configNode of pipelineNode.children()) {
if (configNode.is('dependsOn')) entry.dependsOn = configNode.tail.trim().split(' ')
if (configNode.is('outputs')) entry.outputs = configNode.tail.trim().split(' ')
}
}
return pipeline
})()
turbo.pipeline = pipeline
}
}
await fs.writeFile('./turbo.json', JSON.stringify(turbo, null, ' '))