Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pileks/feat/multidocs #317

Merged
merged 13 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ const config = {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
additionalLanguages: [
"rust"
"toml",
"rust",
"python",
"kotlin",
"swift",
"rust",
"shell-session"
]
},
}),
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@docusaurus/core": "2.4.0",
"@docusaurus/preset-classic": "2.4.0",
"@docusaurus/core": "^2.4.3",
"@docusaurus/preset-classic": "^2.4.3",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@mdx-js/react": "^1.6.22",
Expand All @@ -47,7 +47,7 @@
"react-dom": "^17.0.2"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "2.4.0",
"@docusaurus/module-type-aliases": "^2.4.3",
"@tsconfig/docusaurus": "^1.0.5",
"doc-snippets": "^1.0.0",
"npm-run-all": "^4.1.5",
Expand All @@ -72,10 +72,11 @@
},
"doc-snippets": {
"extract": {
"include": "./**/*.{ts,tsx,json,yaml,txt,md,graphql,cue}",
"include": "./**/*.{ts,tsx,js,json,yaml,txt,md,graphql,cue,kt,kts,py,swift,rs}",
"ignore": [
"./**/node_modules/**",
"./**/.polywrap/**"
"./**/.polywrap/**",
"./**/build/**"
],
"dir": "./snippets"
},
Expand Down
12 changes: 11 additions & 1 deletion sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
const sidebars = {
docs: [
'introduction',
'quick-start',
{
type: 'category',
label: 'Quick Start',
items: [
'quick-start/javascript',
'quick-start/rust',
'quick-start/python',
'quick-start/kotlin',
'quick-start/swift',
]
},
'clients',
'cli',
{
Expand Down
17 changes: 17 additions & 0 deletions snippets/cli/examples/kt-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
wrap
.polywrap
1 change: 1 addition & 0 deletions snippets/cli/examples/kt-example/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
109 changes: 109 additions & 0 deletions snippets/cli/examples/kt-example/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.serialization")
id("com.github.node-gradle.node")
}

android {
namespace = "io.template.polywrap"
compileSdk = 33

defaultConfig {
applicationId = "io.template.polywrap"
minSdk = 24
targetSdk = 33
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.8"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {
// polywrap client
implementation("io.polywrap:polywrap-client:0.10.4")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1")
// polywrap logger plugin
implementation("io.polywrap.plugins:logger:0.10.4")
implementation("com.github.tony19:logback-android:3.0.0")

// ui
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1")

// defaults
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
implementation("androidx.activity:activity-compose:1.7.2")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}

// set up NodeJS to run the Polywrap CLI
// NodeJS installation will be stored in gradle cache
node {
val nullString: String? = null
distBaseUrl.set(nullString)
// Whether to download and install a specific Node.js version or not
// If false, it will use the globally installed Node.js
// If true, it will download node using above parameters
// Note that npm is bundled with Node.js
download.set(true)
}

// run polwyrap codegen
tasks.register<com.github.gradle.node.npm.task.NpxTask>("codegen") {
group = "polywrap"
dependsOn(tasks.npmInstall)
command.set("polywrap")
args.set(listOf("codegen",
"-m", "$rootDir/polywrap.yaml",
"-g", "$projectDir/src/main/java/wrap"
))
}

// set polywrap codegen to run before each build
tasks.withType<KotlinCompile> { dependsOn("codegen") }
21 changes: 21 additions & 0 deletions snippets/cli/examples/kt-example/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.template.polywrap

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("io.template.polywrap", appContext.packageName)
}
}
28 changes: 28 additions & 0 deletions snippets/cli/examples/kt-example/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Template"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Template">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
18 changes: 18 additions & 0 deletions snippets/cli/examples/kt-example/app/src/main/assets/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<configuration
xmlns="https://tony19.github.io/logback-android/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://tony19.github.io/logback-android/xml https://cdn.jsdelivr.net/gh/tony19/logback-android/logback.xsd"
>
<appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
<tagEncoder>
<pattern>%logger{12}</pattern>
</tagEncoder>
<encoder>
<pattern>[%-20thread] %msg</pattern>
</encoder>
</appender>

<root level="DEBUG">
<appender-ref ref="logcat" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.template.polywrap

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import io.template.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
Column(
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxHeight().padding(16.dp)
) {
Surface(
modifier = Modifier.fillMaxWidth().height(60.dp),
color = MaterialTheme.colorScheme.background
) {
PolywrapDemo()
}
}
}
}
}
}

@Composable
fun PolywrapDemo(demoViewModel: PolywrapDemoViewModel = viewModel()) {
Button(onClick = { demoViewModel.polywrapDemo() }) {
Text(text = "Click here and check the logs!")
}
}

@Preview(showBackground = true)
@Composable
fun PolywrapDemoPreview() {
MyApplicationTheme {
PolywrapDemo()
}
}
Loading
Loading