-
-
Save Yardanico/60e3de6af76ee70d6023e1f6256fdf6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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