@molejs/mole-tools
Version:
Configuration and scripts for Mole App.
62 lines (52 loc) • 2.37 kB
JavaScript
/* eslint-disable */
const shelljs = require('shelljs');
const path = require('path');
var fs = require('fs');
var notifier = require('node-notifier');
const gulp = require('gulp');
var fileExists = require('file-exists');
const Utils = require('../lib/utils');
const gulpfilePath = path.resolve(__dirname, '../lib/gulpfile.js');
require('../lib/gulpfile');
const platform = process.env.platform;
const build_type = process.env.build_type;
// 是否正式环境
const isAndroidApp = process.env.platform === 'android';
const configureType = process.env.build_type;
const isProduction = process.env.NODE_ENV === 'production';
const REPO_DIR = path.resolve(__dirname, '../../../../');
const pkgJSON = require(REPO_DIR + '/package.json');
function getDir(target) {
return Utils.getDir(REPO_DIR, target);
}
function copyFiles() {
if (isAndroidApp) {
return ;
}
// shelljs.mkdir('-p', '../../www/res');
// // 复制key.xml
// shelljs.cp('-rf', [getDir('./config/key/key.'+ configureType +'.xml')], getDir('../../www/res/key.xml'));
// // 复制config.xml
// shelljs.cp('-rf', [getDir('./config/config/config.'+ configureType +'.xml')], getDir('../../www/config.xml'));
// shelljs.cp('-rf', [getDir('./config/entitlements/UZApp.entitlements')], getDir('../../www/res/UZApp.entitlements'));
}
// 删除无用文件
shelljs.rm('-rf', [ getDir('../../www/public/lib/base.js'), getDir('../../www/public/lib/assets/*.jpg'), getDir('../../www/public/lib/assets/*.png'), getDir('../../www/public/lib/assets/error.svg'), getDir('../../www/public/lib/assets/loading.svg'), getDir('../../www/public/lib/assets/notive.svg')]);
shelljs.mkdir('-p', getDir('../../www/public/lib'));
if (isProduction) { // build 类型 打包环节
shelljs.exec('node ' + path.resolve(__dirname, './build-html.js'));
shelljs.exec('gulp assets --gulpfile ' + path.resolve(__dirname, '../lib/gulpfile.js'));
copyFiles();
} else { // 开发环节
if (!fileExists.sync(getDir('./lock.txt'))) {
fs.writeFileSync(getDir('./lock.txt'));
shelljs.exec('node ' + path.resolve(__dirname, './build-html.js'));
shelljs.exec(`gulp copy-assets --gulpfile ${gulpfilePath}`);
copyFiles();
shelljs.exec(`concurrently "gulp html --gulpfile ${gulpfilePath}"`)
}
notifier.notify({
'title': '温馨提示',
'message': '编译成功, 可以同步了~'
});
}