Skip to content

Function to generate full package stub #96

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Gumbo = "708ec375-b3d6-5a57-a7ce-8257bf98657a"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
OpenSSH_jll = "9bd350c2-7e96-507f-8002-3f2e150b4e1b"
Sass = "322a6be2-4ae8-5d68-aaf1-3e960788d1d9"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
AbstractTrees = "0.3, 0.4"
Expand All @@ -22,6 +23,7 @@ Git = "1"
Gumbo = "0.7, 0.8"
OpenSSH_jll = "8, 9.9.1"
Sass = "0.1, 0.2"
UUIDs = "1"
julia = "1.6"

[extras]
Expand Down
81 changes: 80 additions & 1 deletion src/Generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Generator

using DocStringExtensions
using UUIDs: uuid4

"""
$(SIGNATURES)
Expand Down Expand Up @@ -41,7 +42,12 @@

makedocs($(sitename)
format = $(fmtstr),
modules = [$(pkgname)]
modules = [$(pkgname)],
# The generated stub will not be in a Git repo usually,
# so we want to disable the remote URL generation (which otherwise
# tries to automatically determine the remote repo by inspecting
# the Git repo's remotes)
remotes=nothing
)

# Documenter can also automatically deploy documentation to gh-pages.
Expand Down Expand Up @@ -142,4 +148,77 @@
"""
end

"""

"""
function genpackage(name::AbstractString; destination::AbstractString=pwd(), force::Bool=false)
package_root = joinpath(destination, name)
package_uuid = string(uuid4())

Check warning on line 156 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L154-L156

Added lines #L154 - L156 were not covered by tests

mktempdir() do tmp_root

Check warning on line 158 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L158

Added line #L158 was not covered by tests
# Generate a basic Julia Project.toml for this package
open(joinpath(tmp_root, "Project.toml"), "w") do io
write(io, """

Check warning on line 161 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L160-L161

Added lines #L160 - L161 were not covered by tests
name = "$(name)"
uuid = "$(package_uuid)"
version = "0.0.0"
""")
end

open(joinpath(tmp_root, "Makefile"), "w") do io
write(io, """

Check warning on line 169 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L168-L169

Added lines #L168 - L169 were not covered by tests
.PHONY: docs
docs: docs/Manifest.toml
\tjulia --project=docs docs/make.jl

docs/Manifest.toml: docs/Project.toml Project.toml
\tjulia --project=docs -e 'using Pkg; Pkg.instantiate()'
""")
end

let src = joinpath(tmp_root, "src")
mkpath(src)
open(joinpath(src, "$(name).jl"); write=true) do io
write(io, "module $(name)\n\nend")

Check warning on line 182 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L179-L182

Added lines #L179 - L182 were not covered by tests
end
end

let docs = joinpath(tmp_root, "docs")
mkpath(docs)
open(joinpath(docs, "Project.toml"); write=true) do io
write(io, """

Check warning on line 189 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L186-L189

Added lines #L186 - L189 were not covered by tests
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
$(name) = "$(package_uuid)"

[sources]
$(name) = { path = ".." }
""")
end
open(joinpath(docs, "make.jl"); write=true) do io
write(io, make(name))

Check warning on line 199 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L198-L199

Added lines #L198 - L199 were not covered by tests
end
let docs_src = joinpath(docs, "src")
mkpath(docs_src)
open(joinpath(docs_src, "index.md"); write=true) do io
write(io, index(name))

Check warning on line 204 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L201-L204

Added lines #L201 - L204 were not covered by tests
end
end
end

if ispath(package_root)
if force && isdir(package_root)
@warn "Removing existing directory" package_root
rm(package_root; recursive=true)

Check warning on line 212 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L209-L212

Added lines #L209 - L212 were not covered by tests
else
error("Something exists at: $(package_root)")

Check warning on line 214 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L214

Added line #L214 was not covered by tests
end
end
@info "Generating $(name)" package_root
mv(tmp_root, package_root)

Check warning on line 218 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L217-L218

Added lines #L217 - L218 were not covered by tests
end

return nothing

Check warning on line 221 in src/Generator.jl

View check run for this annotation

Codecov / codecov/patch

src/Generator.jl#L221

Added line #L221 was not covered by tests
end

end
Loading