File tree 3 files changed +53
-7
lines changed
3 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,11 @@ $ tree 283-move-zeroes
14
14
## ` package.json ` scripts
15
15
You can use the following scripts on each exercise:
16
16
``` json
17
+ // leetcode-node-scripts.json
17
18
{
18
- // ...
19
- "scripts" : {
20
- "start" : " node index.js" ,
21
- "debug" : " node --inspect-brk index.js" ,
22
- "test" : " node test.js"
23
- },
24
- // ...
19
+ "start" : " node index.js" ,
20
+ "debug" : " node --inspect-brk index.js" ,
21
+ "test" : " node test.js"
25
22
}
26
23
27
24
```
@@ -30,3 +27,12 @@ Where:
30
27
- ` start ` : Starts the program
31
28
- ` debug ` : Starts the program in debug mode
32
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
+ ```
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # Check if jq is installed
4
+ if ! command -v jq & > /dev/null
5
+ then
6
+ echo " jq could not be found. Please install it."
7
+ exit 1
8
+ fi
9
+
10
+ # Check if the correct number of arguments is given
11
+ if [ " $# " -ne 1 ]; then
12
+ echo " Usage: $0 path/to/package.json"
13
+ exit 1
14
+ fi
15
+
16
+ # File paths
17
+ PACKAGE_JSON=" $1 "
18
+ SCRIPTS_JSON=" leetcode-node-scripts.json"
19
+
20
+ # Check if the package.json file exists
21
+ if [ ! -f " $PACKAGE_JSON " ]; then
22
+ echo " package.json not found at $PACKAGE_JSON "
23
+ exit 1
24
+ fi
25
+
26
+ # Check if the leetcode-node-scripts.json file exists
27
+ if [ ! -f " $SCRIPTS_JSON " ]; then
28
+ echo " $SCRIPTS_JSON not found"
29
+ exit 1
30
+ fi
31
+
32
+ # Replace the scripts section in package.json
33
+ jq --argfile scripts " $SCRIPTS_JSON " ' .scripts = $scripts' " $PACKAGE_JSON " > temp.json && mv temp.json " $PACKAGE_JSON "
34
+
35
+ echo " Scripts section has been updated in $PACKAGE_JSON "
Original file line number Diff line number Diff line change
1
+ {
2
+ "start" : " node index.js" ,
3
+ "debug" : " node --inspect-brk index.js" ,
4
+ "test" : " node test.js"
5
+ }
You can’t perform that action at this time.
0 commit comments