forked from elicwhite/react-native-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (37 loc) · 1.35 KB
/
index.js
File metadata and controls
46 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import util from 'node:util';
import childProcess from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
const execFile = util.promisify(childProcess.execFile);
async function run() {
const url = new URL('https://reactnative.directory/api/libraries');
url.search = new URLSearchParams({
limit: 9999,
isPopular: true,
});
const result = await fetch(url);
const directoryData = await result.json();
const packages = directoryData.libraries.filter(lib => lib.npm.weekDownloads > 10000);
const repoFullNames = packages.map(pkg => pkg.github.fullName);
const uniqueRepoFullNames = new Set(repoFullNames);
for (const repoName of uniqueRepoFullNames) {
if (!fs.existsSync(path.join('libraries', repoName))) {
console.log('Adding git submodule for', repoName);
await execFile('git', ['submodule', 'add', '--depth', '1', `https://github.com/${repoName}.git`, repoName], {
cwd: 'libraries'
});
}
}
await execFile('git', ['submodule', 'sync', '--recursive'], {
cwd: 'libraries'
});
console.log(`Updating all ${uniqueRepoFullNames.size} git submodules...`);
await execFile('git', ['submodule', 'update', '--depth', '1', "--recursive", '--init', '--force'], {
cwd: 'libraries'
});
console.log('Done!');
}
run().catch(err => {
console.error(err);
process.exit(1);
});