Skip to content

Instantly share code, notes, and snippets.

@Yardanico

Yardanico/fa.nim Secret

Created May 20, 2020 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yardanico/60e3de6af76ee70d6023e1f6256fdf6b to your computer and use it in GitHub Desktop.
Save Yardanico/60e3de6af76ee70d6023e1f6256fdf6b to your computer and use it in GitHub Desktop.
import os, macros, strutils, strformat
const IgnoreFilenames = ["base.nim", "help.nim"]
macro importPlugins*(): untyped =
result = newStmtList()
let folder = "src" / "modules"
for kind, path in walkDir(folder):
if kind != pcFile: continue
let filename = path.extractFilename()
if filename in IgnoreFilenames: continue
# Name of the module for import
let toImport = filename.split(".")
# If file extension isn't .nim or there's "skip" in the name - skip it
if toImport.len != 2 or toImport[1] != "nim" or "skip" in toImport[0]: continue
# Add the import of that module
result.add parseExpr(&"import {folder}/{toImport[0]}")
# Import help in the very end so that all other modules
# registered their commands
result.add parseExpr(&"import {folder}/help")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment