diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07c45cf..d8ffb00 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,12 +36,6 @@ jobs: - name: Run unit tests run: npm test - - name: Run CLI comprehensive tests - run: | - echo "⚠️ Skipping comprehensive CLI tests in CI due to stdin interaction issues" - echo "✅ These tests should be run manually before releases" - echo " Command: npm run build && node test-cli-comprehensive.js" - template-validation: runs-on: ubuntu-latest needs: test diff --git a/README.md b/README.md index 57b4472..0099a12 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,13 @@ A TypeScript SDK toolkit for building Dapps on Polkadot Cloud - inspired by Hard ## Features -🚀 **Quick Project Setup** - Initialize Polkadot Dapp projects in seconds with `kitdot install` -🎨 **React + Solidity Templates** - Production-ready templates with Vite, Tailwind CSS, and wagmi -⚙️ **Smart Contracts** - Hardhat setup for Solidity development on Polkadot Asset Hub -📋 **AI Development Guide** - Integrated AGENTS.md for LLM-assisted development -🔧 **Developer Tools** - Rust toolchain management and status checking -🌐 **Polkadot Integration** - Pre-configured for Paseo testnet with proper network settings +- 🚀 **Quick Project Setup** - Initialize Polkadot Dapp projects in seconds with `kitdot install` +- 🔐 **Web3Auth Social Logins** - Seamless user onboarding with Google, GitHub, Discord, Twitter, and more. [Try the live demo →](https://kitdot-fronted-templates.w3d.community/quick-starts/react-quick-start/) +- 🎨 **React Templates** - Production-ready templates with Vite, Tailwind CSS, and wagmi +- ⚙️ **Smart Contracts** - Hardhat setup for Solidity development on Polkadot Asset Hub +- 📋 **AI Development Guide** - Integrated AGENTS.md for LLM-assisted development +- 🔧 **Developer Tools** - Rust toolchain management and status checking +- 🌐 **Polkadot Integration** - Pre-configured for Paseo testnet with proper network settings ## Installation @@ -33,36 +34,38 @@ npx kitdot init my-polkadot-dapp ## Quick Start -# Quick start with default template +### Recommended: Use Web3Auth Default Templates for Best User Experience +```bash kitdot install -y my-app - ``` +**✨ Live Demo:** [https://kitdot-fronted-templates.w3d.community/quick-starts/react-quick-start/](https://kitdot-fronted-templates.w3d.community/quick-starts/react-quick-start/) + +**Why Web3Auth?** No seed phrases, no private key management - users log in with Google, GitHub, or other social accounts they already use. + The CLI will guide you through setting up: -- **Full-stack Dapp** - React frontend + Solidity contracts + Hardhat -- **Frontend only** - React app with wagmi for Polkadot interaction +- **Frontend only** - React app with Web3Auth social logins + wagmi for Polkadot interaction +- **Full-stack Dapp** - React frontend with Web3Auth + Solidity contracts + Hardhat - **Backend only** - Smart contracts with Hardhat development environment ## Project Structure ``` - my-polkadot-dapp/ -├── contracts/ # Hardhat smart contracts (Solidity) -│ ├── contracts/ # Smart contract source files -│ ├── ignition/ # Hardhat Ignition deployment modules -│ ├── test/ # Contract tests -│ └── hardhat.config.ts # Hardhat configuration for Polkadot -├── frontend/ # React frontend with Polkadot integration -│ ├── src/ # React TypeScript source -│ ├── src/generated.ts # Auto-generated contract types -│ └── wagmi.config.ts # wagmi configuration for Polkadot -├── AGENTS.md # AI development guide for LLMs -└── README.md # Project-specific documentation - -```` +├── contracts/ # Hardhat smart contracts (Solidity) +│ ├── contracts/ # Smart contract source files +│ ├── ignition/ # Hardhat Ignition deployment modules +│ ├── test/ # Contract tests +│ └── hardhat.config.ts # Hardhat configuration for Polkadot +├── frontend/ # React frontend with Polkadot integration +│ ├── src/ # React TypeScript source +│ ├── src/generated.ts # Auto-generated contract types +│ └── wagmi.config.ts # wagmi configuration for Polkadot +├── AGENTS.md # AI development guide for LLMs +└── README.md # Project-specific documentation +``` ## Commands @@ -79,7 +82,7 @@ kitdot tools check # Check tool status # Help kitdot --help # Show all available commands kitdot init --help # Show specific command help -```` +``` > **Note**: Replace `kitdot` with `npx kitdot` if you haven't installed globally. @@ -111,38 +114,21 @@ npm run generate # Generate contract types from deployed c npm run dev # Start development server ``` -### 4. Environment Setup - -```bash -# Set up private key for contract deployment -npx hardhat vars set PRIVATE_KEY # In contracts directory - -# Get testnet tokens -# Visit: https://faucet.polkadot.io/?parachain=1111 -``` - -## Technology Stack - -### Smart Contracts - -- **Hardhat** - Development environment with Polkadot support via `@parity/hardhat-polkadot` -- **Solidity ^0.8.28** - Smart contract programming language (required version) -- **Hardhat Ignition** - Modern deployment system with dependency management -- **Polkadot Asset Hub** - Target network for smart contract deployment - -### Frontend - -- **React 18** - Modern UI library with TypeScript -- **wagmi** - React hooks for Ethereum/Polkadot contract interaction -- **Viem** - TypeScript interface for Ethereum-compatible chains -- **Tailwind CSS** - Utility-first CSS framework with Tailwind UI components -- **Vite** - Fast build tool and development server - ## Templates kitdot includes production-ready templates: -### Default Template +### ⭐ Recommended: React + Web3Auth (Frontend Only) + +- **Social Login Integration** - [Live Demo](https://kitdot-fronted-templates.w3d.community/quick-starts/react-quick-start/) + - **Web3Auth** for seamless social logins (Google, GitHub, Discord, Twitter, etc.) + - No seed phrases or private key management for users + - React 18 frontend with TypeScript and Tailwind CSS + - wagmi hooks for Polkadot interaction + - Pre-configured for Paseo testnet + - Modern, production-ready UX with social authentication + +### Full-stack Template - **React + Solidity + Hardhat** - Full-stack template with: - React 18 frontend with TypeScript and Tailwind CSS @@ -159,8 +145,4 @@ kitdot includes production-ready templates: - Network configurations and deployment instructions - Security patterns and best practices - Troubleshooting checklists and common solutions - - Recommended development workflows - -## License - -MIT License - see [LICENSE](LICENSE) for details. + - Recommended development workflows \ No newline at end of file diff --git a/jest.config.cjs b/jest.config.cjs index 81ce7b2..46b7143 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -14,8 +14,11 @@ module.exports = { '^.+\\.(ts|js)$': ['ts-jest', { useESM: true, tsconfig: { + module: 'ES2022', target: 'ES2022', - module: 'ESNext' + moduleResolution: 'node', + esModuleInterop: true, + resolveJsonModule: true } }] }, diff --git a/package.json b/package.json index c551f19..611a15a 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "start": "node dist/cli.js", "lint": "eslint src/**/*.ts", "lint:fix": "eslint src/**/*.ts --fix", - "test": "jest", - "test:templates": "jest --testPathPattern=template-validation", + "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", + "test:templates": "node --experimental-vm-modules node_modules/jest/bin/jest.js --testPathPattern=template-validation", "prepublishOnly": "npm run build" }, "keywords": [ diff --git a/src/utils/sdk-paths.ts b/src/utils/sdk-paths.ts index 696db9b..3931da1 100644 --- a/src/utils/sdk-paths.ts +++ b/src/utils/sdk-paths.ts @@ -3,19 +3,82 @@ import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); - -function findTemplatesDir(maxUp = 5): string { - let dir = __dirname; - for (let i = 0; i <= maxUp; i++) { - const candidate = path.join(dir, "templates"); - if (fs.existsSync(candidate)) return candidate; +// Get the directory of this source file +// In production: dist/utils/sdk-paths.js +// In development: src/utils/sdk-paths.ts +function getFileDir(): string { + return path.dirname(fileURLToPath(import.meta.url)); +} + +// Find the SDK root by searching upward from this file's location +// This works whether the package is installed globally or run from source +function findSDKRootSync(): string { + let dir = getFileDir(); + const maxUp = 10; // Search up to 10 levels + + for (let i = 0; i < maxUp; i++) { + const packageJsonPath = path.join(dir, "package.json"); + if (fs.existsSync(packageJsonPath)) { + try { + const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + // Check if this is the kitdot package + if (pkg.name === 'kitdot') { + return dir; + } + } catch (_e) { + // Invalid package.json, continue searching + } + } + const parent = path.dirname(dir); + if (parent === dir) break; // Reached root + dir = parent; + } + + // Fallback: search from cwd (useful for tests) + dir = process.cwd(); + for (let i = 0; i < maxUp; i++) { + const packageJsonPath = path.join(dir, "package.json"); + if (fs.existsSync(packageJsonPath)) { + try { + const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + if (pkg.name === 'kitdot') { + return dir; + } + } catch (_e) { + // Invalid package.json, continue searching + } + } const parent = path.dirname(dir); if (parent === dir) break; dir = parent; } - throw new Error("templates folder not found (checked up from __dirname)"); + + throw new Error('Could not find kitdot package root'); +} + +// Cache the SDK root +let _sdkRoot: string | null = null; + +function getSDKRoot(): string { + if (!_sdkRoot) { + _sdkRoot = findSDKRootSync(); + } + return _sdkRoot; +} + +export async function findSDKRoot(): Promise { + return getSDKRoot(); +} + +function findTemplatesDir(): string { + const sdkRoot = getSDKRoot(); + const templatesPath = path.join(sdkRoot, "templates"); + + if (fs.existsSync(templatesPath)) { + return templatesPath; + } + + throw new Error(`templates folder not found in SDK root: ${sdkRoot}`); } export function resolveTemplatePath(templatePath: string): string {