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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lightningkite/khrysalis-runtime

v1.0.5

Published

The runtime for the Kotlin to Typescript transpiler.

Downloads

521

Readme

Khrysalis

This is synced

image

By Lightning Kite

Khrysalis is a low-commitment multiplatform application development system based on converting Android apps into iOS apps.

Khrysalis is actively being used by Lightning Kite to develop apps that are soon to reach production, and is still regularly receiving major upgrades.

Khrysalis is fully open-sourced under the MIT license.

Benefits

  • Results in two entirely separate codebases - one in Kotlin for Android, and one in Swift for iOS. If you want to back out of using Khrysalis, you can do so at any time, just using some basic library pieces from it instead.
  • Gradual introduction into codebase, as existing code can be used with new translated code.
  • Rapid prototyping, allowing a full click-through app to be created with just XML.
  • Full underlying platform access - since you use the underlying languages in their native environments, using native libraries is extremely simple.
  • Easy to learn for existing mobile devs, as the core language is Kotlin and you mostly just use normal Kotlin tools.
  • Leverages the long-used Rx set of libraries, RxJava and RxSwift, for observable-based programming

What actually is it?

A transpiler between Kotlin and Swift with an emphasis on readability over supporting all Kotlin features.

Also includes a runtime for iOS in order to make compilation easier, which over time is being reduced in size.

What code can I share between Android and iOS?

You can share almost all Kotlin code that:

  • uses declarations that have the same signature on both sides OR has translation information in the form of a YAML file
  • doesn't rely on untranslatable generics, such as the use of * in a variable type
  • doesn't use delegates (the by expression in a class header, may be supported in the future)

There are several libraries we use at Lightning Kite that are explicitly Khrysalis supported.

What if I need to do something platform specific?

Cool! That's easy - all you have to do is ensure there are same-signature declarations on both sides!

Simple Example

Let's demonstrate the most basic example of exposing platform-specific code for shared use. We start by making declarations in Android and iOS separately:

// File is greeting.kt
val greeting: String = "Welcome to the Android App!"
// File is greeting.swift
public let greeting: String = "Welcome to the iOS App!"

Now that the declarations match, we can access it in shared code:

// File is demo.shared.kt
// Files with '.shared.kt' at the end can be translated from Kotlin to Swift via a Gradle task
fun demo(){
    println("This is the demo for shared code.")
    println(greeting)
}

Firebase Example

For example, let's say I want to use Firebase Realtime Database on both sides to simply set the user's name. First, we:

  • Set up the library on both apps as normal.
  • Ensure the declarations you intend to use have the same signature on both sides, and if not, add stuff to make them match for what you need.

Based on reading the Firebase documentation, we'll make:

// File is MyFirebase.kt in the Android project
object MyFirebase {
    fun get(): DatabaseReference {
        return FirebaseDatabase.getInstance().reference
    }
}
// File is MyFirebase.swift in the iOS project
public class MyFirebase {
    private init(){}
    static func get() -> DatabaseReference {
        return Database.database().reference()
    }
}

Both sides already define the same signature functions for DatabaseReference, including child(key) and setValue(String), so we don't have to do anything special to use those in shared code.

Now, in shared code file, we could do this:

// File is MyLogic.shared.kt in the Android Project
// Will get syntax-transformed upon running a task in the project.
fun updateUsersName(forUser: String, newName: String){
    MyFirebase.get().child("users").child(forUser).child("username").setValue(newName)
}

You'll likely find that lots of different libraries that have been written for both Android and iOS share a fairly similar API, and thus require little-to-no tweaking to be used.

Usage

This library is published in Maven Central.

Example Project

You can see the example project here.

Usage in a project

In your Gradle file, add the following:

//Using Gradle Kotlin DSL

plugins {
    //...
    id("com.lightningkite.khrysalis")
}

//...

khrysalis {
    projectName = "MyProject"
    overrideIosFolder = project.rootDir.absoluteFile.resolve("../ios") // Path to iOS project root
}

You then need to provide paths to search for Swift equivalent files (ending in swift.yaml) that define how elements in Kotlin code are translated to Swift.

If you are on a Mac, the files are searched for based on your pods. The equivalent files are expected to be in the iOS project and its dependencies.

If you are not on a Mac, you can manually define the paths to search in your local.properties folder as follows:

khrysalis.iospods=path:another/path:yet/another/path

Available Gradle Tasks

  • khrysalisIos
    • Completely converts the project to iOS. Performs all of the following tasks:
      • khrysalisConvertKotlinToSwift
        • Converts Kotlin to Swift for any files with .shared.kt at the end or the @SharedCode annotation.
      • khrysalisUpdateIosVersion
        • Updates the version number/code in the iOS project to match this project.