-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(types): add lexicon type generation #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6325e0a
ignore lexicons dir and temp file
skiniks 7fc335c
adding ts support
skiniks 0e38ff9
types generation packages
skiniks 3d773d8
lock update
skiniks da22d64
generating types from the lexicons
skiniks cc7fd71
moving types to `packages/lexicons`
skiniks 355716f
adding dependencies for generated types
skiniks f8caf66
remove private
skiniks 586ed01
fixing object key order
skiniks d918fe4
adding publishConfig
skiniks 5d3d075
moving devDeps to @tsky/lexicons
skiniks 837a560
adding tsconfig
skiniks 85d37d6
updating gitignores
skiniks 4dc007d
moving script to @tsky/lexicons
skiniks 3775674
Merge branch 'main' into feat/lexicon-type-generation
skiniks 9fbf07b
Update packages/lexicons/package.json
skiniks 224675e
adding generated files
skiniks 2b10ecc
chore: set casing for tsky, Tsky, Bluesky (#24)
patak-dev 889e16d
refactor: migrate to scoped package structure (@tsky/*) (#25)
skiniks f57d7b5
Update packages/lexicons/package.json
skiniks 611e72e
adding generated files
skiniks f467391
Merge branch 'feat/lexicon-type-generation' of https://github.com/ski…
skiniks 169a5c4
Merge branch 'main' into feat/lexicon-type-generation
skiniks 8b372ff
lockfile update
skiniks b77f77b
linting
skiniks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,33 @@ | ||
| { | ||
| "name": "tsky", | ||
| "type": "module", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "packageManager": "pnpm@9.14.2", | ||
| "license": "MIT", | ||
| "homepage": "https://tsky.dev/", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/tsky-dev/tsky.git" | ||
| }, | ||
| "scripts": { | ||
| "dev": "pnpm run --filter @tsky/core dev", | ||
| "build": "pnpm run --filter @tsky/core build", | ||
| "docs:dev": "pnpm run --filter @tsky/docs dev", | ||
| "docs:build": "pnpm run --filter @tsky/docs build", | ||
| "docs:preview": "pnpm run --filter @tsky/docs preview", | ||
| "format": "biome format", | ||
| "format:fix": "biome format --write .", | ||
| "lint": "biome lint .", | ||
| "lint:fix": "biome lint --write .", | ||
| "check": "biome check", | ||
| "check:fix": "biome check --write ." | ||
| }, | ||
| "devDependencies": { | ||
| "@biomejs/biome": "^1.9.4", | ||
| "nano-staged": "^0.8.0" | ||
| }, | ||
| "nano-staged": { | ||
| "*.{js,ts,cjs,mjs,json}": ["biome check --write --"] | ||
| } | ||
| } | ||
| { | ||
| "name": "tsky", | ||
| "type": "module", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "packageManager": "pnpm@9.14.2", | ||
| "license": "MIT", | ||
| "homepage": "https://tsky.dev/", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/tsky-dev/tsky.git" | ||
| }, | ||
| "scripts": { | ||
| "dev": "pnpm run --filter @tsky/core dev", | ||
| "build": "pnpm run --filter @tsky/core build", | ||
| "docs:dev": "pnpm run --filter @tsky/docs dev", | ||
| "docs:build": "pnpm run --filter @tsky/docs build", | ||
| "docs:preview": "pnpm run --filter @tsky/docs preview", | ||
| "format": "biome format", | ||
| "format:fix": "biome format --write .", | ||
| "lint": "biome lint .", | ||
| "lint:fix": "biome lint --write .", | ||
| "check": "biome check", | ||
| "check:fix": "biome check --write ." | ||
| }, | ||
| "devDependencies": { | ||
| "@biomejs/biome": "^1.9.4", | ||
| "nano-staged": "^0.8.0" | ||
| }, | ||
| "nano-staged": { | ||
| "*.{js,ts,cjs,mjs,json}": ["biome check --write --"] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| atproto.tar.gz | ||
| node_modules/ | ||
| dist/ | ||
| /lexicons/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "@tsky/lexicons", | ||
| "type": "module", | ||
| "version": "0.0.1", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsx ./scripts/generate-types.ts" | ||
| }, | ||
| "dependencies": { | ||
skiniks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "@atproto/lexicon": "^0.4.3", | ||
| "@atproto/xrpc": "^0.6.4", | ||
| "multiformats": "^13.3.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@atproto/lex-cli": "^0.5.2", | ||
| "@types/node": "^22.10.1", | ||
| "tar": "^7.4.3", | ||
| "tsx": "^4.19.2", | ||
| "typescript": "^5.7.2" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { Buffer } from 'node:buffer'; | ||
| import { execSync } from 'node:child_process'; | ||
| import fs from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
| import process from 'node:process'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import * as tar from 'tar'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| const LEXICONS_DIR = path.resolve(__dirname, '../lexicons'); | ||
| const TYPES_DIR = path.resolve(__dirname, '../src'); | ||
| const REPO = 'bluesky-social/atproto'; | ||
|
|
||
| async function findJsonFiles(dir: string): Promise<string[]> { | ||
| const files: string[] = []; | ||
| const entries = await fs.readdir(dir, { withFileTypes: true }); | ||
|
|
||
| for (const entry of entries) { | ||
| const fullPath = path.join(dir, entry.name); | ||
| if (entry.isDirectory()) { | ||
| files.push(...(await findJsonFiles(fullPath))); | ||
| } else if (entry.isFile() && entry.name.endsWith('.json')) { | ||
| files.push(fullPath); | ||
| } | ||
| } | ||
|
|
||
| return files; | ||
| } | ||
|
|
||
| async function main() { | ||
| try { | ||
| // Ensure directories exist | ||
| await fs.mkdir(LEXICONS_DIR, { recursive: true }); | ||
| await fs.mkdir(TYPES_DIR, { recursive: true }); | ||
|
|
||
| // Get latest commit SHA for lexicons | ||
| console.log('Getting latest lexicon commit...'); | ||
| const shaResponse = await fetch( | ||
| `https://api.github.com/repos/${REPO}/commits?path=lexicons/`, | ||
| ); | ||
| if (!shaResponse.ok) { | ||
| throw new Error(`Failed to get commit SHA: ${shaResponse.statusText}`); | ||
| } | ||
|
|
||
| const commits = await shaResponse.json(); | ||
| const sha = commits[0]?.sha; | ||
| if (!sha) { | ||
| throw new Error('No commits found for lexicons'); | ||
| } | ||
|
|
||
| // Download specific commit's lexicons | ||
| console.log('Downloading lexicons from atproto...'); | ||
| const response = await fetch( | ||
| `https://github.com/${REPO}/archive/${sha}.tar.gz`, | ||
| ); | ||
| if (!response.ok) { | ||
| throw new Error(`Failed to download lexicons: ${response.statusText}`); | ||
| } | ||
|
|
||
| // Create a temporary file for the tar download | ||
| const tarFile = path.join(LEXICONS_DIR, 'atproto.tar.gz'); | ||
| await fs.writeFile(tarFile, Buffer.from(await response.arrayBuffer())); | ||
|
|
||
| // Extract only lexicon files | ||
| await tar.x({ | ||
| file: tarFile, | ||
| cwd: LEXICONS_DIR, | ||
| filter: (path) => path.includes('/lexicons/'), | ||
| strip: 2, | ||
| }); | ||
|
|
||
| // Clean up tar file | ||
| await fs.unlink(tarFile); | ||
|
|
||
| // Find all lexicon JSON files | ||
| console.log('Finding lexicon files...'); | ||
| const lexiconFiles = await findJsonFiles(LEXICONS_DIR); | ||
| if (lexiconFiles.length === 0) { | ||
| throw new Error('No lexicon files found'); | ||
| } | ||
|
|
||
| // Generate types using @atproto/lex-cli | ||
| console.log('Generating types...'); | ||
| execSync(`pnpm lex gen-api ${TYPES_DIR} ${lexiconFiles.join(' ')}`, { | ||
| stdio: 'inherit', | ||
| cwd: TYPES_DIR, | ||
| }); | ||
|
|
||
| console.log('Done! Types generated in', TYPES_DIR); | ||
| } catch (error) { | ||
| console.error('Error:', error); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "module": "ESNext", | ||
| "moduleResolution": "node", | ||
| "resolveJsonModule": true, | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["scripts/**/*", "src/**/*"], | ||
| "exclude": ["node_modules"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.