jh5_app_build 1.0.21 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build_japp.js +18 -6
- package/lib/build_std.js +77 -0
- package/package.json +1 -1
- package/lib/build_std_apk_tool.js +0 -230
- package/lib/build_std_zip.js +0 -216
package/lib/build_japp.js
CHANGED
|
@@ -4,6 +4,7 @@ let jutils = require('base_parts');
|
|
|
4
4
|
|
|
5
5
|
let fs = require('fs');
|
|
6
6
|
let os = require('os');
|
|
7
|
+
let path = require('path');
|
|
7
8
|
var AdmZip = require('adm-zip');
|
|
8
9
|
|
|
9
10
|
module.exports = async (cmd, buildCfg) => {
|
|
@@ -82,7 +83,7 @@ module.exports = async (cmd, buildCfg) => {
|
|
|
82
83
|
let element = fileList[index].substr(pathSub.length + 1);
|
|
83
84
|
|
|
84
85
|
// 添加文件
|
|
85
|
-
archive.
|
|
86
|
+
archive.file(`${buildCfg.rootPath}/${pathSub}/${element}`, { name: "update_a20/h5app/" + element });
|
|
86
87
|
}
|
|
87
88
|
// 清空应用目录
|
|
88
89
|
shDataStr = shDataStr.replace(/#del_app#/g, "");
|
|
@@ -106,11 +107,11 @@ module.exports = async (cmd, buildCfg) => {
|
|
|
106
107
|
let element = fileList[index].substr(pathSub.length + 1);
|
|
107
108
|
|
|
108
109
|
// 添加文件
|
|
109
|
-
archive.
|
|
110
|
+
archive.file(`${buildCfg.rootPath}/${pathSub}/${element}`, { name: "update_a20/app/bin/" + element });
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
// 添加框架apk
|
|
113
|
-
archive.
|
|
114
|
+
archive.file(`${buildCfg.rootPath}/jbuild_data/app-debug.apk`, { name: "update_a20/app/app-debug.apk" });
|
|
114
115
|
|
|
115
116
|
// 清空模型文件
|
|
116
117
|
shDataStr = shDataStr.replace(/#del_bin#/g, "");
|
|
@@ -125,7 +126,9 @@ module.exports = async (cmd, buildCfg) => {
|
|
|
125
126
|
// 循环添加
|
|
126
127
|
var zipEntries = myZip.getEntries();
|
|
127
128
|
zipEntries.forEach(function (zipEntry) {
|
|
128
|
-
|
|
129
|
+
let tmpFile = path.resolve(`${buildCfg.rootPath}/jbuild_data/${zipEntry.entryName}.tmp`);
|
|
130
|
+
fs.writeFileSync(tmpFile, shDataStr);
|
|
131
|
+
archive.file(tmpFile, { name: "update_a20/" + zipEntry.entryName });
|
|
129
132
|
});
|
|
130
133
|
|
|
131
134
|
// 复制web
|
|
@@ -138,19 +141,28 @@ module.exports = async (cmd, buildCfg) => {
|
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
// 添加sh
|
|
141
|
-
|
|
144
|
+
try {
|
|
145
|
+
let tmpFile = path.resolve(`${buildCfg.rootPath}/jbuild_data/repair.sh.tmp`);
|
|
146
|
+
fs.writeFileSync(tmpFile, shDataStr);
|
|
147
|
+
archive.file(tmpFile, { name: "update_a20/repair.sh" });
|
|
148
|
+
} catch (error) {
|
|
149
|
+
}
|
|
142
150
|
|
|
143
151
|
// 添加设备信息
|
|
144
152
|
try {
|
|
145
153
|
var pkgInfo = os.networkInterfaces();
|
|
146
154
|
pkgInfo.buildTime = jutils.getNowDate();
|
|
147
|
-
|
|
155
|
+
|
|
156
|
+
let tmpFile = path.resolve(`${buildCfg.rootPath}/jbuild_data/build_info.txt`);
|
|
157
|
+
fs.writeFileSync(tmpFile, JSON.stringify(pkgInfo, null, 4));
|
|
158
|
+
archive.file(tmpFile, { name: "update_a20/build_info.txt" });
|
|
148
159
|
} catch (error) {
|
|
149
160
|
}
|
|
150
161
|
|
|
151
162
|
// 开始压缩
|
|
152
163
|
archive.finalize();
|
|
153
164
|
})().catch((err) => {
|
|
165
|
+
console.error(err.message);
|
|
154
166
|
console.error("build error,please run [jh5 update] first.");
|
|
155
167
|
try {
|
|
156
168
|
jutils.jfile_utils.deleteFile(buildCfg.outpath);
|
package/lib/build_std.js
CHANGED
|
@@ -46,12 +46,25 @@ module.exports = async (cmd, buildCfg) => {
|
|
|
46
46
|
// apk配置
|
|
47
47
|
let apkConfig = makeAndGetDir(`${buildCfg.rootPath}/apk_cfg`);
|
|
48
48
|
|
|
49
|
+
// 读取数据
|
|
50
|
+
var apkinfoObj = {
|
|
51
|
+
appName: "" // apk名称
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
apkinfoObj = JSON.parse(fs.readFileSync(apkConfig + "/apkinfo.json", 'utf-8'));
|
|
55
|
+
} catch (error) {
|
|
56
|
+
}
|
|
57
|
+
// 默认软件名
|
|
58
|
+
if (!apkinfoObj.appName) apkinfoObj.appName = "智能终端"
|
|
59
|
+
|
|
49
60
|
// 清理数据
|
|
50
61
|
console.log(`delete temp file ...`);
|
|
51
62
|
await jutils.jfile_utils.deleteFolder(stdBinDir + "/assets/device_webapi");
|
|
52
63
|
await jutils.jfile_utils.deleteFolder(stdBinDir + "/assets/h5app");
|
|
53
64
|
await jutils.jfile_utils.deleteFolder(stdBinDir + "/assets/jext");
|
|
54
65
|
await jutils.jfile_utils.deleteFolder(stdBinDir + "/assets/screen");
|
|
66
|
+
await jutils.jfile_utils.deleteFolder(stdBinDir + "/assets/sounds");
|
|
67
|
+
await jutils.jfile_utils.deleteFolder(stdBinDir + "/build");
|
|
55
68
|
|
|
56
69
|
// 修改版本号
|
|
57
70
|
let platformVer = jutils.getUUID();
|
|
@@ -129,6 +142,31 @@ module.exports = async (cmd, buildCfg) => {
|
|
|
129
142
|
}
|
|
130
143
|
}
|
|
131
144
|
|
|
145
|
+
// 添加音频文件
|
|
146
|
+
{
|
|
147
|
+
let pathSub = "jbuild_res/audio_wav";
|
|
148
|
+
console.log(`scaning ${pathSub} ...`);
|
|
149
|
+
let fileList = glob(`${pathSub}/**/*`, {
|
|
150
|
+
dot: true,
|
|
151
|
+
sync: true,
|
|
152
|
+
nodir: true,
|
|
153
|
+
cwd: buildCfg.rootPath,
|
|
154
|
+
ignore: []
|
|
155
|
+
});
|
|
156
|
+
if (fileList.length === 0) {
|
|
157
|
+
console.error("no dist files!");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
console.log(`add [${fileList.length}] files ...`);
|
|
161
|
+
let baseDir = makeAndGetDir(stdBinDir + "/assets/sounds");
|
|
162
|
+
for (let index = 0; index < fileList.length; index++) {
|
|
163
|
+
let element = fileList[index].substr(pathSub.length + 1);
|
|
164
|
+
|
|
165
|
+
// 添加文件
|
|
166
|
+
await makeDirAndCopy(`${buildCfg.rootPath}/${pathSub}/${element}`, baseDir + element);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
132
170
|
// 添加so文件
|
|
133
171
|
{
|
|
134
172
|
let pathSub = "static/ndkutils";
|
|
@@ -154,6 +192,44 @@ module.exports = async (cmd, buildCfg) => {
|
|
|
154
192
|
}
|
|
155
193
|
}
|
|
156
194
|
|
|
195
|
+
// 添加图标
|
|
196
|
+
try {
|
|
197
|
+
await makeDirAndCopy(`${apkConfig}/icon.png`, stdBinDir + "/res/mipmap/icon.png");
|
|
198
|
+
} catch (error) {
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// 修改其他信息
|
|
202
|
+
try {
|
|
203
|
+
var AndroidManifestPath = stdBinDir + "/AndroidManifest.xml";
|
|
204
|
+
var AndroidManifestPathBak = stdBinDir + "/AndroidManifestBak.xml";
|
|
205
|
+
// 备份
|
|
206
|
+
if (!fs.existsSync(AndroidManifestPathBak)) {
|
|
207
|
+
fs.copyFileSync(AndroidManifestPath, AndroidManifestPathBak);
|
|
208
|
+
}
|
|
209
|
+
var anfData = fs.readFileSync(AndroidManifestPathBak);
|
|
210
|
+
|
|
211
|
+
// 修改应用名
|
|
212
|
+
if (apkinfoObj.appName) {
|
|
213
|
+
let tmpName = Buffer.from("7A3657B017788420AE749039F9D25A2E", 'utf16le');
|
|
214
|
+
var nameIndex = anfData.indexOf(tmpName);
|
|
215
|
+
if (nameIndex > 0) {
|
|
216
|
+
let toName = Buffer.from(apkinfoObj.appName, 'utf16le');
|
|
217
|
+
// 清空
|
|
218
|
+
for (let index = 0; index < tmpName.length; index++) {
|
|
219
|
+
anfData[nameIndex + index] = 0;
|
|
220
|
+
}
|
|
221
|
+
// 写入名
|
|
222
|
+
for (let index = 0; index < toName.length; index++) {
|
|
223
|
+
anfData[nameIndex + index] = toName[index];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// 写入
|
|
229
|
+
fs.writeFileSync(AndroidManifestPath, anfData);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
}
|
|
232
|
+
|
|
157
233
|
// 需要web
|
|
158
234
|
if (!buildCfg.platform.includes("noweb")) {
|
|
159
235
|
// 添加框架二进制
|
|
@@ -195,6 +271,7 @@ module.exports = async (cmd, buildCfg) => {
|
|
|
195
271
|
}
|
|
196
272
|
|
|
197
273
|
}
|
|
274
|
+
|
|
198
275
|
// 添加设备信息
|
|
199
276
|
try {
|
|
200
277
|
let pkgInfo = os.networkInterfaces();
|
package/package.json
CHANGED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
let glob = require("glob")
|
|
2
|
-
let archiver = require('archiver');
|
|
3
|
-
let jutils = require('base_parts');
|
|
4
|
-
|
|
5
|
-
let fs = require('fs');
|
|
6
|
-
let path = require('path');
|
|
7
|
-
let os = require('os');
|
|
8
|
-
let AdmZip = require('adm-zip');
|
|
9
|
-
let child_process = require('child_process');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 创建目录并获取尾部带斜线的路径
|
|
14
|
-
* @param {string} dirPath 路径
|
|
15
|
-
* @returns {string} 路径(尾部带斜线)
|
|
16
|
-
*/
|
|
17
|
-
function makeAndGetDir(dirPath) {
|
|
18
|
-
try {
|
|
19
|
-
fs.mkdirSync(dirPath);
|
|
20
|
-
} catch (error) {
|
|
21
|
-
}
|
|
22
|
-
return path.resolve(dirPath) + "\\";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 创建目录并复制文件
|
|
27
|
-
* @param {string} srcFile 源文件
|
|
28
|
-
* @param {string} dstFile 目标文件
|
|
29
|
-
* @returns {void}
|
|
30
|
-
*/
|
|
31
|
-
async function makeDirAndCopy(srcFile, dstFile) {
|
|
32
|
-
await jutils.jfile_utils.createDirs(dstFile, true);
|
|
33
|
-
fs.copyFileSync(srcFile, dstFile);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = async (cmd, buildCfg) => {
|
|
37
|
-
console.log(`build file to ${buildCfg.outpath}`);
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
// 模板目录
|
|
41
|
-
var stdBinDir = `${buildCfg.rootPath}/jbuild_data/std_bins`;
|
|
42
|
-
|
|
43
|
-
// jre目录
|
|
44
|
-
let jreCwd = "C:\\jdev_develop\\jre\\bin";
|
|
45
|
-
|
|
46
|
-
// 清理数据
|
|
47
|
-
console.log(`delete temp file ...`);
|
|
48
|
-
await jutils.jfile_utils.deleteFolder(stdBinDir + "/assets/device_webapi");
|
|
49
|
-
await jutils.jfile_utils.deleteFolder(stdBinDir + "/assets/h5app");
|
|
50
|
-
await jutils.jfile_utils.deleteFolder(stdBinDir + "/assets/jext");
|
|
51
|
-
|
|
52
|
-
// 修改版本号
|
|
53
|
-
let platformVer = jutils.getUUID();
|
|
54
|
-
try {
|
|
55
|
-
console.log(`change dist ver ...`);
|
|
56
|
-
let repFile = `${buildCfg.rootPath}\\dist\\index.html`;
|
|
57
|
-
let indexStr = fs.readFileSync(repFile, "utf8");
|
|
58
|
-
indexStr = indexStr.replace(/#J_APPNAME#/g, buildCfg.appName);
|
|
59
|
-
indexStr = indexStr.replace(/#J_DATE#/g, buildCfg.dateStr);
|
|
60
|
-
|
|
61
|
-
// 读取H5版本
|
|
62
|
-
try {
|
|
63
|
-
let bInfoStr = fs.readFileSync(`${buildCfg.rootPath}/jbuild_data/info.txt`, "utf8");
|
|
64
|
-
let bInfoObj = JSON.parse(bInfoStr);
|
|
65
|
-
if (bInfoObj.version) {
|
|
66
|
-
platformVer = bInfoObj.version;
|
|
67
|
-
indexStr = indexStr.replace(/#J_H5_VER#/g, bInfoObj.version);
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.log(`no h5Ver!`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 保存
|
|
74
|
-
fs.writeFileSync(repFile, indexStr);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 添加用户文件
|
|
79
|
-
{
|
|
80
|
-
let pathSub = "dist";
|
|
81
|
-
console.log(`scaning ${pathSub} ...`);
|
|
82
|
-
let fileList = glob(`${pathSub}/**/*`, {
|
|
83
|
-
dot: true,
|
|
84
|
-
sync: true,
|
|
85
|
-
nodir: true,
|
|
86
|
-
cwd: buildCfg.rootPath,
|
|
87
|
-
ignore: []
|
|
88
|
-
});
|
|
89
|
-
if (fileList.length === 0) {
|
|
90
|
-
console.error("no dist files!");
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
console.log(`add [${fileList.length}] files ...`);
|
|
94
|
-
let baseDir = makeAndGetDir(stdBinDir + "/assets/h5app");
|
|
95
|
-
for (let index = 0; index < fileList.length; index++) {
|
|
96
|
-
let element = fileList[index].substr(pathSub.length + 1);
|
|
97
|
-
|
|
98
|
-
// 添加文件
|
|
99
|
-
await makeDirAndCopy(`${buildCfg.rootPath}/${pathSub}/${element}`, baseDir + element);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// 需要web
|
|
104
|
-
if (!buildCfg.platform.includes("noweb")) {
|
|
105
|
-
// 添加框架二进制
|
|
106
|
-
{
|
|
107
|
-
let pathSub = "jbuild_data/jext";
|
|
108
|
-
console.log(`scaning ${pathSub} ...`);
|
|
109
|
-
let fileList = glob(`${pathSub}/**/*`, {
|
|
110
|
-
dot: true,
|
|
111
|
-
sync: true,
|
|
112
|
-
nodir: true,
|
|
113
|
-
cwd: buildCfg.rootPath,
|
|
114
|
-
ignore: []
|
|
115
|
-
});
|
|
116
|
-
console.log(`add [${fileList.length}] files ...`);
|
|
117
|
-
let baseDir = makeAndGetDir(stdBinDir + "/assets/jext");
|
|
118
|
-
for (let index = 0; index < fileList.length; index++) {
|
|
119
|
-
let element = fileList[index].substr(pathSub.length + 1);
|
|
120
|
-
|
|
121
|
-
// 添加文件
|
|
122
|
-
await makeDirAndCopy(`${buildCfg.rootPath}/${pathSub}/${element}`, baseDir + element);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// 添加后台服务
|
|
127
|
-
{
|
|
128
|
-
console.log(`add device_webapi files ...`);
|
|
129
|
-
let baseDir = makeAndGetDir(stdBinDir + "/assets/device_webapi");
|
|
130
|
-
// 载入zip
|
|
131
|
-
let myZip = new AdmZip(`${buildCfg.rootPath}/jbuild_data/device_webapi.zip`);
|
|
132
|
-
|
|
133
|
-
// 循环添加
|
|
134
|
-
let zipEntries = myZip.getEntries();
|
|
135
|
-
zipEntries.forEach(function (zipEntry) {
|
|
136
|
-
fs.writeFileSync(baseDir + zipEntry.entryName, zipEntry.getData());
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// 版本号
|
|
140
|
-
fs.writeFileSync(baseDir + "info.txt", Buffer.from(platformVer));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
// 添加设备信息
|
|
145
|
-
try {
|
|
146
|
-
let pkgInfo = os.networkInterfaces();
|
|
147
|
-
pkgInfo.buildTime = jutils.getNowDate();
|
|
148
|
-
fs.writeFileSync(stdBinDir + "/assets/info.txt", JSON.stringify(pkgInfo, null, 4));
|
|
149
|
-
} catch (error) {
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// 打包
|
|
153
|
-
console.log(`making apk...`);
|
|
154
|
-
child_process.execFileSync("C:\\jdev_develop\\jre\\bin\\java.exe", [
|
|
155
|
-
"-jar", "C:\\jdev_develop\\h5_bin\\apktool.jar",
|
|
156
|
-
"b", stdBinDir,
|
|
157
|
-
"-o", buildCfg.outpath
|
|
158
|
-
], {
|
|
159
|
-
cwd: jreCwd
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// 生成apk签名
|
|
163
|
-
console.log(`not find keystore,making ...`);
|
|
164
|
-
let keyStoreFile = `${buildCfg.rootPath}/sigin/apk_cert.keystore`;
|
|
165
|
-
try {
|
|
166
|
-
fs.mkdirSync(path.dirname(keyStoreFile));
|
|
167
|
-
} catch (error) {
|
|
168
|
-
}
|
|
169
|
-
if (!fs.existsSync(keyStoreFile)) {
|
|
170
|
-
// 生成签名
|
|
171
|
-
child_process.execFileSync("C:\\jdev_develop\\jre\\bin\\keytool.exe", [
|
|
172
|
-
"-genkey",
|
|
173
|
-
"-storepass", "123456",
|
|
174
|
-
"-keypass", "123456",
|
|
175
|
-
"-alias", "cert",
|
|
176
|
-
"-keyalg", "RSA",
|
|
177
|
-
"-validity", "20000",
|
|
178
|
-
"-keystore", keyStoreFile,
|
|
179
|
-
"-dname", "CN=10.10.6.100,OU=utils,O=utils,L=beijing,ST=beijing,c=cn"
|
|
180
|
-
], {
|
|
181
|
-
cwd: jreCwd
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// 签名
|
|
186
|
-
console.log(`sign apk ...`);
|
|
187
|
-
var singApkTmp = buildCfg.outpath + "_sign.apk";
|
|
188
|
-
child_process.execFileSync("C:\\jdev_develop\\jre\\bin\\jarsigner.exe", [
|
|
189
|
-
"-verbose",
|
|
190
|
-
"-storepass", "123456",
|
|
191
|
-
"-keypass", "123456",
|
|
192
|
-
"-keystore", keyStoreFile,
|
|
193
|
-
"-signedjar", singApkTmp,
|
|
194
|
-
buildCfg.outpath,
|
|
195
|
-
"cert"
|
|
196
|
-
], {
|
|
197
|
-
cwd: jreCwd
|
|
198
|
-
});
|
|
199
|
-
fs.unlinkSync(buildCfg.outpath); // 删除未签名的
|
|
200
|
-
|
|
201
|
-
// 对齐apk
|
|
202
|
-
console.log(`zip align ...`);
|
|
203
|
-
child_process.execFileSync("C:\\jdev_develop\\jre\\bin\\zipalign.exe", [
|
|
204
|
-
"-v", "4",
|
|
205
|
-
singApkTmp,
|
|
206
|
-
buildCfg.outpath
|
|
207
|
-
], {
|
|
208
|
-
cwd: jreCwd
|
|
209
|
-
});
|
|
210
|
-
fs.unlinkSync(singApkTmp); // 删除未对齐的
|
|
211
|
-
|
|
212
|
-
// 完成
|
|
213
|
-
console.log(`build success:${buildCfg.outpath}`);
|
|
214
|
-
} catch (error) {
|
|
215
|
-
// 延迟报错
|
|
216
|
-
setTimeout(() => {
|
|
217
|
-
console.error("build error,please run [jh5 update] first.");
|
|
218
|
-
}, 500);
|
|
219
|
-
// 向上抛出
|
|
220
|
-
throw error;
|
|
221
|
-
}
|
|
222
|
-
finally {
|
|
223
|
-
// 清理文件
|
|
224
|
-
try {
|
|
225
|
-
jutils.jfile_utils.deleteFile(buildCfg.outpath);
|
|
226
|
-
} catch (error) {
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
package/lib/build_std_zip.js
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
let glob = require("glob")
|
|
2
|
-
let archiver = require('archiver');
|
|
3
|
-
let jutils = require('base_parts');
|
|
4
|
-
|
|
5
|
-
let fs = require('fs');
|
|
6
|
-
let path = require('path');
|
|
7
|
-
let os = require('os');
|
|
8
|
-
let AdmZip = require('adm-zip');
|
|
9
|
-
let child_process = require('child_process');
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
module.exports = async (cmd, buildCfg) => {
|
|
13
|
-
// 生成无签名的apk
|
|
14
|
-
await new Promise((resolve, reject) => {
|
|
15
|
-
(async () => {
|
|
16
|
-
// 建立压缩文件
|
|
17
|
-
console.log(`build file to ${buildCfg.outpath}`);
|
|
18
|
-
let output = fs.createWriteStream(buildCfg.outpath);
|
|
19
|
-
let archive = archiver('zip', {
|
|
20
|
-
zlib: { level: 9 }
|
|
21
|
-
});
|
|
22
|
-
output.on('close', function () {
|
|
23
|
-
console.log(archive.pointer() + ' total bytes');
|
|
24
|
-
resolve();
|
|
25
|
-
});
|
|
26
|
-
output.on('end', function () {
|
|
27
|
-
});
|
|
28
|
-
archive.on('warning', function (err) {
|
|
29
|
-
if (err.code === 'ENOENT') {
|
|
30
|
-
} else {
|
|
31
|
-
reject(err);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
archive.on('error', function (err) {
|
|
35
|
-
reject(err);
|
|
36
|
-
});
|
|
37
|
-
archive.pipe(output);
|
|
38
|
-
|
|
39
|
-
// 修改版本号
|
|
40
|
-
let platformVer = jutils.getUUID();
|
|
41
|
-
try {
|
|
42
|
-
console.log(`change dist ver ...`);
|
|
43
|
-
let repFile = `${buildCfg.rootPath}\\dist\\index.html`;
|
|
44
|
-
let indexStr = fs.readFileSync(repFile, "utf8");
|
|
45
|
-
indexStr = indexStr.replace(/#J_APPNAME#/g, buildCfg.appName);
|
|
46
|
-
indexStr = indexStr.replace(/#J_DATE#/g, buildCfg.dateStr);
|
|
47
|
-
|
|
48
|
-
// 读取H5版本
|
|
49
|
-
try {
|
|
50
|
-
let bInfoStr = fs.readFileSync(`${buildCfg.rootPath}/jbuild_data/info.txt`, "utf8");
|
|
51
|
-
let bInfoObj = JSON.parse(bInfoStr);
|
|
52
|
-
if (bInfoObj.version) {
|
|
53
|
-
platformVer = bInfoObj.version;
|
|
54
|
-
indexStr = indexStr.replace(/#J_H5_VER#/g, bInfoObj.version);
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.log(`no h5Ver!`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 保存
|
|
61
|
-
fs.writeFileSync(repFile, indexStr);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 载入apk
|
|
66
|
-
{
|
|
67
|
-
console.log(`load files ...`);
|
|
68
|
-
let myZip = new AdmZip(`${buildCfg.rootPath}/jbuild_data/std_bins/app-release.apk`);
|
|
69
|
-
|
|
70
|
-
// 循环添加
|
|
71
|
-
let zipEntries = myZip.getEntries();
|
|
72
|
-
zipEntries.forEach(function (zipEntry) {
|
|
73
|
-
// 过滤签名
|
|
74
|
-
if (zipEntry.entryName.toUpperCase().indexOf("META-INF/") !== 0) {
|
|
75
|
-
archive.append(zipEntry.getData(), { name: zipEntry.entryName });
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 添加用户文件
|
|
81
|
-
{
|
|
82
|
-
let pathSub = "dist";
|
|
83
|
-
console.log(`scaning ${pathSub} ...`);
|
|
84
|
-
let fileList = glob(`${pathSub}/**/*`, {
|
|
85
|
-
dot: true,
|
|
86
|
-
sync: true,
|
|
87
|
-
nodir: true,
|
|
88
|
-
cwd: buildCfg.rootPath,
|
|
89
|
-
ignore: []
|
|
90
|
-
});
|
|
91
|
-
if (fileList.length === 0) {
|
|
92
|
-
console.error("no dist files!");
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
console.log(`add [${fileList.length}] files ...`);
|
|
96
|
-
for (let index = 0; index < fileList.length; index++) {
|
|
97
|
-
let element = fileList[index].substr(pathSub.length + 1);
|
|
98
|
-
|
|
99
|
-
// 添加文件
|
|
100
|
-
archive.append(fs.readFileSync(`${buildCfg.rootPath}/${pathSub}/${element}`), { name: "assets/h5app/" + element });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 需要web
|
|
105
|
-
if (!buildCfg.platform.includes("noweb")) {
|
|
106
|
-
// 添加框架二进制
|
|
107
|
-
{
|
|
108
|
-
let pathSub = "jbuild_data/jext";
|
|
109
|
-
console.log(`scaning ${pathSub} ...`);
|
|
110
|
-
let fileList = glob(`${pathSub}/**/*`, {
|
|
111
|
-
dot: true,
|
|
112
|
-
sync: true,
|
|
113
|
-
nodir: true,
|
|
114
|
-
cwd: buildCfg.rootPath,
|
|
115
|
-
ignore: []
|
|
116
|
-
});
|
|
117
|
-
console.log(`add [${fileList.length}] files ...`);
|
|
118
|
-
for (let index = 0; index < fileList.length; index++) {
|
|
119
|
-
let element = fileList[index].substr(pathSub.length + 1);
|
|
120
|
-
|
|
121
|
-
// 添加文件
|
|
122
|
-
archive.append(fs.readFileSync(`${buildCfg.rootPath}/${pathSub}/${element}`), { name: "assets/jext/" + element });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// 添加后台服务
|
|
127
|
-
{
|
|
128
|
-
console.log(`add device_webapi files ...`);
|
|
129
|
-
// 载入zip
|
|
130
|
-
let myZip = new AdmZip(`${buildCfg.rootPath}/jbuild_data/device_webapi.zip`);
|
|
131
|
-
|
|
132
|
-
// 循环添加
|
|
133
|
-
let zipEntries = myZip.getEntries();
|
|
134
|
-
zipEntries.forEach(function (zipEntry) {
|
|
135
|
-
archive.append(zipEntry.getData(), { name: "assets/device_webapi/" + zipEntry.entryName });
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// 版本号
|
|
139
|
-
archive.append(Buffer.from(platformVer), { name: "assets/device_webapi/info.txt" });
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
// 添加设备信息
|
|
144
|
-
try {
|
|
145
|
-
let pkgInfo = os.networkInterfaces();
|
|
146
|
-
pkgInfo.buildTime = jutils.getNowDate();
|
|
147
|
-
archive.append(JSON.stringify(pkgInfo, null, 4), { name: "assets/build_info.txt" });
|
|
148
|
-
} catch (error) {
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// 开始压缩
|
|
152
|
-
archive.finalize();
|
|
153
|
-
})().catch((err) => {
|
|
154
|
-
console.error("build error,please run [jh5 update] first.");
|
|
155
|
-
try {
|
|
156
|
-
jutils.jfile_utils.deleteFile(buildCfg.outpath);
|
|
157
|
-
} catch (error) {
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// 生成apk签名
|
|
163
|
-
console.log(`not find keystore,making ...`);
|
|
164
|
-
let jreCwd = "C:\\jdev_develop\\jre\\bin";
|
|
165
|
-
let keyStoreFile = `${buildCfg.rootPath}/sigin/apk_cert.keystore`;
|
|
166
|
-
try {
|
|
167
|
-
fs.mkdirSync(path.dirname(keyStoreFile));
|
|
168
|
-
} catch (error) {
|
|
169
|
-
}
|
|
170
|
-
if (!fs.existsSync(keyStoreFile)) {
|
|
171
|
-
// 生成签名
|
|
172
|
-
child_process.execFileSync("C:\\jdev_develop\\jre\\bin\\keytool.exe", [
|
|
173
|
-
"-genkey",
|
|
174
|
-
"-storepass", "123456",
|
|
175
|
-
"-keypass", "123456",
|
|
176
|
-
"-alias", "cert",
|
|
177
|
-
"-keyalg", "RSA",
|
|
178
|
-
"-validity", "20000",
|
|
179
|
-
"-keystore", keyStoreFile,
|
|
180
|
-
"-dname", "CN=10.10.6.100,OU=utils,O=utils,L=beijing,ST=beijing,c=cn"
|
|
181
|
-
], {
|
|
182
|
-
cwd: jreCwd
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// 签名
|
|
187
|
-
console.log(`sign apk ...`);
|
|
188
|
-
var singApkTmp = buildCfg.outpath + "_sign.apk";
|
|
189
|
-
child_process.execFileSync("C:\\jdev_develop\\jre\\bin\\jarsigner.exe", [
|
|
190
|
-
"-verbose",
|
|
191
|
-
"-storepass", "123456",
|
|
192
|
-
"-keypass", "123456",
|
|
193
|
-
"-keystore", keyStoreFile,
|
|
194
|
-
"-signedjar", singApkTmp,
|
|
195
|
-
buildCfg.outpath,
|
|
196
|
-
"cert"
|
|
197
|
-
], {
|
|
198
|
-
cwd: jreCwd
|
|
199
|
-
});
|
|
200
|
-
fs.unlinkSync(buildCfg.outpath); // 删除未签名的
|
|
201
|
-
|
|
202
|
-
// 对齐apk
|
|
203
|
-
console.log(`zip align ...`);
|
|
204
|
-
child_process.execFileSync("C:\\jdev_develop\\jre\\bin\\zipalign.exe", [
|
|
205
|
-
"-v", "4",
|
|
206
|
-
singApkTmp,
|
|
207
|
-
buildCfg.outpath
|
|
208
|
-
], {
|
|
209
|
-
cwd: jreCwd
|
|
210
|
-
});
|
|
211
|
-
fs.unlinkSync(singApkTmp); // 删除未对齐的
|
|
212
|
-
|
|
213
|
-
// 完成
|
|
214
|
-
console.log(`build success:${buildCfg.outpath}`);
|
|
215
|
-
}
|
|
216
|
-
|