Project Templates extension for VSCode
Visual Studio code extension that allows you to quickly create new projects based on custom templates.
Inspired by this File Templates Extension, which is itself inspired by a similar Atom Extension.
In Visual Studio code, Press F1 to open the command menu and type ext install cantonios.project-templates
.
This extension contributes the following settings:
{
"projectTemplates.templatesDirectory": "", // default directory containing project templates
"projectTemplates.usePlaceholders": true, // activate placeholder substitution
"projectTemplates.placeholders": { }, // dictionary of default placeholder key-value pairs
"projectTemplates.placeholderRegExp": "#{(\\w+?)}" // regular expression to use for detecting placeholders
}
See CHANGELOG for release notes.
Extension commands can be executed from the Command Palette or from the context menu when selecting a folder.
Variable placeholders can be used in templates in the following way:
Author: #{author}
Title: #{title}
When a file is created from a template containing placeholders, the user is prompted for a value to enter. Placeholders can also be used in filenames.
"projectTemplates.usePlaceholders": false
"projectTemplates.placeholderRegExp": "#{(\\w+?)}"
The first capture group in the regular expression is used to idenfity the placeholder key."projectTemplates.placeholders": {
"author" : "John Smith",
"company": "Wonderful Widgets Inc."
}
These placeholders will be replaced without prompting.By default, this extension expects the project templates to be placed within the user's data directory for VSCode, which is OS-specific. For the non-portable version of VSCode, this is typically
$HOME/.config/Code/User/ProjectTemplates # Linux
$HOME/Library/Application Support/Code/User/ProjectTemplates # macOS
%APPDATA%\Code\User\ProjectTemplates # Windows
For the portable version of vscode, or if a --user-data-dir
is specified at the command-line, the default template location is
$USER_DATA_DIR/User/ProjectTemplates
You can change the templates location by adding the following to your user or workspace settings:
"projectTemplates.templatesDirectory": "path/to/my/templates"
This path supports VSCode's predefined variables, such as ${env:HOME}
.
A set of sample templates can be found here