更新 gh-pages 脚本

This commit is contained in:
2betop 2020-08-21 16:19:26 +08:00
parent db4562853b
commit e86cd69a89
5 changed files with 70 additions and 647 deletions

4
.gitignore vendored
View File

@ -7,7 +7,7 @@ npm-debug.log
# Folders
.idea/
.sass-cache
_gh_pages
gh_pages
_site
node_modules
/dist
@ -20,4 +20,4 @@ node_modules
/toolkit/amis-renderer
/toolkit/output
/coverage
/package-lock.json
/package-lock.json

View File

@ -1,58 +1,73 @@
const bosSDK = require('bce-sdk-js');
const fs = require('fs');
const walk = require('fs-walk');
const path = require('path');
const tokenFile = process.argv[2] || '~/bos.credentials';
const ak = process.argv[2];
const sk = process.argv[3];
if (!fs.existsSync(tokenFile)) {
console.error(tokenFile + ' does not exists!');
process.exit(1);
if (!ak || !sk) {
console.error('ak and sk is required for deploy cdn!');
process.exit(1);
}
const config = JSON.parse(fs.readFileSync(tokenFile, 'utf-8'));
const config = {
credentials: {
ak,
sk
},
endpoint: 'https://bj.bcebos.com',
bucket: 'bce-cdn'
};
const client = new bosSDK.BosClient(config);
const bucketName = config.bucket || 'bce-cdn';
const prefix = 'fex/';
async function main() {
const folder = 'gh-pages';
const productName = 'amis-gh-pages';
const folder = 'gh-pages';
const productName = 'amis-gh-pages';
if (!fs.existsSync(folder)) {
throw new Error('文件夹不存在');
if (!fs.existsSync(folder)) {
throw new Error('文件夹不存在');
}
if (!productName) {
throw new Error('请指定产品名称');
}
const promises = [];
walk.walkSync(folder, (basedir, filename, stat) => {
if (stat.isDirectory() || /\.html$/.test(filename)) {
return;
}
if (!productName) {
throw new Error('请指定产品名称');
const relativePath = path.relative(folder, basedir);
// 隐藏文件跳过。
if (/^\./.test(relativePath)) {
return;
}
const promises = [];
walk.walkSync(folder, (basedir, filename, stat) => {
if (stat.isDirectory() || /\.html$/.test(filename)) {
return;
}
const objectName = path.join(prefix, productName, relativePath, filename);
promises.push(() =>
client
.putObjectFromFile(bucketName, objectName, path.join(basedir, filename))
.then(
() => console.log(` ==> ${objectName}`),
res => console.error(res)
)
);
});
const relativePath = path.relative(folder, basedir);
const objectName = path.join(prefix, productName, relativePath, filename);
promises.push(() => client
.putObjectFromFile(bucketName, objectName, path.join(basedir, filename))
.then(
() => console.log(` ==> ${objectName}`),
res => console.error(res)
)
);
});
if (!promises.length) {
console.log('Nothing need to upload');
}
if (!promises.length) {
console.log('Nothing need to upload');
}
return promises
.reduce((preview, current) => {
return preview.then(current);
}, Promise.resolve());
return promises.reduce((preview, current) => {
return preview.then(current);
}, Promise.resolve());
}
main().then(() => console.log('Done!')).catch(e => console.error(e.message, e.stack));
main()
.then(() => console.log('Done!'))
.catch(e => console.error(e.message, e.stack));

View File

@ -1,38 +1,28 @@
#!/bin/bash
set -e
if [ -z "$(git status --porcelain)" ]; then
# Working directory clean
echo "Working directory clean"
else
# Uncommitted changes
read -p "You got uncommitted changes, press y to continue? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "Skiped!"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
fi
rm -rf gh-pages
echo "Cloning"
git clone -b gh-pages https://github.com/baidu/amis.git gh-pages
echo "building"
node ./build/generate-search-data.js
fis3 release gh-pages -c
node ./build/upload2cdn.js $1
node ./build/upload2cdn.js $1 $2
node ./build/generate-search-data.js
echo "pushing"
git add gh-pages -f
cd gh-pages
git commit -m "更新 gh-pages"
git config user.email "liaoxuezhi@icloud.com"
git config user.name "liaoxuezhi"
git push
git add .
git commit --allow-empty -m "自动同步 gh-pages"
git subtree push --prefix gh-pages origin gh-pages
git commit -m 'rebuild pages' --allow-empty
git push origin
git push --tags https://github.com/baidu/amis.git gh-pages
echo "done"

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,8 @@
"dev": "fis3 release -cwd ./public",
"publish2npm": "sh publish.sh && npm publish",
"build": "sh publish.sh",
"prettier": "prettier --write '{src,examples,scss}/**/*.{tsx,ts,jsx,scss}'"
"prettier": "prettier --write '{src,examples,scss}/**/*.{tsx,ts,jsx,scss}'",
"deploy-gh-page": "sh ./deploy-gh-pages.sh"
},
"repository": {
"type": "git",