Skip to content

Commit 25cdb7d

Browse files
committed
Reboot Project
1 parent acedd2a commit 25cdb7d

16 files changed

+386
-17
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ intellij/out
2222

2323
### BSP ###
2424
.bsp/
25+
26+
### Metals ###
27+
.metals/
28+
.bloop/
29+
project/**/metals.sbt

.jindo.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
preCommit:
2+
- id: scalafmt
3+
dependencies:
4+
- org.scalameta::scalafmt-cli:latest.release
5+
main: org.scalafmt.cli.Cli

README.adoc

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Jindo(珍島)
2+
3+
Bringing git-hooks into JVM world 🐕
4+
5+
Jindo is a lightweight, JVM-based Git hooks manager that simplifies your development workflow.
6+
It allows you to run JVM applications as Git hooks without external dependencies.
7+
8+
## Why Jindo?
9+
10+
While tools like pre-commit and husky are great, they often introduce complexity and additional dependencies to JVM projects. Here's why Jindo is different:
11+
12+
### 🚀 Zero External Dependencies
13+
* Only requires JVM 8+
14+
* No need for Node.js, Python, or other runtimes
15+
* Minimal setup overhead
16+
17+
### 🔧 Simple Yet Powerful Configuration
18+
* Easy-to-understand YAML configuration
19+
* Support for multiple repositories
20+
* Flexible hook management
21+
22+
### 📦 Seamless JVM Integration
23+
* Direct access to Maven Central
24+
* Automatic dependency resolution via Coursier
25+
* Run any JVM-based tools (Java, Scala, Kotlin, etc.)
26+
27+
### 🔒 Reliable and Consistent
28+
* Same JVM environment across all hooks
29+
* Predictable behavior in CI/CD
30+
* Better performance for JVM-based checks
31+
* Direct execution without wrappers

build.sbt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1+
import sbt.Keys._
2+
import sbtassembly.MergeStrategy
3+
import sbtassembly.PathList
4+
15
ThisBuild / version := "0.1.0-SNAPSHOT"
26
ThisBuild / scalaVersion := "2.13.12"
37

8+
lazy val commonSettings = Seq(
9+
organization := "io.vanslog",
10+
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked")
11+
)
12+
413
lazy val root = (project in file("."))
514
.settings(
6-
name := "jindo"
15+
name := "jindo",
16+
commonSettings,
17+
libraryDependencies ++= Seq(
18+
"io.circe" %% "circe-yaml" % "0.14.2",
19+
"io.circe" %% "circe-generic" % "0.14.2",
20+
"io.get-coursier" %% "coursier" % "2.1.7",
21+
"com.github.scopt" %% "scopt" % "4.1.0",
22+
),
23+
assembly / assemblyJarName := "jindo.jar",
24+
assembly / assemblyMergeStrategy := {
25+
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
26+
case _ => MergeStrategy.first
27+
}
728
)

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
2+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")

src/main/scala/Main.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
import cli.Cli
2+
import command.{Command, CommandFactory, CommandType}
3+
14
object Main {
2-
def main(args: Array[String]): Unit = {}
5+
def main(args: Array[String]): Unit = {
6+
Cli.parse(args) match {
7+
case Some(config) =>
8+
CommandType.fromString(config.command) match {
9+
case Some(cmdType) =>
10+
val cmd = CommandFactory.create(cmdType, config.projectRoot)
11+
cmd.execute()
12+
case None =>
13+
Cli.showUsage()
14+
}
15+
case None =>
16+
Cli.showUsage()
17+
}
18+
}
319
}

src/main/scala/cli/Cli.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cli
2+
3+
import scopt.OParser
4+
import java.nio.file.{Path, Paths}
5+
6+
case class CliConfig(
7+
command: String = "",
8+
projectRoot: Path = Paths.get(scala.util.Properties.userDir)
9+
)
10+
11+
object Cli {
12+
private val builder = OParser.builder[CliConfig]
13+
private val parser = {
14+
import builder._
15+
OParser.sequence(
16+
programName("jindo"),
17+
head("jindo", "0.1.0"),
18+
cmd("install")
19+
.action((_, c) => c.copy(command = "install"))
20+
.text("Install git hooks based on .jindo.yaml configuration"),
21+
cmd("run")
22+
.action((_, c) => c.copy(command = "run"))
23+
.text("Run git hooks")
24+
)
25+
}
26+
27+
def parse(args: Array[String]): Option[CliConfig] = {
28+
OParser.parse(parser, args, CliConfig())
29+
}
30+
31+
def showUsage(): Unit = {
32+
System.err.println(OParser.usage(parser))
33+
}
34+
}

src/main/scala/command/Command.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package command
2+
3+
import java.nio.file.Path
4+
import config.ConfigLoader
5+
import hook.HookManager
6+
import hook.HookExecutor
7+
8+
sealed trait Command {
9+
def execute(): Unit
10+
}
11+
12+
case class InstallCommand(projectRoot: Path) extends Command {
13+
def execute(): Unit = {
14+
val configLoader = new ConfigLoader(projectRoot)
15+
val config = configLoader.loadConfig()
16+
17+
val hookManager = new HookManager(projectRoot)
18+
hookManager.installHooks(config)
19+
println("Git hooks installed successfully")
20+
}
21+
}
22+
23+
case class RunCommand(projectRoot: Path) extends Command {
24+
def execute(): Unit = {
25+
val configLoader = new ConfigLoader(projectRoot)
26+
val config = configLoader.loadConfig()
27+
28+
val hookExecutor = new HookExecutor(projectRoot)
29+
hookExecutor.execute(config)
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package command
2+
3+
import java.nio.file.Path
4+
5+
object CommandFactory {
6+
def create(cmdType: CommandType, projectRoot: Path): Command = cmdType match {
7+
case CommandType.Install => InstallCommand(projectRoot)
8+
case CommandType.Run => RunCommand(projectRoot)
9+
}
10+
}

0 commit comments

Comments
 (0)