@atproto/lex-cli 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts DELETED
@@ -1,14 +0,0 @@
1
- export interface GeneratedFile {
2
- path: string
3
- content: string
4
- }
5
-
6
- export interface GeneratedAPI {
7
- files: GeneratedFile[]
8
- }
9
-
10
- export interface FileDiff {
11
- act: 'add' | 'mod' | 'del'
12
- path: string
13
- content?: string
14
- }
package/src/util.ts DELETED
@@ -1,151 +0,0 @@
1
- import fs from 'node:fs'
2
- import { join } from 'node:path'
3
- import chalk from 'chalk'
4
- import { ZodError, type ZodFormattedError } from 'zod'
5
- import { type LexiconDoc, parseLexiconDoc } from '@atproto/lexicon'
6
- import { type FileDiff, type GeneratedAPI } from './types.js'
7
-
8
- export function readAllLexicons(paths: string[]): LexiconDoc[] {
9
- paths = [...paths].sort() // incoming path order may have come from locale-dependent shell globs
10
- const docs: LexiconDoc[] = []
11
- for (const path of paths) {
12
- if (!path.endsWith('.json') || !fs.statSync(path).isFile()) {
13
- continue
14
- }
15
- try {
16
- docs.push(readLexicon(path))
17
- } catch {
18
- // skip
19
- }
20
- }
21
- return docs
22
- }
23
-
24
- export function readLexicon(path: string): LexiconDoc {
25
- let str: string
26
- let obj: unknown
27
- try {
28
- str = fs.readFileSync(path, 'utf8')
29
- } catch (e) {
30
- console.error(`Failed to read file`, path)
31
- throw e
32
- }
33
- try {
34
- obj = JSON.parse(str)
35
- } catch (e) {
36
- console.error(`Failed to parse JSON in file`, path)
37
- throw e
38
- }
39
- if (
40
- obj &&
41
- typeof obj === 'object' &&
42
- typeof (obj as LexiconDoc).lexicon === 'number'
43
- ) {
44
- try {
45
- return parseLexiconDoc(obj)
46
- } catch (e) {
47
- console.error(`Invalid lexicon`, path)
48
- if (e instanceof ZodError) {
49
- printZodError(e.format())
50
- }
51
- throw e
52
- }
53
- } else {
54
- console.error(`Not lexicon schema`, path)
55
- throw new Error(`Not lexicon schema`)
56
- }
57
- }
58
-
59
- export function genTsObj(lexicons: LexiconDoc[]): string {
60
- return `export const lexicons = ${JSON.stringify(lexicons, null, 2)}`
61
- }
62
-
63
- export function genFileDiff(outDir: string, api: GeneratedAPI) {
64
- const diffs: FileDiff[] = []
65
- const existingFiles = readdirRecursiveSync(outDir)
66
-
67
- for (const file of api.files) {
68
- file.path = join(outDir, file.path)
69
- if (existingFiles.includes(file.path)) {
70
- diffs.push({ act: 'mod', path: file.path, content: file.content })
71
- } else {
72
- diffs.push({ act: 'add', path: file.path, content: file.content })
73
- }
74
- }
75
- for (const filepath of existingFiles) {
76
- if (api.files.find((f) => f.path === filepath)) {
77
- // do nothing
78
- } else {
79
- diffs.push({ act: 'del', path: filepath })
80
- }
81
- }
82
-
83
- return diffs
84
- }
85
-
86
- export function printFileDiff(diff: FileDiff[]) {
87
- for (const d of diff) {
88
- switch (d.act) {
89
- case 'add':
90
- console.log(`${chalk.greenBright('[+ add]')} ${d.path}`)
91
- break
92
- case 'mod':
93
- console.log(`${chalk.yellowBright('[* mod]')} ${d.path}`)
94
- break
95
- case 'del':
96
- console.log(`${chalk.redBright('[- del]')} ${d.path}`)
97
- break
98
- }
99
- }
100
- }
101
-
102
- export function applyFileDiff(diff: FileDiff[]) {
103
- for (const d of diff) {
104
- switch (d.act) {
105
- case 'add':
106
- case 'mod':
107
- fs.mkdirSync(join(d.path, '..'), { recursive: true }) // lazy way to make sure the parent dir exists
108
- fs.writeFileSync(d.path, d.content || '', 'utf8')
109
- break
110
- case 'del':
111
- fs.unlinkSync(d.path)
112
- break
113
- }
114
- }
115
- }
116
-
117
- function printZodError(node: ZodFormattedError<any>, path = ''): boolean {
118
- if (node._errors?.length) {
119
- console.log(chalk.red(`Issues at ${path}:`))
120
- for (const err of dedup(node._errors)) {
121
- console.log(chalk.red(` - ${err}`))
122
- }
123
- return true
124
- } else {
125
- for (const k in node) {
126
- if (k === '_errors') {
127
- continue
128
- }
129
- printZodError(node[k], `${path}/${k}`)
130
- }
131
- }
132
- return false
133
- }
134
-
135
- function readdirRecursiveSync(root: string, files: string[] = [], prefix = '') {
136
- const dir = join(root, prefix)
137
- if (!fs.existsSync(dir)) return files
138
- if (fs.statSync(dir).isDirectory())
139
- fs.readdirSync(dir).forEach(function (name) {
140
- readdirRecursiveSync(root, files, join(prefix, name))
141
- })
142
- else if (prefix.endsWith('.ts')) {
143
- files.push(join(root, prefix))
144
- }
145
-
146
- return files
147
- }
148
-
149
- function dedup(arr: string[]): string[] {
150
- return Array.from(new Set(arr))
151
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig/node.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- },
7
- "include": ["./src"],
8
- }
@@ -1 +0,0 @@
1
- {"version":"7.0.0-dev.20260614.1","root":["./src/index.ts","./src/types.ts","./src/util.ts","./src/codegen/client.ts","./src/codegen/common.ts","./src/codegen/lex-gen.ts","./src/codegen/server.ts","./src/codegen/util.ts","./src/mdgen/index.ts"]}
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "include": [],
3
- "references": [{ "path": "./tsconfig.build.json" }],
4
- }