UNPKG

@molejs/mole-tools

Version:

Configuration and scripts for Mole App.

82 lines (73 loc) 3.23 kB
const shelljs = require('shelljs'); const path = require('path'); const fs = require('fs'); const osenv = require('osenv'); const moment = require('moment'); /** * 判断文件夹是否存在 */ 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' ? 'android' : 'android-official' const branchNameHotfix = build_type === 'beta' ? 'hotfix-android' : 'android-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 + ' android '); shelljs.cd('./android'); // widget目录不存在,则创建 if (!fsExistsSync('./widget')) { shelljs.mkdir('./widget'); } shelljs.rm('-rf', ['./widget/res', './widget/modules', './widget/config.xml', './widget/public']) shelljs.cp('-rf', ['../../../public', '../../../modules',], './widget') //删除IOS专用的文件 shelljs.rm('-rf', path.resolve('./widget/public/assets/image/ios')); shelljs.rm('-rf', path.resolve('./widget/public/assets/video')); //入口文件 shelljs.rm('-rf', path.resolve('./widget/modules/index.html')); shelljs.rm('-rf', path.resolve('./widget/modules/index.page.js')); shelljs.rm('-rf', path.resolve('./widget/modules/index.page.css')); //签到历史 shelljs.rm('-rf', path.resolve('./widget/modules/children/attendance/index.html')); //入口页面 shelljs.rm('-rf', path.resolve('./widget/modules/children/entrance')); //消息页面 shelljs.rm('-rf', path.resolve('./widget/modules/children/message/index.html')); //通讯录页面 shelljs.rm('-rf', path.resolve('./widget/modules/children/staff')); //common-frames-launchView shelljs.rm('-rf', path.resolve('./widget/modules/children/common/frames/launchView')); //common-frames-layout shelljs.rm('-rf', path.resolve('./widget/modules/children/common/frames/layout')); //common-frames-unlock shelljs.rm('-rf', path.resolve('./widget/modules/children/common/frames/unlock')); //common-widgets shelljs.rm('-rf', path.resolve('./widget/modules/children/common/widgets/actionsheet')); shelljs.rm('-rf', path.resolve('./widget/modules/children/common/wins')); shelljs.rm('-rf', path.resolve('./widget/modules/children/setting/children/welcome')); //shelljs.rm('-f', ['./widget/modules/**/*.js', './widget/modules/**/*.css']); 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 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('../../../'); }