-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsync.ts
55 lines (44 loc) · 1.4 KB
/
sync.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
import fs from 'fs-extra';
import junk from 'junk';
import path from 'path';
import axios from 'axios';
import { fetchConfig } from '@hypermod/fetcher';
const COMMUNITY_PATH = path.join(__dirname, '..', 'community');
const CODESHIFT_WORKER_URL = 'http://codeshift.delcore.workers.dev/packages';
interface DocsData {
pkgName: string;
targets: string;
}
async function main() {
console.log('🚚 Syncing community packages with the hypermod worker');
const communityCodemods = fs.readdirSync(COMMUNITY_PATH);
const data: DocsData[] = [];
const directories = communityCodemods.filter(dir => junk.not(dir));
for (const dir of directories) {
const { config } = await fetchConfig(path.join(COMMUNITY_PATH, dir));
if (!config) {
throw new Error(`Unable to locate config for path: ${dir}`);
}
const pkgName = `@hypermod/mod-${dir.replace('@', '').replace('/', '__')}`;
const rawPkgName = dir.replace('__', '/');
data.push({
pkgName,
targets: rawPkgName + (config.targets ? `, ${config.targets}` : ''),
});
}
const response = await axios.post(
CODESHIFT_WORKER_URL,
JSON.stringify(data),
{
headers: {
'Content-Type': 'application/json',
'X-Custom-PSK': process.env.WORKER_PRESHARED_KEY!,
},
},
);
console.log(response.data);
}
main().catch(error => {
console.error('Syncing error:', error.message);
process.exit(1);
});