How to replace a string in a directory including directory name, file name & file content

Hello,

I want to create a Rust program that provide a nodeJS template and automaticly replace directory name, file name & file content by the program name chosen by the user.

For instance this a a (simple) nodeJS template

{application-name-kebab-case}
      {application-name-lowercase}.js
      index.js

where index.js contains :

require("./{application-name-lowercase}.js").start();
  1. I am using the following pattern to match different naming convention
{application-name-PascalCase}
{application-name-camelCase}
{application-name-snake_case}
{application-name-lowercase}
{application-name-kebab-case}
{application-name-space-delimited}

Is there a proper way to fully replace in an entire directory both directory name, file name and content ?

For the moment, I have only find the std::fs::rename but it's pretty basic ?

Thanks in advance,

JP

I found the amazing tool Ruplacer (https://github.com/TankerHQ/ruplacer) that also manage naming convention. I am wandering whether I can use it as a library and not a cmd tool.

This sounds quite similar to cargo-generate, although it looks like you'd need ashleygwilliams/cargo-generate#159.

Even so, you may be able to find some inspiration by skimming through its source code and seeing how they do things.

It looks like it does expose an (undocumented) library API: https://docs.rs/ruplacer/0.4.1/ruplacer/struct.DirectoryPatcher.html. I don't know how helpful it is, but it exists and can be depended on?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.