@@ -100,7 +100,7 @@ _(Note: The name must match exactly.)_
100
100
** Templates can also be added from GitHub with:**
101
101
102
102
``` bash
103
- init -c " https://github.com/user/repoitoryName"
103
+ init -c " https://github.com/user/repoitoryName.git "
104
104
```
105
105
106
106
##### Example
@@ -109,6 +109,13 @@ init -c "https://github.com/user/repoitoryName"
109
109
110
110
This process involves cloning the repository into the current terminal directory, removing the .git folder from the cloned repository, executing the init -a "repoName" command to create a copy in the templates folder, and then deleting the cloned repository folder from the current terminal location.
111
111
112
+ I have used this Regex to verify if the given string is a link or not.
113
+
114
+ ``` js
115
+ const urlRegex =
116
+ / ^ (https? | ftp):\/\/ (([a-z \d ] ([a-z \d -] * [a-z \d ] )? \. )+ [a-z ] {2,} | localhost)(\/ [-a-z \d %_. ~+] * )* (\? [;&a-z \d %_. ~+=-] * )? (\# [-a-z \d _] * )? $ / i ;
117
+ ```
118
+
112
119
The reason it performs all these steps is because I attempted to accomplish it in a simpler manner but couldn't find one.
113
120
114
121
** To see all the Commands (Help)**
@@ -232,7 +239,7 @@ const [, , ...args] = process.argv;
232
239
233
240
const options = {
234
241
condition: null ,
235
- folderPath : null ,
242
+ folderPathOrNameOrLink : null ,
236
243
nodeFlagParam: " " ,
237
244
};
238
245
@@ -247,7 +254,7 @@ for (let i = 0; i < args.length; i++) {
247
254
break ;
248
255
case " -h" :
249
256
options .condition = arg;
250
- options .folderPath = " " ;
257
+ options .folderPathOrNameOrLink = " " ;
251
258
break ;
252
259
case " -y" :
253
260
// Check if the previous option was '-a'
@@ -263,7 +270,7 @@ for (let i = 0; i < args.length; i++) {
263
270
console .error (` Invalid option: ${ arg} ` );
264
271
process .exit (1 );
265
272
} else {
266
- options .folderPath = arg;
273
+ options .folderPathOrNameOrLink = arg;
267
274
}
268
275
break ;
269
276
}
@@ -422,7 +429,17 @@ if (!condition) {
422
429
});
423
430
};
424
431
432
+ const urlRegex =
433
+ / ^ (https? | ftp):\/\/ (([a-z \d ] ([a-z \d -] * [a-z \d ] )? \. )+ [a-z ] {2,} | localhost)(\/ [-a-z \d %_. ~+] * )* (\? [;&a-z \d %_. ~+=-] * )? (\# [-a-z \d _] * )? $ / i ;
434
+
425
435
const repoLink = process .argv [3 ];
436
+
437
+ if (! urlRegex .test (repoLink)) {
438
+ console .log (" Invalid repository link provided." );
439
+ process .exit (1 );
440
+ } else {
441
+ console .log (" Repository link is valid." );
442
+ }
426
443
const gitCommand = ` git clone --depth 1 ${ repoLink} ` ;
427
444
let projectName;
428
445
@@ -541,7 +558,7 @@ ${chalk.bold.underline.white("Package Commands:")}
541
558
` ` ` json
542
559
{
543
560
" name" : " @s54a/init" ,
544
- " version" : " 4.0 .0" ,
561
+ " version" : " 4.2 .0" ,
545
562
" description" : " Project Initializer" ,
546
563
" main" : " ./index.js" ,
547
564
" type" : " module" ,
0 commit comments