69 lines
2.1 KiB
JavaScript
69 lines
2.1 KiB
JavaScript
import fs from 'node:fs/promises'
|
|
import { useDocument } from '../packages/js/dist/esm/index.js'
|
|
import { createFileReader } from '../packages/js/dist/esm/readers/node-readline.js'
|
|
|
|
// NOTE: The children() iterator now works correctly with file readers after fixing the parser
|
|
|
|
function useHelpers() {
|
|
|
|
async function kvObject(parentNode, handleValue) {
|
|
const object = {}
|
|
for await (const child of parentNode.children()) {
|
|
if (!child.head) continue
|
|
object[child.head] = handleValue ? await handleValue(child) : child.tail.trim()
|
|
}
|
|
return object
|
|
}
|
|
|
|
return { kvObject }
|
|
}
|
|
|
|
async function buildPackage() {
|
|
const doc = useDocument(createFileReader('./repo/package.tce'))
|
|
const { kvObject } = useHelpers()
|
|
|
|
const pkg = {}
|
|
|
|
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 (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 doc = useDocument(createFileReader('./repo/turbo.tce'), ' ')
|
|
const { kvObject } = useHelpers()
|
|
|
|
const turbo = {}
|
|
|
|
for await (const node of doc) {
|
|
if (node.is('#schema')) turbo['$schema'] = node.tail.trim()
|
|
if (node.is('pipeline')) {
|
|
const pipeline = {}
|
|
for await (const pipelineNode of node.children()) {
|
|
if (!pipelineNode.head) continue
|
|
|
|
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(' ')
|
|
}
|
|
}
|
|
turbo.pipeline = pipeline
|
|
}
|
|
}
|
|
|
|
await fs.writeFile('./turbo.json', JSON.stringify(turbo, null, ' '))
|
|
}
|
|
|
|
buildPackage()
|
|
buildTurbo()
|