1 |
|
2 | const shelljs = require('shelljs');
|
3 | const path = require('path');
|
4 | var fs = require('fs');
|
5 | var notifier = require('node-notifier');
|
6 | const gulp = require('gulp');
|
7 |
|
8 | var fileExists = require('file-exists');
|
9 | const Utils = require('../lib/utils');
|
10 | const gulpfilePath = path.resolve(__dirname, '../lib/gulpfile.js');
|
11 | require('../lib/gulpfile');
|
12 | const platform = process.env.platform;
|
13 | const build_type = process.env.build_type;
|
14 |
|
15 | const isAndroidApp = process.env.platform === 'android';
|
16 | const configureType = process.env.build_type;
|
17 |
|
18 | const isProduction = process.env.NODE_ENV === 'production';
|
19 | const REPO_DIR = path.resolve(__dirname, '../../../../');
|
20 | const pkgJSON = require(REPO_DIR + '/package.json');
|
21 |
|
22 | const coreLibs = pkgJSON.coreLibs || '@beisen/bsapp-core';
|
23 | function getDir(target) {
|
24 | return Utils.getDir(REPO_DIR, target);
|
25 | }
|
26 |
|
27 | function copyFiles() {
|
28 |
|
29 | shelljs.cp('-rf', [getDir('./node_modules/' + coreLibs + '/dist/*')], getDir('../../public/lib'));
|
30 |
|
31 |
|
32 |
|
33 | if (isAndroidApp) {
|
34 | return ;
|
35 | }
|
36 |
|
37 | shelljs.mkdir('../../res');
|
38 |
|
39 | shelljs.cp('-rf', [getDir('./config/key/key.'+ configureType +'.xml')], getDir('../../res/key.xml'));
|
40 |
|
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 |
|
46 | shelljs.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 |
|
48 | shelljs.mkdir('-p', getDir('../../public/lib'));
|
49 |
|
50 | if (isProduction) {
|
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 | }
|