lessPreCompile.py 756 B

123456789101112131415161718192021222324
  1. import os
  2. def find_less_files(folder_path):
  3. less_files = []
  4. for root, dirs, files in os.walk(folder_path):
  5. for file in files:
  6. if file.endswith('.less'):
  7. less_files.append(os.path.relpath(os.path.join(root, file), folder_path).replace('\\','/'))
  8. return less_files
  9. def write_paths_to_file(file_paths, output_file):
  10. with open(output_file, 'w') as f:
  11. for path in file_paths:
  12. f.write(f'@import "{path}";' + '\n')
  13. if __name__ == "__main__":
  14. folder_path = "sugarcube/src"
  15. output_file = "sugarcube/src/main.less"
  16. if os.path.exists(output_file):
  17. os.remove(output_file)
  18. less_files = find_less_files(folder_path)
  19. write_paths_to_file(less_files, output_file)