jh5_app_build 1.0.23 → 1.0.26

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.
@@ -122,7 +122,11 @@ program
122
122
  value: "std"
123
123
  },
124
124
  {
125
- name: 'Std device lite(*.apk file,no web)',
125
+ name: 'Weds device lite(*.jap file)',
126
+ value: "weds,nobin,noweb"
127
+ },
128
+ {
129
+ name: 'Std device lite(*.apk file)',
126
130
  value: "std,noweb"
127
131
  }
128
132
  ]
@@ -133,6 +137,19 @@ program
133
137
  // 标准应用
134
138
  buildCfg.isStdApp = buildCfg.platform.includes("std");
135
139
 
140
+ // 不加入app
141
+ if (buildCfg.platform.includes("noapp")) {
142
+ cmd.noapp = true;
143
+ }
144
+ // 不加入bin
145
+ if (buildCfg.platform.includes("nobin")) {
146
+ cmd.nobin = true;
147
+ }
148
+ // 不加入web
149
+ if (buildCfg.platform.includes("noweb")) {
150
+ cmd.noweb = true;
151
+ }
152
+
136
153
  // 缺省输出文件
137
154
  if (cmd.outpath) {
138
155
  buildCfg.outpath = cmd.outpath;
package/lib/build_japp.js CHANGED
@@ -4,11 +4,15 @@ 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) => {
10
11
  return new Promise((resolve, reject) => {
11
12
  (async () => {
13
+ // 待删除列表
14
+ var deleteList = [];
15
+
12
16
  // 读取sh脚本
13
17
  var shDataStr = fs.readFileSync(buildCfg.rootPath + "/jbuild_data/repair.sh", "utf8");
14
18
 
@@ -19,6 +23,12 @@ module.exports = async (cmd, buildCfg) => {
19
23
  zlib: { level: 9 }
20
24
  });
21
25
  output.on('close', function () {
26
+ // 清理
27
+ for (const iterator of deleteList) {
28
+ fs.unlinkSync(iterator);
29
+ }
30
+
31
+ // 完成
22
32
  console.log(archive.pointer() + ' total bytes');
23
33
  console.log(`build success:${buildCfg.outpath}`);
24
34
  resolve();
@@ -82,7 +92,7 @@ module.exports = async (cmd, buildCfg) => {
82
92
  let element = fileList[index].substr(pathSub.length + 1);
83
93
 
84
94
  // 添加文件
85
- archive.append(fs.readFileSync(`${buildCfg.rootPath}/${pathSub}/${element}`), { name: "update_a20/h5app/" + element });
95
+ archive.file(`${buildCfg.rootPath}/${pathSub}/${element}`, { name: "update_a20/h5app/" + element });
86
96
  }
87
97
  // 清空应用目录
88
98
  shDataStr = shDataStr.replace(/#del_app#/g, "");
@@ -106,11 +116,11 @@ module.exports = async (cmd, buildCfg) => {
106
116
  let element = fileList[index].substr(pathSub.length + 1);
107
117
 
108
118
  // 添加文件
109
- archive.append(fs.readFileSync(`${buildCfg.rootPath}/${pathSub}/${element}`), { name: "update_a20/app/bin/" + element });
119
+ archive.file(`${buildCfg.rootPath}/${pathSub}/${element}`, { name: "update_a20/app/bin/" + element });
110
120
  }
111
121
 
112
122
  // 添加框架apk
113
- archive.append(fs.readFileSync(`${buildCfg.rootPath}/jbuild_data/app-debug.apk`), { name: "update_a20/app/app-debug.apk" });
123
+ archive.file(`${buildCfg.rootPath}/jbuild_data/app-debug.apk`, { name: "update_a20/app/app-debug.apk" });
114
124
 
115
125
  // 清空模型文件
116
126
  shDataStr = shDataStr.replace(/#del_bin#/g, "");
@@ -125,7 +135,10 @@ module.exports = async (cmd, buildCfg) => {
125
135
  // 循环添加
126
136
  var zipEntries = myZip.getEntries();
127
137
  zipEntries.forEach(function (zipEntry) {
128
- archive.append(zipEntry.getData(), { name: "update_a20/" + zipEntry.entryName });
138
+ let tmpFile = path.resolve(`${buildCfg.rootPath}/jbuild_data/${zipEntry.entryName}.tmp`);
139
+ fs.writeFileSync(tmpFile, zipEntry.getData());
140
+ deleteList.push(tmpFile);
141
+ archive.file(tmpFile, { name: "update_a20/" + zipEntry.entryName });
129
142
  });
130
143
 
131
144
  // 复制web
@@ -138,19 +151,30 @@ module.exports = async (cmd, buildCfg) => {
138
151
  }
139
152
 
140
153
  // 添加sh
141
- archive.append(shDataStr, { name: "update_a20/repair.sh" });
154
+ try {
155
+ let tmpFile = path.resolve(`${buildCfg.rootPath}/jbuild_data/repair.sh.tmp`);
156
+ fs.writeFileSync(tmpFile, shDataStr);
157
+ deleteList.push(tmpFile);
158
+ archive.file(tmpFile, { name: "update_a20/repair.sh" });
159
+ } catch (error) {
160
+ }
142
161
 
143
162
  // 添加设备信息
144
163
  try {
145
164
  var pkgInfo = os.networkInterfaces();
146
165
  pkgInfo.buildTime = jutils.getNowDate();
147
- archive.append(JSON.stringify(pkgInfo, null, 4), { name: "update_a20/build_info.txt" });
166
+
167
+ let tmpFile = path.resolve(`${buildCfg.rootPath}/jbuild_data/build_info.txt`);
168
+ fs.writeFileSync(tmpFile, JSON.stringify(pkgInfo, null, 4));
169
+ deleteList.push(tmpFile);
170
+ archive.file(tmpFile, { name: "update_a20/build_info.txt" });
148
171
  } catch (error) {
149
172
  }
150
173
 
151
174
  // 开始压缩
152
175
  archive.finalize();
153
176
  })().catch((err) => {
177
+ console.error(err.message);
154
178
  console.error("build error,please run [jh5 update] first.");
155
179
  try {
156
180
  jutils.jfile_utils.deleteFile(buildCfg.outpath);
package/lib/build_std.js CHANGED
@@ -231,7 +231,7 @@ module.exports = async (cmd, buildCfg) => {
231
231
  }
232
232
 
233
233
  // 需要web
234
- if (!buildCfg.platform.includes("noweb")) {
234
+ if (!cmd.noweb) {
235
235
  // 添加框架二进制
236
236
  {
237
237
  let pathSub = "jbuild_data/jext";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jh5_app_build",
3
- "version": "1.0.23",
3
+ "version": "1.0.26",
4
4
  "description": "jaskle jh5_app_build",
5
5
  "main": "./bin/jh5_app_build.js",
6
6
  "registry": true,
@@ -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
-
@@ -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
-