question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Is there a way to "package" kscripts?

See original GitHub issue

First off, this is an awesome project and itā€™s been super useful to me! Thanks for all your work on it!

Iā€™m wondering whether thereā€™s a way to support this use case:

  • I write a script (or set of scripts) using kscript. Obviously, I have kscript installed on my computer.
  • I want to share this with someone who does not have kscript installed on their computer, and have them be able to run it as well.

Right now, what Iā€™m doing is having them install kscript (some people donā€™t have sdkman or homebrew installed, and they donā€™t like installing them).

However, in an ideal world, I would be able to instead send them a jar file (and possibly an accompanying shell script to execute the jar file), which would run without them having to install kscript.

This would be similar to gradle, accompanied by a gradle wrapper script.

Ideally, even Java would be fetched by the wrapper shell script (if they donā€™t have Java installed), but I suspect this is a mess not worth getting into.

I can do all of this manually by creating a gradle project, and a shadowJar, but it takes a fair amount of effort, and it would be great if that part could be automated with something like perhaps: kscript --package foo.kts.

Thoughts?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
holgerbrandlcommented, Feb 9, 2018

Gentleman, thanks to @fab1anā€™s pointer Iā€™ve used https://github.com/puniverse/capsule to implement packaging of scripts.

See https://github.com/holgerbrandl/kscript#deploy-scripts-as-standalone-binaries for an usage example.

I guess there are some glitches, but feel welcome to report them. šŸ˜ƒ

1reaction
holgerbrandlcommented, Nov 20, 2017

Interesting question. šŸ‘

What we could certainly do is to provide a docker container for kscript containing all dependencies. But docker is even more invasive that kotlin/java/kscript, and some users would struggle with it as well. It still might be a solution for more advanced users.

So if docker does not work for somebody, we need to make at least some assumption about her setup. E.g. that thereā€™s bash. For bootstrapping the remaining java, kotlin and kscript, I think that sdkman is actually the best tool at the moment.

So I think --package could at best combine the sdk setup, that is installing all java and kotlin, if not present on the target system, and run the app from some binary payload (which is the scriptā€™s compiler jar created within kscript). So something along:

!#/bin/env bash

if no sdkman --> install sdkman
if no java --> yes | sdk install java
if no kotlin --> yes | sdk install kotlin

MYSELF=$(which "$0" 2>/dev/null)
exec kotlin -cp $MYSELF <<other args as used normally within kscript to create user process>>
<<binary payload: the compiled jar>>

This would be script created by kscript --package 'println("foo")'.

And as you can see from the mockup, kscript would not be needed for the packaged application

For details about payloads see https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable.

One drawback of such a solution would be that binary payloads are compatible between mac and linux, but think not with windows (afaik). The packaged kscript-apps would not work on the respective other side of the os-world.

What do you think? Reading your comment again, such a solution would be even better, because it would allow to ship just a single executable file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scripts - npm Docs
Package scripts run in an environment where many pieces of information are made available regarding the setup of npm and the current state...
Read more >
An Introduction to Package JSON Scripts in Node.js
package.json Scripts - An Overview. An npm script is a convenient way to bundle common shell commands like a set of built-in and...
Read more >
Distributing NPM Scripts With A Package For Use By Project ...
One way you can do it is with Builder. Builder allows you to ship npm scripts as NPM packages,Ā ...
Read more >
Add Powershell Script as a Package - How to - ManageEngine
Navigate to Software Deployment >> Packages and click on "Add Package >> Windows". Ā· Enter the name of the package as desired, and...
Read more >
How YOU can create a script package for the PowerShell gallery
Install the script. This will place the script in a specific downloads folder. We will still need to dot source it to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found