@atproto/lex-cli 0.9.8 → 0.10.0-next.0
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 +30 -0
- package/LICENSE.txt +1 -1
- package/bin.js +9 -0
- package/dist/codegen/client.d.ts +1 -1
- package/dist/codegen/client.d.ts.map +1 -1
- package/dist/codegen/client.js +44 -47
- package/dist/codegen/client.js.map +1 -1
- package/dist/codegen/common.d.ts +1 -1
- package/dist/codegen/common.d.ts.map +1 -1
- package/dist/codegen/common.js +14 -20
- package/dist/codegen/common.js.map +1 -1
- package/dist/codegen/lex-gen.js +40 -59
- 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 +32 -35
- package/dist/codegen/server.js.map +1 -1
- package/dist/codegen/util.js +8 -15
- package/dist/codegen/util.js.map +1 -1
- package/dist/index.js +24 -62
- package/dist/index.js.map +1 -1
- package/dist/mdgen/index.js +5 -11
- package/dist/mdgen/index.js.map +1 -1
- package/dist/types.js +1 -2
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +31 -42
- package/dist/util.js.map +1 -1
- package/package.json +13 -8
- package/src/codegen/client.ts +4 -4
- package/src/codegen/common.ts +3 -3
- package/src/codegen/lex-gen.ts +4 -4
- package/src/codegen/server.ts +4 -4
- package/src/index.ts +4 -4
- package/src/mdgen/index.ts +1 -1
- package/src/util.ts +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
package/dist/util.js
CHANGED
|
@@ -1,40 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.readLexicon = readLexicon;
|
|
8
|
-
exports.genTsObj = genTsObj;
|
|
9
|
-
exports.genFileDiff = genFileDiff;
|
|
10
|
-
exports.printFileDiff = printFileDiff;
|
|
11
|
-
exports.applyFileDiff = applyFileDiff;
|
|
12
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
|
-
const node_path_1 = require("node:path");
|
|
14
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
15
|
-
const zod_1 = require("zod");
|
|
16
|
-
const lexicon_1 = require("@atproto/lexicon");
|
|
17
|
-
function readAllLexicons(paths) {
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { ZodError } from 'zod';
|
|
5
|
+
import { parseLexiconDoc } from '@atproto/lexicon';
|
|
6
|
+
export function readAllLexicons(paths) {
|
|
18
7
|
paths = [...paths].sort(); // incoming path order may have come from locale-dependent shell globs
|
|
19
8
|
const docs = [];
|
|
20
9
|
for (const path of paths) {
|
|
21
|
-
if (!path.endsWith('.json') || !
|
|
10
|
+
if (!path.endsWith('.json') || !fs.statSync(path).isFile()) {
|
|
22
11
|
continue;
|
|
23
12
|
}
|
|
24
13
|
try {
|
|
25
14
|
docs.push(readLexicon(path));
|
|
26
15
|
}
|
|
27
|
-
catch
|
|
16
|
+
catch {
|
|
28
17
|
// skip
|
|
29
18
|
}
|
|
30
19
|
}
|
|
31
20
|
return docs;
|
|
32
21
|
}
|
|
33
|
-
function readLexicon(path) {
|
|
22
|
+
export function readLexicon(path) {
|
|
34
23
|
let str;
|
|
35
24
|
let obj;
|
|
36
25
|
try {
|
|
37
|
-
str =
|
|
26
|
+
str = fs.readFileSync(path, 'utf8');
|
|
38
27
|
}
|
|
39
28
|
catch (e) {
|
|
40
29
|
console.error(`Failed to read file`, path);
|
|
@@ -51,11 +40,11 @@ function readLexicon(path) {
|
|
|
51
40
|
typeof obj === 'object' &&
|
|
52
41
|
typeof obj.lexicon === 'number') {
|
|
53
42
|
try {
|
|
54
|
-
return
|
|
43
|
+
return parseLexiconDoc(obj);
|
|
55
44
|
}
|
|
56
45
|
catch (e) {
|
|
57
46
|
console.error(`Invalid lexicon`, path);
|
|
58
|
-
if (e instanceof
|
|
47
|
+
if (e instanceof ZodError) {
|
|
59
48
|
printZodError(e.format());
|
|
60
49
|
}
|
|
61
50
|
throw e;
|
|
@@ -66,14 +55,14 @@ function readLexicon(path) {
|
|
|
66
55
|
throw new Error(`Not lexicon schema`);
|
|
67
56
|
}
|
|
68
57
|
}
|
|
69
|
-
function genTsObj(lexicons) {
|
|
58
|
+
export function genTsObj(lexicons) {
|
|
70
59
|
return `export const lexicons = ${JSON.stringify(lexicons, null, 2)}`;
|
|
71
60
|
}
|
|
72
|
-
function genFileDiff(outDir, api) {
|
|
61
|
+
export function genFileDiff(outDir, api) {
|
|
73
62
|
const diffs = [];
|
|
74
63
|
const existingFiles = readdirRecursiveSync(outDir);
|
|
75
64
|
for (const file of api.files) {
|
|
76
|
-
file.path =
|
|
65
|
+
file.path = join(outDir, file.path);
|
|
77
66
|
if (existingFiles.includes(file.path)) {
|
|
78
67
|
diffs.push({ act: 'mod', path: file.path, content: file.content });
|
|
79
68
|
}
|
|
@@ -91,40 +80,40 @@ function genFileDiff(outDir, api) {
|
|
|
91
80
|
}
|
|
92
81
|
return diffs;
|
|
93
82
|
}
|
|
94
|
-
function printFileDiff(diff) {
|
|
83
|
+
export function printFileDiff(diff) {
|
|
95
84
|
for (const d of diff) {
|
|
96
85
|
switch (d.act) {
|
|
97
86
|
case 'add':
|
|
98
|
-
console.log(`${
|
|
87
|
+
console.log(`${chalk.greenBright('[+ add]')} ${d.path}`);
|
|
99
88
|
break;
|
|
100
89
|
case 'mod':
|
|
101
|
-
console.log(`${
|
|
90
|
+
console.log(`${chalk.yellowBright('[* mod]')} ${d.path}`);
|
|
102
91
|
break;
|
|
103
92
|
case 'del':
|
|
104
|
-
console.log(`${
|
|
93
|
+
console.log(`${chalk.redBright('[- del]')} ${d.path}`);
|
|
105
94
|
break;
|
|
106
95
|
}
|
|
107
96
|
}
|
|
108
97
|
}
|
|
109
|
-
function applyFileDiff(diff) {
|
|
98
|
+
export function applyFileDiff(diff) {
|
|
110
99
|
for (const d of diff) {
|
|
111
100
|
switch (d.act) {
|
|
112
101
|
case 'add':
|
|
113
102
|
case 'mod':
|
|
114
|
-
|
|
115
|
-
|
|
103
|
+
fs.mkdirSync(join(d.path, '..'), { recursive: true }); // lazy way to make sure the parent dir exists
|
|
104
|
+
fs.writeFileSync(d.path, d.content || '', 'utf8');
|
|
116
105
|
break;
|
|
117
106
|
case 'del':
|
|
118
|
-
|
|
107
|
+
fs.unlinkSync(d.path);
|
|
119
108
|
break;
|
|
120
109
|
}
|
|
121
110
|
}
|
|
122
111
|
}
|
|
123
112
|
function printZodError(node, path = '') {
|
|
124
113
|
if (node._errors?.length) {
|
|
125
|
-
console.log(
|
|
114
|
+
console.log(chalk.red(`Issues at ${path}:`));
|
|
126
115
|
for (const err of dedup(node._errors)) {
|
|
127
|
-
console.log(
|
|
116
|
+
console.log(chalk.red(` - ${err}`));
|
|
128
117
|
}
|
|
129
118
|
return true;
|
|
130
119
|
}
|
|
@@ -139,15 +128,15 @@ function printZodError(node, path = '') {
|
|
|
139
128
|
return false;
|
|
140
129
|
}
|
|
141
130
|
function readdirRecursiveSync(root, files = [], prefix = '') {
|
|
142
|
-
const dir =
|
|
143
|
-
if (!
|
|
131
|
+
const dir = join(root, prefix);
|
|
132
|
+
if (!fs.existsSync(dir))
|
|
144
133
|
return files;
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
readdirRecursiveSync(root, files,
|
|
134
|
+
if (fs.statSync(dir).isDirectory())
|
|
135
|
+
fs.readdirSync(dir).forEach(function (name) {
|
|
136
|
+
readdirRecursiveSync(root, files, join(prefix, name));
|
|
148
137
|
});
|
|
149
138
|
else if (prefix.endsWith('.ts')) {
|
|
150
|
-
files.push(
|
|
139
|
+
files.push(join(root, prefix));
|
|
151
140
|
}
|
|
152
141
|
return files;
|
|
153
142
|
}
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAA0B,MAAM,KAAK,CAAA;AACtD,OAAO,EAAmB,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAGnE,MAAM,UAAU,eAAe,CAAC,KAAe;IAC7C,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,EAAE,CAAA,CAAC,sEAAsE;IAChG,MAAM,IAAI,GAAiB,EAAE,CAAA;IAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3D,SAAQ;QACV,CAAC;QACD,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;QACT,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,IAAI,GAAW,CAAA;IACf,IAAI,GAAY,CAAA;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACrC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAA;QAC1C,MAAM,CAAC,CAAA;IACT,CAAC;IACD,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,C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AAI,IAAI,CAAC,EAAE,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY,EAAE,QAAkB,EAAE,EAAE,MAAM,GAAG,EAAE;IAC3E,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC9B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA;IACrC,IAAI,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE;QAChC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI;YACxC,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;QACvD,CAAC,CAAC,CAAA;SACC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAA;IAChC,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,KAAK,CAAC,GAAa;IAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;AACjC,CAAC","sourcesContent":["import fs from 'node:fs'\nimport { join } from 'node:path'\nimport chalk from 'chalk'\nimport { ZodError, type ZodFormattedError } from 'zod'\nimport { type LexiconDoc, parseLexiconDoc } from '@atproto/lexicon'\nimport { type FileDiff, type GeneratedAPI } from './types.js'\n\nexport function readAllLexicons(paths: string[]): LexiconDoc[] {\n paths = [...paths].sort() // incoming path order may have come from locale-dependent shell globs\n const docs: LexiconDoc[] = []\n for (const path of paths) {\n if (!path.endsWith('.json') || !fs.statSync(path).isFile()) {\n continue\n }\n try {\n docs.push(readLexicon(path))\n } catch {\n // skip\n }\n }\n return docs\n}\n\nexport function readLexicon(path: string): LexiconDoc {\n let str: string\n let obj: unknown\n try {\n str = fs.readFileSync(path, 'utf8')\n } catch (e) {\n console.error(`Failed to read file`, path)\n throw e\n }\n try {\n obj = JSON.parse(str)\n } catch (e) {\n console.error(`Failed to parse JSON in file`, path)\n throw e\n }\n if (\n obj &&\n typeof obj === 'object' &&\n typeof (obj as LexiconDoc).lexicon === 'number'\n ) {\n try {\n return parseLexiconDoc(obj)\n } catch (e) {\n console.error(`Invalid lexicon`, path)\n if (e instanceof ZodError) {\n printZodError(e.format())\n }\n throw e\n }\n } else {\n console.error(`Not lexicon schema`, path)\n throw new Error(`Not lexicon schema`)\n }\n}\n\nexport function genTsObj(lexicons: LexiconDoc[]): string {\n return `export const lexicons = ${JSON.stringify(lexicons, null, 2)}`\n}\n\nexport function genFileDiff(outDir: string, api: GeneratedAPI) {\n const diffs: FileDiff[] = []\n const existingFiles = readdirRecursiveSync(outDir)\n\n for (const file of api.files) {\n file.path = join(outDir, file.path)\n if (existingFiles.includes(file.path)) {\n diffs.push({ act: 'mod', path: file.path, content: file.content })\n } else {\n diffs.push({ act: 'add', path: file.path, content: file.content })\n }\n }\n for (const filepath of existingFiles) {\n if (api.files.find((f) => f.path === filepath)) {\n // do nothing\n } else {\n diffs.push({ act: 'del', path: filepath })\n }\n }\n\n return diffs\n}\n\nexport function printFileDiff(diff: FileDiff[]) {\n for (const d of diff) {\n switch (d.act) {\n case 'add':\n console.log(`${chalk.greenBright('[+ add]')} ${d.path}`)\n break\n case 'mod':\n console.log(`${chalk.yellowBright('[* mod]')} ${d.path}`)\n break\n case 'del':\n console.log(`${chalk.redBright('[- del]')} ${d.path}`)\n break\n }\n }\n}\n\nexport function applyFileDiff(diff: FileDiff[]) {\n for (const d of diff) {\n switch (d.act) {\n case 'add':\n case 'mod':\n fs.mkdirSync(join(d.path, '..'), { recursive: true }) // lazy way to make sure the parent dir exists\n fs.writeFileSync(d.path, d.content || '', 'utf8')\n break\n case 'del':\n fs.unlinkSync(d.path)\n break\n }\n }\n}\n\nfunction printZodError(node: ZodFormattedError<any>, path = ''): boolean {\n if (node._errors?.length) {\n console.log(chalk.red(`Issues at ${path}:`))\n for (const err of dedup(node._errors)) {\n console.log(chalk.red(` - ${err}`))\n }\n return true\n } else {\n for (const k in node) {\n if (k === '_errors') {\n continue\n }\n printZodError(node[k], `${path}/${k}`)\n }\n }\n return false\n}\n\nfunction readdirRecursiveSync(root: string, files: string[] = [], prefix = '') {\n const dir = join(root, prefix)\n if (!fs.existsSync(dir)) return files\n if (fs.statSync(dir).isDirectory())\n fs.readdirSync(dir).forEach(function (name) {\n readdirRecursiveSync(root, files, join(prefix, name))\n })\n else if (prefix.endsWith('.ts')) {\n files.push(join(root, prefix))\n }\n\n return files\n}\n\nfunction dedup(arr: string[]): string[] {\n return Array.from(new Set(arr))\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-next.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "TypeScript codegen tool for atproto Lexicon schemas",
|
|
6
6
|
"keywords": [
|
|
@@ -14,12 +14,10 @@
|
|
|
14
14
|
"directory": "packages/lex-cli"
|
|
15
15
|
},
|
|
16
16
|
"bin": {
|
|
17
|
-
"lex": "
|
|
17
|
+
"lex": "bin.js"
|
|
18
18
|
},
|
|
19
|
-
"main": "dist/index.js",
|
|
20
|
-
"types": "dist/index.d.ts",
|
|
21
19
|
"engines": {
|
|
22
|
-
"node": ">=
|
|
20
|
+
"node": ">=22"
|
|
23
21
|
},
|
|
24
22
|
"dependencies": {
|
|
25
23
|
"chalk": "^4.1.2",
|
|
@@ -28,11 +26,18 @@
|
|
|
28
26
|
"ts-morph": "^24.0.0",
|
|
29
27
|
"yesno": "^0.4.0",
|
|
30
28
|
"zod": "^3.23.8",
|
|
31
|
-
"@atproto/
|
|
32
|
-
"@atproto/
|
|
29
|
+
"@atproto/syntax": "^0.6.0-next.0",
|
|
30
|
+
"@atproto/lexicon": "^0.7.0-next.0"
|
|
33
31
|
},
|
|
34
32
|
"devDependencies": {
|
|
35
|
-
"typescript": "^
|
|
33
|
+
"typescript": "^6.0.3"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
}
|
|
36
41
|
},
|
|
37
42
|
"scripts": {
|
|
38
43
|
"build": "tsc --build tsconfig.build.json"
|
package/src/codegen/client.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
} from 'ts-morph'
|
|
7
7
|
import { type LexRecord, type LexiconDoc, Lexicons } from '@atproto/lexicon'
|
|
8
8
|
import { NSID } from '@atproto/syntax'
|
|
9
|
-
import { type GeneratedAPI } from '../types'
|
|
10
|
-
import { gen, lexiconsTs, utilTs } from './common'
|
|
9
|
+
import { type GeneratedAPI } from '../types.js'
|
|
10
|
+
import { gen, lexiconsTs, utilTs } from './common.js'
|
|
11
11
|
import {
|
|
12
12
|
genCommonImports,
|
|
13
13
|
genImports,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
genXrpcInput,
|
|
17
17
|
genXrpcOutput,
|
|
18
18
|
genXrpcParams,
|
|
19
|
-
} from './lex-gen'
|
|
19
|
+
} from './lex-gen.js'
|
|
20
20
|
import {
|
|
21
21
|
type DefTreeNode,
|
|
22
22
|
lexiconsToDefTree,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
toCamelCase,
|
|
25
25
|
toScreamingSnakeCase,
|
|
26
26
|
toTitleCase,
|
|
27
|
-
} from './util'
|
|
27
|
+
} from './util.js'
|
|
28
28
|
|
|
29
29
|
const ATP_METHODS = {
|
|
30
30
|
list: 'com.atproto.repo.listRecords',
|
package/src/codegen/common.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Options as PrettierOptions, format } from 'prettier'
|
|
2
2
|
import { Project, SourceFile, VariableDeclarationKind } from 'ts-morph'
|
|
3
3
|
import { type LexiconDoc } from '@atproto/lexicon'
|
|
4
|
-
import { type GeneratedFile } from '../types'
|
|
5
|
-
import { toTitleCase } from './util'
|
|
4
|
+
import { type GeneratedFile } from '../types.js'
|
|
5
|
+
import { toTitleCase } from './util.js'
|
|
6
6
|
|
|
7
7
|
const PRETTIER_OPTS: PrettierOptions = {
|
|
8
8
|
parser: 'typescript',
|
|
@@ -147,7 +147,7 @@ export const lexiconsTs = (project, lexicons: LexiconDoc[]) =>
|
|
|
147
147
|
{ name: 'ValidationResult', isTypeOnly: true },
|
|
148
148
|
])
|
|
149
149
|
|
|
150
|
-
//= import { is$typed, maybe$typed, type $Typed } from './util'
|
|
150
|
+
//= import { is$typed, maybe$typed, type $Typed } from './util.js'
|
|
151
151
|
file
|
|
152
152
|
.addImportDeclaration({
|
|
153
153
|
moduleSpecifier: './util.js',
|
package/src/codegen/lex-gen.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
type LexToken,
|
|
12
12
|
Lexicons,
|
|
13
13
|
} from '@atproto/lexicon'
|
|
14
|
-
import { toCamelCase, toScreamingSnakeCase, toTitleCase } from './util'
|
|
14
|
+
import { toCamelCase, toScreamingSnakeCase, toTitleCase } from './util.js'
|
|
15
15
|
|
|
16
16
|
interface Commentable {
|
|
17
17
|
addJsDoc: ({ description }: { description: string }) => JSDoc
|
|
@@ -50,7 +50,7 @@ export function genCommonImports(file: SourceFile, baseNsid: string) {
|
|
|
50
50
|
moduleSpecifier: `${baseNsid
|
|
51
51
|
.split('.')
|
|
52
52
|
.map((_str) => '..')
|
|
53
|
-
.join('/')}/lexicons`,
|
|
53
|
+
.join('/')}/lexicons.js`,
|
|
54
54
|
})
|
|
55
55
|
.addNamedImports([{ name: 'validate', alias: '_validate' }])
|
|
56
56
|
|
|
@@ -60,7 +60,7 @@ export function genCommonImports(file: SourceFile, baseNsid: string) {
|
|
|
60
60
|
moduleSpecifier: `${baseNsid
|
|
61
61
|
.split('.')
|
|
62
62
|
.map((_str) => '..')
|
|
63
|
-
.join('/')}/util`,
|
|
63
|
+
.join('/')}/util.js`,
|
|
64
64
|
})
|
|
65
65
|
.addNamedImports([
|
|
66
66
|
{ name: '$Typed', isTypeOnly: true },
|
|
@@ -71,7 +71,7 @@ export function genCommonImports(file: SourceFile, baseNsid: string) {
|
|
|
71
71
|
// tsc adds protection against circular imports, which hurts bundle size.
|
|
72
72
|
// Since we know that lexicon.ts and util.ts do not depend on the file being
|
|
73
73
|
// generated, we can safely bypass this protection.
|
|
74
|
-
// Note that we are not using `import * as util from '../../util'` because
|
|
74
|
+
// Note that we are not using `import * as util from '../../util.js'` because
|
|
75
75
|
// typescript will emit is own helpers for the import, which we want to avoid.
|
|
76
76
|
file.addVariableStatement({
|
|
77
77
|
isExported: false,
|
package/src/codegen/server.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
} from 'ts-morph'
|
|
7
7
|
import { type LexiconDoc, Lexicons } from '@atproto/lexicon'
|
|
8
8
|
import { NSID } from '@atproto/syntax'
|
|
9
|
-
import { type GeneratedAPI } from '../types'
|
|
10
|
-
import { gen, lexiconsTs, utilTs } from './common'
|
|
9
|
+
import { type GeneratedAPI } from '../types.js'
|
|
10
|
+
import { gen, lexiconsTs, utilTs } from './common.js'
|
|
11
11
|
import {
|
|
12
12
|
genCommonImports,
|
|
13
13
|
genImports,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
genXrpcInput,
|
|
17
17
|
genXrpcOutput,
|
|
18
18
|
genXrpcParams,
|
|
19
|
-
} from './lex-gen'
|
|
19
|
+
} from './lex-gen.js'
|
|
20
20
|
import {
|
|
21
21
|
type DefTreeNode,
|
|
22
22
|
lexiconsToDefTree,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
toCamelCase,
|
|
25
25
|
toScreamingSnakeCase,
|
|
26
26
|
toTitleCase,
|
|
27
|
-
} from './util'
|
|
27
|
+
} from './util.js'
|
|
28
28
|
|
|
29
29
|
export async function genServerApi(
|
|
30
30
|
lexiconDocs: LexiconDoc[],
|
package/src/index.ts
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { Command } from 'commander'
|
|
5
5
|
import yesno from 'yesno'
|
|
6
|
-
import { genClientApi } from './codegen/client'
|
|
7
|
-
import { genServerApi } from './codegen/server'
|
|
8
|
-
import * as mdGen from './mdgen'
|
|
6
|
+
import { genClientApi } from './codegen/client.js'
|
|
7
|
+
import { genServerApi } from './codegen/server.js'
|
|
8
|
+
import * as mdGen from './mdgen/index.js'
|
|
9
9
|
import {
|
|
10
10
|
applyFileDiff,
|
|
11
11
|
genFileDiff,
|
|
12
12
|
genTsObj,
|
|
13
13
|
printFileDiff,
|
|
14
14
|
readAllLexicons,
|
|
15
|
-
} from './util'
|
|
15
|
+
} from './util.js'
|
|
16
16
|
|
|
17
17
|
const program = new Command()
|
|
18
18
|
program.name('lex').description('Lexicon CLI').version('0.0.0')
|
package/src/mdgen/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export async function process(outFilePath: string, lexicons: LexiconDoc[]) {
|
|
|
13
13
|
let existingContent = ''
|
|
14
14
|
try {
|
|
15
15
|
existingContent = fs.readFileSync(outFilePath, 'utf8')
|
|
16
|
-
} catch
|
|
16
|
+
} catch {
|
|
17
17
|
// ignore - no existing content
|
|
18
18
|
}
|
|
19
19
|
const fileLines: StringTree = existingContent.split('\n')
|
package/src/util.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { join } from 'node:path'
|
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import { ZodError, type ZodFormattedError } from 'zod'
|
|
5
5
|
import { type LexiconDoc, parseLexiconDoc } from '@atproto/lexicon'
|
|
6
|
-
import { type FileDiff, type GeneratedAPI } from './types'
|
|
6
|
+
import { type FileDiff, type GeneratedAPI } from './types.js'
|
|
7
7
|
|
|
8
8
|
export function readAllLexicons(paths: string[]): LexiconDoc[] {
|
|
9
9
|
paths = [...paths].sort() // incoming path order may have come from locale-dependent shell globs
|
|
@@ -14,7 +14,7 @@ export function readAllLexicons(paths: string[]): LexiconDoc[] {
|
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
16
16
|
docs.push(readLexicon(path))
|
|
17
|
-
} catch
|
|
17
|
+
} catch {
|
|
18
18
|
// skip
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
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"],"version":"
|
|
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"],"version":"6.0.3"}
|