forked from kscripting/kscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/python npm packaging #8
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Updated README.adoc to provide more current information and accurately reflect the project's state in 2024. Key changes include: - Introduction: Replaced outdated "Good News about Kotlin 1.4 scripting" section with a more timeless description of kscript's value. Removed a very dated (2017) conference link. - Installation: - Added a note clarifying that package manager versions (SDKMAN, Homebrew, Scoop) may not be the absolute latest, and recommending the "Build it yourself" section for cutting-edge use. - Updated the "Build it yourself" section to encourage its use for modern Kotlin/Java versions (e.g., Kotlin 2.2.0+, Java 21+), and to note JDK requirements. - Script Configuration / Annotations: - Added a cautionary note regarding the age of the `kscript-annotations:1.5` artifact and potential compatibility considerations with modern Kotlin 2.x. - Clarified that kscript historically used v1.5 internally. - Feature Descriptions: - Verified that no unmerged/non-existent features like Proguard were mentioned (none were, so no changes needed on this point). - How to contribute?: - Removed outdated, specific YouTrack issue links from 2017-2019. - Replaced with general guidance to use the kscript GitHub issue tracker and the official JetBrains YouTrack for IDE/Kotlin issues. - FAQ: - Updated the answer comparing Kotlin and Python scripting performance to be more nuanced and cover JVM startup/compilation overhead vs. peak performance. These changes aim to improve clarity, set realistic expectations for you, and ensure the documentation is more helpful and up-to-date.
This commit introduces the new command-line option `--export-to-gradle-project <script> <output_dir>`, which allows you to generate a complete, standalone Gradle project from an existing kscript file. This "last mile toolkit" feature facilitates graduating a kscript into a more formal project structure, ready for further development, testing, and packaging using standard Gradle workflows. Key functionalities implemented in `ProjectGenerator.kt`: - Parses the input kscript for dependencies, Maven repositories, package name, and entry point using kscript's internal resolvers. - Creates the specified output directory. - Determines project properties (group, name, version), intelligently deriving the group and main class from script annotations or defaults. - Generates `settings.gradle.kts` with the project name. - Generates a comprehensive `build.gradle.kts` including: - Kotlin JVM and Application plugins (using kscript's own Kotlin version, e.g., 2.2.0-RC2, and targeting Java 21). - Project group and version. - Maven Central and any custom repositories from the script. - Kotlin standard library and all dependencies from the script. - Application main class configuration. - Standard Kotlin compiler options and Java toolchain settings. - Creates the standard Maven/Gradle directory structure: - `src/main/kotlin/[package_path]` - `src/main/resources` - `src/test/kotlin/[package_path]` - `src/test/resources` - Transforms the original kscript content by: - Removing the shebang and kscript-specific file-level annotations. - Adding an appropriate package declaration. - Saves the result as a `.kt` file within `src/main/kotlin/[package_path]`. - Generates a `.gitignore` file with common Kotlin/Gradle patterns. - Copies and configures the Gradle Wrapper (`gradlew`, `gradlew.bat`, `gradle/wrapper/*`) from kscript's own project, ensuring the generated project uses a consistent and recent Gradle version (e.g., 8.14.1). The command-line interface in `Kscript.kt` and option parsing in `OptionsUtils.kt` have been updated to support this new feature.
This commit enhances the `--export-to-gradle-project` feature by allowing kscripts to define their own target Maven coordinates (groupId, artifactId, version) via a new `@file:ProjectCoordinates` annotation. Key changes: 1. **Annotation Parsing (`Script.kt`, `Parser.kt`, `model/ProjectCoordinates.kt`):** - I introduced a new data class `model.ProjectCoordinates` to hold `group`, `artifact`, and `version`. - The `Script` model now includes an optional `projectCoordinates` field. - I updated `LineParser.kt` and `Parser.kt` to recognize and parse `@file:ProjectCoordinates(group="...", artifact="...", version="...")` annotations from script files. - The parsed coordinates are stored in the `Script` object via `ResolutionContext` and `SectionResolver`. 2. **Project Generation (`generator/ProjectGenerator.kt`):** - The `exportToGradleProject` function now retrieves any `ProjectCoordinates` defined in the script. - These script-defined coordinates are prioritized when setting: - `group` in `build.gradle.kts`. - `version` in `build.gradle.kts`. - `rootProject.name` in `settings.gradle.kts` (derived from the artifactId). - Fallback logic (using script package name, output directory name, or defaults) is retained if the annotation or specific attributes are missing. - The package path for source files (`src/main/kotlin/...`, `src/test/kotlin/...`) and the `package` declaration in the generated `.kt` file are now based on the `effectiveProjectGroup` (derived from the annotation or fallbacks). - Default `mainClassName` derivation also uses `effectiveProjectGroup`. This makes the project generation feature more declarative, allowing the script itself to be the source of truth for its intended Maven identity when being "graduated" into a full Gradle project.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.