diff --git a/projector-launcher/build.gradle.kts b/projector-launcher/build.gradle.kts index 2a4c7ddae..4ff38ab02 100644 --- a/projector-launcher/build.gradle.kts +++ b/projector-launcher/build.gradle.kts @@ -15,32 +15,20 @@ val npmCommand = when (DefaultNativePlatform.getCurrentOperatingSystem().isWindo false -> listOf("npm") } -val distElectron by tasks.creating(Exec::class) { +val npmInstall by tasks.creating(Exec::class) { group = "dist" - workingDir(project.projectDir) - commandLine(npmCommand + listOf("run", "packager")) + workingDir(project.file("electronapp/build/distributions")) + commandLine(npmCommand + listOf("install")) } -val copyDeps by tasks.creating(Copy::class) { +val runPackager by tasks.creating(Exec::class) { group = "dist" - dependsOn(distElectron) - - // inspired by https://stackoverflow.com/a/42133267/6639500 - val filesToCopy = copySpec { - from("build/js/node_modules") - } - - into("out") - - val destinations = listOf( - "projector-linux-x64/resources/app/node_modules", - "projector-win32-x64/resources/app/node_modules", - "projector-darwin-x64/projector.app/Contents/Resources/app/node_modules" - ) - destinations.forEach { into(it) { with(filesToCopy) } } + dependsOn(npmInstall) + workingDir(project.projectDir) + commandLine(npmCommand + listOf("run", "packager")) } tasks.create("dist") { group = "dist" - dependsOn(copyDeps) + dependsOn(runPackager) } diff --git a/projector-launcher/electronapp/build.gradle.kts b/projector-launcher/electronapp/build.gradle.kts index 5858b8ac9..24b7b91b8 100644 --- a/projector-launcher/electronapp/build.gradle.kts +++ b/projector-launcher/electronapp/build.gradle.kts @@ -1,6 +1,3 @@ -import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension -import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin - plugins { kotlin("js") } @@ -13,17 +10,9 @@ val kotlinExtensionsVersion: String by project kotlin { js { - nodejs { - compilations.all { - kotlinOptions { - kotlinOptions.moduleKind = "umd" - kotlinOptions.sourceMap = true - kotlinOptions.sourceMapEmbedSources = "always" - kotlinOptions.metaInfo = true - kotlinOptions.main = "call" - } - } - } + // todo: switch to nodejs or electron (KT-35327) + // while webpack is not supported in nodejs target, need to override target in webpack.config.d + browser() } } @@ -34,20 +23,3 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutinesVersion") implementation("org.jetbrains:kotlin-extensions:$kotlinExtensionsVersion") } - -tasks.named("nodeTest") { - enabled = false -} - -val copyResources = task("copyResources") { - copy { - from("src/main/resources") - into("../build/js/packages/projector-launcher-electronapp") - } -} - -tasks["compileKotlinJs"].dependsOn(copyResources) - -rootProject.plugins.withType { - rootProject.the().download = false -} diff --git a/projector-launcher/electronapp/src/main/resources/package.json b/projector-launcher/electronapp/src/main/resources/package.json new file mode 100644 index 000000000..ed60deee0 --- /dev/null +++ b/projector-launcher/electronapp/src/main/resources/package.json @@ -0,0 +1,25 @@ +{ + "main": "electronapp.js", + "devDependencies": {}, + "dependencies": { + "electron": "^10.1.2", + "open": "^7.2.1" + }, + "scripts": { + "electron": "electron ." + }, + "peerDependencies": {}, + "optionalDependencies": {}, + "bundledDependencies": [], + "keywords": [ + "projector", + "jetbrains", + "kotlin", + "kotlin-js" + ], + "author": "projector", + "license": "MIT", + "name": "projector-launcher", + "description": "Desktop launcher for Projector, written in Kotlin, Electron and Node", + "version": "1.0.0" +} diff --git a/projector-launcher/electronapp/webpack.config.d/webpack.config.js b/projector-launcher/electronapp/webpack.config.d/webpack.config.js new file mode 100644 index 000000000..25a36e794 --- /dev/null +++ b/projector-launcher/electronapp/webpack.config.d/webpack.config.js @@ -0,0 +1,6 @@ +// todo: remove after https://youtrack.jetbrains.com/issue/KT-35327 is fixed +config.target = 'electron-renderer'; + +// todo: remove after https://youtrack.jetbrains.com/issue/KT-40159 is fixed +config.output = config.output || {}; +config.output.globalObject = "this"; diff --git a/projector-launcher/package.json b/projector-launcher/package.json index d786298e6..1688a376d 100644 --- a/projector-launcher/package.json +++ b/projector-launcher/package.json @@ -8,7 +8,7 @@ "build": "./gradlew build", "run": "electron build/js/packages/projector-launcher-electronapp", "gradle-node": "./gradlew -p electronapp nodeRun", - "packager": "electron-packager --executable-name=projector --out=./out --overwrite --icon=./electronapp/src/main/resources/assets/img/electron-icon.ico --all ./build/js/packages/projector-launcher-electronapp projector" + "packager": "electron-packager --executable-name=projector --out=./out --overwrite --icon=./electronapp/src/main/resources/assets/img/electron-icon.ico --all ./electronapp/build/distributions projector" }, "keywords": [ "projector",