diff --git a/src/licensing/license.nim b/src/licensing/license.nim index 329f056..7b54750 100644 --- a/src/licensing/license.nim +++ b/src/licensing/license.nim @@ -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: diff --git a/src/licensing/license_APACHEv2.txt b/src/licensing/license_APACHEv2.txt index 1329def..d1d2a0b 100644 --- a/src/licensing/license_APACHEv2.txt +++ b/src/licensing/license_APACHEv2.txt @@ -1,5 +1,6 @@ {projectName} is licensed under the Apache License version 2 Copyright (c) {year} {copyrightHolder} +----------------------------------------------------- Apache License Version 2.0, January 2004 diff --git a/src/licensing/license_GPLv2.txt b/src/licensing/license_GPLv2.txt index 66eb923..de1f811 100644 --- a/src/licensing/license_GPLv2.txt +++ b/src/licensing/license_GPLv2.txt @@ -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 diff --git a/src/licensing/license_GPLv3.txt b/src/licensing/license_GPLv3.txt index 2d675f1..74a9cd3 100644 --- a/src/licensing/license_GPLv3.txt +++ b/src/licensing/license_GPLv3.txt @@ -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 diff --git a/src/licensing/license_MIT.txt b/src/licensing/license_MIT.txt index 38d93c6..5d666db 100644 --- a/src/licensing/license_MIT.txt +++ b/src/licensing/license_MIT.txt @@ -1,5 +1,6 @@ {projectName} is licensed under the MIT License Copyright (c) {year} {copyrightHolder} +----------------------------------------------------- The MIT License (MIT) diff --git a/src/nimbusLaunch.nim b/src/nimbusLaunch.nim index 4a42863..bdb4e86 100644 --- a/src/nimbusLaunch.nim +++ b/src/nimbusLaunch.nim @@ -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