Skip to content

Commit

Permalink
Code set up script :wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Oct 14, 2024
1 parent e116d90 commit a011e94
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .mvn/parent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@
<defaultGoal>verify</defaultGoal>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
68 changes: 52 additions & 16 deletions set_up.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,63 @@

import static java.util.Map.entry;

import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;
import java.util.stream.Stream;

private Console console = System.console();
Scanner scanner = new Scanner(System.in);
FileSystem fs = FileSystems.getDefault();

void main() {
var options = List.of(
entry("GitHub", prompt("Keep GitHub workflows and templates: (Yn)", "y")),
entry("GitLab", prompt("Keep GitLab workflows and templates: (Yn)", "y")),
entry("GitLab", prompt("Keep 'CODE_OF_CONDUCT.md' file: (Yn)", "y")),
entry("GitLab", prompt("Keep 'CONTRIBUTING.md' file: (Yn)", "y")),
entry("GitLab", prompt("Keep 'LICENSE.md' file: (Yn)", "y")),
entry("GitLab", prompt("Keep this set up file 'set_up.java' file: (Yn)", "y"))
);

// Rename artifacts, groups or base package
// Restart Git history (or delete it)
var deletions =
Stream.of(
entry(".github", prompt("Keep GitHub workflows and templates (Yn): ", "y")),
entry(".gitlab*", prompt("Keep GitLab workflows and templates (Yn): ", "y")),
entry("CODE_OF_CONDUCT.md", prompt("Keep 'CODE_OF_CONDUCT.md' file (Yn): ", "y")),
entry("CONTRIBUTING.md", prompt("Keep 'CONTRIBUTING.md' file (Yn): ", "y")),
entry("LICENSE.md", prompt("Keep 'LICENSE.md' file (Yn): ", "y")),
// entry(".git", prompt("Keep Git history (Yn): ", "y")),
entry("set_up.java", prompt("Keep this set up file 'set_up.java' file (Yn): ", "y"))
)
.filter(it -> it.getValue().equalsIgnoreCase("n"))
.toList();

// TODO Rename artifacts, groups or base package
// TODO Show summary before applying changes

deletions.forEach(it -> delete(it.getKey()));
}

public String prompt(String message, String defaultValue) {
console.printf(message);
var v = console.readLine();
String prompt(String message, String defaultValue) {
System.out.print(message);
var v = scanner.nextLine();
return v == null || v.isBlank() ? defaultValue : v;
}

void delete(String glob) {
var matcher = fs.getPathMatcher("glob:./" + glob);
var cwd = new File(".");
Optional
.ofNullable(cwd.listFiles(it -> matcher.matches(it.toPath())))
.map(List::of)
.orElse(List.of())
.forEach(it -> {
try (Stream<Path> paths = Files.walk(it.toPath())) {
paths
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(System.out::println); // (File::delete);
}
catch (IOException _) {
System.out.println("Error deleting " + it);
}
});
}

0 comments on commit a011e94

Please sign in to comment.