mtcute/scripts/utils.mjs
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* feat: moved tl-runtime to esm and native ArrayBuffers

* feat: migration to esm

* fix(core): web-related fixes

* test: finally, some good fucking e2e

* chore: fixed linters etc

* ci: added e2e to ci

* build(tl): fixed gen-code on node 20

* fix: codegen Uint8Array, not Buffer

never `git reset --hard` kids

* build: only do type-aware linting for `packages/*`

* build: ignore no-unresolved in ci for e2e

* fix: node 16 doesn't have subtle crypto apparently?

* fix(tests): use Uint8Array

for gods sake please can i just merge this already

* ci: don't parallel tasks in ci

because machines are utter garbage and it may just randomly break

* ci: pass secrets to e2e tests

* ci: separate cli command for ci

apparently im retarded

* fix: run codegen in e2e

im actually retarded

* ci: more fixes for e2e

* ci: debugging stuff

* ci: still debugging

* ci: hopefully fix ci???
2023-10-16 19:23:53 +03:00

28 lines
859 B
JavaScript

import { readdir, readFile } from 'fs/promises'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
export const rootDir = join(dirname(fileURLToPath(import.meta.url)), '../')
export async function tryParsePackageJson(packageName) {
try {
const path = packageName === '$root' ? rootDir : join(rootDir, 'packages', packageName)
return JSON.parse(
await readFile(join(path, 'package.json'), 'utf-8'),
)
} catch (e) {
if (e.code !== 'ENOENT') throw e
return null
}
}
export async function getPackageJsons(includeRoot = false) {
const packages = (await readdir(join(rootDir, 'packages')))
.filter((s) => !s.startsWith('.'))
if (includeRoot) packages.push('$root')
return Promise.all(packages.map(tryParsePackageJson)).then((f) => f.filter(Boolean))
}