-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-rust.js
62 lines (55 loc) · 1.87 KB
/
setup-rust.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const simpleGit = require('simple-git');
const fs = require('fs').promises;
const path = require('path');
const rustDir = 'rust';
const repoOwner = 'pubky';
const repoName = 'pubky-core-mobile-sdk';
const branch = 'main';
const tempDir = 'temp';
async function setupRustDirectory() {
try {
// Check if rust directory exists
const rustExists = await fs
.access(rustDir)
.then(() => true)
.catch(() => false);
if (!rustExists) {
console.log('Creating rust directory...');
await fs.mkdir(rustDir);
// Clone the repository directly into rust directory
const git = simpleGit();
await git.clone(
`https://github.com/${repoOwner}/${repoName}.git`,
tempDir,
['--depth', '1', `--branch=${branch}`]
);
// Move all contents from temp directory to rust directory
const tempContents = await fs.readdir(path.join(tempDir));
await Promise.all(
tempContents.map(async (item) => {
if (item !== '.git') {
// Skip .git directory
const source = path.join(tempDir, item);
const dest = path.join(rustDir, item);
await fs.cp(source, dest, { recursive: true });
}
})
);
// Clean up temp directory
await fs.rm(tempDir, { recursive: true, force: true });
console.log('Rust directory setup completed successfully!');
} else {
console.log('Rust directory already exists, skipping setup...');
}
} catch (error) {
console.error('Error during rust directory setup:', error);
// Try to clean up temp directory if it exists
try {
await fs.rm(tempDir, { recursive: true, force: true });
} catch (cleanupError) {
console.error('Failed to clean up temporary directory:', cleanupError);
}
throw error; // Re-throw to be handled by the main try-catch
}
}
setupRustDirectory();