UNPKG

2.59 kBJavaScriptView Raw
1/* eslint-disable */
2const shelljs = require('shelljs');
3const path = require('path');
4var fs = require('fs');
5var notifier = require('node-notifier');
6const gulp = require('gulp');
7
8var fileExists = require('file-exists');
9const Utils = require('../lib/utils');
10const gulpfilePath = path.resolve(__dirname, '../lib/gulpfile.js');
11require('../lib/gulpfile');
12const platform = process.env.platform;
13const build_type = process.env.build_type;
14// 是否正式环境
15const isAndroidApp = process.env.platform === 'android';
16const configureType = process.env.build_type;
17
18const isProduction = process.env.NODE_ENV === 'production';
19const REPO_DIR = path.resolve(__dirname, '../../../../');
20const pkgJSON = require(REPO_DIR + '/package.json');
21
22const coreLibs = pkgJSON.coreLibs || '@beisen/bsapp-core';
23function getDir(target) {
24 return Utils.getDir(REPO_DIR, target);
25}
26
27function copyFiles() {
28 // 复制bsapp-core下dist
29 shelljs.cp('-rf', [getDir('./node_modules/' + coreLibs + '/dist/*')], getDir('../../public/lib'));
30 // // 复制static下video/image
31 // shelljs.cp('-rf', [getDir('./resource/assets/*')], getDir('./'));
32
33 if (isAndroidApp) {
34 return ;
35 }
36
37 shelljs.mkdir('../../res');
38 // 复制key.xml
39 shelljs.cp('-rf', [getDir('./config/key/key.'+ configureType +'.xml')], getDir('../../res/key.xml'));
40 // 复制config.xml
41 shelljs.cp('-rf', [getDir('./config/config/config.'+ configureType +'.xml')], getDir('../../config.xml'));
42 shelljs.cp('-rf', [getDir('./config/entitlements/UZApp.entitlements')], getDir('../../res/UZApp.entitlements'));
43}
44
45// 删除无用文件
46shelljs.rm('-rf', [ getDir('../../public/lib/base.js'), getDir('../../public/lib/assets/*.jpg'), getDir('../../public/lib/assets/*.png'), getDir('../../public/lib/assets/error.svg'), getDir('./public/lib/assets/loading.svg'), getDir('./public/lib/assets/notive.svg')]);
47
48shelljs.mkdir('-p', getDir('../../public/lib'));
49
50if (isProduction) { // build 类型 打包环节
51 shelljs.exec('node ' + path.resolve(__dirname, './build-html.js'));
52 shelljs.exec('gulp assets --gulpfile ' + path.resolve(__dirname, '../lib/gulpfile.js'));
53 copyFiles();
54} else { // 开发环节
55 if (!fileExists.sync(getDir('./lock.txt'))) {
56
57 fs.writeFileSync(getDir('./lock.txt'));
58 shelljs.exec('node ' + path.resolve(__dirname, './build-html.js'));
59 shelljs.exec(`gulp copy-assets --gulpfile ${gulpfilePath}`);
60 copyFiles();
61 shelljs.exec(`concurrently "gulp html --gulpfile ${gulpfilePath}"`)
62 }
63 notifier.notify({
64 'title': '温馨提示',
65 'message': '编译成功, 可以同步了~'
66 });
67}