This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
generated from hirosystems/clarity-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-contracts.ts
85 lines (66 loc) · 2.08 KB
/
sync-contracts.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// File: processFiles.ts
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
import { join } from 'path';
interface FileRequest {
fileName: string;
replacements: { [id: string]: string };
}
const processFile = (fileRequest: FileRequest) => {
const sourceDir = 'simnet-contracts';
const targetDir = 'mainnet-contracts';
const fileName = fileRequest.fileName;
const sourcePath = join(sourceDir, fileName);
const targetPath = join(targetDir, fileName);
// Check if source file exists
if (!existsSync(sourcePath)) {
console.error(`File not found: ${sourcePath}`);
return;
}
// Read the file
const data = readFileSync(sourcePath, 'utf8');
let result = data;
const isDictionaryEmpty = (dict: { [id: string]: string }): boolean => {
return Object.keys(dict).length === 0;
};
let processed = false;
if (!isDictionaryEmpty(fileRequest.replacements)) {
for (let key in fileRequest.replacements) {
if (fileRequest.replacements.hasOwnProperty(key)) {
let value = fileRequest.replacements[key];
result = data.split(key).join(value);
}
}
processed = true;
}
else {
console.log(`Nothing to process for ${fileName}`);
}
// Ensure target directory exists
if (!existsSync(targetDir)) {
mkdirSync(targetDir);
}
// Write the file
writeFileSync(targetPath, result);
if (processed) {
console.log(`File ${fileName} processed and saved to ${targetPath}`);
}
};
const main = () => {
const fileRequests: FileRequest[] = [
{
fileName: 'taral-bank.clar',
replacements: {
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdt": "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-susdt"
}
},
{
fileName: 'taral-bank-storage.clar',
replacements: {}
},
];
// List of files to process
fileRequests.forEach(file => {
processFile(file);
});
};
main();