Skip to content

Commit d0d5a53

Browse files
committed
update readme examples, prefer npm over yarn, collapse code
1 parent 860e36c commit d0d5a53

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

README.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ run-if-changed is functional as-is, but it's still quite basic and rough as it h
1212
## Installation and setup
1313

1414
<details open>
15-
<summary><b>Install with npm:</b></summary>
15+
<summary><b>Install with npm</b></summary>
1616

1717
```shell
1818
npm install --save-dev husky @hkdobrev/run-if-changed
@@ -28,12 +28,10 @@ npm install --save-dev husky @hkdobrev/run-if-changed
2828
</details>
2929

3030
<details>
31-
<summary><b>Install with Yarn:</b></summary>
32-
33-
#### Install with Yarn:
31+
<summary><b>Install with Yarn</b></summary>
3432

3533
```shell
36-
yarn add --save-dev husky @hkdobrev/run-if-changed
34+
yarn add --dev husky @hkdobrev/run-if-changed
3735
```
3836

3937
##### Recommended setup:
@@ -48,7 +46,7 @@ yarn add --save-dev husky @hkdobrev/run-if-changed
4846
### Set up Git hooks
4947

5048
<details open>
51-
<summary><b>If you use [Husky](https://typicode.github.io/husky/):</b></summary>
49+
<summary><b>Using [Husky](https://typicode.github.io/husky/)</b></summary>
5250

5351
```shell
5452
echo "npm run run-if-changed" > .husky/post-commit
@@ -58,12 +56,12 @@ echo "npm run run-if-changed" > .husky/post-rewrite
5856
```
5957

6058
<details>
61-
<summary><b>Just Git hooks:</b></summary>
59+
<summary><b>Pure Git hooks:</b></summary>
6260
```shell
63-
echo "npm run run-if-changed" > .git/hooks/post-commit && chmod +x .git/hooks/post-commit
64-
echo "npm run run-if-changed" > .git/hooks/post-checkout && chmod +x .git/hooks/post-checkout
65-
echo "npm run run-if-changed" > .git/hooks/post-merge && chmod +x .git/hooks/post-merge
66-
echo "npm run run-if-changed" > .git/hooks/post-rewrite && chmod +x .git/hooks/post-rewrite
61+
echo "npm run run-if-changed" >> .git/hooks/post-commit && chmod +x .git/hooks/post-commit
62+
echo "npm run run-if-changed" >> .git/hooks/post-checkout && chmod +x .git/hooks/post-checkout
63+
echo "npm run run-if-changed" >> .git/hooks/post-merge && chmod +x .git/hooks/post-merge
64+
echo "npm run run-if-changed" >> .git/hooks/post-rewrite && chmod +x .git/hooks/post-rewrite
6765
```
6866
</details>
6967

@@ -89,7 +87,7 @@ Supported are any executables installed locally or globally via `npm` or Yarn as
8987

9088
> Using globally installed scripts is discouraged, since run-if-changed may not work for someone who doesn't have it installed.
9189
92-
`run-if-changed` is using [npm-which](https://github.com/timoxley/npm-which) to locate locally installed scripts. So in your `.run-if-changedrc` you can write:
90+
`run-if-changed` is using [execa](https://github.com/sindresorhus/execa) to locate locally installed scripts and run them. So in your `.run-if-changedrc` you can just write and it would use the local version:
9391

9492
```json
9593
{
@@ -108,14 +106,14 @@ If you use a dependency manager with a lock file like npm, Yarn, Composer, Bundl
108106
Here's example configuration of `run-if-changed`:
109107

110108
<details open>
111-
<summary><b>When using Yarn:</b></summary>
109+
<summary><b>npm:</b></summary>
112110

113111
`package.json`:
114112

115113
```json
116114
{
117115
"run-if-changed": {
118-
"yarn.lock": "yarn install --prefer-offline --pure-lockfile --color=always"
116+
"package-lock.json": "npm install --prefer-offline --no-audit"
119117
}
120118
}
121119
```
@@ -124,21 +122,21 @@ Here's example configuration of `run-if-changed`:
124122

125123
```json
126124
{
127-
"yarn.lock": "yarn install --prefer-offline --pure-lockfile --color=always"
125+
"package-lock.json": "npm install --prefer-offline --no-audit"
128126
}
129127
```
130128

131129
</details>
132130

133131
<details>
134-
<summary><b>When using npm:</b></summary>
132+
<summary><b>Yarn</b></summary>
135133

136134
`package.json`:
137135

138136
```json
139137
{
140138
"run-if-changed": {
141-
"package-lock.json": "npm install --prefer-offline --no-audit"
139+
"yarn.lock": "yarn install --prefer-offline --pure-lockfile --color=always"
142140
}
143141
}
144142
```
@@ -147,14 +145,14 @@ Here's example configuration of `run-if-changed`:
147145

148146
```json
149147
{
150-
"package-lock.json": "npm install --prefer-offline --no-audit"
148+
"yarn.lock": "yarn install --prefer-offline --pure-lockfile --color=always"
151149
}
152150
```
153151

154152
</details>
155153

156154
<details>
157-
<summary><b>When using Composer:</b></summary>
155+
<summary><b>Composer:</b></summary>
158156

159157
`package.json`:
160158

@@ -169,7 +167,7 @@ Here's example configuration of `run-if-changed`:
169167
</details>
170168

171169
<details>
172-
<summary><b>When using Bundler:</b></summary>
170+
<summary><b>Bundler:</b></summary>
173171

174172
`package.json`:
175173

@@ -187,6 +185,9 @@ Here's example configuration of `run-if-changed`:
187185

188186
If you keep database migrations in your repository, you'd usually want to run them when you check out a branch or pull from master.
189187

188+
<details>
189+
<summary>Example of running Doctrine migrations when pulling or changing branches</summary>
190+
190191
`package.json`:
191192

192193
```json
@@ -197,16 +198,21 @@ If you keep database migrations in your repository, you'd usually want to run th
197198
}
198199
```
199200

200-
The above example assumes PHP Doctrine migrations.
201+
</details>
201202

202203
#### Compile sources in a build folder after pulling new code.
203204

205+
<details>
206+
<summary>Example for running build on changing src folder when pulling or changing branches</summary>
207+
204208
`package.json`:
205209

206210
```json
207211
{
208212
"run-if-changed": {
209-
"src": "yarn build"
213+
"src": "npm run build"
210214
}
211215
}
212216
```
217+
218+
</details>

0 commit comments

Comments
 (0)