11import fs from 'node:fs/promises'
22import path from 'node:path'
33
4- import mkdir from 'mkdirp'
54import pMap from 'p-map'
65
76import { formatSource } from '../src/formatter'
@@ -13,7 +12,7 @@ import {
1312
1413async function main ( ) {
1514 const outDir = path . join ( 'packages' , 'sklearn' , 'src' , 'generated' )
16- await mkdir ( outDir )
15+ await fs . mkdir ( outDir , { recursive : true } )
1716
1817 // 487 total definitions
1918 // 228 functions
@@ -24,8 +23,8 @@ async function main() {
2423 // console.log(JSON.stringify(scikitDocUrls, null, 2))
2524
2625 const sources = scikitDocUrls . filter ( ( url ) => {
27- const nameParts = url . split ( '/' ) . slice ( - 1 ) [ 0 ] . split ( '.' )
28- const name = nameParts . slice ( - 2 ) [ 0 ]
26+ const nameParts = url . split ( '/' ) . at ( - 1 ) . split ( '.' )
27+ const name = nameParts . at ( - 2 )
2928 if ( name . toLowerCase ( ) === name ) {
3029 // TODO: likely a function
3130 // console.log('skipping', nameParts.slice(0, -1).join('.'))
@@ -38,12 +37,14 @@ async function main() {
3837 // return
3938
4039 // const sources = [
41- // 'https://scikit-learn.org/stable/modules/generated/sklearn.metrics.average_precision_score.html'
40+ // // 'https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html'
41+ // 'https://scikit-learn.org/stable/modules/generated/sklearn.utils.metadata_routing.MetadataRouter.html'
42+ // // 'https://scikit-learn.org/stable/modules/generated/sklearn.metrics.average_precision_score.html',
4243 // // 'https://scikit-learn.org/stable/modules/generated/sklearn.manifold.TSNE.html',
4344 // // 'https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html',
4445 // // 'https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html',
4546 // // 'https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html',
46- // // 'https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler .html'
47+ // // 'https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV .html'
4748 // ]
4849
4950 console . log ( `\nfetching ${ sources . length } docs...\n` )
@@ -74,12 +75,12 @@ async function main() {
7475 console . log ( `\nprocessing ${ docs . length } docs...\n` )
7576 // console.log(
7677 // JSON.stringify(
77- // docs.map((doc) => doc.name.split('.').slice (-1)[0] ),
78+ // docs.map((doc) => doc.name.split('.').at (-1)),
7879 // null,
7980 // 2
8081 // )
8182 // )
82- // // console.log(JSON.stringify(docs[0], null, 2))
83+ // console.log(JSON.stringify(docs[0], null, 2))
8384
8485 const errors : string [ ] = [ ]
8586 const generatedDirs : any = { }
@@ -99,10 +100,10 @@ async function main() {
99100 const fileName = `${ doc . name } .ts`
100101 const namespaceDirs = doc . namespace . split ( '.' ) . slice ( 1 )
101102 const destDir = path . join ( outDir , ...namespaceDirs )
102- await mkdir ( destDir )
103+ await fs . mkdir ( destDir , { recursive : true } )
103104
104105 const filePath = path . join ( destDir , fileName )
105- await fs . writeFile ( filePath , source , 'utf-8 ' )
106+ await fs . writeFile ( filePath , source , 'utf8 ' )
106107
107108 let generatedDir = generatedDirs
108109 for ( const dir of namespaceDirs ) {
@@ -158,7 +159,7 @@ async function main() {
158159 const source = await formatSource ( indexFileSource )
159160 const fileName = 'index.ts'
160161 const filePath = path . join ( destDir , fileName )
161- await fs . writeFile ( filePath , source , 'utf-8 ' )
162+ await fs . writeFile ( filePath , source , 'utf8 ' )
162163 console . log ( filePath )
163164 }
164165
@@ -179,7 +180,7 @@ If you found this project helpful, please consider [donating to the official sci
179180
180181 const fileName = 'readme.md'
181182 const filePath = path . join ( destDir , fileName )
182- await fs . writeFile ( filePath , readmeFileSource , 'utf-8 ' )
183+ await fs . writeFile ( filePath , readmeFileSource , 'utf8 ' )
183184 console . log ( filePath )
184185 }
185186 }
@@ -195,4 +196,4 @@ If you found this project helpful, please consider [donating to the official sci
195196 )
196197}
197198
198- main ( )
199+ await main ( )
0 commit comments