Configuration Examples
Two complete codebaker.config.json5 files for real templates, and a few habits worth keeping. Every key is explained in the Configuration Reference.
Both examples declare the ___VAR___ placeholder style, use string variables only and keep paths, open and expand consistent
with the folder you generate into.
Example 1: a model, generated inside app/Models
Template folder:
.CodeBaker/LaravelModel/
├── codebaker.config.json5
└── ___modelName___.php
codebaker.config.json5:
{
id: "laravel-model",
name: "Laravel Model",
version: "1.0.0",
placeholders: ["___VAR___"],
vars: {
modelName: "User",
tableName: "___modelName___s",
modelNamespace: "App\\Models",
},
// Offered when you right-click app/Models or any folder below it
paths: {
include: ["app/Models", "app/Models/**"],
},
// Relative to the folder you right-clicked
open: ["___modelName___.php"],
}
___modelName___.php:
<?php
namespace ___modelNamespace___;
class ___modelName___ extends Model
{
protected $table = '___tableName___';
}
Right-click app/Models, choose the template, and app/Models/User.php is created and opened. Because the
file name carries the placeholder, no advanced mapping is needed.
Example 2: several files, generated from the project root
When the files belong in different folders, keep that structure inside the template and generate from the project root, so every path lines up.
.CodeBaker/RestEndpoint/
├── codebaker.config.json5
├── notes.md
├── app/Http/Controllers/Api/___entityName___Controller.php
└── tests/Feature/Api/___entityName___Test.php
{
id: "rest-endpoint",
name: "REST API Endpoint",
version: "1.0.0",
placeholders: ["___VAR___"],
vars: {
entityName: "Product",
pluralName: "___entityName___s",
routePrefix: "api/v1",
},
// Lists live in the JSON area; "fields" becomes a variable you can loop over
json: {
fields: ["name", "description", "price"],
},
// Author notes next to the template are not generated
ignore: ["notes.md"],
// Relative to the project root, the folder this template is generated into
open: [
"app/Http/Controllers/Api/___entityName___Controller.php",
"tests/Feature/Api/___entityName___Test.php",
],
expand: ["app/Http/Controllers/Api", "tests/Feature/Api"],
}
There is no paths here, so the template is offered in every folder. Generate it from the project root; from
another folder the same relative paths would end up below that folder.
To move files out of the template's own structure, repeat them, or write a file only once, see Advanced Templates.
Good habits
1. Variable Naming
- Use short, descriptive names (
modelName, notmn), made of letters, digits and_ - Pick one style and stay with it:
dbHost,dbPort,dbNameordb_host,db_port,db_name - Remember that variables are text: put lists and objects in
json
2. File Organization
- Files you do not mention in
codebaker.advanced.json5are copied as they are, with the same relative path. Mention only the files that need something else - Keep the template's own folder structure close to the output structure; it keeps
open,expandandpathssimple
3. Path Filtering
- Be specific with
includeso the template does not clutter every context menu - Exclude folders such as
vendorandnode_modules, and remember to list the folder itself as well asfolder/** - Try the template in the folders you care about: an unsupported pattern fails quietly or skips the template
4. User Experience
- Use
opento show the most important generated file; the last one in the list gets focus - Use
expandto reveal the generated folders - Give the template a clear
nameand aversion
5. Variable Patterns
- Declare the placeholder style you use, for example
placeholders: ["___VAR___"], so names,open,expandand file contents can use your placeholders; nothing but Pebble is built in - Add a second style only when you must, and note it in your template's own README
Next
- Configuration Reference: every key, with its default and what happens when it is wrong.
- Advanced Templates: the mapping file.