@atproto/lex-cli 0.10.2 → 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/CHANGELOG.md +16 -0
- package/bin.js +8 -4
- package/dist/codegen/client.d.ts +1 -1
- package/dist/codegen/client.d.ts.map +1 -1
- package/dist/codegen/client.js +1 -1
- package/dist/codegen/client.js.map +1 -1
- package/dist/codegen/common.d.ts +4 -4
- package/dist/codegen/common.d.ts.map +1 -1
- package/dist/codegen/common.js +1 -1
- package/dist/codegen/common.js.map +1 -1
- package/dist/codegen/lex-gen.js +2 -1
- package/dist/codegen/lex-gen.js.map +1 -1
- package/dist/codegen/server.d.ts +1 -1
- package/dist/codegen/server.d.ts.map +1 -1
- package/dist/codegen/server.js +1 -1
- package/dist/codegen/server.js.map +1 -1
- package/dist/codegen/util.js +1 -0
- package/dist/codegen/util.js.map +1 -1
- package/dist/mdgen/index.js +3 -2
- package/dist/mdgen/index.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js.map +1 -1
- package/package.json +17 -13
- package/src/codegen/client.ts +0 -566
- package/src/codegen/common.ts +0 -283
- package/src/codegen/lex-gen.ts +0 -720
- package/src/codegen/server.ts +0 -448
- package/src/codegen/util.ts +0 -84
- package/src/index.ts +0 -105
- package/src/mdgen/index.ts +0 -77
- package/src/types.ts +0 -14
- package/src/util.ts +0 -151
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -4
package/src/types.ts
DELETED
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
|
-
}
|
package/tsconfig.build.json
DELETED
|
@@ -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