mirror of
https://github.com/SangeloDev/niminit.git
synced 2024-11-22 16:32:40 +00:00
Started work on config implementation
This commit is contained in:
parent
0dfe2bbe69
commit
f313efe86e
6 changed files with 80 additions and 47 deletions
|
@ -3,15 +3,13 @@
|
|||
# (c) Sangelo - 2023 #
|
||||
#######################
|
||||
[general]
|
||||
# Should the home directory appended before the config directory?
|
||||
appendHome = true
|
||||
# The path to the config file (no trailing slashes!)
|
||||
configDirectory = "/.config/niminit"
|
||||
# Should compatibility warnings be suppressed?
|
||||
suppressWarnings = false
|
||||
|
||||
[files]
|
||||
# The directory to be created inside the project
|
||||
directory = ".vscode"
|
||||
files = [
|
||||
"launch.json",
|
||||
"tasks.json"
|
||||
]
|
||||
[project]
|
||||
# This is the directory inside your home folder containing all of your templates.
|
||||
sourceDirectory = "/.config/niminit/templates"
|
||||
# The directory to be created inside the project, and to copy the selected project template into. (for example: utils)
|
||||
targetDirectory = ".vscode"
|
||||
# The default template to use when not explicitly specified. (for example: java)
|
||||
defaultTemplate = "nim"
|
12
config/templates/nim/init.toml
Normal file
12
config/templates/nim/init.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
########################
|
||||
# niminit Nim Template #
|
||||
# (c) Sangelo - 2023 #
|
||||
########################
|
||||
|
||||
[general]
|
||||
# Should a script be ran after initialising?
|
||||
runScript = false
|
||||
# What script should be executed?
|
||||
scriptPath = ""
|
||||
# Should a git repo be initialised?
|
||||
initGitRepo = true
|
|
@ -26,7 +26,7 @@ mkdir -p $HOME/.local/bin &&
|
|||
cp bin/niminit $HOME/.local/bin/niminit &&
|
||||
# Create config directory & copy files
|
||||
mkdir -p $HOME/.config/niminit &&
|
||||
cp config/* $HOME/.config/niminit &&
|
||||
cp -r config/* $HOME/.config/niminit &&
|
||||
|
||||
# Print info message to export local bin if not already
|
||||
printf "\n"
|
||||
|
|
|
@ -5,13 +5,31 @@ import parsetoml
|
|||
|
||||
# TODO: Make .nimble creator
|
||||
|
||||
# OS detection
|
||||
# Windows detection
|
||||
when defined(windows):
|
||||
echo "Warning: Windows is currently unsupported!"
|
||||
quit 1
|
||||
|
||||
# Initialise config
|
||||
let homeDir = getEnv("HOME")
|
||||
let config = parseToml.parseFile(joinPath(homeDir,
|
||||
"/.config/niminit/config.toml"))
|
||||
|
||||
# Set necessary variables (home directory, config path)
|
||||
let projectTarget = config["project"]["targetDirectory"].getStr(".vscode")
|
||||
# var projectTarget = config["project"].getStr("targetDirectory", ".vscode")
|
||||
var projectSource = config["project"]["sourceDirectory"].getStr("/.config")
|
||||
var projectTemplate = config["project"]["defaultTemplate"].getStr("nim")
|
||||
|
||||
# let tasksPath = joinPath(homeDir, "/.config/niminit/tasks.json")
|
||||
# let launchPath = joinPath(homeDir, "/.config/niminit/launch.json")
|
||||
|
||||
# Set configuration variables
|
||||
let suppressWarnings = config["general"]["suppressWarnings"].getBool(false)
|
||||
|
||||
when defined(macosx):
|
||||
if "-s" in (commandLineParams()):
|
||||
echo "Suppressing experimental support warning"
|
||||
if "-s" or suppressWarnings == true in (commandLineParams()):
|
||||
echo "Suppressing experimental support warning."
|
||||
else:
|
||||
echo "Warning: macOS is currently untested. Would you like to continue? [y/N]"
|
||||
var input = stdin.readLine()
|
||||
|
@ -22,24 +40,6 @@ when defined(macosx):
|
|||
echo "Cancelling..."
|
||||
quit 0
|
||||
|
||||
# Check for files in directory
|
||||
var count = 0
|
||||
for entry in walkDir("."):
|
||||
count += 1
|
||||
# If there are files, ask for confirmation, otherwise continue.
|
||||
if count == 0:
|
||||
echo "Initialising..."
|
||||
else:
|
||||
echo "This directory is not empty."
|
||||
echo "Continue initialising? [y/N]"
|
||||
var input = stdin.readLine()
|
||||
case input.toLower
|
||||
of "yes", "y", "z", "j":
|
||||
echo "Initialising non-empty directory..."
|
||||
else:
|
||||
echo "Cancelling..."
|
||||
quit 0
|
||||
|
||||
# Define how to handle failed copies
|
||||
proc copyFile(src, dest: string): bool =
|
||||
try:
|
||||
|
@ -73,24 +73,47 @@ proc configureGitRepo(gitRemote, gitBranch: string) =
|
|||
else:
|
||||
echo &"Failed to set branch {gitBranch}"
|
||||
|
||||
#-------------------------------------------------------------------------------#
|
||||
#--#
|
||||
|
||||
# Set necessary variables (home directory, config path)
|
||||
let homeDir = getEnv("HOME")
|
||||
let vscodeDir = ".vscode"
|
||||
let tasksPath = joinPath(homeDir, "/.config/niminit/tasks.json")
|
||||
let launchPath = joinPath(homeDir, "/.config/niminit/launch.json")
|
||||
# Check for files in directory
|
||||
var count = 0
|
||||
for entry in walkDir("."):
|
||||
count += 1
|
||||
# If there are files, ask for confirmation, otherwise continue.
|
||||
if count == 0:
|
||||
echo "Initialising..."
|
||||
else:
|
||||
echo "This directory is not empty."
|
||||
echo "Continue initialising? [y/N]"
|
||||
var input = stdin.readLine()
|
||||
case input.toLower
|
||||
of "yes", "y", "z", "j":
|
||||
echo "Initialising non-empty directory..."
|
||||
else:
|
||||
echo "Cancelling..."
|
||||
quit 0
|
||||
|
||||
# Create .vscode directory and copy files into it
|
||||
let vscDirCreated = createDir(vscodeDir)
|
||||
let tasksCopied = copyFile(tasksPath, joinPath(vscodeDir, "tasks.json"))
|
||||
let launchCopied = copyFile(launchPath, joinPath(vscodeDir, "launch.json"))
|
||||
# Create project directory and copy files into it
|
||||
let projectDirCreated = createDir(projectTarget)
|
||||
|
||||
# Get a list of all the files in the source directory
|
||||
let srcDir =
|
||||
let files = walkDir(joinPath(projectSource, "/", projectTemplate))
|
||||
|
||||
# Loop through each file and copy it to the destination directory
|
||||
for file in files:
|
||||
let srcFile = joinPath(srcDir, file)
|
||||
let destFile = joinPath(destDir, file)
|
||||
if not isDir(srcFile):
|
||||
copyFile(srcFile, destFile)
|
||||
let copiedFiles = copyFile(joinPath(projectSource, "/", projectTemplate,
|
||||
"/*"), projectTarget)
|
||||
|
||||
# Check for success and quit if command errored
|
||||
if vscDirCreated and tasksCopied and launchCopied:
|
||||
echo "All files copied successfully"
|
||||
if projectDirCreated and copiedFiles: # and tasksCopied and launchCopied:
|
||||
echo "All files created successfully"
|
||||
else:
|
||||
echo "Failed to copy one or more files"
|
||||
echo "Failed to create one or more files"
|
||||
quit 1
|
||||
|
||||
# Handle -g parameter for git repos.
|
||||
|
@ -114,4 +137,4 @@ if "-g" in (commandLineParams()):
|
|||
else:
|
||||
echo: "Failed creating local git repository."
|
||||
|
||||
echo "Done!"
|
||||
echo "Done!"
|
||||
|
|
Loading…
Reference in a new issue