Skip to content
Closed
Show file tree
Hide file tree
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 Dec 1, 2024
7fc335c
adding ts support
skiniks Dec 1, 2024
0e38ff9
types generation packages
skiniks Dec 1, 2024
3d773d8
lock update
skiniks Dec 1, 2024
da22d64
generating types from the lexicons
skiniks Dec 1, 2024
cc7fd71
moving types to `packages/lexicons`
skiniks Dec 1, 2024
355716f
adding dependencies for generated types
skiniks Dec 1, 2024
f8caf66
remove private
skiniks Dec 1, 2024
586ed01
fixing object key order
skiniks Dec 1, 2024
d918fe4
adding publishConfig
skiniks Dec 1, 2024
5d3d075
moving devDeps to @tsky/lexicons
skiniks Dec 2, 2024
837a560
adding tsconfig
skiniks Dec 2, 2024
85d37d6
updating gitignores
skiniks Dec 2, 2024
4dc007d
moving script to @tsky/lexicons
skiniks Dec 2, 2024
3775674
Merge branch 'main' into feat/lexicon-type-generation
skiniks Dec 2, 2024
9fbf07b
Update packages/lexicons/package.json
skiniks Dec 2, 2024
224675e
adding generated files
skiniks Dec 2, 2024
2b10ecc
chore: set casing for tsky, Tsky, Bluesky (#24)
patak-dev Dec 2, 2024
889e16d
refactor: migrate to scoped package structure (@tsky/*) (#25)
skiniks Dec 2, 2024
f57d7b5
Update packages/lexicons/package.json
skiniks Dec 2, 2024
611e72e
adding generated files
skiniks Dec 2, 2024
f467391
Merge branch 'feat/lexicon-type-generation' of https://github.com/ski…
skiniks Dec 4, 2024
169a5c4
Merge branch 'main' into feat/lexicon-type-generation
skiniks Dec 4, 2024
8b372ff
lockfile update
skiniks Dec 4, 2024
b77f77b
linting
skiniks Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions package.json
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 --"]
}
}
4 changes: 4 additions & 0 deletions packages/lexicons/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
atproto.tar.gz
node_modules/
dist/
/lexicons/
23 changes: 23 additions & 0 deletions packages/lexicons/package.json
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": {
"@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"
}
}
98 changes: 98 additions & 0 deletions packages/lexicons/scripts/generate-types.ts
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();
14 changes: 14 additions & 0 deletions packages/lexicons/tsconfig.json
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"]
}
Loading
Loading