@@ -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,24 @@ 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+ console . log ( "x" , x ) ;
77+ return x . replace ( "/" , "" ) . replace ( "." , "" ) ;
78+ } ) ; // first replace first . / by empty string
79+ values = values . map ( function ( x ) {
80+ console . log ( "x" , x ) ;
81+ return x . replaceAll ( "/" , separator ) . replaceAll ( "." , separator ) ;
82+ } ) ; // then replace all . / by separator
83+ console . log ( "values" , values ) ;
84+ jsonData [ "$id" ] = values
85+ . filter ( function ( val ) {
86+ return val ;
87+ } )
88+ . join ( separator ) ;
4789 schemas [ filename ] = jsonData ;
4890 } catch ( error ) {
4991 console . error (
@@ -63,7 +105,7 @@ function return_json_schema(directoryPath, folder_path, project_name) {
63105 } , folders_schemas ) ;
64106 } else {
65107 var new_folder_path = folder_path + "/" + folder . name ;
66- var test = return_json_schema ( folder . path , new_folder_path , project_name ) ;
108+ var test = return_json_schema ( folder . path , new_folder_path , projectName ) ;
67109 folders_schemas [ folder . name ] = test ;
68110 }
69111 } ) ;
@@ -75,6 +117,6 @@ if (fs.existsSync(outputFile)) {
75117}
76118
77119const finalJson = { } ;
78- finalJson [ project_name ] = return_json_schema ( directoryPath , "" , project_name ) ;
120+ finalJson [ projectName ] = return_json_schema ( directoryPath , "" , projectName ) ;
79121
80122fs . writeFileSync ( outputFile , JSON . stringify ( finalJson , null , 2 ) ) ;
0 commit comments