default dir with licenses

This commit is contained in:
mratsim 2018-03-14 21:58:10 +01:00
parent 8dc903804f
commit 5db1458218
6 changed files with 64 additions and 10 deletions

View File

@ -31,6 +31,20 @@ const
GPLv3: "GPL v2 license (license terms in the root directory or at https://www.gnu.org/licenses/gpl.html)."
}.toTable
licenseFileName* = {
Apache2: "LICENSE-APACHEv2",
MIT: "LICENSE-MIT",
GPLv2: "LICENSE-GPLv2",
GPLv3: "LICENSE-GPLv3"
}.toTable
proc getLicense*(licenses: Licenses): License =
## Extract the license from a Licenses set
assert licenses.card == 1
for license in licenses:
result = license
break
proc license*(projectName: string, license: License, year = getTime().utc().format("yyyy"),
copyrightHolder = "Status Research & Development GmbH"): string =
@ -51,12 +65,7 @@ proc licenseHeader*(projectName: string, licenses: Licenses,
result.add &"# Copyright (c) {year} {copyrightHolder}\n"
if nbLicenses == 1:
# Extract the unique license
var license: License
for lic in licenses:
license = lic
break
let license = licenses.getLicense
result.add "# Licensed and distributed under the " & licenseHeaders.getOrDefault(license)
else:

View File

@ -1,5 +1,6 @@
{projectName} is licensed under the Apache License version 2
Copyright (c) {year} {copyrightHolder}
-----------------------------------------------------
Apache License
Version 2.0, January 2004

View File

@ -1,5 +1,6 @@
{projectName} is licensed under the GNU General Public License version 2
Copyright (c) {year} {copyrightHolder}
-----------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991

View File

@ -1,5 +1,6 @@
{projectName} is licensed under the GNU General Public License version 3
Copyright (c) {year} {copyrightHolder}
-----------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

View File

@ -1,5 +1,6 @@
{projectName} is licensed under the MIT License
Copyright (c) {year} {copyrightHolder}
-----------------------------------------------------
The MIT License (MIT)

View File

@ -8,8 +8,9 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import cligen,
os, strutils,
./private/[datatypes, error_checking, cligen_extensions]
os, strutils, tables,
./private/[datatypes, error_checking, cligen_extensions],
./licensing/license
# ##############################
# Logic
@ -19,16 +20,56 @@ proc nimbusLaunch(projectName: string,
nimbleName: string,
licenses: Licenses = {MIT, Apache2}): int =
let prjDir = githubName
let nbLicenses = licenses.card
# Validity checks
if projectName.isNil or githubName.isNil or nimbleName.isNil:
error "nimbusLaunch requires 3 arguments at minimum: projectName, githubName, nimbleName.\n Run nimbleLaunch --help for more information."
if not githubName.validGithub:
error "The package name on Github (" & githubName & ") must consist of lowercase ASCII, numbers and hyphens (uppercase and underscores are not allowed)."
if not nimbleName.validIdentifier:
error "The package name on nimble (" & nimbleName & ") must be a valid Nim identifier: ASCII, digits, underscore (no hyphen and doesn't start by a number)."
if githubName.existsDir:
if prjDir.existsDir:
error "A directory with the name \"" & githubName & "\" already exists in the directory."
if licenses.card == 0:
if nbLicenses == 0:
error "The project must have at least one license."
# Create the folder structure
# .
# ├── LICENSE-APACHEv2 (if applicable)
# ├── LICENSE-MIT (if applicable)
# ├── README.md
# ├── benchmarks
# ├── build
# ├── docs
# ├── examples
# ├── {nimbleName}.nimble
# ├── src
# │ ├── {nimbleName}.nim
# │ └── private
# └── tests
# └── all_tests.nim
createDir(prjDir & "/benchmarks")
createDir(prjDir & "/build")
createDir(prjDir & "/docs")
createDir(prjDir & "/examples")
createDir(prjDir & "/src/private")
createDir(prjDir & "/tests")
if nbLicenses == 1:
writeFile(
prjDir & "/LICENSE",
license(projectName, licenses.getLicense)
)
else:
for license in licenses:
writeFile(
prjDir & "/" & licenseFileName.getOrDefault(license),
license(projectName, license)
)
when isMainModule:
dispatch nimbusLaunch