Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'vapor new ProjectName --template github/url' does not set 'name:' in Package.swift #428

Open
marc-medley opened this issue Nov 8, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@marc-medley
Copy link

marc-medley commented Nov 8, 2023

Describe the bug

vapor new ProjectName --template github/some/url does not set Package.swift name: to the ProjectName.

To Reproduce

Steps to reproduce the behavior:

  1. Create a template based repository.
vapor new VaporHello --template https://github.com/vapor/template-bare
  1. Examine the resulting Package.swift:
let package = Package(
    name: "template-bare",

Expected behavior

I had expected the project name to be handled similar to vapor new VaporHello -n command.

vapor new VaporHello -n

Package.swift

let package = Package(
    name: "VaporHello",

Environment

  • Vapor Framework version: 4.86.2
  • Vapor Toolbox version: 18.7.4
  • OS version: macOS 13.6

Additional context

Comment: Updating the Package.swift name: seemed like a reasonable action for the vapor toolbox. If one wants the vapor template as-is then a git clone or a zip download could be solid alternatives. That said, there may be other considerations that I'm not aware of.

@marc-medley marc-medley added the bug Something isn't working label Nov 8, 2023
@0xTim
Copy link
Member

0xTim commented Nov 9, 2023

@marc-medley the issue is that the bare template is auto generated and doesn't have any of the information needed to be able to switch it out. See https://github.com/vapor/template/blob/main/manifest.yml and https://github.com/vapor/template/blob/main/Package.swift#L5

Updating the package manifest for INSERT_SOME_URL here is difficult because there's not a good library for parsing and manipulating it and there are a load of edge cases we'd have to take into account. Essentially the --template flag is only designed to work with repos that have a manifest and variables we can replace

@marc-medley
Copy link
Author

marc-medley commented Nov 12, 2023

… information needed to be able to switch [name] out …

In particular, the information appears to variables which use Mustache syntax. (TemplateScaffolder.swift)

import PackageDescription

let package = Package(
    name: "{{name}}",
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", from: "4.83.1"),{{#fluent}}
        .package(url: "https://github.com/vapor/fluent-{{fluent.db.url}}-driver.git", from: "{{fluent.db.version}}"),{{/fluent}}{{#leaf}}

Essentially the --template flag is only designed to work with repos that have a manifest and variables we can replace

If the forward looking roadmap is to generally support Mustache-based Vapor Repository Templates (or some alternative), then it would be helpful to have documentation about the process.

Some areas of potential confusion:

  1. Whether this variable-based-repo type is intended for use by the broader Vapor community to also create such templates.
  2. A "GitHub Template Repository" makes a copy (instead of a clone|fork) without any variable substitution process.
  3. "Vapor Template" contexts which exist today:
    • … as in static-can-use-as-is-repo
    • … as in variable-based-repo
    • … as in leaf
  4. A variable-based-repo template repository likely cannnot be used "as-is" via a clone or downloaded copy. Running some tool|script variable-substition process needs to be available to run after a download|copy of a raw variable-based-repo. Perhaps the Vapor toolbox could provide an after download (or after cloning) variable substitution capability.

The current Vapor toolbox is operational with either a static-can-use-as-is-repo or a variable-based-repo. The .git/ is set up in both cases.

vapor new VaporHello --template https://github.com/vapor/template-bare
# Cloning template...
# Creating git repository
# Adding first commit

The "a Git repository to use as a template." is appropriate as minimal information. As the items listed above are addressed, then the --help information could possibly be amplified with some "See [docs|man|help] for more info on static vs variable-based Vapor template repositories."

vapor new --help
# <name> [--template,-T] [--branch] [--output,-o] [--no-commit] [--no-git] 
#
# Options:
#    template The URL of a Git repository to use as a template.

@0xTim
Copy link
Member

0xTim commented Nov 24, 2023

@marc-medley what's the specific request here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants