From 685dc5596af2e43dda11b2971ed84e76dd563b25 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Mon, 1 Nov 2021 22:13:48 +0100 Subject: [PATCH 1/2] Create script run-me to change JSOTemplate to the new name of the package --- README.md | 9 ++++++--- run-me.jl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 run-me.jl diff --git a/README.md b/README.md index d6daf25..001e72b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ This is a template/skeleton for JSO packages. It should be used for new packages, and as a reference for changes in existing packages. -## Things to change +## How to use -- Project.toml: name and uuid -- LICENSE.md: Check if MPL-v2 is the correct choice \ No newline at end of file +- Click on the button "Use template". +- Clone. +- Run `julia run-me.jl` and enter the new package name. +- Check if MPL-v2 is the correct choice. +- Update this README. \ No newline at end of file diff --git a/run-me.jl b/run-me.jl new file mode 100644 index 0000000..3b57c17 --- /dev/null +++ b/run-me.jl @@ -0,0 +1,52 @@ +using UUIDs + +print("Thanks for using JSOTemplate. What's your intended package name?: \n") +pkgname = readline() + +green(msg) = "\033[0;32m$msg\033[0m" +yellow(msg) = "\033[0;33m$msg\033[0m" + +println(""" +This script will help using JSOTemplate by performing the following steps: +- Change $(green("JSOTemplate")) to $(green("$pkgname")) wherever it is found +- Change the $(green("UUID")) of the package +- Change file $(green("src/JSOTemplate.jl")) to $(green("src/$pkgname.jl")) +- $(yellow("Remove this script")) +- Create a $(yellow("commit")) with the change +""") + + +files = readdir() +deleteat!(files, findfirst(files .== ".git")) +while !all(isfile.(files)) + idx = findall(.!isfile.(files)) + for dir in files[idx] + append!(files, readdir(dir, join=true)) + end + deleteat!(files, idx) +end +run(`sed -i "s/JSOTemplate/$pkgname/g" $files`) +println(green("✓ All occurrences of JSOTemplate should have been changed to $pkgname")) + +lines = readlines("Project.toml") +uuid = "" +for line in lines + if line[1:4] == "uuid" + global uuid = split(line, "\"")[2] + break + end +end +new_uuid = string(uuid4()) +files = ["Project.toml", "test/Project.toml", "docs/Project.toml"] |> x -> filter(isfile, x) +run(`sed -i "s/$uuid/$new_uuid/g" $files`) +println(green("✓ UUID has been updated in $files")) + +mv("src/JSOTemplate.jl", "src/$pkgname.jl") +println(green("✓ src/JSOTemplate.jl ⟶ src/$pkgname.jl")) + +rm("run-me.jl") +println(green("✓ run-me.jl was removed")) + +run(`git add src/$pkgname.jl`) +run(`git commit -am ":robot: [run-me.jl] Change JSOTemplate to $pkgname"`) +println(green("✓ commit was created")) \ No newline at end of file From b80ca8c24b0a3c0ac19e6735fd6fa56fc8eaff64 Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Mon, 8 Nov 2021 19:46:01 +0100 Subject: [PATCH 2/2] Fixes for MacOS --- run-me.jl | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/run-me.jl b/run-me.jl index 3b57c17..119ce69 100644 --- a/run-me.jl +++ b/run-me.jl @@ -16,16 +16,12 @@ This script will help using JSOTemplate by performing the following steps: """) -files = readdir() -deleteat!(files, findfirst(files .== ".git")) -while !all(isfile.(files)) - idx = findall(.!isfile.(files)) - for dir in files[idx] - append!(files, readdir(dir, join=true)) - end - deleteat!(files, idx) +files = split(readchomp(`git ls-tree -r main --name-only`), "\n") +for file ∈ files + file_type = readchomp(`file $file`) + match(r"text", file_type) === nothing && continue # skip binary files + run(`sed -i "" "s/JSOTemplate/$pkgname/g" "$file"`) end -run(`sed -i "s/JSOTemplate/$pkgname/g" $files`) println(green("✓ All occurrences of JSOTemplate should have been changed to $pkgname")) lines = readlines("Project.toml") @@ -38,7 +34,7 @@ for line in lines end new_uuid = string(uuid4()) files = ["Project.toml", "test/Project.toml", "docs/Project.toml"] |> x -> filter(isfile, x) -run(`sed -i "s/$uuid/$new_uuid/g" $files`) +run(`sed -i "" "s/$uuid/$new_uuid/g" $files`) println(green("✓ UUID has been updated in $files")) mv("src/JSOTemplate.jl", "src/$pkgname.jl")