-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathsyncStyleFromAntd.js
69 lines (65 loc) · 1.86 KB
/
syncStyleFromAntd.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
63
64
65
66
67
68
69
const { Octokit } = require('@octokit/rest');
const Base64 = require('js-base64').Base64;
const fs = require('fs');
const fse = require('fs-extra');
const path = require('path');
const owner = 'ant-design';
const repo = 'ant-design';
const tag = '3.26.13';
const clientId = '5f6ccfdc4cdc69f8ba12';
const clientSecret = process.env.CLIENT_SECRET;
const github = new Octokit();
async function syncFiles(data = []) {
for (const item of data) {
try {
const { data: itemData } = await github.repos.getContents({
owner,
repo,
path: `${item.path}`,
ref: tag,
client_id: clientId,
client_secret: clientSecret,
});
if (Array.isArray(itemData)) {
syncFiles(itemData);
} else {
const toPath = path.join(__dirname, '..', itemData.path.replace(`/${itemData.name}`, ''));
if (!fs.existsSync(toPath)) {
fse.ensureDirSync(toPath);
}
// eslint-disable-next-line no-console
console.log('update style: ', path.join(toPath, itemData.name.replace('.tsx', '.js')));
const content = Base64.decode(itemData.content);
fs.writeFileSync(path.join(toPath, itemData.name.replace('.tsx', '.js')), content);
}
} catch (e) {}
}
}
async function syncStyle() {
const { data = [] } = await github.repos.getContents({
owner,
repo,
path: 'components',
ref: tag,
client_id: clientId,
client_secret: clientSecret,
});
for (const item of data) {
try {
if (item.name === 'style') {
syncFiles([item]);
} else {
const { data: itemData } = await github.repos.getContents({
owner,
repo,
path: `${item.path}/style`,
ref: tag,
client_id: clientId,
client_secret: clientSecret,
});
syncFiles(itemData);
}
} catch (e) {}
}
}
syncStyle();