From 279b599b7f000e62e28c9534741257db9dd5ff3e Mon Sep 17 00:00:00 2001 From: James Fenn Date: Mon, 11 May 2020 19:32:58 -0400 Subject: [PATCH] implement plain-js bundle example/test --- README.md | 10 +++++++ build.gradle | 2 ++ example-js/build.gradle | 15 ++++++++++ example-js/index.html | 28 +++++++++++++++++++ example-kotlinbrowser/build.gradle | 2 +- example-nodejs/build.gradle | 2 +- example-nodejs/package.json | 2 +- example-nodejs/src/index.js | 6 ++-- {common => gitrest}/build.gradle | 14 ++++++++++ .../kotlin/gitrest/RequestProviderDelegate.kt | 0 .../kotlin/gitrest/base/RequestProvider.kt | 0 .../kotlin/gitrest/base/ServiceBuilder.kt | 0 .../gitrest/impl/gitea/GiteaProvider.kt | 0 .../gitrest/impl/gitea/model/GiteaLicense.kt | 0 .../gitrest/impl/gitea/model/GiteaRepo.kt | 0 .../gitrest/impl/gitea/model/GiteaUser.kt | 0 .../gitrest/impl/github/GithubProvider.kt | 0 .../impl/github/model/GithubLicense.kt | 0 .../gitrest/impl/github/model/GithubRepo.kt | 0 .../gitrest/impl/github/model/GithubUser.kt | 0 .../gitrest/impl/gitlab/GitlabProvider.kt | 0 .../impl/gitlab/model/GitlabLicense.kt | 0 .../gitrest/impl/gitlab/model/GitlabRepo.kt | 0 .../gitrest/impl/gitlab/model/GitlabUser.kt | 0 .../kotlin/gitrest/model/DelegateResource.kt | 0 .../kotlin/gitrest/model/License.kt | 0 .../kotlin/gitrest/model/ProviderString.kt | 0 .../commonMain/kotlin/gitrest/model/Repo.kt | 0 .../commonMain/kotlin/gitrest/model/User.kt | 0 .../kotlin/gitrest/ProviderStringTest.kt | 0 .../src/jsMain/kotlin}/RequestProvider.kt | 3 +- .../src/jsMain/kotlin/gitrest/js/License.kt | 0 .../src/jsMain/kotlin/gitrest/js/Repo.kt | 0 .../src/jsMain/kotlin/gitrest/js/User.kt | 0 .../src/jsTest/kotlin/gitrest/BasicTest.kt | 0 settings.gradle | 3 +- 36 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 example-js/build.gradle create mode 100644 example-js/index.html rename {common => gitrest}/build.gradle (85%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/RequestProviderDelegate.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/base/RequestProvider.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/base/ServiceBuilder.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/gitea/GiteaProvider.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaLicense.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaRepo.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaUser.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/github/GithubProvider.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/github/model/GithubLicense.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/github/model/GithubRepo.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/github/model/GithubUser.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/gitlab/GitlabProvider.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabLicense.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabRepo.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabUser.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/model/DelegateResource.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/model/License.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/model/ProviderString.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/model/Repo.kt (100%) rename {common => gitrest}/src/commonMain/kotlin/gitrest/model/User.kt (100%) rename {common => gitrest}/src/commonTest/kotlin/gitrest/ProviderStringTest.kt (100%) rename {common/src/jsMain/kotlin/gitrest => gitrest/src/jsMain/kotlin}/RequestProvider.kt (97%) rename {common => gitrest}/src/jsMain/kotlin/gitrest/js/License.kt (100%) rename {common => gitrest}/src/jsMain/kotlin/gitrest/js/Repo.kt (100%) rename {common => gitrest}/src/jsMain/kotlin/gitrest/js/User.kt (100%) rename {common => gitrest}/src/jsTest/kotlin/gitrest/BasicTest.kt (100%) diff --git a/README.md b/README.md index 028ea20..7de144f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.gradle b/build.gradle index 9bbeddf..998c121 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/example-js/build.gradle b/example-js/build.gradle new file mode 100644 index 0000000..0821529 --- /dev/null +++ b/example-js/build.gradle @@ -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); + } +} diff --git a/example-js/index.html b/example-js/index.html new file mode 100644 index 0000000..1d57436 --- /dev/null +++ b/example-js/index.html @@ -0,0 +1,28 @@ + + + + + Git-REST Wrapper (JavaScript) + + +

Hello!

+

+ Repository name:
+ Description:
+

+            git clone 
+        
+

+ + + + diff --git a/example-kotlinbrowser/build.gradle b/example-kotlinbrowser/build.gradle index bf66ad1..533fa2b 100644 --- a/example-kotlinbrowser/build.gradle +++ b/example-kotlinbrowser/build.gradle @@ -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() diff --git a/example-nodejs/build.gradle b/example-nodejs/build.gradle index 4ccb47b..a4a7faa 100644 --- a/example-nodejs/build.gradle +++ b/example-nodejs/build.gradle @@ -20,7 +20,7 @@ node { } yarn_install { - dependsOn ':common:assemble' + dependsOn ':gitrest:assemble' } task run(type: YarnTask) { diff --git a/example-nodejs/package.json b/example-nodejs/package.json index 8e33643..67d2af9 100644 --- a/example-nodejs/package.json +++ b/example-nodejs/package.json @@ -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": {}, diff --git a/example-nodejs/src/index.js b/example-nodejs/src/index.js index 9330bb0..fcd44b1 100644 --- a/example-nodejs/src/index.js +++ b/example-nodejs/src/index.js @@ -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); }); diff --git a/common/build.gradle b/gitrest/build.gradle similarity index 85% rename from common/build.gradle rename to gitrest/build.gradle index eb2b3e9..f5c5538 100644 --- a/common/build.gradle +++ b/gitrest/build.gradle @@ -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 { diff --git a/common/src/commonMain/kotlin/gitrest/RequestProviderDelegate.kt b/gitrest/src/commonMain/kotlin/gitrest/RequestProviderDelegate.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/RequestProviderDelegate.kt rename to gitrest/src/commonMain/kotlin/gitrest/RequestProviderDelegate.kt diff --git a/common/src/commonMain/kotlin/gitrest/base/RequestProvider.kt b/gitrest/src/commonMain/kotlin/gitrest/base/RequestProvider.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/base/RequestProvider.kt rename to gitrest/src/commonMain/kotlin/gitrest/base/RequestProvider.kt diff --git a/common/src/commonMain/kotlin/gitrest/base/ServiceBuilder.kt b/gitrest/src/commonMain/kotlin/gitrest/base/ServiceBuilder.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/base/ServiceBuilder.kt rename to gitrest/src/commonMain/kotlin/gitrest/base/ServiceBuilder.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/gitea/GiteaProvider.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/gitea/GiteaProvider.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/gitea/GiteaProvider.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/gitea/GiteaProvider.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaLicense.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaLicense.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaLicense.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaLicense.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaRepo.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaRepo.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaRepo.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaRepo.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaUser.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaUser.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaUser.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/gitea/model/GiteaUser.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/github/GithubProvider.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/github/GithubProvider.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/github/GithubProvider.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/github/GithubProvider.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/github/model/GithubLicense.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubLicense.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/github/model/GithubLicense.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubLicense.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/github/model/GithubRepo.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubRepo.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/github/model/GithubRepo.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubRepo.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/github/model/GithubUser.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubUser.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/github/model/GithubUser.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/github/model/GithubUser.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/gitlab/GitlabProvider.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/GitlabProvider.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/gitlab/GitlabProvider.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/GitlabProvider.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabLicense.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabLicense.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabLicense.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabLicense.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabRepo.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabRepo.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabRepo.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabRepo.kt diff --git a/common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabUser.kt b/gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabUser.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabUser.kt rename to gitrest/src/commonMain/kotlin/gitrest/impl/gitlab/model/GitlabUser.kt diff --git a/common/src/commonMain/kotlin/gitrest/model/DelegateResource.kt b/gitrest/src/commonMain/kotlin/gitrest/model/DelegateResource.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/model/DelegateResource.kt rename to gitrest/src/commonMain/kotlin/gitrest/model/DelegateResource.kt diff --git a/common/src/commonMain/kotlin/gitrest/model/License.kt b/gitrest/src/commonMain/kotlin/gitrest/model/License.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/model/License.kt rename to gitrest/src/commonMain/kotlin/gitrest/model/License.kt diff --git a/common/src/commonMain/kotlin/gitrest/model/ProviderString.kt b/gitrest/src/commonMain/kotlin/gitrest/model/ProviderString.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/model/ProviderString.kt rename to gitrest/src/commonMain/kotlin/gitrest/model/ProviderString.kt diff --git a/common/src/commonMain/kotlin/gitrest/model/Repo.kt b/gitrest/src/commonMain/kotlin/gitrest/model/Repo.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/model/Repo.kt rename to gitrest/src/commonMain/kotlin/gitrest/model/Repo.kt diff --git a/common/src/commonMain/kotlin/gitrest/model/User.kt b/gitrest/src/commonMain/kotlin/gitrest/model/User.kt similarity index 100% rename from common/src/commonMain/kotlin/gitrest/model/User.kt rename to gitrest/src/commonMain/kotlin/gitrest/model/User.kt diff --git a/common/src/commonTest/kotlin/gitrest/ProviderStringTest.kt b/gitrest/src/commonTest/kotlin/gitrest/ProviderStringTest.kt similarity index 100% rename from common/src/commonTest/kotlin/gitrest/ProviderStringTest.kt rename to gitrest/src/commonTest/kotlin/gitrest/ProviderStringTest.kt diff --git a/common/src/jsMain/kotlin/gitrest/RequestProvider.kt b/gitrest/src/jsMain/kotlin/RequestProvider.kt similarity index 97% rename from common/src/jsMain/kotlin/gitrest/RequestProvider.kt rename to gitrest/src/jsMain/kotlin/RequestProvider.kt index 94333ea..071f6b1 100644 --- a/common/src/jsMain/kotlin/gitrest/RequestProvider.kt +++ b/gitrest/src/jsMain/kotlin/RequestProvider.kt @@ -1,5 +1,4 @@ -package gitrest - +import gitrest.RequestProviderDelegate import gitrest.base.ServiceBuilder import gitrest.impl.gitea.GiteaProvider import gitrest.impl.github.GithubProvider diff --git a/common/src/jsMain/kotlin/gitrest/js/License.kt b/gitrest/src/jsMain/kotlin/gitrest/js/License.kt similarity index 100% rename from common/src/jsMain/kotlin/gitrest/js/License.kt rename to gitrest/src/jsMain/kotlin/gitrest/js/License.kt diff --git a/common/src/jsMain/kotlin/gitrest/js/Repo.kt b/gitrest/src/jsMain/kotlin/gitrest/js/Repo.kt similarity index 100% rename from common/src/jsMain/kotlin/gitrest/js/Repo.kt rename to gitrest/src/jsMain/kotlin/gitrest/js/Repo.kt diff --git a/common/src/jsMain/kotlin/gitrest/js/User.kt b/gitrest/src/jsMain/kotlin/gitrest/js/User.kt similarity index 100% rename from common/src/jsMain/kotlin/gitrest/js/User.kt rename to gitrest/src/jsMain/kotlin/gitrest/js/User.kt diff --git a/common/src/jsTest/kotlin/gitrest/BasicTest.kt b/gitrest/src/jsTest/kotlin/gitrest/BasicTest.kt similarity index 100% rename from common/src/jsTest/kotlin/gitrest/BasicTest.kt rename to gitrest/src/jsTest/kotlin/gitrest/BasicTest.kt diff --git a/settings.gradle b/settings.gradle index a54e00c..1de6002 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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' -- GitLab