Skip to content

Commit fa4ca50

Browse files
committed
Enable twoslash
1 parent 1691436 commit fa4ca50

File tree

8 files changed

+4751
-852
lines changed

8 files changed

+4751
-852
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
lint-and-build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: "20"
21+
22+
- name: Setup pnpm
23+
uses: pnpm/action-setup@v4
24+
with:
25+
run_install: false
26+
27+
- name: Get pnpm store directory
28+
shell: bash
29+
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
30+
31+
- name: Setup pnpm cache
32+
uses: actions/cache@v4
33+
with:
34+
path: ${{ env.STORE_PATH }}
35+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
36+
restore-keys: |
37+
${{ runner.os }}-pnpm-store-
38+
39+
- name: Install dependencies
40+
run: pnpm install --frozen-lockfile
41+
42+
- name: Validate Twoslash code blocks
43+
run: pnpm validate-twoslash

CLAUDE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,15 @@ The documentation covers three main products:
4747
- Key dependencies: React 18, Starknet libraries, Cartridge connector
4848
- Vocs alpha version (1.0.0-alpha.55)
4949

50+
### TypeScript Twoslash Integration
51+
The documentation site supports TypeScript Twoslash for enhanced code blocks that provide:
52+
- Type information on hover
53+
- IntelliSense-like features
54+
- Compile-time error checking in documentation
55+
56+
To use Twoslash in code blocks, add `twoslash` to the language identifier:
57+
```typescript twoslash
58+
// Your TypeScript code here with full type checking
59+
```
60+
5061
When editing content, maintain the existing markdown structure and follow the established sidebar navigation patterns in `vocs.config.ts`.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
"scripts": {
66
"dev": "vocs dev",
77
"build": "vocs build",
8-
"preview": "vocs preview"
8+
"preview": "vocs preview",
9+
"validate-twoslash": "node scripts/validate-twoslash.js"
910
},
1011
"dependencies": {
11-
"@cartridge/connector": "^0.3.46",
12+
"@cartridge/controller": "^0.8.0",
13+
"@cartridge/connector": "^0.8.0",
1214
"@starknet-react/chains": "^0.1.7",
1315
"@starknet-react/core": "^3.5.0",
1416
"@types/react": "^18.3.12",

pnpm-lock.yaml

Lines changed: 4574 additions & 848 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/validate-twoslash.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env node
2+
3+
import { glob } from 'glob';
4+
import { readFile, writeFile, mkdir } from 'fs/promises';
5+
import { join, dirname } from 'path';
6+
import { fileURLToPath } from 'url';
7+
import { exec } from 'child_process';
8+
import { promisify } from 'util';
9+
10+
const execAsync = promisify(exec);
11+
const __dirname = dirname(fileURLToPath(import.meta.url));
12+
const rootDir = join(__dirname, '..');
13+
const tempDir = join(rootDir, 'temp-validation');
14+
15+
// Find all markdown and mdx files
16+
const files = await glob('src/pages/**/*.{md,mdx}', { cwd: rootDir });
17+
18+
let hasErrors = false;
19+
let totalBlocks = 0;
20+
let validatedBlocks = 0;
21+
22+
console.log('🔍 Validating Twoslash code blocks...\n');
23+
24+
// Create temp directory
25+
await mkdir(tempDir, { recursive: true });
26+
27+
for (const file of files) {
28+
const filePath = join(rootDir, file);
29+
const content = await readFile(filePath, 'utf-8');
30+
31+
// Match code blocks with twoslash
32+
const twoslashBlocks = content.match(/```(?:typescript|ts|javascript|js)\s+twoslash\n([\s\S]*?)\n```/g);
33+
34+
if (!twoslashBlocks) continue;
35+
36+
console.log(`📄 Checking ${file}...`);
37+
38+
for (let i = 0; i < twoslashBlocks.length; i++) {
39+
totalBlocks++;
40+
const block = twoslashBlocks[i];
41+
42+
// Extract the code content
43+
const codeMatch = block.match(/```(?:typescript|ts|javascript|js)\s+twoslash\n([\s\S]*?)\n```/);
44+
if (!codeMatch) continue;
45+
46+
const code = codeMatch[1];
47+
const blockNumber = i + 1;
48+
const tempFileName = `${file.replace(/[/\\]/g, '_')}_block_${blockNumber}.ts`;
49+
const tempFilePath = join(tempDir, tempFileName);
50+
51+
try {
52+
// Write code to temp file
53+
await writeFile(tempFilePath, code);
54+
55+
// Run TypeScript compiler
56+
try {
57+
await execAsync(`npx tsc --project tsconfig.validation.json --noEmit "${tempFilePath}"`, {
58+
cwd: rootDir,
59+
env: { ...process.env, NODE_PATH: join(rootDir, 'node_modules') }
60+
});
61+
62+
console.log(`✅ ${file} (block ${blockNumber}): Valid`);
63+
validatedBlocks++;
64+
} catch (error) {
65+
console.error(`❌ ${file} (block ${blockNumber}): TypeScript compilation failed`);
66+
console.error(` ${error.stdout || error.stderr || error.message}`);
67+
hasErrors = true;
68+
}
69+
} catch (error) {
70+
console.error(`❌ ${file} (block ${blockNumber}): Validation error`);
71+
console.error(` ${error.message}`);
72+
hasErrors = true;
73+
}
74+
}
75+
}
76+
77+
// Cleanup temp directory
78+
try {
79+
await execAsync(`rm -rf "${tempDir}"`);
80+
} catch (error) {
81+
console.warn(`Warning: Could not clean up temp directory: ${error.message}`);
82+
}
83+
84+
console.log(`\n📊 Validation Summary:`);
85+
console.log(` Total blocks: ${totalBlocks}`);
86+
console.log(` Valid blocks: ${validatedBlocks}`);
87+
console.log(` Failed blocks: ${totalBlocks - validatedBlocks}`);
88+
89+
if (hasErrors) {
90+
console.error('\n❌ Twoslash validation failed. Please fix the errors above.');
91+
process.exit(1);
92+
} else {
93+
console.log('\n✅ All Twoslash code blocks are valid!');
94+
process.exit(0);
95+
}

src/pages/controller/getting-started.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ seamlessly integrated into your application like any other wallet.
1212

1313
The fastest way to get started is to install the controller package and connect to Cartridge:
1414

15-
```ts
15+
```ts twoslash
1616
import Controller from "@cartridge/controller";
1717

18-
const controller = new Controller();
18+
const controller = new Controller({});
1919
const account = await controller.connect();
2020

2121
// You're ready to execute transactions!

tsconfig.validation.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ES2022",
5+
"moduleResolution": "node",
6+
"allowSyntheticDefaultImports": true,
7+
"esModuleInterop": true,
8+
"strict": true,
9+
"skipLibCheck": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"types": ["node"],
12+
"noEmit": true,
13+
"baseUrl": ".",
14+
"paths": {
15+
"@/*": ["./src/*"]
16+
}
17+
},
18+
"include": ["temp-validation/**/*"]
19+
}

vocs.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ export default defineConfig({
190190
],
191191
},
192192

193+
// Twoslash configuration
194+
twoslash: {},
195+
193196
// Vite configuration
194197
vite: {
195198
plugins: [svgr()],

0 commit comments

Comments
 (0)