Skip to content

Commit bb43d1c

Browse files
committed
adds automation
1 parent fa966f5 commit bb43d1c

File tree

14 files changed

+315
-0
lines changed

14 files changed

+315
-0
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node genIndex.js

Readme.tl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Learn Node.js by building a backend framework - [Velocy](https://github.com/ishtms/velocy)
2+
3+
<p align="center">
4+
<img src="./assets/imgs/cover.jpg" alt="Learn nodejs the hard way" width="500">
5+
</p>
6+
7+
You can access the current version of the book in the [chapters directory](/chapters) or in PDF format (both Light and Dark modes are available) by [clicking here](https://github.com/ishtms/learn-nodejs-hard-way/releases). Note that this version includes the current release of the content, and is not the final version.
8+
9+
> This book is still in a very early stage. It contains an insignificant portion of the total content that the book is supposed to cover. Theres going to be 0 dependencies for our [backend framework](https://github.com/ishtms/velocy), as well as our [logging library](https://github.com/ishtms/logtar). Everything will be done using vanilla Node.js, the hard-way (the best way to learn).
10+
11+
---
12+
13+
## Note
14+
15+
If you're not familiar with javascript, you may also check out my other repository - [Learn Javascript - The Easy Way](https://github.com/ishtms/learn-javascript-easy-way) that takes you on a deep and a fun journey into Javascript - from the very basics to the advanced concepts that you'd ever need, without diving into too much theory. Only practical code examples.
16+
17+
---
18+
19+
To master a new concept, it's often best to begin from the ground up. This isn't just another Node.js guide; it's a comprehensive, code-along experience aimed at building a real world product that may be used by thousands of developers. The product that we're going to build will be a backend framework, that too from scratch.
20+
21+
You won't just learn how Node.js works, but also why it operates in a particular way. The guide also includes discussions on relevant data structures and design patterns.
22+
23+
The book also includes a wide range of exercises specifically created to challenge you, that may require commitment and consistent effort on your part. The first exercises start from [chapter 7](/chapters/ch06.5-ex-implementing-a-trie.md)
24+
25+
This guide goes beyond the basics. We're focused on delivering a modular, optimized backend framework that is close to being production-ready. Topics like performance optimization, security measures, and various testing approaches will be covered to ensure the framework is both reliable and extendable.
26+
27+
I highly recommend actively coding alongside this guide, rather than just reading through it, for a full understanding of Node.js and its more intricate aspects.
28+
29+
The repo for our backend framework- [Velocy](https://github.com/ishtms/velocy). (W.I.P)
30+
31+
[![Read Next](/assets/imgs/next.png)](/chapters/ch01-what-is-a-web-server-anyway.md)
32+
33+
# Table of contents
34+
35+
{{toc}}

genIndex.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const readline = require("readline");
4+
5+
const rootDir = __dirname;
6+
const chaptersDir = path.join(rootDir, "chapters");
7+
const readmeTemplatePath = path.join(rootDir, "Readme.tl");
8+
const readmeOutputPath = path.join(rootDir, "Readme.md");
9+
10+
async function generateTOC() {
11+
const files = fs.readdirSync(chaptersDir).filter((file) => file.endsWith(".md") && file !== "Readme.md");
12+
let toc = "# Table of contents\n\n";
13+
14+
for (const file of files) {
15+
const filePath = path.join(chaptersDir, file);
16+
const headings = await extractHeadings(filePath);
17+
const relativePath = path.relative(rootDir, filePath).replace(/\\/g, "/");
18+
toc += formatHeadings(headings, relativePath);
19+
}
20+
21+
const templateContent = fs.readFileSync(readmeTemplatePath, "utf-8");
22+
const outputContent = templateContent.replace("{{toc}}", toc);
23+
fs.writeFileSync(readmeOutputPath, outputContent);
24+
25+
console.log("Table of contents generated successfully!");
26+
}
27+
28+
async function extractHeadings(filePath) {
29+
const fileStream = fs.createReadStream(filePath);
30+
const rl = readline.createInterface({
31+
input: fileStream,
32+
crlfDelay: Infinity,
33+
});
34+
35+
const headings = [];
36+
let insideCodeBlock = false;
37+
38+
for await (const line of rl) {
39+
if (line.trim().startsWith("```")) {
40+
insideCodeBlock = !insideCodeBlock;
41+
}
42+
43+
if (!insideCodeBlock) {
44+
const match = line.match(/^(#{1,6})\s+(.*)/);
45+
if (match) {
46+
const level = match[1].length;
47+
const text = match[2];
48+
const anchor = text.toLowerCase().replace(/[^\w]+/g, "-");
49+
headings.push({ level, text, anchor });
50+
}
51+
}
52+
}
53+
54+
return headings;
55+
}
56+
57+
function formatHeadings(headings, relativePath) {
58+
let formatted = "";
59+
for (const heading of headings) {
60+
const indent = " ".repeat(heading.level - 1);
61+
const link = `${relativePath}#${heading.anchor}`;
62+
formatted += `${indent}- [${heading.text}](${link})\n`;
63+
}
64+
return formatted;
65+
}
66+
67+
generateTOC().catch((err) => console.error(err));

node_modules/.bin/husky

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/husky/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/husky/README.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/husky/bin.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/husky/husky

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/husky/index.d.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)