parent
931f3a63ca
commit
8cd18c6f8c
@ -1,3 +1,26 @@ |
||||
## Replicate `ls` |
||||
|
||||
This starts you off with a simple command line parsing library and a globbing library to get going. |
||||
This starts you off with a simple command line parsing library and a globbing library to get going named [fast-glob](https://www.npmjs.com/package/fast-glob). "Globbing" is what you're doing when you use regular expression patterns to match files like this: |
||||
|
||||
```bash |
||||
ls *.txt |
||||
``` |
||||
|
||||
The `fast-glob` library is a good library with only one quirk to watch out for: It will not convert `\` (backslash) characters to `/` in your glob. That means if you use `C:\Users\zed\*.txt` it will fail. You'll have to convert all `\` to `/` on Windows. |
||||
|
||||
## File Attributes |
||||
|
||||
Part of the `ls` command is printing out the attributes of a file. For that you'll need `fs.stat` found in the [fs](https://nodejs.org/docs/latest-v16.x/api/fs.html) module. |
||||
|
||||
## Removing `fast-glob` |
||||
|
||||
If you can get your `ls` copy working with `fast-glob` then try removing `fast-glob` and replicate its functionality with your own code. You'll need the [fs](https://nodejs.org/docs/latest-v16.x/api/fs.html) module and specifically the `readdir` function. |
||||
|
||||
## Learning Objectives |
||||
|
||||
As with all of the exercises thus far you aren't just learning how to replicated `ls` but you'll also: |
||||
|
||||
1. Learn more about the `fs` module. |
||||
2. Learn how to process command line options. Try [commander](https://github.com/tj/commander.js/). |
||||
3. Learn how to list files recursively based on a pattern using `fast-glob` and how `fast-glob` works by replacing it. |
||||
4. Learn about file attributes with the `fs.stat` function. |
||||
|
@ -1 +1,24 @@ |
||||
## Replicate `find` |
||||
|
||||
This exercise is very similar to the `ls` exercise, but instead of simply listing based on a pattern you are taking various commands to more finely control the search. This will help you solidify your understanding of the `fs` module which will be _essential_ for future exercises. |
||||
|
||||
## Notes on Commander.js |
||||
|
||||
The `find` command is an odd one because it uses the non-standard `-name` style (one dash, one word) while the rest of Unix tools use `--name` style (two dash, one word) or `-n` (one dash, one letter) style. For now, if you want to keep using [commander.js](https://github.com/tj/commander.js/) then you'll have to use the `--name` style and just go with it for now. |
||||
|
||||
## `find` For Windows |
||||
|
||||
Windows doesn't have `find` so you'll have to research how it works either inside `Windows Subsystem for Linux` or from the [man page](https://man7.org/linux/man-pages/man1/find.1.html). |
||||
|
||||
Another option is to replicate the PowerShell [Get-ChildItem](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.2) or `gci` for short. If you're not interested in running WSL for this exercise then I recommend this path, but my tutorial will replicate `find`. |
||||
|
||||
## Learning Objectives |
||||
|
||||
This exercise is all about cementing your understanding of everything learned so far: |
||||
|
||||
1. Patterns using Regular Expressions (RegExp). |
||||
2. Recursively processing and finding files. |
||||
3. Using `fs.stat` to read the attributes of a file. |
||||
4. Getting command line options from the user. |
||||
|
||||
Once you're done with this exercise you should be well versed in files, directories, file attributes, and how to find them for processing. |
||||
|
Loading…
Reference in new issue