2019-01-12 03:33:27 +00:00
|
|
|
const GitHub = require('@octokit/rest');
|
|
|
|
const Base64 = require('js-base64').Base64;
|
|
|
|
const fs = require('fs');
|
|
|
|
const fse = require('fs-extra');
|
|
|
|
const path = require('path');
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const owner = 'ant-design';
|
|
|
|
const repo = 'ant-design';
|
2019-03-05 05:16:32 +00:00
|
|
|
const tag = '3.13.6';
|
2019-01-12 03:33:27 +00:00
|
|
|
const clientId = '5f6ccfdc4cdc69f8ba12';
|
|
|
|
const clientSecret = process.env.CLIENT_SECRET;
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const github = new GitHub();
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
async function syncFiles(data = []) {
|
2018-09-05 13:28:54 +00:00
|
|
|
for (const item of data) {
|
|
|
|
try {
|
2019-01-02 13:01:56 +00:00
|
|
|
const { data: itemData } = await github.repos.getContents({
|
2018-09-05 13:28:54 +00:00
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
path: `${item.path}`,
|
|
|
|
ref: tag,
|
|
|
|
client_id: clientId,
|
|
|
|
client_secret: clientSecret,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
if (Array.isArray(itemData)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
syncFiles(itemData);
|
2018-09-05 13:28:54 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
const toPath = path.join(__dirname, '..', itemData.path.replace(`/${itemData.name}`, ''));
|
2018-09-05 13:28:54 +00:00
|
|
|
if (!fs.existsSync(toPath)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
fse.ensureDirSync(toPath);
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
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);
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
} catch (e) {}
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
async function syncStyle() {
|
2018-09-05 13:28:54 +00:00
|
|
|
const { data = [] } = await github.repos.getContent({
|
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
path: 'components',
|
|
|
|
ref: tag,
|
|
|
|
client_id: clientId,
|
|
|
|
client_secret: clientSecret,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
for (const item of data) {
|
|
|
|
try {
|
|
|
|
if (item.name === 'style') {
|
2019-01-12 03:33:27 +00:00
|
|
|
syncFiles([item]);
|
2018-09-05 13:28:54 +00:00
|
|
|
} else {
|
|
|
|
const { data: itemData } = await github.repos.getContent({
|
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
path: `${item.path}/style`,
|
|
|
|
ref: tag,
|
|
|
|
client_id: clientId,
|
|
|
|
client_secret: clientSecret,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
syncFiles(itemData);
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
syncStyle();
|