@molejs/mole-tools
Version:
Configuration and scripts for Mole App.
60 lines (50 loc) • 1.87 kB
JavaScript
const shelljs = require('shelljs');
const path = require('path');
const fs = require('fs');
const osenv = require('osenv');
const moment = require('moment');
// // 本地仓库地址
// const gitlabWorkDir = '.mole-tools-tmp/gitlab';
/**
* 判断文件夹是否存在
*/
function fsExistsSync(path) {
try {
fs.accessSync(path, fs.F_OK);
} catch(e) {
return false;
}
return true;
}
exports.publish = function({
repo_url,
build_type,
}) {
const branchName = build_type === 'beta' ? 'ios' : 'ios-official'
const branchNameHotfix = build_type === 'beta' ? 'hotfix-ios' : 'ios-official-hotfix'
const tagName = 'v' + branchName + '-' + moment().format('YYYYMMDDHHmmss');
// 本地仓库地址
const gitlabWorkDir = '.mole-tools-tmp/' + build_type;
shelljs.rm('-rf', gitlabWorkDir);
shelljs.mkdir('-p', gitlabWorkDir);
shelljs.cd(gitlabWorkDir);
shelljs.exec('git clone -b '+ branchName +' --depth=1 ' + repo_url + ' ios ');
shelljs.cd('./ios');
// widget目录不存在,则创建
if (!fsExistsSync('./widget')) {
shelljs.mkdir('./widget');
}
shelljs.rm('-rf', ['./widget/public', './widget/res', './widget/modules', './widget/config.xml'])
shelljs.cp('-rf', ['../../../public', '../../../res', '../../../modules', '../../../config.xml'], './widget')
shelljs.exec('git branch -D ' + branchNameHotfix);
shelljs.exec('git add .');
const publishUser = shelljs.exec('echo $USER');
shelljs.exec(`git commit -m "auto commit ${build_type} by ${publishUser}"`);
// shelljs.exec('git commit -m "auto commit"');
shelljs.exec('git push origin ' + branchName + ' -f');
shelljs.exec('git tag ' + tagName);
shelljs.exec('git push origin --tag ' + tagName);
shelljs.exec('git checkout -b ' + branchNameHotfix);
shelljs.exec('git push origin '+ branchNameHotfix +' -f');
shelljs.cd('../../../');
}