Library structure finalised. Structure is also enforced.

Main file is optional for now.
This commit is contained in:
Dominik Picheta 2012-12-02 12:47:52 +00:00
commit d7c412b353
3 changed files with 62 additions and 10 deletions

View file

@ -1,10 +1,11 @@
; Example babel file
[Package]
name = "babel"
name = "jester"
version = "0.1.0"
author = "Dominik Picheta"
description = """Jester is a web framework inspired by Sinatra."""
[Library]
SkipDirs = "tests"
;SkipDirs = "dir"
;SkipFiles = "file.txt"

View file

@ -63,6 +63,17 @@ proc parseCmdLine(): TAction =
if result.typ == ActionNil:
writeHelp()
proc prompt(question: string): bool =
echo(question & " [y/N]")
let yn = stdin.readLine()
case yn.normalize
of "y", "yes":
return true
of "n", "no":
return false
else:
return false
proc update(url: string = defaultPackageURL) =
echo("Downloading package list from " & url)
downloadFile(url, getHomeDir() / ".babel" / "packages.json")
@ -134,9 +145,18 @@ proc installFromDir(dir: string) =
if babelFile == "":
quit("Specified directory does not contain a .babel file.", QuitFailure)
var pkgInfo = readPackageInfo(babelFile)
if not existsDir(dir / pkgInfo.name):
quit("Package modules should be placed in a " & pkgInfo.name & dirSep &
" directory.", QuitFailure)
if not existsDir(getLibsDir() / pkgInfo.name):
createDir(getLibsDir() / pkgInfo.name)
else: echo("Warning: Package already exists.")
else:
if not prompt("Package already exists. Overwrite?"):
quit(QuitSuccess)
removeDir(getLibsDir() / pkgInfo.name)
createDir(getLibsDir() / pkgInfo.name)
# Find main project file.
let nimFile = dir / pkgInfo.name.addFileExt("nim")
@ -149,9 +169,11 @@ proc installFromDir(dir: string) =
copyFileD(nimrodFile, changeRoot(dir, getLibsDir(), nimrodFile))
pkgInfo.skipFiles.add(changeRoot(dir, "", nimrodFile))
else:
quit("Could not find main package file.", QuitFailure)
# TODO: Make this an error? Which can be overriden in .babel file?
echo("Warning: Could not find main package file.")
copyFilesRec(dir, dir, pkgInfo)
copyFilesRec(dir / pkgInfo.name, dir / pkgInfo.name, pkgInfo)
echo(pkgInfo.name & " installed successfully.")
proc install(packages: seq[String]) =
if packages == @[]:

View file

@ -3,14 +3,43 @@ Babel is a work in progress package manager for Nimrod.
## Babel's folder structure
Babel stores everything that has been installed in ~/.babel on Unix systems and
in your $home/babel on Windows. Libraries are stored in ~/.babel/libs.
in your $home/babel on Windows. Libraries are stored in $babelDir/libs.
## Libraries
Libraries should contain a ``ProjectName.nim`` file, this file will be copied
Libraries may contain a ``ProjectName.nim`` file, this file will be copied
to ~/.babel/libs/ProjectName.nim allowing anyone to import it by doing
``import ProjectName``. Any private files should be placed, by convention, in
a ``private`` folder, these are files which the user of your library should not
be using. Every other file and folder will be copied to ~/.babel/libs/ProjectName/.
``import ProjectName``, it is recommended to include such a file, however
it's not a requirement.
All public modules should be placed in a ``ProjectName/`` folder. The reason for
this is that the main project file can then import the modules that it needs
and the import filename will work before the installation and after.
Any private modules should be placed, by convention, in
a ``private`` folder inside the ``ProjectName/`` folder, these are modules which
the user of your library should not be importing. All files and folders in
``ProjectName/`` will be copied as-is, you can however specify to skip some
directories or files in your .babel file.
## Example .babel file
```ini
; Example babel file
[Package]
name = "ProjectName"
version = "0.1.0"
author = "Dominik Picheta"
description = """Example .babel file."""
[Library]
SkipDirs = "SomeDir" ; ./ProjectName/SomeDir will be skipped.
SkipFiles = "file.txt,file2.txt" ; ./ProjectName/{file.txt, file2.txt} will be skipped.
```
## Submitting your package to the package list.
Babel's packages list is stored on github and everyone is encouraged to add
their own packages to it! Take a look at
[nimrod-code/packages](https://github.com/nimrod-code/packages) to learn more.
## Contribution
If you would like to help, feel free to fork and make any additions you see