Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 6131362

Browse files
committed
precommit hook builds README on hooks documentation changes
1 parent c1e1b8d commit 6131362

File tree

4 files changed

+63
-22
lines changed

4 files changed

+63
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/), and this
77
**Table of Contents**
88

99
- [[Unreleased]](#unreleased)
10-
- [[v1.4.0] - (2020-12-02)](#v140---2020-12-02)
10+
- [[v1.4.0] - (2020-12-03)](#v140---2020-12-03)
1111
- [[v1.3.2] - (2020-12-02)](#v132---2020-12-02)
1212
- [Added](#added)
1313
- [[v1.3.1] - (2020-11-30)](#v131---2020-11-30)
@@ -38,7 +38,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/), and this
3838

3939
---
4040

41-
## [v1.4.0] - (2020-12-02)
41+
## [v1.4.0] - (2020-12-03)
4242

4343
---
4444

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ _Table Of Contents_
3939
- [Demo](#demo-2)
4040
- [Props](#props-2)
4141
- [Example](#example-2)
42+
- [Hooks](#hooks)
43+
- [useHashScroll](#usehashscroll)
44+
- [Summary](#summary-3)
45+
- [Demo](#demo-3)
46+
- [Params](#params)
47+
- [Example](#example-3)
4248
- [Contributing](#contributing)
4349
- [More Info (Badges)](#more-info-badges)
4450

@@ -333,6 +339,22 @@ const App = () => {
333339

334340
---
335341

342+
## Hooks
343+
344+
### useHashScroll
345+
346+
#### Summary
347+
348+
Creates a ref that scrolls to its assigned element when a specified hash is present in the url
349+
350+
#### Demo
351+
352+
#### Params
353+
354+
#### Example
355+
356+
---
357+
336358
## Contributing
337359

338360
- Go to the [github repository](https://github.com/YashTotale/react-hash-scroll)

docs/Hooks/useHashScroll.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### useHashScroll
2+
3+
#### Summary
4+
5+
Creates a ref that scrolls to its assigned element when a specified hash is present in the url
6+
7+
#### Demo
8+
9+
#### Params
10+
11+
#### Example

scripts/precommit.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -156,35 +156,43 @@ const checkReadme = async () => {
156156

157157
const docsDir = join(ROOT_DIR, "docs");
158158

159-
const componentsPath = "docs/Components/";
159+
const docsPath = "docs/";
160160

161-
if (staged.includes(componentsPath)) {
162-
const componentsDir = join(docsDir, "Components");
161+
if (staged.includes(docsPath)) {
162+
const createReadme = async (name: string) => {
163+
const path = docsPath + name + "/";
163164

164-
const files = await readDir(join(componentsDir));
165+
if (staged.includes(path)) {
166+
const dir = join(docsDir, name);
165167

166-
for (const file of files) {
167-
if (staged.includes(`${componentsPath}${file}`)) {
168-
const readme = await getReadme();
168+
const files = await readDir(dir);
169169

170-
const titleIndex = readme.indexOf(`### ${parse(file).name}`);
170+
for (const file of files) {
171+
if (staged.includes(`${path}${file}`)) {
172+
const readme = await getReadme();
171173

172-
const endIndex = readme.indexOf("---", titleIndex);
174+
const titleIndex = readme.indexOf(`### ${parse(file).name}`);
173175

174-
const fileContents = await readFile(
175-
join(componentsDir, file),
176-
"utf-8"
177-
);
176+
const endIndex = readme.indexOf("---", titleIndex);
178177

179-
const newReadme =
180-
readme.substring(0, titleIndex) +
181-
fileContents +
182-
"\n" +
183-
readme.substring(endIndex);
178+
const fileContents = await readFile(join(dir, file), "utf-8");
184179

185-
await writeFile(readmeDest, newReadme);
180+
const newReadme =
181+
readme.substring(0, titleIndex) +
182+
fileContents +
183+
"\n" +
184+
readme.substring(endIndex);
185+
186+
await writeFile(readmeDest, newReadme);
187+
}
188+
}
186189
}
187-
}
190+
};
191+
192+
await createReadme("Components");
193+
194+
await createReadme("Hooks");
195+
188196
await gitAdd(readmeDest);
189197
}
190198

0 commit comments

Comments
 (0)