@@ -3,29 +3,55 @@ const path = require("path");
33const  glob  =  require ( "glob" ) ; 
44const  process  =  require ( "process" ) ; 
55
6- const  findDirectoryPath  =  ( targetDirectoryName )  =>  { 
7-   const  pathToCheck  =  path . join ( process . cwd ( ) ,  targetDirectoryName ) ; 
6+ console . log ( "process.argv" ,  process . argv ) ; 
7+ 
8+ var  projectName  =  process . argv [ 2 ] ; 
9+ console . log ( "projectName" ,  projectName ) ; 
10+ var  folderName  =  process . argv [ 3 ] ; 
11+ console . log ( "folderName" ,  folderName ) ; 
12+ var  key  =  process . argv [ 4 ] ; 
13+ console . log ( "key" ,  key ) ; 
14+ var  separator  =  process . argv [ 5 ] ; 
15+ console . log ( "separator" ,  separator ) ; 
16+ 
17+ const  findDirectoryPath  =  ( targetDirectoryName ,  folderName )  =>  { 
18+   const  pathToCheck  =  path . join ( 
19+     process . cwd ( ) , 
20+     "/src" , 
21+     "/" , 
22+     targetDirectoryName 
23+   ) ; 
24+   console . log ( "pathToCheck" ,  pathToCheck ) ; 
25+ 
826  const  folders  =  fs 
927    . readdirSync ( pathToCheck ,  {  withFileTypes : true  } ) 
1028    . filter ( 
11-       ( folder )  =>  folder . isDirectory ( )  &&  ! folder . name . endsWith ( ".egg-info" ) 
29+       ( folder )  => 
30+         folder . isDirectory ( )  && 
31+         ! folder . name . endsWith ( ".egg-info" )  && 
32+         folder . name  !=  "tests"  && 
33+         folder . name  !=  "__pycache__"  && 
34+         folder . name . includes ( folderName ) 
1235    ) 
1336    . map ( ( folder )  =>  ( { 
1437      name : folder . name , 
1538      path : path . join ( pathToCheck ,  folder . name ) , 
1639    } ) ) ; 
17-   const  routesDirectory  =  path . join ( folders [ 0 ] . path ,  "routes" ) ; 
18-   return  [ routesDirectory ,  folders [ 0 ] . name ] ; 
40+   console . log ( "folders" ,  folders ) ; 
41+   const  routesDirectory  =  path . join ( folders [ 0 ] . path ) ; 
42+   return  routesDirectory ; 
1943} ; 
2044
21- const  [ directoryPath ,   project_name ]   =  findDirectoryPath ( "src/" ) ; 
45+ const  directoryPath   =  findDirectoryPath ( projectName ,   folderName ) ; 
2246
2347const  outputFile  =  path . join ( process . cwd ( ) ,  "schemas.json" ) ; 
2448
25- function  return_json_schema ( directoryPath ,  folder_path ,  project_name )  { 
49+ function  return_json_schema ( directoryPath ,  folder_path ,  projectName )  { 
50+   console . log ( "return_json_schema" ,  directoryPath ,  folder_path ,  projectName ) ; 
51+ 
2652  const  folders  =  fs 
2753    . readdirSync ( path . normalize ( directoryPath ) ,  {  withFileTypes : true  } ) 
28-     . filter ( ( folder )  =>  folder . isDirectory ( ) ) 
54+     . filter ( ( folder )  =>  folder . isDirectory ( )   &&   folder . name   !=   "__pycache__" ) 
2955    . map ( ( folder )  =>  ( { 
3056      name : folder . name , 
3157      path : path . join ( directoryPath ,  folder . name ) , 
@@ -42,8 +68,21 @@ function return_json_schema(directoryPath, folder_path, project_name) {
4268          var  filename  =  filePath 
4369            . replace ( / ^ .* [ \\ / ] / ,  "" ) 
4470            . replace ( / \. [ ^ / . ] + $ / ,  "" ) ; 
45-           var  route  =  jsonData [ "route" ] ; 
46-           jsonData [ "$id" ]  =  project_name  +  folder_path  +  route ; 
71+           var  route  =  jsonData [ key ] ; 
72+           console . log ( "FOLDER PATH" ,  projectName ) ; 
73+           var  values  =  [ projectName ,  folder_path ,  route ] ; 
74+           console . log ( "values" ,  values ) ; 
75+           values  =  values . map ( function  ( x )  { 
76+             return  x . replace ( "/" ,  "" ) ; 
77+           } ) ; 
78+           values  =  values . map ( function  ( x )  { 
79+             return  x . replace ( "." ,  "" ) ; 
80+           } ) ; 
81+           jsonData [ "$id" ]  =  values 
82+             . filter ( function  ( val )  { 
83+               return  val ; 
84+             } ) 
85+             . join ( separator ) ; 
4786          schemas [ filename ]  =  jsonData ; 
4887        }  catch  ( error )  { 
4988          console . error ( 
@@ -63,7 +102,7 @@ function return_json_schema(directoryPath, folder_path, project_name) {
63102      } ,  folders_schemas ) ; 
64103    }  else  { 
65104      var  new_folder_path  =  folder_path  +  "/"  +  folder . name ; 
66-       var  test  =  return_json_schema ( folder . path ,  new_folder_path ,  project_name ) ; 
105+       var  test  =  return_json_schema ( folder . path ,  new_folder_path ,  projectName ) ; 
67106      folders_schemas [ folder . name ]  =  test ; 
68107    } 
69108  } ) ; 
@@ -75,6 +114,6 @@ if (fs.existsSync(outputFile)) {
75114} 
76115
77116const  finalJson  =  { } ; 
78- finalJson [ project_name ]  =  return_json_schema ( directoryPath ,  "" ,  project_name ) ; 
117+ finalJson [ projectName ]  =  return_json_schema ( directoryPath ,  "" ,  projectName ) ; 
79118
80119fs . writeFileSync ( outputFile ,  JSON . stringify ( finalJson ,  null ,  2 ) ) ; 
0 commit comments