vapor / toolbox

Simplifies common command line tasks when using Vapor
MIT License
283 stars 85 forks source link

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

Open marc-medley opened 8 months ago

marc-medley commented 8 months ago

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

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.

0xTim commented 8 months ago

@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 commented 8 months ago

… 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 commented 7 months ago

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