@@ -12,8 +12,14 @@ function toKebabCase(input) {
12
12
. toLowerCase ( ) ; // Convert to lowercase
13
13
}
14
14
15
- export function createModuleLink ( moduleName ) {
16
- return `/apidocs/${ toKebabCase ( moduleName ) } ` ;
15
+ export function createAPIModuleLink ( moduleName ) {
16
+ // This function is called before import.meta.env.BASE_URL is set.
17
+ // So, I'm hardcoding the path here.
18
+ return `apidocs/${ toKebabCase ( moduleName ) } ` ;
19
+ }
20
+
21
+ export function createTypeModuleLink ( parentModuleLink , typeName ) {
22
+ return `${ parentModuleLink } /${ toKebabCase ( typeName ) } ` ;
17
23
}
18
24
19
25
function mapTypeModules ( parentModuleLink , file ) {
@@ -27,20 +33,20 @@ function mapTypeModules(parentModuleLink, file) {
27
33
return files
28
34
. filter ( ( f ) => f . endsWith ( ".res" ) )
29
35
. map ( ( file ) => {
30
- const fullPath = path . join ( folder , file ) ;
36
+ const filePath = path . join ( folder , file ) ;
31
37
32
38
const moduleName = file
33
39
. replace ( "$" , "" )
34
40
. replace ( folder , "" )
35
41
. replace ( ".res" , "" ) ;
36
42
const apiRouteParameter = toKebabCase ( moduleName ) ;
37
- const link = ` ${ parentModuleLink } / ${ apiRouteParameter } ` ;
43
+ const link = createTypeModuleLink ( parentModuleLink , moduleName ) ;
38
44
const typeName = moduleName [ 0 ] . toLocaleLowerCase ( ) + moduleName . slice ( 1 ) ;
39
45
40
46
return [
41
47
typeName ,
42
48
{
43
- fullPath ,
49
+ filePath ,
44
50
moduleName,
45
51
link,
46
52
apiRouteParameter,
@@ -49,13 +55,10 @@ function mapTypeModules(parentModuleLink, file) {
49
55
} ) ;
50
56
}
51
57
52
- function mapRescriptFile ( file ) {
53
- const moduleName = path
54
- . basename ( file , ".res" )
55
- . replace ( "$" , "" )
56
- . replace ( "API" , " API" ) ;
57
- const filePath = path . join ( import . meta. dirname , file ) ;
58
- const link = createModuleLink ( moduleName ) ;
58
+ function mapRescriptFile ( srcDir , file ) {
59
+ const moduleName = path . basename ( file , ".res" ) . replace ( "$" , "" ) ;
60
+ const filePath = path . join ( srcDir , file ) ;
61
+ const link = createAPIModuleLink ( moduleName ) ;
59
62
const items = Object . fromEntries ( mapTypeModules ( link , filePath ) ) ;
60
63
61
64
return {
@@ -67,13 +70,8 @@ function mapRescriptFile(file) {
67
70
} ;
68
71
}
69
72
70
- export const apiModules = Object . keys (
71
- import . meta. glob ( "../../../src/*.res" ) ,
72
- ) . map ( mapRescriptFile ) ;
73
-
74
- export const fileModules = Object . keys (
75
- import . meta. glob ( "../../../src/**/*.res" ) ,
76
- ) . map ( mapRescriptFile ) ;
73
+ const srcDir = path . resolve ( process . cwd ( ) , "src" ) ;
74
+ export const apiModules = readdirSync ( srcDir ) . filter ( f => f . endsWith ( ".res" ) ) . map ( r => mapRescriptFile ( srcDir , r ) ) ;
77
75
78
76
export async function getDoc ( absoluteFilePath ) {
79
77
const { stdout, stderr } = await execAsync (
0 commit comments