Skip to content

Commit b84bc48

Browse files
committedJan 18, 2024
Update: README.md for adding clarity on exercise execution, debugging and testing
1 parent 7ab1347 commit b84bc48

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed
 

‎README.md

+28-18
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@
22
Exercises taken from the Leetcode 75 interview problem compilation. Each exercise folder has the
33
following files:
44
```sh
5-
$ tree 283-move-zeroes
6-
283-move-zeroes # Exercise name
5+
$ tree ,<exercise-name>
6+
,<exercise-name>
77
├── index.js # Solution implementation
88
├── package.json # Contains execution scripts
99
├── README.md # Problem description
1010
└── test.js # Test cases implementation
1111

1212
```
1313

14-
## `package.json` scripts
15-
You can use the following scripts on each exercise:
14+
## Usage
15+
To streamline the setup process for each exercise, you can automatically inject the common scripts
16+
defined in `leetcode-node-scripts.json` into the `package.json` of each exercise directory using the
17+
`add-scripts.sh` bash script.
18+
19+
### Injecting Scripts Automatically
20+
1. Ensure you have a `package.json` file in your exercise directory (create one with `npm init -y`
21+
if necessary).
22+
2. Use the `add-scripts.sh` script to inject the scripts from `leetcode-node-scripts.json` into your
23+
`package.json`:
24+
25+
```sh
26+
# Execute from the repository root
27+
$ ./add-scripts.sh <path-to-exercise>/package.json
28+
29+
```
30+
31+
After running the script, your package.json will include the following scripts from
32+
`leetcode-node-scripts.json`:
1633
```json
17-
// leetcode-node-scripts.json
1834
{
1935
"start": "node index.js",
2036
"debug": "node --inspect-brk index.js",
@@ -23,16 +39,10 @@ You can use the following scripts on each exercise:
2339

2440
```
2541

26-
Where:
27-
- `start`: Starts the program
28-
- `debug`: Starts the program in debug mode
29-
- `test`: Run the test suite for this exercise
30-
31-
### Populating Automatically the `scripts` Key of `package.json` files
32-
Execute the following script, in this example the `package.json` file has been created beforehand
33-
inside the directory `./1004-max-consecutive-ones-iii` using `npm init -y`:
34-
```sh
35-
# Execute from the repository root
36-
$ ./add-scripts.sh ./1004-max-consecutive-ones-iii/package.json
37-
38-
```
42+
### Understanding the Scripts
43+
- `start`: Runs the `index.js` file to start the program. Use this when you want to run you
44+
solution.
45+
- `debug`: Starts the program in debug mode with `--inspect-brk`, allowing you to attach a debugger
46+
and step through the code.
47+
- `test`: Runs the `test.js` file to execute all test cases associated with the exercise, ensuring
48+
your solution meets the specified requirements.

0 commit comments

Comments
 (0)