[QUESTION] How to replace the template published on mdn to the template generated by cargo generate?

[!NOTE]
Highlights

I would like to ask about the following project-template that I discovered today on 2023-11-11 JST. The link is as follows:

  • mdn/project-template

The function of this template is to automatically output the files displayed by the tree -a command by simply executing the following shell command:

tree -a
.
├── .editorconfig
├── .git
│   ├── FETCH_HEAD
│   ├── HEAD
│   ├── config
│   ├── description
│   ├── hooks
│   │   ├── applypatch-msg.sample
│   │   ├── commit-msg.sample
│   │   ├── fsmonitor-watchman.sample
│   │   ├── post-update.sample
│   │   ├── pre-applypatch.sample
│   │   ├── pre-commit.sample
│   │   ├── pre-merge-commit.sample
│   │   ├── pre-push.sample
│   │   ├── pre-rebase.sample
│   │   ├── pre-receive.sample
│   │   ├── prepare-commit-msg.sample
│   │   ├── push-to-checkout.sample
│   │   ├── sendemail-validate.sample
│   │   └── update.sample
│   ├── index
│   ├── info
│   │   └── exclude
│   ├── logs
│   │   ├── HEAD
│   │   └── refs
│   │       ├── heads
│   │       │   └── main
│   │       └── remotes
│   │           └── origin
│   │               └── HEAD
│   ├── objects
│   │   ├── info
│   │   └── pack
│   │       ├── pack-1740cd7451243231c55292114d6e00c115e8fc9e.idx
│   │       ├── pack-1740cd7451243231c55292114d6e00c115e8fc9e.pack
│   │       └── pack-1740cd7451243231c55292114d6e00c115e8fc9e.rev
│   ├── packed-refs
│   └── refs
│       ├── heads
│       │   └── main
│       ├── remotes
│       │   └── origin
│       │       └── HEAD
│       └── tags
├── .github
│   ├── ISSUE_TEMPLATE
│   │   ├── bug.yml
│   │   └── config.yml
│   ├── PULL_REQUEST_TEMPLATE
│   ├── settings.yml
│   └── workflows
│       ├── auto-merge.yml
│       ├── codeql.yml.template
│       ├── idle.yml
│       └── welcome-bot.yml
├── .prettierrc.json
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README-template.md
├── README.md
├── REVIEWING.md
└── SECURITY.md

The question you have is how to apply the above template to the template generated by cargo new project-name by default. If there is already an option or a tool that can be installed with cargo, please let me know.

To the best of my knowledge, there is no built-in option in cargo new to apply a template by default. However, you can use the cargo-generate tool to generate a new project based on a template. Here are the steps to use cargo-generate:

  1. Install cargo-generate by running the following command:
cargo install cargo-generate
  1. Clone the mdn/project-template repository to your local machine:
git clone https://github.com/mdn/project-template.git
  1. Run the following command to generate a new project based on the mdn/project-template:
cargo generate --git https://github.com/mdn/project-template.git --name <project-name>

Replace <project-name> with the name of your project.

This will generate a new project based on the mdn/project-template in a directory with the name <project-name>.

Reference < Does Cargo have the ability to create a new project based off a template>
Thank you very much for your cooperation.

That's correct. You can find the PR for the RFC for Cargo templates here (currently closed due to the author being unable to continue their work).


I'm having trouble understanding your question(s). It looks to me like you have solved your problem with cargo generate, no?


This step seems redundant to me given that you use the template from the git repository in step 3.

1 Like

Dear jofas
日本語で失礼します。
ご返信いただきましてありがとうございます。
もっと注意深く自身で調べてから質問すべき内容でした。

ありがとう。

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.