Skip to content

Commit 2015e43

Browse files
committed
Add cloning feature to index tool
1 parent 6f8670e commit 2015e43

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

tools/create-index.mjs

+32-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ import path from 'path';
33
import { execSync } from 'child_process';
44
import yaml from 'js-yaml';
55

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+
617
const getGitHubUrl = (rootPath) => {
718
try {
819
// Get the GitHub repository URL
@@ -63,12 +74,18 @@ const searchPackages = (directory, outputFilename, indexUrl) => {
6374
} else {
6475
const isPackageJson = file === 'package.json';
6576
const isManifestPy = file === 'manifest.py';
77+
const packageName = path.basename(dir);
78+
79+
if(packageName.startsWith("_")) {
80+
continue; // Skip "private" packages
81+
}
6682

6783
if (isPackageJson || isManifestPy) {
6884
const packageInfo = {
69-
name: path.basename(dir),
85+
name: packageName,
7086
docs: constructGitHubUrl(gitHubUrl, currentBranch, repositoryRoot, dir),
7187
index: indexUrl,
88+
author: 'MicroPython',
7289
};
7390

7491
if (isManifestPy) {
@@ -109,14 +126,22 @@ const searchPackages = (directory, outputFilename, indexUrl) => {
109126
};
110127

111128
// Check if command line arguments are provided
112-
if (process.argv.length < 5) {
129+
if (process.argv.length < 3) {
113130
// 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>');
116133
} 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];
120145

121146
searchPackages(directory, outputFilename, indexUrl);
122147
}

0 commit comments

Comments
 (0)