import sys, os
proj_path = os.path.dirname(os.path.abspath(__file__))
readme_path = "README.md"
lib_path = "src/lib.rs"
os.chdir(proj_path)
with open(readme_path, 'r') as f:
readme = f.readlines()
doc = ["//! " + line for line in readme]
with open(lib_path, 'r') as f:
lib = f.readlines()
desserted_doc = []
lib = list(reversed(lib))
while len(lib) > 0 and (lib[-1].startswith("//!") or lib[-1].isspace()):
line = lib.pop()
desserted_doc.append(line)
lib = list(reversed(lib))
print(">>>>>>")
for line in desserted_doc:
print(line, end="")
print("<<<<<<")
lib = doc + ["\n"] + lib
with open(lib_path, 'w') as f:
f.writelines(lib)