npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thelacanians/vue-native-codegen

v0.6.4

Published

Code generator for Vue Native <native> blocks - generates Swift, Kotlin, and TypeScript code

Readme

@thelacanians/vue-native-codegen

Code generator for Vue Native <native> blocks. Generates Swift, Kotlin, and TypeScript code from native blocks extracted from Vue Single File Components.

Installation

bun add @thelacanians/vue-native-codegen

Usage

Basic Usage

import { parseDirectory } from '@thelacanians/vue-native-sfc-parser'
import { generateCode, writeGeneratedFiles } from '@thelacanians/vue-native-codegen'

// Parse SFCs to extract native blocks
const result = parseDirectory('app/', { exclude: ['node_modules', 'dist'] })

// Generate code
const codegen = generateCode(result.allNativeBlocks)

// Write to disk
writeGeneratedFiles(codegen)

console.log(`Generated ${codegen.stats.swiftFiles} Swift files`)
console.log(`Generated ${codegen.stats.kotlinFiles} Kotlin files`)
console.log(`Generated ${codegen.stats.typescriptFiles} TypeScript files`)

With Custom Options

const codegen = generateCode(result.allNativeBlocks, {
  root: '/path/to/project',
  iosOutputDir: 'native/ios/GeneratedModules',
  androidOutputDir: 'native/android/GeneratedModules',
  typescriptOutputDir: 'src/generated',
  generateSwift: true,
  generateKotlin: true,
  generateTypeScript: true,
  includeHeader: true,
})

Generate Specific File Types

// Generate only Swift (no Kotlin or TypeScript)
const swiftOnly = generateCode(blocks, {
  generateSwift: true,
  generateKotlin: false,
  generateTypeScript: false,
})

// Generate only TypeScript composables
const tsOnly = generateCode(blocks, {
  generateSwift: false,
  generateKotlin: false,
  generateTypeScript: true,
})

Clean Generated Files

import { cleanGeneratedFiles } from '@thelacanians/vue-native-codegen'

cleanGeneratedFiles({
  iosOutputDir: 'native/ios/GeneratedModules',
  androidOutputDir: 'native/android/GeneratedModules',
  typescriptOutputDir: 'src/generated',
})

API Reference

Functions

generateCode(blocks, options)

Generate code from native blocks.

  • Parameters:
    • blocks (NativeBlock[]) - Array of native blocks
    • options (CodegenOptions) - Generation options
  • Returns: CodegenResult

writeGeneratedFiles(result, rootDir)

Write generated files to disk.

  • Parameters:
    • result (CodegenResult) - Code generation result
    • rootDir (string) - Project root directory
  • Returns: { written: number, errors: ParseError[] }

cleanGeneratedFiles(options, rootDir)

Clean generated files from output directories.

  • Parameters:
    • options (CodegenOptions) - Generation options
    • rootDir (string) - Project root directory

generateSwiftFile(block, options)

Generate a single Swift file from a native block.

  • Parameters:
    • block (NativeBlock) - Native block
    • options (CodegenOptions) - Generation options
  • Returns: GeneratedFile

generateKotlinFile(block, options)

Generate a single Kotlin file from a native block.

  • Parameters:
    • block (NativeBlock) - Native block
    • options (CodegenOptions) - Generation options
  • Returns: GeneratedFile

generateTypeScriptFile(blocks, componentName, options)

Generate a TypeScript composable file from native blocks.

  • Parameters:
    • blocks (NativeBlock[]) - Native blocks for the component
    • componentName (string) - Component name
    • options (CodegenOptions) - Generation options
  • Returns: GeneratedFile

generateSwiftRegistration(blocks)

Generate Swift module registration code.

  • Parameters:
    • blocks (NativeBlock[]) - Swift native blocks
  • Returns: string

generateKotlinRegistration(blocks)

Generate Kotlin module registration code.

  • Parameters:
    • blocks (NativeBlock[]) - Kotlin native blocks
  • Returns: string

Types

CodegenOptions

interface CodegenOptions {
  root?: string
  iosOutputDir?: string
  androidOutputDir?: string
  macosOutputDir?: string
  typescriptOutputDir?: string
  generateTypeScript?: boolean
  generateSwift?: boolean
  generateKotlin?: boolean
  includeHeader?: boolean
}

CodegenResult

interface CodegenResult {
  files: GeneratedFile[]
  errors: ParseError[]
  warnings: ParseError[]
  stats: {
    totalBlocks: number
    swiftFiles: number
    kotlinFiles: number
    typescriptFiles: number
  }
}

GeneratedFile

interface GeneratedFile {
  platform: 'ios' | 'android' | 'macos'
  language: 'swift' | 'kotlin' | 'typescript'
  content: string
  outputPath: string
  sourceBlock: NativeBlock
}

Example Output

Input: Vue SFC with <native> Block

<template>
  <VView>
    <VText>{{ message }}</VText>
  </VView>
</template>

<script setup lang="ts">
import { useHaptics } from '@/generated/useHaptics'
const { vibrate } = useHaptics()
</script>

<native platform="ios">
class HapticsModule: NativeModule {
  var moduleName: String { "Haptics" }
  
  func invoke(method: String, args: [Any], callback: @escaping (Any?, String?) -> Void) {
    switch method {
    case "vibrate":
      let style = args[0] as? String ?? "medium"
      vibrate(style: style)
      callback(nil, nil)
    default:
      callback(nil, "Unknown method")
    }
  }
  
  func vibrate(style: String) {
    // Implementation
  }
}
</native>

Output: Generated Swift File

// ────────────────────────────────────────────────────────────────────────────────
//  Auto-Generated Code
// ────────────────────────────────────────────────────────────────────────────────
//
//  Generated from: Haptics.vue
//  Component: Haptics
//  Platform: ios
//  Language: Swift
//
//  ⚠️  WARNING: This file is auto-generated. DO NOT EDIT MANUALLY.
//      Changes will be overwritten by the code generator.
//
// ────────────────────────────────────────────────────────────────────────────────

import Foundation
import VueNativeCore

/// Auto-generated native module from Haptics.vue
/// Platform: ios
final class HapticsModule: NativeModule {
    var moduleName: String { "Haptics" }
    
    // User-provided implementation
    class HapticsModule: NativeModule {
      var moduleName: String { "Haptics" }
      
      func invoke(method: String, args: [Any], callback: @escaping (Any?, String?) -> Void) {
        // ...
      }
    }
}

Output: Generated TypeScript Composable

// ────────────────────────────────────────────────────────────────────────────────
//  Auto-Generated Code
// ────────────────────────────────────────────────────────────────────────────────
//
//  Component: Haptics
//  Language: TypeScript
//
//  ⚠️  WARNING: This file is auto-generated. DO NOT EDIT MANUALLY.
//      Changes will be overwritten by the code generator.
//
// ────────────────────────────────────────────────────────────────────────────────

import { NativeBridge } from '../bridge'

/**
 * Type-safe interface for the Haptics native module
 * Auto-generated from <native> blocks in Haptics.vue
 */
export interface HapticsModule {
  vibrate(style: string): Promise<void>
}

/**
 * Composable for using the Haptics native module
 */
export function useHaptics(): HapticsModule {
  return {
    vibrate(style: string) {
      return NativeBridge.invokeNativeModule('Haptics', 'vibrate', [style])
    },
  }
}

License

MIT