Skip to content

Instantly share code, notes, and snippets.

@hollodotme
Last active October 16, 2017 16:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hollodotme/4d068e6dcf9356d84a8f1205b68aab70 to your computer and use it in GitHub Desktop.
Save hollodotme/4d068e6dcf9356d84a8f1205b68aab70 to your computer and use it in GitHub Desktop.
[DRAFT] PhpStorm feature request to make project templates more beneficial

Background

I often start new projects and need to set up a bunch of strings and variables inside my project created from a template. You can see my github repo template here. Just search it for "VendorName" or "PackageName" and you'll see what I mean.

These variables are always the same in the beginning and I need to remember what names I used and where I need to replace them. Since this is a repetitive task, I seek more automation. Currently the project template feature in PhpStorm 2017.1 does not support custom variables at all.

I also work in a team that uses a similar project template. The team should be able to benefit from the updates to the project template, and everyone on the team should be able to update the template. That's why we use a git repository for that, instead of local PhpStorm project templates. Again repetitive work has to be done when creating a new project from that repository (git clone, remember and replace variables, etc.). Currently the project templates are stored locally in PhpStorm 2017.1.

I wrote up this draft for a PhpStorm feature request to find a solution for (preferably) all the above named downsides of the current PhpStorm project template feature and manual project template maintenance.

But before I place this request at JetBrains' ticket tracker, I'd like to hear your feedback.

  • Is it a good approach?
  • Do you miss something essential?
  • Do you have ideas for further improvements/simplification regarding the basic goals?

Basic goals

  • Improve the distribution and maintenance of a project templates within teams/organizations
  • Reduce initial effort to set up a new project created from template
  • Allow multiple individuals to edit the project template

Feature requests

  • Allow a vcs repository to be the project template (like the settings repository)
  • Remove the vcs files when creating a new project from template
  • Allow to set up variables in a .ProjectTemplate file
[variables]
$VendorName$="Vendor name (e.g. hollodotme)",default="hollodotme"
$ProjectName$="Projekt name (e.g. NewProject)"
$PackageName$="Package name (e.g. hollodotme/new-project)",default="hollodotme/"
$ProjectDomain$="new-project.de"

As you can see a variable definition follows this scheme:

$VARIABLE_NAME$="VARIABLE_VALUE"[,default="DEFAULT_VALUE"]
  • Based on .ProjectTemplate ask for the variable values in Dialog File > New Project… > User-defined > ProjectTemplate

This dialog could then look like this:

Location:                                   [ /path/to/projects/untitled ]
--------------------------------------------------------------------------
Custom variables:
Vendor name (e.g. hollodotme):              [ hollodotme                 ]
Project name (e.g. NewProject):             [                            ]
Package name (e.g. hollodotme/new-project): [ hollodotme/                ]
Project domain (e.g. new-project.org):      [                            ]

This is pretty much the same functionality as already implemented in the new file dialog when using file template variables. (Settings > Editor > File and Code Templates)

  • Replace all occurrences of the variables with its entered values in ALL files (including .*) of the project template
(A control view like the new search-replace in path modal would be awesome to check replacements before done!)
  • Allow to set up a script in .ProjectTemplate to run before/after the new project was created from template
[run-before]
/path/to/executable/script.sh    # absolute static path
[run-after]
bin/script.sh                    # relative path in the project directory

# Note: The working dir should be the project directory
  • Also remove the .ProjectTemplate when all is done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment