fixed #581 nimble init does not overwrite existing files with its templates anymore
This commit is contained in:
parent
98e566adab
commit
df8317585f
1 changed files with 11 additions and 7 deletions
|
|
@ -14,6 +14,10 @@ type
|
||||||
pkgNimDep: string
|
pkgNimDep: string
|
||||||
pkgType: string
|
pkgType: string
|
||||||
|
|
||||||
|
proc writeFileIfNonExistent(file: string, content: string) =
|
||||||
|
if not existsFile(file):
|
||||||
|
writeFile(file, content)
|
||||||
|
|
||||||
proc createPkgStructure*(info: PkgInitInfo, pkgRoot: string) =
|
proc createPkgStructure*(info: PkgInitInfo, pkgRoot: string) =
|
||||||
# Create source directory
|
# Create source directory
|
||||||
createDirD(pkgRoot / info.pkgSrcDir)
|
createDirD(pkgRoot / info.pkgSrcDir)
|
||||||
|
|
@ -23,7 +27,7 @@ proc createPkgStructure*(info: PkgInitInfo, pkgRoot: string) =
|
||||||
case info.pkgType
|
case info.pkgType
|
||||||
of "binary":
|
of "binary":
|
||||||
let mainFile = pkgRoot / info.pkgSrcDir / info.pkgName.changeFileExt("nim")
|
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
|
# This is just an example to get you started. A typical binary package
|
||||||
# uses this file as the main entry point of the application.
|
# uses this file as the main entry point of the application.
|
||||||
|
|
@ -35,7 +39,7 @@ when isMainModule:
|
||||||
nimbleFileOptions.add("bin = @[\"$1\"]\n" % info.pkgName)
|
nimbleFileOptions.add("bin = @[\"$1\"]\n" % info.pkgName)
|
||||||
of "library":
|
of "library":
|
||||||
let mainFile = pkgRoot / info.pkgSrcDir / info.pkgName.changeFileExt("nim")
|
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
|
# 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
|
# 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)
|
createDirD(pkgRoot / info.pkgSrcDir / info.pkgName)
|
||||||
let submodule = pkgRoot / info.pkgSrcDir / info.pkgName /
|
let submodule = pkgRoot / info.pkgSrcDir / info.pkgName /
|
||||||
"submodule".addFileExt("nim")
|
"submodule".addFileExt("nim")
|
||||||
writeFile(submodule,
|
writeFileIfNonExistent(submodule,
|
||||||
"""
|
"""
|
||||||
# This is just an example to get you started. Users of your library will
|
# 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
|
# import this file by writing ``import $1/submodule``. Feel free to rename or
|
||||||
|
|
@ -68,7 +72,7 @@ proc initSubmodule*(): Submodule =
|
||||||
)
|
)
|
||||||
of "hybrid":
|
of "hybrid":
|
||||||
let mainFile = pkgRoot / info.pkgSrcDir / info.pkgName.changeFileExt("nim")
|
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
|
# This is just an example to get you started. A typical hybrid package
|
||||||
# uses this file as the main entry point of the application.
|
# 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"
|
let pkgSubDir = pkgRoot / info.pkgSrcDir / info.pkgName & "pkg"
|
||||||
createDirD(pkgSubDir)
|
createDirD(pkgSubDir)
|
||||||
let submodule = pkgSubDir / "submodule".addFileExt("nim")
|
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
|
# 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
|
# 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":
|
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
|
# 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`
|
# tests into a single file, or separate them into multiple `test1`, `test2`
|
||||||
|
|
@ -129,7 +133,7 @@ test "can add":
|
||||||
""" % info.pkgName
|
""" % info.pkgName
|
||||||
)
|
)
|
||||||
else:
|
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
|
# 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`
|
# tests into a single file, or separate them into multiple `test1`, `test2`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue