@webos-tools/cli 3.0.5 → 3.1.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## 3.1.0 (July 12, 2024)
2
+ ### ares-generate
3
+ * Fixed a bug that can not generate without tample option
4
+
5
+ ### ares-setup-device
6
+ * Enhance usability of --add option.
7
+ * Enhance emulator remove usability
8
+ * Change default device information of TV profile (user: prisoner, port:9922)
9
+ * Change devie name validation logic that accept all of charactors except "$" & "%"
10
+
11
+ ### common
12
+ * Upgrade node modules: shelljs(v0.8.5), async(v3.2.5), ssh2(v1.15.0), tar(v6.2.0).
13
+
14
+
15
+ ## 3.0.6 (April 04, 2024)
16
+ ### ares-log
17
+ * Fixed a bug that invalid json format
18
+
19
+
20
+ ## 3.0.5 (April 01, 2024)
21
+ ### Common
22
+ * Fixed a bug that can not install on window by CMD or Powershell
23
+
24
+
1
25
  ## 3.0.4 (March 30, 2024)
2
26
  ### Common
3
27
  * Fixed a bug that always requires sudo permission when exec ares commands
@@ -170,6 +170,10 @@ function generate() {
170
170
  const gen = getGenerator();
171
171
  const templates = gen.getTmpl();
172
172
 
173
+ if(!options.tmplName){
174
+ options.tmplName = Object.keys(templates).find(t => templates[t].default === true);
175
+ }
176
+
173
177
  if (options.tmplName === "true") {
174
178
  return finish(errHndl.getErrMsg("EMPTY_VALUE", "TEMPLATE"));
175
179
  }
@@ -118,12 +118,9 @@ function getkey(next) {
118
118
  }
119
119
  process.stdin.resume();
120
120
  process.stdin.setEncoding('utf8');
121
- process.stdout.write('input passphrase [default: webos]:');
121
+ process.stdout.write('input passphrase:');
122
122
  process.stdin.on('data', function(text) {
123
- let passphrase = text.toString().trim();
124
- if (passphrase === '') {
125
- passphrase = 'webos';
126
- }
123
+ const passphrase = text.toString().trim();
127
124
  log.info('registered passphrase is ', passphrase);
128
125
  next(null, keyFileName, passphrase);
129
126
  });
@@ -186,9 +186,10 @@ function _queryAddRemove(ssdpDevices, next) {
186
186
  if (ssdpDevice) {
187
187
  if (ssdpDevice.op === 'modify') return inqChoices;
188
188
  else return ['add'];
189
- } else {
190
- return totChoices;
191
- }
189
+ }
190
+ if (deviceNames.length > 1) return totChoices;
191
+ // deveice list has emulator only > unsupported remove option
192
+ return inqChoices.concat(dfChoices);
192
193
  },
193
194
  filter: function(val) {
194
195
  return val.toLowerCase();
@@ -221,12 +222,20 @@ function _queryAddRemove(ssdpDevices, next) {
221
222
  return true;
222
223
  }
223
224
  }, {
225
+ type: "list",
226
+ name: "device_name",
227
+ message: "Select a device",
228
+ choices: deviceNames.filter(dv => dv !== "emulator"),
229
+ when: function(answers) {
230
+ return (["remove"].indexOf(answers.op) !== -1 && !ssdpDevice);
231
+ }
232
+ },{
224
233
  type: "list",
225
234
  name: "device_name",
226
235
  message: "Select a device",
227
236
  choices: deviceNames,
228
237
  when: function(answers) {
229
- return (["modify", "remove", "set default"].indexOf(answers.op) !== -1 && !ssdpDevice);
238
+ return (["modify", "set default"].indexOf(answers.op) !== -1 && !ssdpDevice);
230
239
  }
231
240
  }];
232
241
  inquirer.prompt(questions)
@@ -250,14 +259,15 @@ function _queryAddRemove(ssdpDevices, next) {
250
259
  function _queryDeviceInfo(selDevice, next) {
251
260
  let mode = selDevice.mode;
252
261
  const deviceName = selDevice.name,
253
- resolver = this.resolver || (this.resolver = new novacom.Resolver());
254
-
262
+ resolver = this.resolver || (this.resolver = new novacom.Resolver()),
263
+ defaultDeviceInfo = appdata.getConfig(true).defaultDeviceInfo;
264
+
255
265
  questions = [{
256
266
  type: "input",
257
267
  name: "ip",
258
268
  message: "Enter Device IP address:",
259
269
  default: function() {
260
- return selDevice.host || "127.0.0.1";
270
+ return selDevice.host || defaultDeviceInfo.ipAddress;
261
271
  },
262
272
  validate: function(answers) {
263
273
  if (!setupDevice.isValidIpv4(answers)) {
@@ -273,7 +283,7 @@ function _queryDeviceInfo(selDevice, next) {
273
283
  name: "port",
274
284
  message: "Enter Device Port:",
275
285
  default: function() {
276
- return selDevice.port || "22";
286
+ return selDevice.port || defaultDeviceInfo.port;
277
287
  },
278
288
  validate: function(answers) {
279
289
  if (!setupDevice.isValidPort(answers)) {
@@ -289,7 +299,7 @@ function _queryDeviceInfo(selDevice, next) {
289
299
  name: "user",
290
300
  message: "Enter ssh user:",
291
301
  default: function() {
292
- return selDevice.username || "root";
302
+ return selDevice.username || defaultDeviceInfo.user;
293
303
  },
294
304
  when: function() {
295
305
  return _needInq(mode)(inqChoices);
@@ -299,7 +309,7 @@ function _queryDeviceInfo(selDevice, next) {
299
309
  name: "description",
300
310
  message: "Enter description:",
301
311
  default: function() {
302
- return selDevice.description || "new device";
312
+ return selDevice.description || defaultDeviceInfo.description;
303
313
  },
304
314
  when: function() {
305
315
  return _needInq(mode)(inqChoices);
@@ -316,8 +326,8 @@ function _queryDeviceInfo(selDevice, next) {
316
326
  }
317
327
  return idx;
318
328
  },
319
- when: function() {
320
- return _needInq(mode)(inqChoices);
329
+ when: function(answers) {
330
+ return _needInq(mode)(inqChoices) && answers.user === 'root';
321
331
  }
322
332
  }, {
323
333
  type: "password",
@@ -336,18 +346,8 @@ function _queryDeviceInfo(selDevice, next) {
336
346
  when: function(answers) {
337
347
  return _needInq(mode)(inqChoices) && (answers.auth_type === "ssh key");
338
348
  }
339
- }, {
340
- type: "input",
341
- name: "ssh_passphrase",
342
- message: "Enter key's passphrase:",
343
- default: function() {
344
- return selDevice.passphrase || undefined;
345
- },
346
- when: function(answers) {
347
- return _needInq(mode)(inqChoices) && (answers.auth_type === "ssh key");
348
-
349
- }
350
- }, {
349
+ },
350
+ {
351
351
  type: "confirm",
352
352
  name: "default",
353
353
  message: "Set default ?",
@@ -381,16 +381,18 @@ function _queryDeviceInfo(selDevice, next) {
381
381
  default: answers.default
382
382
  };
383
383
 
384
- if (mode === 'add' || mode === 'modify') {
384
+
385
+ if (answers.
386
+ user !== 'prisoner' && ["add", "modify"].includes(mode)) {
385
387
  if (answers.auth_type && answers.auth_type === "password") {
386
388
  inDevice.password = answers.password;
387
389
  inDevice.privateKey = "@DELETE@";
388
390
  inDevice.passphrase = "@DELETE@";
389
391
  inDevice.privateKeyName = "@DELETE@";
390
- } else if (answers.auth_type && answers.auth_type === "ssh key") {
392
+ } else if ((answers.auth_type && answers.auth_type === "ssh key") || answers.user === "developer") {
391
393
  inDevice.password = "@DELETE@";
392
394
  inDevice.privateKey = {
393
- "openSsh": answers.ssh_key
395
+ "openSsh": answers.ssh_key || "webos_emul"
394
396
  };
395
397
  inDevice.passphrase = answers.ssh_passphrase || "@DELETE@";
396
398
  inDevice.privateKeyName = "@DELETE@";
@@ -411,12 +413,18 @@ function _queryDeviceInfo(selDevice, next) {
411
413
  async.series([
412
414
  resolver.load.bind(resolver),
413
415
  resolver.modifyDeviceFile.bind(resolver, mode, inDevice),
414
- setupDevice.showDeviceList.bind(this, finish)
416
+ setupDevice.showDeviceList.bind(this),
415
417
  ], function(err, results) {
416
418
  if (err) {
417
- return next(err);
419
+ return next(err,);
420
+ }
421
+ if(results[2] && results[2].msg){
422
+ console.log(results[2].msg);
423
+ }
424
+ if(inDevice.username === 'prisoner' && mode === 'add'){
425
+ setupDevice.displayGetKeyGuide(inDevice.name);
418
426
  }
419
- next(null, results[1]);
427
+ finish();
420
428
  });
421
429
  });
422
430
  }
package/bin/ares.js CHANGED
@@ -119,7 +119,7 @@ function display (next) {
119
119
  for (const arg in argv) {
120
120
  if (Object.hasOwnProperty.call(commandsList, 'ares-'+ arg) && fs.existsSync(path.join(__dirname, 'ares-'+ arg + '.js'))) {
121
121
  if (commandsList['ares-'+ arg].profile && !commandsList['ares-'+ arg].profile.includes(profile)) {
122
- next(errHndl.getErrMsg("NOT_SUPPORT_COMMOND", profile));
122
+ return next(errHndl.getErrMsg("NOT_SUPPORT_COMMOND", profile));
123
123
  } else {
124
124
  help.display('ares-'+arg, appdata.getConfig(true).profile);
125
125
  found = true;
@@ -127,9 +127,9 @@ function display (next) {
127
127
  }
128
128
 
129
129
  if (!found) {
130
- next(errHndl.getErrMsg("INVALID_COMMAND"));
130
+ return next(errHndl.getErrMsg("INVALID_COMMAND"));
131
131
  } else {
132
- next();
132
+ return next();
133
133
  }
134
134
  }
135
135
  } catch (err) {
@@ -11,6 +11,15 @@
11
11
  "native": "executable"
12
12
  }
13
13
  },
14
+ "defaultDeviceInfo": {
15
+ "ipAddress": "127.0.0.1",
16
+ "port": "9922",
17
+ "user": "prisoner",
18
+ "description": "new device description",
19
+ "files": "stream",
20
+ "default": false,
21
+ "type": "starfish"
22
+ },
14
23
  "logFilePath": "/media/developer/log/devlog",
15
24
  "install": {
16
25
  "tempDirForIpk": "/media/developer/temp",
@@ -10,6 +10,14 @@
10
10
  "native": "executable"
11
11
  }
12
12
  },
13
+ "defaultDeviceInfo":{
14
+ "ipAddress": "127.0.0.1",
15
+ "port": "22",
16
+ "user": "root",
17
+ "description": "new device description",
18
+ "files": "stream",
19
+ "default": false
20
+ },
13
21
  "logFilePath": "/media/developer/log/devlog",
14
22
  "install": {
15
23
  "tempDirForIpk": "/media/developer/temp",
@@ -11,6 +11,15 @@
11
11
  "native": "executable"
12
12
  }
13
13
  },
14
+ "defaultDeviceInfo": {
15
+ "ipAddress": "127.0.0.1",
16
+ "port": "9922",
17
+ "user": "prisoner",
18
+ "description": "new device description",
19
+ "files": "stream",
20
+ "default": false,
21
+ "type": "starfish"
22
+ },
14
23
  "logFilePath": "/media/developer/log/devlog",
15
24
  "install": {
16
25
  "tempDirForIpk": "/media/developer/temp",
@@ -13,7 +13,8 @@
13
13
  },
14
14
  "description" : [
15
15
  {
16
- "default": [
16
+ "default":[],
17
+ "ose": [
17
18
  "This command manages the information of the devices.",
18
19
  "",
19
20
  "** Attributes of DEVICE_INFO **",
@@ -23,7 +24,24 @@
23
24
  " username [string] user name to connect ('developer')",
24
25
  " privatekey [string] ssh private key file name",
25
26
  " ssh private key should exist under $HOME/.ssh/",
26
- " passphrase [string] passphrase used for generating ssh keys",
27
+ " password [string] password for ssh connection",
28
+ " default [boolean] set default device with 'add' option",
29
+ "",
30
+ "This command can set a default device.",
31
+ "If you don't specify a target device, the default device is used as the target device.",
32
+ "",
33
+ "LEVEL is priority of logs. (e.g., silly, verbose, info, warn, error)"
34
+ ],
35
+ "tv": [
36
+ "This command manages the information of the devices.",
37
+ "",
38
+ "** Attributes of DEVICE_INFO **",
39
+ " description [string] description of target device",
40
+ " host [string] ip address",
41
+ " port [string] port number",
42
+ " username [string] user name to connect ('prisoner')",
43
+ " privatekey [string] ssh private key file name",
44
+ " ssh private key should exist under $HOME/.ssh/",
27
45
  " password [string] password for ssh connection",
28
46
  " default [boolean] set default device with 'add' option",
29
47
  "",
@@ -36,7 +54,8 @@
36
54
  ],
37
55
  "examples" : [
38
56
  {
39
- "default" : [
57
+ "default":[],
58
+ "ose" : [
40
59
  "",
41
60
  "# Add a DEVICE and set the username, host, port",
42
61
  "ares-setup-device -a DEVICE -i \"{'username':'root', 'host':'127.0.0.1','port':'22'}\"",
@@ -57,6 +76,28 @@
57
76
  "# Change the ssh password of the DEVICE as an empty value",
58
77
  "ares-setup-device -m DEVICE -i \"password=\"",
59
78
  ""
79
+ ],
80
+ "tv" : [
81
+ "",
82
+ "# Add a DEVICE and set the username, host, port",
83
+ "ares-setup-device -a DEVICE -i \"{'username':'prisoner', 'host':'127.0.0.1','port':'9922'}\"",
84
+ " Or",
85
+ "ares-setup-device -a DEVICE -i \"username=prisoner\" -i \"host=127.0.0.1\" -i \"port=9922\"",
86
+ "",
87
+ "# Modify the information of the DEVICE",
88
+ "ares-setup-device -m DEVICE -i \"{'username':'prisoner','host':'192.168.0.123'}\"",
89
+ " Or",
90
+ "ares-setup-device -m DEVICE -i \"username=prisoner\" -i \"host=192.168.0.123\"",
91
+ "",
92
+ "# Remove the DEVICE",
93
+ "ares-setup-device -r DEVICE",
94
+ "",
95
+ "# Set default the DEVICE",
96
+ "ares-setup-device -f DEVICE",
97
+ "",
98
+ "# Change the ssh password of the DEVICE as an empty value",
99
+ "ares-setup-device -m DEVICE -i \"password=\"",
100
+ ""
60
101
  ]
61
102
  }
62
103
  ],
@@ -41,7 +41,7 @@ window.onload = function() {
41
41
  * In this case, the service name is used as default name "com.domain.app.service" is.
42
42
  * If you change this service name, you need to change the service name of the following API.
43
43
  *
44
- * If you change the name to helloParmas as you want, the contents will be reflected on the screen.
44
+ * If you change the name to helloParams as you want, the contents will be reflected on the screen.
45
45
  */
46
46
  var helloApi = 'luna://com.domain.app.service/hello';
47
47
  var helloParams = '{"name":"webOS"}';
@@ -80,7 +80,7 @@ const log = require('npmlog'),
80
80
  "INVALID_TEMPLATE": "Invalid template name",
81
81
  "INVALID_FILE": "Invalid file",
82
82
  "INVALID_VALUE": "Invalid value",
83
- "INVALID_DEVICENAME": "Invalid device name. The device name should consist of letters, numbers, and special characters ('-','_','#') and should start with letters or '_'",
83
+ "INVALID_DEVICENAME": "Invalid device name. The device name should not start with '%' or '$'",
84
84
  "INVALID_OBJECT": "Object format error",
85
85
  "INVALID_MODE": "Please specify an option, either '--add' or '--modify'",
86
86
  "INVALID_REMOVE_MODE": "Please set remove option",
@@ -107,7 +107,7 @@ const log = require('npmlog'),
107
107
  "NOT_EXIST_SSHKEY_PASSWD": "Private key file or password does not exist",
108
108
  "NOT_EXIST_DISPLAY": "No existing displayId from getSessionList",
109
109
  "NOT_EXIST_SIMULATOR": "No existing simulator excutable file which name starting with",
110
- "NOT_SUPPORT_COMMOND_DEPRECATED": "This command is deprecated. Please use \"ares-device\" instead of \"ares-device-info\"",
110
+ "NOT_SUPPORT_COMMOND_DEPRECATED": "This command is deprecated. Please use \"ares-device -i\" instead of \"ares-device-info\"",
111
111
  "NOT_SUPPORT_COMMOND": "This command is not supported by current profile\nIf you want to use this command, please change profile using \"ares-config\" command\nCurrent profile:",
112
112
  "NOT_SUPPORT_OPTION": "This option is not supported by current profile\nIf you want to use this command, please change profile using \"ares-config\" command\nCurrent profile:",
113
113
  "NOT_SUPPORT_SESSION": "This device does not support multiple sessions",
@@ -593,7 +593,7 @@ const async = require('async'),
593
593
 
594
594
  if (!this.ssh) {
595
595
  this.forwardedPorts = [];
596
- this.ssh = new Ssh2();
596
+ this.ssh = new Ssh2.Client();
597
597
  this.ssh.on('connect', function() {
598
598
  log.info("novacom#Session()#begin()", "ssh session event: connected");
599
599
  });
@@ -907,7 +907,7 @@ const async = require('async'),
907
907
  log.silly("novacom#Session()#run()", "stdout: function");
908
908
  write.stdout = stdout;
909
909
  } else {
910
- setImmediate(next, errHndl.getErrMsg("INVALID_VALUE", "stdout", util.inspect(stdout)));
910
+ return setImmediate(next, errHndl.getErrMsg("INVALID_VALUE", "stdout", util.inspect(stdout)));
911
911
  }
912
912
 
913
913
  if (!stderr) {
@@ -921,7 +921,7 @@ const async = require('async'),
921
921
  log.silly("novacom#Session()#run()", "stderr: function");
922
922
  write.stderr = stderr;
923
923
  } else {
924
- setImmediate(next, errHndl.getErrMsg("INVALID_VALUE", "stderr", util.inspect(stderr)));
924
+ return setImmediate(next, errHndl.getErrMsg("INVALID_VALUE", "stderr", util.inspect(stderr)));
925
925
  }
926
926
 
927
927
  // execute command
@@ -964,7 +964,7 @@ const async = require('async'),
964
964
  chStream.on('close', function() {
965
965
  log.silly("novacom#Session()#run()", "event close (cmd:" + cmd + ")");
966
966
  if (err === undefined) {
967
- setImmediate(next);
967
+ setImmediate(next);
968
968
  }
969
969
  });
970
970
 
@@ -19,18 +19,8 @@ const async = require('async'),
19
19
 
20
20
  const appdata = new Appdata(),
21
21
  devicetools = {},
22
- defaultDeviceInfo = {
23
- profile: appdata.getConfig(true).profile,
24
- host: "127.0.0.1",
25
- port: 22,
26
- username: "root",
27
- description: "new device description",
28
- files: "stream",
29
- default: false
30
- };
31
- if(defaultDeviceInfo.profile !== "ose"){
32
- defaultDeviceInfo.type = "starfish";
33
- }
22
+ defaultDeviceInfo = appdata.getConfig(true).defaultDeviceInfo;
23
+ defaultDeviceInfo.profile = appdata.getConfig(true).profile;
34
24
 
35
25
  if (typeof module !== 'undefined' && module.exports) {
36
26
  module.exports = devicetools;
@@ -38,11 +28,11 @@ const async = require('async'),
38
28
  module.exports.isValidIpv4 = isValidIpv4;
39
29
  module.exports.isValidPort =isValidPort;
40
30
  module.exports.replaceDefaultDeviceInfo = replaceDefaultDeviceInfo;
31
+ module.exports.displayGetKeyGuide = displayGetKeyGuide;
41
32
  }
42
33
 
43
34
  function isValidDeviceName(name) {
44
- const re = new RegExp("^[_a-zA-Z][a-zA-Z0-9#_-]*");
45
- return (name === String(name.match(re)));
35
+ return ['$', '%'].indexOf(name[0]) === -1;
46
36
  }
47
37
 
48
38
  function isValidIpv4(host) {
@@ -210,11 +200,17 @@ const async = require('async'),
210
200
  async.series([
211
201
  resolver.load.bind(resolver),
212
202
  resolver.modifyDeviceFile.bind(resolver, mode, inDevice),
213
- this.showDeviceList.bind(this, next)
214
- ], function(err) {
203
+ this.showDeviceList.bind(this),
204
+ ], function(err, results) {
215
205
  if (err) {
216
206
  return next(err);
217
207
  }
208
+ if(results[2] && results[2].msg){
209
+ console.log(results[2].msg);
210
+ }
211
+ if(inDevice.username === 'prisoner' && mode === 'add'){
212
+ displayGetKeyGuide(inDevice.name);
213
+ }
218
214
  next();
219
215
  });
220
216
  } catch (err) {
@@ -317,12 +313,23 @@ const async = require('async'),
317
313
  if (inDevice) {
318
314
  inDevice.profile = inDevice.profile || defaultDeviceInfo.profile;
319
315
  inDevice.type = inDevice.type || defaultDeviceInfo.type;
320
- inDevice.host = inDevice.host || defaultDeviceInfo.host;
316
+ inDevice.host = inDevice.host || defaultDeviceInfo.ipAddress;
321
317
  inDevice.port = inDevice.port || defaultDeviceInfo.port;
322
- inDevice.username = inDevice.username || defaultDeviceInfo.username;
318
+ inDevice.username = inDevice.username || defaultDeviceInfo.user;
323
319
  inDevice.files = inDevice.files || defaultDeviceInfo.files;
324
320
  inDevice.description = inDevice.description || defaultDeviceInfo.description;
325
321
  inDevice.default = inDevice.default || defaultDeviceInfo.default;
326
322
  }
327
323
  }
324
+
325
+ function displayGetKeyGuide(deviceName) {
326
+ const guideSteps = "** To connect to TV you need to do following steps:"
327
+ + "\n 1. Turning on Developer Mode following this guide: https://webostv.developer.lge.com/develop/getting-started/developer-mode-app"
328
+ + "\n 2. Launch the Developer Mode app and click the Key Server button in the Developer Mode app"
329
+ + "\n 3. Get the ssh key file from your webOS TV with the following command on your PC"
330
+ + "\n > ares-novacom --device " + deviceName + " --getkey"
331
+ + "\n > Enter the passphrase displayed on the Developer Mode app";
332
+
333
+ console.log(guideSteps);
334
+ }
328
335
  }());
package/lib/inspect.js CHANGED
@@ -425,7 +425,7 @@ let platformNodeVersion = "0";
425
425
  break;
426
426
  }
427
427
  }
428
- next();
428
+ next(null, listFiles);
429
429
  });
430
430
  }
431
431
 
@@ -460,8 +460,8 @@ let platformNodeVersion = "0";
460
460
  }
461
461
 
462
462
  async.whilst(
463
- function() {
464
- return listFiles.length > 0;
463
+ function(callBack) {
464
+ callBack(null, listFiles && listFiles.length > 0);
465
465
  },
466
466
  _getDisplayUrl.bind(this),
467
467
  function(err) {
package/lib/log.js CHANGED
@@ -64,8 +64,8 @@ const util = require('util'),
64
64
 
65
65
  function _onData(data) {
66
66
  log.info("log#show()#_onData()");
67
- const str = (Buffer.isBuffer(data)) ? data.toString() : data;
68
- console.log(str.trim()); // Do not remove
67
+ const strLogs = (Buffer.isBuffer(data)) ? data.toString() : data;
68
+ process.stdout.write(strLogs);
69
69
 
70
70
  if (options.argv.save) {
71
71
  fs.writeFileSync(savedFilePath, data, {encoding: 'utf8', flag:'a'});
@@ -569,13 +569,13 @@ const util = require('util'),
569
569
  return next(errHndl.getErrMsg(err));
570
570
  }
571
571
  fs.closeSync(fd);
572
+ next();
572
573
  });
573
574
  // Defense code
574
575
  if (fs.existsSync(savedFilePath)) {
575
576
  fs.unlinkSync(savedFilePath);
576
577
  }
577
578
  log.verbose("log#createLogFile()", savedFilePath + " is exist: " + fs.existsSync(savedFilePath));
578
- next();
579
579
  }
580
580
 
581
581
  if (typeof module !== 'undefined' && module.exports) {
package/lib/package.js CHANGED
@@ -25,9 +25,8 @@ const ar = require('ar-async'),
25
25
  temp = require('temp'),
26
26
  uglify = require('terser'),
27
27
  util = require('util'),
28
- zlib = require('zlib'),
29
- tarFilterPack = require('./tar-filter-pack'),
30
- errHndl = require('./base/error-handler');
28
+ errHndl = require('./base/error-handler'),
29
+ tar = require('tar');
31
30
 
32
31
  (function() {
33
32
  log.heading = 'packager';
@@ -1426,31 +1425,50 @@ const ar = require('ar-async'),
1426
1425
  const pkgServiceNames = this.pkgServiceNames;
1427
1426
  // @see https://github.com/isaacs/node-tar/issues/7
1428
1427
  // it is a workaround for packaged ipk on windows can set +x into directory
1429
- const fixupDirs = function(entry) {
1428
+ const fixupDirs = function (filePath, entry) {
1429
+ const fileOrFolderName = filePath.split("/").pop();
1430
+ // opkg does not support Posix Tar fully
1431
+ if (fileOrFolderName.length !== Buffer.byteLength(fileOrFolderName)) {
1432
+ const errMsg = "Please use the file name in english letters. \n\t\t (" + filePath + ")",
1433
+ em = new (require('events').EventEmitter)();
1434
+ em.emit('error', new Error(errMsg));
1435
+ }
1430
1436
  // Make sure readable directories have execute permission
1431
- if (entry.props.type === "Directory") {
1437
+ if (entry.isDirectory()) {
1432
1438
  let maskingBits = 201; // 0311
1433
1439
  // special case for service directory should have writable permission.
1434
- if (pkgServiceNames.indexOf(entry.props.basename) !== -1) {
1440
+ if (pkgServiceNames.indexOf(fileOrFolderName) !== -1) {
1435
1441
  maskingBits = 219; // 0333
1436
1442
  }
1437
- entry.props.mode |= (entry.props.mode >>> 2) & maskingBits;
1438
- } else if (entry.props.type === "File") {
1443
+ entry.mode |= (entry.mode >>> 2) & maskingBits;
1444
+ } else if (entry.isFile()) {
1439
1445
  // Add other user's readable permission to all files
1440
- entry.props.mode |= 4; // 04
1446
+ entry.mode |= 4; // 04
1447
+ }
1448
+ if (entry.uid > 0o7777777) {
1449
+ entry.uid = 0;
1450
+ }
1451
+
1452
+ if (entry.gid > 0o7777777) {
1453
+ entry.gid = 0;
1441
1454
  }
1455
+
1442
1456
  return true;
1443
1457
  };
1444
1458
 
1445
- // TODO: when this PR (https://github.com/npm/node-tar/pull/73) is merged, need to update node-tar
1446
- fstream
1447
- .Reader({path: srcDir, type: 'Directory', filter: fixupDirs })
1448
- .pipe(tarFilterPack({ noProprietary: true, fromBase: true, permission: this.packageProperties }))
1449
- // .pipe(tarFilterPack({ noProprietary: true, pathFilter: filter, permission: this.packageProperties }))
1450
- .pipe(zlib.createGzip())
1451
- .pipe(fs.createWriteStream(dstDir))
1452
- .on("close", next)
1453
- .on('error', next);
1459
+ fs.readdir(srcDir, function (err, fileList) {
1460
+ if (err) setImmediate(next, err);
1461
+ else {
1462
+ tar.c({
1463
+ file: dstDir,
1464
+ gzip: true,
1465
+ cwd: srcDir,
1466
+ filter: fixupDirs
1467
+ }, fileList)
1468
+ .then(() => setImmediate(next))
1469
+ .catch(error => setImmediate(next, error));
1470
+ }
1471
+ });
1454
1472
  }
1455
1473
 
1456
1474
  function setIpkFileName(next) {
@@ -1601,7 +1619,7 @@ const ar = require('ar-async'),
1601
1619
  this.rscCount++;
1602
1620
  log.verbose("FOUND resourceinfo.json, rscCount " + this.rscCount);
1603
1621
  if (this.appCount > 0 || this.svcDir && this.svcDir.length > 0) {
1604
- callback(errHndl.getErrMsg("NOT_PACKAGE_WITH_RESOURCE"));
1622
+ return callback(errHndl.getErrMsg("NOT_PACKAGE_WITH_RESOURCE"));
1605
1623
  }
1606
1624
  this.resources = this.resources || [];
1607
1625
  const rsc = {};
@@ -2078,7 +2096,7 @@ const ar = require('ar-async'),
2078
2096
  fs.writeFileSync(ivFilePath, encryptedIV, 'binary');
2079
2097
 
2080
2098
  } catch (err) {
2081
- setImmediate(next, errHndl.getErrMsg(err));
2099
+ return setImmediate(next, errHndl.getErrMsg(err));
2082
2100
  }
2083
2101
  setImmediate(next);
2084
2102
  }