jh5_app_build 1.0.17 → 1.0.18

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/.eslintrc.js CHANGED
@@ -126,7 +126,7 @@ module.exports = {
126
126
  "no-iterator": "error",
127
127
  "no-label-var": "error",
128
128
  "no-labels": "error",
129
- "no-lone-blocks": "error",
129
+ "no-lone-blocks": "off",
130
130
  "no-lonely-if": "error",
131
131
  "no-loop-func": "off",
132
132
  "no-magic-numbers": "off",
@@ -9,6 +9,8 @@ var jlog = jutils.jlog(__filename);
9
9
 
10
10
  var AdmZip = require('adm-zip');
11
11
 
12
+ var inquirer = require('inquirer');
13
+
12
14
  // 关闭日志输出
13
15
  jlog.setEnable(false, "*");
14
16
 
@@ -71,6 +73,20 @@ function getBuildCfg(cmd) {
71
73
  return buildCfg;
72
74
  }
73
75
 
76
+ /**
77
+ * 检查项目
78
+ * @param {*} buildCfg 构建配置
79
+ * @returns {void}
80
+ */
81
+ function chkProj(buildCfg) {
82
+ // 判断是否为h5项目
83
+ if (!fs.existsSync(buildCfg.rootPath + "/public/index.html")) {
84
+ console.error("The directory is not valid");
85
+ process.exit(-1);
86
+ return null;
87
+ }
88
+ }
89
+
74
90
 
75
91
  // 命令
76
92
  program
@@ -87,6 +103,36 @@ program
87
103
  // 获取配置
88
104
  var buildCfg = getBuildCfg(cmd);
89
105
 
106
+ // 检查项目
107
+ chkProj(buildCfg);
108
+
109
+ // 选择编译类型
110
+ var answers = await inquirer.prompt([
111
+ {
112
+ type: 'list',
113
+ name: 'platform',
114
+ message: 'Please select a compilation platform:',
115
+ choices: [
116
+ {
117
+ name: 'Weds device(*.jap file)',
118
+ value: "weds"
119
+ },
120
+ {
121
+ name: 'Std device(*.apk file)',
122
+ value: "std"
123
+ },
124
+ {
125
+ name: 'Std device lite(*.apk file,no web)',
126
+ value: "std,noweb"
127
+ }
128
+ ]
129
+ }
130
+ ]);
131
+ buildCfg.platform = answers.platform.split(",");
132
+
133
+ // 标准应用
134
+ buildCfg.isStdApp = buildCfg.platform.includes("std");
135
+
90
136
  // 缺省输出文件
91
137
  if (cmd.outpath) {
92
138
  buildCfg.outpath = cmd.outpath;
@@ -108,14 +154,22 @@ program
108
154
  buildCfg.dateStr = jutils.getNowDate().replace(/(-|:)/g, "").replace(/ /g, "_").substr(2, 11);
109
155
 
110
156
  // 处理文件名
111
- buildCfg.outpath = `${process.cwd()}/jh5_${buildCfg.appName}_${buildCfg.dateStr}.jap`;
157
+ buildCfg.outpath = `${process.cwd()}/jh5_${buildCfg.appName}_${buildCfg.dateStr}.${buildCfg.isStdApp ? "apk" : "jap"}`;
112
158
  }
113
159
  buildCfg.outpath = path.resolve(buildCfg.outpath);
114
160
  jfile_utils.createDirs(buildCfg.outpath, true); // 建立目录
115
161
  console.log("[Out path] " + buildCfg.outpath);
116
162
 
117
- // 执行编译
118
- await require('../lib/build_japp')(cmd, buildCfg);
163
+ // 标准应用
164
+ if (buildCfg.isStdApp) {
165
+ // 执行编译
166
+ await require('../lib/build_std')(cmd, buildCfg);
167
+ }
168
+ // weds 应用
169
+ else {
170
+ // 执行编译
171
+ await require('../lib/build_japp')(cmd, buildCfg);
172
+ }
119
173
 
120
174
  // 执行自定义脚本
121
175
  var scriptObj = await loadUpdateScript(buildCfg.rootPath);
@@ -141,6 +195,9 @@ async function cmdUpdate(cmd) {
141
195
  // 获取配置
142
196
  var buildCfg = getBuildCfg(cmd);
143
197
 
198
+ // 检查项目
199
+ chkProj(buildCfg);
200
+
144
201
  // 使用开发版
145
202
  if (!cmd.ver && cmd.insiders) cmd.ver = "insiders";
146
203
 
@@ -224,6 +281,10 @@ program
224
281
  .action(async (cmd) => {
225
282
  // 获取配置
226
283
  var buildCfg = getBuildCfg(cmd);
284
+
285
+ // 检查项目
286
+ chkProj(buildCfg);
287
+
227
288
  console.log("clean...");
228
289
 
229
290
  // 删除下载包
@@ -236,7 +297,7 @@ program
236
297
  var filelist = await jutils.jfile_utils.readdir(buildCfg.rootPath);
237
298
  for (let index = 0; index < filelist.length; index++) {
238
299
  const element = filelist[index];
239
- if ([".jap", ".jzip", ".tmp"].indexOf(path.extname(element)) >= 0) {
300
+ if ([".jzip", ".tmp"].indexOf(path.extname(element)) >= 0) {
240
301
  console.log("delete:" + element);
241
302
  await jutils.jfile_utils.deleteFile(buildCfg.rootPath + "/" + element);
242
303
  }
@@ -0,0 +1,164 @@
1
+ let glob = require("glob")
2
+ let archiver = require('archiver');
3
+ let jutils = require('base_parts');
4
+
5
+ let fs = require('fs');
6
+ let os = require('os');
7
+ let AdmZip = require('adm-zip');
8
+
9
+ module.exports = async (cmd, buildCfg) => {
10
+ return new Promise((resolve, reject) => {
11
+ (async () => {
12
+
13
+ // 建立压缩文件
14
+ console.log(`build file to ${buildCfg.outpath}`);
15
+ let output = fs.createWriteStream(buildCfg.outpath);
16
+ let archive = archiver('zip', {
17
+ zlib: { level: 9 }
18
+ });
19
+ output.on('close', function () {
20
+ console.log(archive.pointer() + ' total bytes');
21
+ console.log(`build success:${buildCfg.outpath}`);
22
+ resolve();
23
+ });
24
+ output.on('end', function () {
25
+ });
26
+ archive.on('warning', function (err) {
27
+ if (err.code === 'ENOENT') {
28
+ } else {
29
+ reject(err);
30
+ }
31
+ });
32
+ archive.on('error', function (err) {
33
+ reject(err);
34
+ });
35
+ archive.pipe(output);
36
+
37
+ // 修改版本号
38
+ let platformVer = jutils.getUUID();
39
+ try {
40
+ console.log(`change dist ver ...`);
41
+ let repFile = `${buildCfg.rootPath}\\dist\\index.html`;
42
+ let indexStr = fs.readFileSync(repFile, "utf8");
43
+ indexStr = indexStr.replace(/#J_APPNAME#/g, buildCfg.appName);
44
+ indexStr = indexStr.replace(/#J_DATE#/g, buildCfg.dateStr);
45
+
46
+ // 读取H5版本
47
+ try {
48
+ let bInfoStr = fs.readFileSync(`${buildCfg.rootPath}/jbuild_data/info.txt`, "utf8");
49
+ let bInfoObj = JSON.parse(bInfoStr);
50
+ if (bInfoObj.version) {
51
+ platformVer = bInfoObj.version;
52
+ indexStr = indexStr.replace(/#J_H5_VER#/g, bInfoObj.version);
53
+ }
54
+ } catch (error) {
55
+ console.log(`no h5Ver!`);
56
+ }
57
+
58
+ // 保存
59
+ fs.writeFileSync(repFile, indexStr);
60
+ } catch (error) {
61
+ }
62
+
63
+ // 载入apk
64
+ {
65
+ console.log(`load files ...`);
66
+ let myZip = new AdmZip(`${buildCfg.rootPath}/jbuild_data/std_bins/app-release.apk`);
67
+
68
+ // 循环添加
69
+ let zipEntries = myZip.getEntries();
70
+ zipEntries.forEach(function (zipEntry) {
71
+ // 过滤签名
72
+ if (!["META-INF/CERT.RSA", "META-INF/CERT.SF", "META-INF/MANIFEST.MF"].includes(zipEntry.entryName.toUpperCase())) {
73
+ archive.append(zipEntry.getData(), { name: zipEntry.entryName });
74
+ }
75
+ else {
76
+ console.error(">>>>>>>>>" + zipEntry);
77
+ }
78
+ });
79
+ }
80
+
81
+ // 添加用户文件
82
+ {
83
+ let pathSub = "dist";
84
+ console.log(`scaning ${pathSub} ...`);
85
+ let fileList = glob(`${pathSub}/**/*`, {
86
+ dot: true,
87
+ sync: true,
88
+ nodir: true,
89
+ cwd: buildCfg.rootPath,
90
+ ignore: []
91
+ });
92
+ if (fileList.length === 0) {
93
+ console.error("no dist files!");
94
+ return;
95
+ }
96
+ console.log(`add [${fileList.length}] files ...`);
97
+ for (let index = 0; index < fileList.length; index++) {
98
+ let element = fileList[index].substr(pathSub.length + 1);
99
+
100
+ // 添加文件
101
+ archive.append(fs.readFileSync(`${buildCfg.rootPath}/${pathSub}/${element}`), { name: "assets/h5app/" + element });
102
+ }
103
+ }
104
+
105
+ // 需要web
106
+ if (!buildCfg.platform.includes("noweb")) {
107
+ // 添加框架二进制
108
+ {
109
+ let pathSub = "jbuild_data/jext";
110
+ console.log(`scaning ${pathSub} ...`);
111
+ let fileList = glob(`${pathSub}/**/*`, {
112
+ dot: true,
113
+ sync: true,
114
+ nodir: true,
115
+ cwd: buildCfg.rootPath,
116
+ ignore: []
117
+ });
118
+ console.log(`add [${fileList.length}] files ...`);
119
+ for (let index = 0; index < fileList.length; index++) {
120
+ let element = fileList[index].substr(pathSub.length + 1);
121
+
122
+ // 添加文件
123
+ archive.append(fs.readFileSync(`${buildCfg.rootPath}/${pathSub}/${element}`), { name: "assets/jext/" + element });
124
+ }
125
+ }
126
+
127
+ // 添加后台服务
128
+ {
129
+ console.log(`add device_webapi files ...`);
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
+ archive.append(zipEntry.getData(), { name: "assets/device_webapi/" + zipEntry.entryName });
137
+ });
138
+
139
+ // 版本号
140
+ archive.append(Buffer.from(platformVer), { name: "assets/device_webapi/info.txt" });
141
+ }
142
+
143
+ }
144
+ // 添加设备信息
145
+ try {
146
+ let pkgInfo = os.networkInterfaces();
147
+ pkgInfo.buildTime = jutils.getNowDate();
148
+ archive.append(JSON.stringify(pkgInfo, null, 4), { name: "assets/build_info.txt" });
149
+ } catch (error) {
150
+ }
151
+
152
+ // 开始压缩
153
+ archive.finalize();
154
+ })().catch((err) => {
155
+ console.error("build error,please run [jh5 update] first.");
156
+ try {
157
+ jutils.jfile_utils.deleteFile(buildCfg.outpath);
158
+ } catch (error) {
159
+ }
160
+ });
161
+ });
162
+
163
+ }
164
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jh5_app_build",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "jaskle jh5_app_build",
5
5
  "main": "./bin/jh5_app_build.js",
6
6
  "registry": true,
@@ -22,6 +22,7 @@
22
22
  "base_parts": "^2.*",
23
23
  "commander": "^2.*",
24
24
  "glob": "^7.*",
25
+ "inquirer": "^8.2.4",
25
26
  "request": "^2.*"
26
27
  },
27
28
  "devDependencies": {