mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-23 17:28:39 +02:00
flake-modules/new-plugin: find project root
This commit is contained in:
parent
35b6d9bc9d
commit
85b990286d
1 changed files with 17 additions and 2 deletions
|
@ -91,6 +91,18 @@ def write_to_file(file_path, content: str):
|
|||
f.write(content)
|
||||
|
||||
|
||||
def find_project_root(root_identifier):
|
||||
current_path = os.getcwd()
|
||||
while True:
|
||||
if root_identifier in os.listdir(current_path):
|
||||
return current_path
|
||||
parent_path = os.path.dirname(current_path)
|
||||
if parent_path == current_path:
|
||||
return None
|
||||
os.chdir("..")
|
||||
current_path = os.getcwd()
|
||||
|
||||
|
||||
# TODO: support interactive unmanaged args
|
||||
def main():
|
||||
"""
|
||||
|
@ -109,8 +121,11 @@ def main():
|
|||
name = kebab_case(args.originalName)
|
||||
|
||||
# Define paths
|
||||
plugin_path = f"plugins/by-name/{name}/default.nix"
|
||||
test_path = f"tests/test-sources/plugins/by-name/{name}/default.nix"
|
||||
root_identifier = "flake.nix"
|
||||
root_dir = find_project_root(root_identifier)
|
||||
|
||||
plugin_path = f"{root_dir}/plugins/by-name/{name}/default.nix"
|
||||
test_path = f"{root_dir}/tests/test-sources/plugins/by-name/{name}/default.nix"
|
||||
|
||||
# Create files
|
||||
create_nix_file(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue