You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
support top level custom keywords starting with "x-"
* "x-" prefixed top level keywords are now supported. This allows alias this data in env
* env can now alias "x-" prefixed maps which will be merged with "env"
* improve docs - sidebar now has better nesting
* improve docs - add conditional "init" explanation
* add bats and unit tests
Copy file name to clipboardExpand all lines: docs/docs/best_practices.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title: Best practices
5
5
6
6
### Naming conventions
7
7
8
-
Prefer single word over plural.
8
+
Prefer single word over plural.
9
9
10
10
It is better to leverage semantics of `lets` as an intention to do something. For example it is natural saying `lets test` or `lets build` something.
11
11
@@ -106,3 +106,28 @@ As you can see, we execute `build` command each time we execute `run` command (`
106
106
107
107
`persist_checksum` will save calculated checksum to `.lets` directory and all subsequent calls of `build` command will
108
108
read checksum from disk, calculate new checksum, and compare them. If `package.json` will change - we will rebuild the image.
109
+
110
+
111
+
### Initialize project using `init`
112
+
113
+
You can use `init` keyword to write a script that will do some initialization on lets startup, like creating some dirs, configs or installing project dependencies.
114
+
115
+
By default, `init` runs each time the `lets` program is executed.
116
+
117
+
You can make `init` conditional, by simply creating a file and checking if it exists at the start of `init` script.
118
+
119
+
Example:
120
+
121
+
```
122
+
shell: bash
123
+
124
+
init: |
125
+
if [[ ! -f .lets/init_done ]]; then
126
+
echo "calling init script"
127
+
touch .lets/init_done
128
+
fi
129
+
```
130
+
131
+
In this example we are checking for `.lets/init_done` file existence. If it does not exist, we will call init script and create `init_done` file as a marker of successfull init script invocation.
132
+
133
+
We are using `.lets` dir here because this dir will be created by `lets` itself and is generally a good place to create such files, but you are free to create files with any name and in any directory you want.
-[Override arguments in depends command](#override-arguments-in-depends-command)
27
+
-[`options`](#options)
28
+
-[`env`](#env)
29
+
-[`eval_env`](#eval_env)
30
+
-[`checksum`](#checksum)
31
+
-[`persist_checksum`](#persist_checksum)
32
+
-[`ref`](#ref)
33
+
-[`args`](#args)
34
+
-[Aliasing:](#aliasing)
35
+
-[Env aliasing](#env-aliasing)
25
36
26
37
27
38
## Top-level directives:
@@ -139,11 +150,19 @@ commands:
139
150
140
151
`type: string`
141
152
142
-
Specify init script which will be executed only once. It is execured right before first command call.
153
+
Specify init script which will be executed only once during each lets invocation. It is execured right before first command call.
143
154
144
-
`init`script is a good place for some intialization that sould be done once, for example,
155
+
> Main difference from `before` is that `before` called before each command invocation (including commands specified in depends)
145
156
146
-
create docker network, check if some directory exist, clear caches, etc.
157
+
`init` script is a good place for some initialization that should be done once at lets startup, for example:
158
+
159
+
* create docker network
160
+
* check if some directory exist
161
+
* clear caches,
162
+
* install dependencies
163
+
* etc.
164
+
165
+
Example usage:
147
166
148
167
```yaml
149
168
shell: bash
@@ -171,6 +190,29 @@ From before
171
190
Bar
172
191
```
173
192
193
+
#### Conditional init
194
+
195
+
If you need to make sure that code in `init` is called once with some condition,
196
+
you can for example create a file at the end of `init` script and check if this
197
+
file exists at the beginning of `init` script.
198
+
199
+
Example:
200
+
201
+
```
202
+
shell: bash
203
+
204
+
init: |
205
+
if [[ ! -f .lets/init_done ]]; then
206
+
echo "calling init script"
207
+
touch .lets/init_done
208
+
fi
209
+
```
210
+
211
+
In this example we are checking for `.lets/init_done` file existence. If it does not exist, we will call init script and create `init_done` file as a marker of successfull init script invocation.
212
+
213
+
We are using `.lets` dir here because this dir will be created by `lets` itself and is generally a good place to create such files, but you are free to create files with any name and in any directory you want.
214
+
215
+
174
216
### Mixins
175
217
176
218
`key: mixins`
@@ -828,3 +870,24 @@ commands:
828
870
829
871
`args`is used only with [ref](#ref) and allows to set additional positional args to referenced command. See [ref](#ref) example.
830
872
873
+
874
+
## Aliasing:
875
+
876
+
Lets supports YAML aliasing in various places in the config
877
+
878
+
### Env aliasing
879
+
880
+
You can define any mapping and alias it in `env` configuration:
881
+
882
+
```yaml
883
+
shell: bash
884
+
885
+
.default-env: &default-env
886
+
FOO: BAR
887
+
888
+
env:
889
+
<<: *default-env
890
+
HELLO: WORLD
891
+
```
892
+
893
+
This will merge `env` and `.default-env`. Any environment variables declarations after `<<: ` will override variables defined in aliased map.
0 commit comments