Browse Source

implement plain-js bundle example/test

main
James Fenn 1 year ago
parent
commit
279b599b7f
36 changed files with 78 additions and 9 deletions
  1. +10
    -0
      README.md
  2. +2
    -0
      build.gradle
  3. +15
    -0
      example-js/build.gradle
  4. +28
    -0
      example-js/index.html
  5. +1
    -1
      example-kotlinbrowser/build.gradle
  6. +1
    -1
      example-nodejs/build.gradle
  7. +1
    -1
      example-nodejs/package.json
  8. +3
    -3
      example-nodejs/src/index.js
  9. +14
    -0
      gitrest/build.gradle
  10. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/RequestProviderDelegate.kt
  11. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/base/RequestProvider.kt
  12. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/base/ServiceBuilder.kt
  13. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/gitea/GiteaProvider.kt
  14. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaLicense.kt
  15. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaRepo.kt
  16. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaUser.kt
  17. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/github/GithubProvider.kt
  18. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubLicense.kt
  19. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubRepo.kt
  20. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubUser.kt
  21. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/GitlabProvider.kt
  22. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabLicense.kt
  23. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabRepo.kt
  24. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabUser.kt
  25. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/model/DelegateResource.kt
  26. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/model/License.kt
  27. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/model/ProviderString.kt
  28. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/model/Repo.kt
  29. +0
    -0
      gitrest/src/commonMain/kotlin/gitrest/model/User.kt
  30. +0
    -0
      gitrest/src/commonTest/kotlin/gitrest/ProviderStringTest.kt
  31. +1
    -2
      gitrest/src/jsMain/kotlin/RequestProvider.kt
  32. +0
    -0
      gitrest/src/jsMain/kotlin/gitrest/js/License.kt
  33. +0
    -0
      gitrest/src/jsMain/kotlin/gitrest/js/Repo.kt
  34. +0
    -0
      gitrest/src/jsMain/kotlin/gitrest/js/User.kt
  35. +0
    -0
      gitrest/src/jsTest/kotlin/gitrest/BasicTest.kt
  36. +2
    -1
      settings.gradle

+ 10
- 0
README.md View File

@@ -6,6 +6,10 @@ This is a cross-platform API wrapper for GitHub, GitLab, and Gitea, in an attemp

What are you doing here? This project isn't finished yet! I'll update this once I have a better understanding of how kotlin-multiplatform works.

### Development

The `:gitrest:jsBrowserTest` task seems to fail sporadically due to trying to parse... `/etc/fonts/fonts.conf`? Well, it spits out a lot of logs about it, then fails to actually run the tests, so it's not doing very much. You can append `-x :gitrest:jsBrowserTest` to any gradle commands to prevent it from running.

### Example Projects

#### example-kotlinbrowser
@@ -20,6 +24,12 @@ This module is built using [yarn](https://yarnpkg.com/), to provide an example o

- `./gradlew :example-nodejs:run`: execute the `src/index.js` file (with a few example tests/calls using Promises)

#### example-js

This module demonstrates the use of the bundled JS file in a webpage, without the use of Kotlin/JS.

- `./gradlew :example-js:run`: serve the `index.html` and `gitrest.js` files on `localhost:8080`.

## Specification

### URI Scheme


+ 2
- 0
build.gradle View File

@@ -11,12 +11,14 @@ buildscript {
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url "https://dl.bintray.com/kotlin/kotlin-dev" }
maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "gradle.plugin.com.github.salomonbrys.gradle.kotlin.js:kotlin-js-npm-bundle:1.0.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files


+ 15
- 0
example-js/build.gradle View File

@@ -0,0 +1,15 @@
task copyFiles(type: Copy) {
dependsOn ':gitrest:jsBrowserWebpack'
from "../gitrest/build/distributions", "index.html"
into "$buildDir"
}

task run {
dependsOn ':example-js:copyFiles'
doLast {
SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
HttpFileServer server = factory.start(new File("example-js/build"), 8080)
println("Server started on 8080 - Ctrl+C to kill it")
java.lang.Thread.sleep(Long.MAX_VALUE);
}
}

+ 28
- 0
example-js/index.html View File

@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Git-REST Wrapper (JavaScript)</title>
</head>
<body>
<h1>Hello!</h1>
<p>
Repository name: <a id="repoLink"><span id="repoName"></span></a><br>
Description: <span id="repoDesc"></span><br>
<pre>
<code>git clone <span id="sshUrl"></span></code>
</pre>
</p>
</body>
<script src="./gitrest.js"></script>
<script type="text/javascript">
let delegate = new gitrest.RequestProvider();
delegate.getRepo("github@api.github.com:fennifith/Attribouter").then((repo) => {
console.log(repo);
document.getElementById("repoName").innerText = repo.slug;
document.getElementById("repoDesc").innerText = repo.description;
document.getElementById("repoLink").href = repo.url;
document.getElementById("sshUrl").innerText = repo.gitUrlSsh;
});
</script>
</html>

+ 1
- 1
example-kotlinbrowser/build.gradle View File

@@ -15,7 +15,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.6'
implementation "org.jetbrains.kotlinx:kotlinx-html-js:0.7.1"

implementation project(':common')
implementation project(':gitrest')
}

kotlin.target.browser()

+ 1
- 1
example-nodejs/build.gradle View File

@@ -20,7 +20,7 @@ node {
}

yarn_install {
dependsOn ':common:assemble'
dependsOn ':gitrest:assemble'
}

task run(type: YarnTask) {


+ 1
- 1
example-nodejs/package.json View File

@@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"workspaces": [
"../build/js/packages/git-rest-wrapper-common",
"../build/js/packages/git-rest-wrapper-gitrest",
"../build/js/packages_imported/*/*"
],
"devDependencies": {},


+ 3
- 3
example-nodejs/src/index.js View File

@@ -1,11 +1,11 @@
const { gitrest } = require("git-rest-wrapper-common");
const { RequestProvider } = require("git-rest-wrapper-gitrest");

let delegate = new gitrest.RequestProvider();
let delegate = new RequestProvider();

delegate.getUser("fennifith").then((obj) => {
console.log(obj);
});

delegate.getRepo("gitlab:snowdrift/outreach").then((obj) => {
delegate.getRepo("gitlab@salsa.debian.org:reproducible-builds/reproducible-website").then((obj) => {
console.log(obj);
});

common/build.gradle → gitrest/build.gradle View File

@@ -9,6 +9,20 @@ kotlin {
js {
compilations.main.kotlinOptions.moduleKind = 'umd'
nodejs()
browser {
dceTask {
keep 'git-rest-wrapper-gitrest.RequestProvider', "ktor-ktor-io.\$\$importsForInline\$\$.ktor-ktor-io.io.ktor.utils.io"
}
compilations.all {
kotlinOptions {
metaInfo = true
sourceMap = true
sourceMapEmbedSources = "always"
moduleKind = "umd"
main = "call"
}
}
}
}

sourceSets {

common/src/commonMain/kotlin/gitrest/RequestProviderDelegate.kt → gitrest/src/commonMain/kotlin/gitrest/RequestProviderDelegate.kt View File


common/src/commonMain/kotlin/gitrest/base/RequestProvider.kt → gitrest/src/commonMain/kotlin/gitrest/base/RequestProvider.kt View File


common/src/commonMain/kotlin/gitrest/base/ServiceBuilder.kt → gitrest/src/commonMain/kotlin/gitrest/base/ServiceBuilder.kt View File


common/src/commonMain/kotlin/gitrest/impl/gitea/GiteaProvider.kt → gitrest/src/commonMain/kotlin/gitrest/impl/gitea/GiteaProvider.kt View File


common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaLicense.kt → gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaLicense.kt View File


common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaRepo.kt → gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaRepo.kt View File


common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaUser.kt → gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaUser.kt View File


common/src/commonMain/kotlin/gitrest/impl/github/GithubProvider.kt → gitrest/src/commonMain/kotlin/gitrest/impl/github/GithubProvider.kt View File


common/src/commonMain/kotlin/gitrest/impl/github/model/GithubLicense.kt → gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubLicense.kt View File


common/src/commonMain/kotlin/gitrest/impl/github/model/GithubRepo.kt → gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubRepo.kt View File


common/src/commonMain/kotlin/gitrest/impl/github/model/GithubUser.kt → gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubUser.kt View File


common/src/commonMain/kotlin/gitrest/impl/gitlab/GitlabProvider.kt → gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/GitlabProvider.kt View File


common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabLicense.kt → gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabLicense.kt View File


common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabRepo.kt → gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabRepo.kt View File


common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabUser.kt → gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabUser.kt View File


common/src/commonMain/kotlin/gitrest/model/DelegateResource.kt → gitrest/src/commonMain/kotlin/gitrest/model/DelegateResource.kt View File


common/src/commonMain/kotlin/gitrest/model/License.kt → gitrest/src/commonMain/kotlin/gitrest/model/License.kt View File


common/src/commonMain/kotlin/gitrest/model/ProviderString.kt → gitrest/src/commonMain/kotlin/gitrest/model/ProviderString.kt View File


common/src/commonMain/kotlin/gitrest/model/Repo.kt → gitrest/src/commonMain/kotlin/gitrest/model/Repo.kt View File


common/src/commonMain/kotlin/gitrest/model/User.kt → gitrest/src/commonMain/kotlin/gitrest/model/User.kt View File


common/src/commonTest/kotlin/gitrest/ProviderStringTest.kt → gitrest/src/commonTest/kotlin/gitrest/ProviderStringTest.kt View File


common/src/jsMain/kotlin/gitrest/RequestProvider.kt → gitrest/src/jsMain/kotlin/RequestProvider.kt View File

@@ -1,5 +1,4 @@
package gitrest

import gitrest.RequestProviderDelegate
import gitrest.base.ServiceBuilder
import gitrest.impl.gitea.GiteaProvider
import gitrest.impl.github.GithubProvider

common/src/jsMain/kotlin/gitrest/js/License.kt → gitrest/src/jsMain/kotlin/gitrest/js/License.kt View File


common/src/jsMain/kotlin/gitrest/js/Repo.kt → gitrest/src/jsMain/kotlin/gitrest/js/Repo.kt View File


common/src/jsMain/kotlin/gitrest/js/User.kt → gitrest/src/jsMain/kotlin/gitrest/js/User.kt View File


common/src/jsTest/kotlin/gitrest/BasicTest.kt → gitrest/src/jsTest/kotlin/gitrest/BasicTest.kt View File


+ 2
- 1
settings.gradle View File

@@ -1,6 +1,7 @@
rootProject.name='git-rest-wrapper'
enableFeaturePreview('GRADLE_METADATA')
include ':common'
include ':gitrest'
include ':example-android'
include ':example-js'
include ':example-nodejs'
include ':example-kotlinbrowser'

Loading…
Cancel
Save