Skip to content

Commit

Permalink
Merge branch 'main' of github.com:loreanvictor/tmplr
Browse files Browse the repository at this point in the history
  • Loading branch information
loreanvictor committed Mar 19, 2023
2 parents 75c4bba + 12336ef commit 4481950
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
73 changes: 48 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,19 @@ Recipes might have access to following contextual values, depending on the condi

<br/>

### Path Context
### Filesystem Context

- `path.rootdir`: The name of the root directory
- `path.rootempty`: This is an empty string if root directory is not empty, and `yes` if it is. `.git` and `.tmplr.yml` are ignored.
- `filesystem.root`: Absolute address of the root directory (which the recipe is being executed in)
- `filesystem.rootdir`: The name of the root directory
- `filesystem.scope`: Absolute address of the scope of this recipe.
- `filesystem.scopedir`: The name of the scope directory.

The root directory, accessible via `filesystem.root`, is where the recipe file is located. This is also the addrerss which all
relative addresses in the recipe are interpreted relative to. The scope, accessible via `filesystem.scope`, dictates which files
the recipe has access to: The recipe can only access files in the scope (or in sub directories in the scope, recursively). The scope
is by default the same as the root, however when a recipe invokes a child recipe (via [run](#run) or [use](#use) commands), then
the scope differs from the root, as the invoked recipe might be in a subdirectory (which would cause its root to differ from the
parent recipe), while its scope remains the same as the parent recipe.

<br/>

Expand Down Expand Up @@ -425,6 +434,7 @@ Commands instruct `tmplr` to read values, update contents of files, etc. Here yo
- [**copy**](#copy): copy contents of a file to a new file, while replacing variables with values read.
- [**remove**](#remove): removes a file.
- [**steps**](#steps): runs a bunch of commands in a step by step manner.
- [**if**](#if): runs a command conditionally.
- [**degit**](#degit): copies content of given repository to given folder, without bringing the git history.
- [**exit**](#exit): ends the recipe early.
- [**run**](#run): runs another local recipe file, with given arguments.
Expand Down Expand Up @@ -478,6 +488,11 @@ steps:
path: '{{ docs_folder }}/Home.md'
```

👉 Update also supports [extended glob pattern](https://www.npmjs.com/package/minimatch), so you can update multiple files at once:
```yml
update: 'src/**/*.java'
```

<br/>

#### Copy
Expand Down Expand Up @@ -551,45 +566,53 @@ steps:
```

<br/>

#### Degit

#### If
> _Command_
> ```yml
> degit:
> <expression>
> to?:
> if: <contextual-variable>
> <command>
> else?:
> <command>
> ```
> ```yml
> if:
> <expression>
> <command>
> else?:
> <command>
> ```
Will fetch the contents of given repository and copy them into specified folder. If destination is not specified, will copy
into the same folder as the running recipe. Accepts the same sources as `tmplr` command itself (basically runs [degit](https://github.com/Rich-Harris/degit)).
Runs given command if given contextual variable (or value) exists and has a non-empty value. Can be given an expression instead
of a contextual variable (e.g. [eval](#eval)), where it will check if the resolved value is a non-empty string. Will run the _else_ command if the
condition fails (and an _else_ command is provided).
```yml
steps:
- degit: user/repo
to:
eval: '{{ tmpdir.repo }}'
- if: git.remote_url
copy: README.git-template.md
to: README.md
else:
copy: README.non-git-template.md
to: README.md
```

<br/>

#### Exit
#### Degit

> _Command_
> ```yml
> exit:
> degit:
> <expression>
> to?:
> <expression>
> ```
Will end the templating process early (for example because value is not set or due to user's choice). Will evaluate and display given
message.
Will fetch the contents of given repository and copy them into specified folder. If destination is not specified, will copy
into the same folder as the running recipe. Accepts the same sources as `tmplr` command itself (basically runs [degit](https://github.com/Rich-Harris/degit)).
```yml
steps:
- read: remote_url
from: git.remote_url
fallback:
eval: _
steps:
- exit: Must be a git repository!
# ...
- degit: user/repo
to:
eval: '{{ tmpdir.repo }}'
```

<br/>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tmplr",
"version": "0.2.0",
"version": "0.2.1",
"description": "Easy templating for repositories",
"bin": "dist/src/index.js",
"engines": {
Expand Down

0 comments on commit 4481950

Please sign in to comment.