@@ -3,6 +3,17 @@ import path from 'path';
3
3
import { execSync } from 'child_process' ;
4
4
import yaml from 'js-yaml' ;
5
5
6
+ const cloneRepository = ( url , directory ) => {
7
+ try {
8
+ // Clone the repository
9
+ execSync ( `git clone ${ url } ${ directory } ` ) ;
10
+ return true ;
11
+ } catch ( error ) {
12
+ console . error ( `Error cloning repository: ${ error . message } ` ) ;
13
+ return false ;
14
+ }
15
+ } ;
16
+
6
17
const getGitHubUrl = ( rootPath ) => {
7
18
try {
8
19
// Get the GitHub repository URL
@@ -63,12 +74,18 @@ const searchPackages = (directory, outputFilename, indexUrl) => {
63
74
} else {
64
75
const isPackageJson = file === 'package.json' ;
65
76
const isManifestPy = file === 'manifest.py' ;
77
+ const packageName = path . basename ( dir ) ;
78
+
79
+ if ( packageName . startsWith ( "_" ) ) {
80
+ continue ; // Skip "private" packages
81
+ }
66
82
67
83
if ( isPackageJson || isManifestPy ) {
68
84
const packageInfo = {
69
- name : path . basename ( dir ) ,
85
+ name : packageName ,
70
86
docs : constructGitHubUrl ( gitHubUrl , currentBranch , repositoryRoot , dir ) ,
71
87
index : indexUrl ,
88
+ author : 'MicroPython' ,
72
89
} ;
73
90
74
91
if ( isManifestPy ) {
@@ -109,14 +126,22 @@ const searchPackages = (directory, outputFilename, indexUrl) => {
109
126
} ;
110
127
111
128
// Check if command line arguments are provided
112
- if ( process . argv . length < 5 ) {
129
+ if ( process . argv . length < 3 ) {
113
130
// Note: Official MicroPython lib index is: https://micropython.org/pi/v2
114
- // Example usage: node create-index.mjs ../ micropython-lib/micropython micropython-lib .yml https://micropython.org/pi/v2
115
- console . error ( 'Usage: node create-index.mjs <directory> < outputFilename.yml> <indexUrl >' ) ;
131
+ // Example usage: node create-index.mjs micropython-lib.yml
132
+ console . error ( 'Usage: node create-index.mjs <outputFilename.yml>' ) ;
116
133
} else {
117
- const directory = process . argv [ 2 ] ;
118
- const outputFilename = process . argv [ 3 ] ;
119
- const indexUrl = process . argv [ 4 ] ;
134
+ // Make build directory if it doesn't exist
135
+ if ( ! fs . existsSync ( 'build' ) ) {
136
+ fs . mkdirSync ( 'build' ) ;
137
+ }
138
+
139
+ if ( ! fs . existsSync ( 'build/micropython-lib' ) ) {
140
+ cloneRepository ( "[email protected] :micropython/micropython-lib.git" , "build/micropython-lib" ) ;
141
+ }
142
+ const directory = "build/micropython-lib" ;
143
+ const indexUrl = "https://micropython.org/pi/v2" ;
144
+ const outputFilename = process . argv [ 2 ] ;
120
145
121
146
searchPackages ( directory , outputFilename , indexUrl ) ;
122
147
}
0 commit comments