fixed #581 nimble init does not overwrite existing files with its templates anymore

This commit is contained in:
liquid600pgm 2019-06-22 00:10:41 +02:00 committed by Dominik Picheta
commit df8317585f

View file

@ -14,6 +14,10 @@ type
pkgNimDep: string
pkgType: string
proc writeFileIfNonExistent(file: string, content: string) =
if not existsFile(file):
writeFile(file, content)
proc createPkgStructure*(info: PkgInitInfo, pkgRoot: string) =
# Create source directory
createDirD(pkgRoot / info.pkgSrcDir)
@ -23,7 +27,7 @@ proc createPkgStructure*(info: PkgInitInfo, pkgRoot: string) =
case info.pkgType
of "binary":
let mainFile = pkgRoot / info.pkgSrcDir / info.pkgName.changeFileExt("nim")
writeFile(mainFile,
writeFileIfNonExistent(mainFile,
"""
# This is just an example to get you started. A typical binary package
# uses this file as the main entry point of the application.
@ -35,7 +39,7 @@ when isMainModule:
nimbleFileOptions.add("bin = @[\"$1\"]\n" % info.pkgName)
of "library":
let mainFile = pkgRoot / info.pkgSrcDir / info.pkgName.changeFileExt("nim")
writeFile(mainFile,
writeFileIfNonExistent(mainFile,
"""
# This is just an example to get you started. A typical library package
# exports the main API in this file. Note that you cannot rename this file
@ -50,7 +54,7 @@ proc add*(x, y: int): int =
createDirD(pkgRoot / info.pkgSrcDir / info.pkgName)
let submodule = pkgRoot / info.pkgSrcDir / info.pkgName /
"submodule".addFileExt("nim")
writeFile(submodule,
writeFileIfNonExistent(submodule,
"""
# This is just an example to get you started. Users of your library will
# import this file by writing ``import $1/submodule``. Feel free to rename or
@ -68,7 +72,7 @@ proc initSubmodule*(): Submodule =
)
of "hybrid":
let mainFile = pkgRoot / info.pkgSrcDir / info.pkgName.changeFileExt("nim")
writeFile(mainFile,
writeFileIfNonExistent(mainFile,
"""
# This is just an example to get you started. A typical hybrid package
# uses this file as the main entry point of the application.
@ -83,7 +87,7 @@ when isMainModule:
let pkgSubDir = pkgRoot / info.pkgSrcDir / info.pkgName & "pkg"
createDirD(pkgSubDir)
let submodule = pkgSubDir / "submodule".addFileExt("nim")
writeFile(submodule,
writeFileIfNonExistent(submodule,
"""
# This is just an example to get you started. Users of your hybrid library will
# import this file by writing ``import $1pkg/submodule``. Feel free to rename or
@ -112,7 +116,7 @@ proc getWelcomeMessage*(): string = "Hello, World!"
)
if info.pkgType == "library":
writeFile(pkgTestPath / "test1".addFileExt("nim"),
writeFileIfNonExistent(pkgTestPath / "test1".addFileExt("nim"),
"""
# This is just an example to get you started. You may wish to put all of your
# tests into a single file, or separate them into multiple `test1`, `test2`
@ -129,7 +133,7 @@ test "can add":
""" % info.pkgName
)
else:
writeFile(pkgTestPath / "test1".addFileExt("nim"),
writeFileIfNonExistent(pkgTestPath / "test1".addFileExt("nim"),
"""
# This is just an example to get you started. You may wish to put all of your
# tests into a single file, or separate them into multiple `test1`, `test2`