zmp-cli 3.6.0 → 3.7.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/dist/index.dev.js CHANGED
@@ -47,7 +47,9 @@ var buildApp = require('./build/index');
47
47
 
48
48
  var deployApp = require('./deploy/index');
49
49
 
50
- var migrateApp = require('./migrate/index'); // const generateAssets = require('./assets/index');
50
+ var migrateApp = require('./migrate/index');
51
+
52
+ var os = require('os'); // const generateAssets = require('./assets/index');
51
53
  // const server = require('./ui/server');
52
54
 
53
55
 
@@ -178,7 +180,7 @@ program.usage('<command> [options]').command('login').description('Login ZMP').a
178
180
  }
179
181
  });
180
182
  });
181
- program.usage('<command> [options]').command('start').option('-P, --port <n>', 'Specify server port. By default it is 3000', parseInt).option('-U, --show-mobile-ui', 'Show Mobile UI').option('-Z, --zalo-app', 'Preview on zalo').option('-D, --dev', 'Development environment').description('Start a ZMP project').action(function _callee3(options) {
183
+ program.usage('<command> [options]').command('start').option('-iosH, --ios-host-name <n>', 'Specify server hostname. By default it is os.hostname').option('-P, --port <n>', 'Specify server port. By default it is 3000', parseInt).option('-Z, --zalo-app', 'Preview on zalo').option('-ios, --ios', 'Run on ios').option('-D, --dev', 'Development environment').description('Start a ZMP project').action(function _callee3(options) {
182
184
  var currentProject;
183
185
  return regeneratorRuntime.async(function _callee3$(_context3) {
184
186
  while (1) {
@@ -204,8 +206,10 @@ program.usage('<command> [options]').command('start').option('-P, --port <n>', '
204
206
  return regeneratorRuntime.awrap(startApp({
205
207
  cwd: cwd,
206
208
  port: options && options.port || 3000,
209
+ iosHostName: options && options.iosHostName || os.hostname(),
207
210
  showMobileUI: options && options.showMobileUi || false,
208
- previewOnZalo: options && options.zaloApp || false
211
+ previewOnZalo: options && options.zaloApp || false,
212
+ ios: options && options.ios || false
209
213
  }, logger));
210
214
 
211
215
  case 5:
package/index.js CHANGED
@@ -20,6 +20,7 @@ const startApp = require('./start/index');
20
20
  const buildApp = require('./build/index');
21
21
  const deployApp = require('./deploy/index');
22
22
  const migrateApp = require('./migrate/index');
23
+ const os = require('os');
23
24
  // const generateAssets = require('./assets/index');
24
25
  // const server = require('./ui/server');
25
26
  const pkg = require('./package.json');
@@ -107,13 +108,17 @@ program
107
108
  program
108
109
  .usage('<command> [options]')
109
110
  .command('start')
111
+ .option(
112
+ '-iosH, --ios-host-name <n>',
113
+ 'Specify server hostname. By default it is os.hostname'
114
+ )
110
115
  .option(
111
116
  '-P, --port <n>',
112
117
  'Specify server port. By default it is 3000',
113
118
  parseInt
114
119
  )
115
- .option('-U, --show-mobile-ui', 'Show Mobile UI')
116
120
  .option('-Z, --zalo-app', 'Preview on zalo')
121
+ .option('-ios, --ios', 'Run on ios')
117
122
  .option('-D, --dev', 'Development environment')
118
123
  .description('Start a ZMP project')
119
124
  .action(async (options) => {
@@ -138,8 +143,10 @@ program
138
143
  {
139
144
  cwd,
140
145
  port: (options && options.port) || 3000,
146
+ iosHostName: (options && options.iosHostName) || os.hostname(),
141
147
  showMobileUI: (options && options.showMobileUi) || false,
142
148
  previewOnZalo: (options && options.zaloApp) || false,
149
+ ios: (options && options.ios) || false,
143
150
  },
144
151
  logger
145
152
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmp-cli",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "ZMP command line utility (CLI)",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -15,6 +15,8 @@ var ora = require('ora');
15
15
 
16
16
  var path = require('path');
17
17
 
18
+ var os = require('os');
19
+
18
20
  var qrcode = require('qrcode-terminal');
19
21
 
20
22
  var logSymbols = require('log-symbols');
@@ -41,8 +43,9 @@ module.exports = function _callee() {
41
43
  errorExit,
42
44
  cwd,
43
45
  appId,
44
- isShowMobileUI,
45
46
  previewOnZalo,
47
+ isIOS,
48
+ iosHostName,
46
49
  host,
47
50
  port,
48
51
  hrConfigPath,
@@ -84,11 +87,12 @@ module.exports = function _callee() {
84
87
  spinner.start();
85
88
  cwd = options.cwd || process.cwd();
86
89
  appId = options.appId || envUtils.getEnv(config.env.appId);
87
- isShowMobileUI = options.showMobileUI;
88
90
  previewOnZalo = options.previewOnZalo;
89
- host = 'localhost';
91
+ isIOS = options.ios;
92
+ iosHostName = options.iosHostName;
93
+ host = isIOS ? iosHostName : 'localhost';
90
94
  port = options.port;
91
- _context.prev = 12;
95
+ _context.prev = 13;
92
96
 
93
97
  if (previewOnZalo) {
94
98
  hrConfigPath = path.join(cwd, 'hr.config.json');
@@ -108,8 +112,8 @@ module.exports = function _callee() {
108
112
 
109
113
  localServer = {};
110
114
  publicServer = {
111
- // host: '0.0.0.0',
112
- https: true,
115
+ host: '0.0.0.0',
116
+ https: !isIOS,
113
117
  hmr: {
114
118
  host: host
115
119
  }
@@ -121,7 +125,7 @@ module.exports = function _callee() {
121
125
  viteConfig = 'vite.config.ts';
122
126
  }
123
127
 
124
- _context.next = 21;
128
+ _context.next = 22;
125
129
  return regeneratorRuntime.awrap(createServer({
126
130
  configFile: path.join(cwd, viteConfig),
127
131
  root: cwd,
@@ -134,20 +138,20 @@ module.exports = function _callee() {
134
138
  }, previewOnZalo ? publicServer : localServer)
135
139
  }));
136
140
 
137
- case 21:
141
+ case 22:
138
142
  server = _context.sent;
139
- _context.next = 24;
143
+ _context.next = 25;
140
144
  return regeneratorRuntime.awrap(server.listen());
141
145
 
142
- case 24:
146
+ case 25:
143
147
  app = _context.sent;
144
148
 
145
149
  if (previewOnZalo) {
146
- _context.next = 35;
150
+ _context.next = 36;
147
151
  break;
148
152
  }
149
153
 
150
- _context.next = 28;
154
+ _context.next = 29;
151
155
  return regeneratorRuntime.awrap(createServer({
152
156
  // any valid user config options, plus `mode` and `configFile`
153
157
  configFile: false,
@@ -159,73 +163,85 @@ module.exports = function _callee() {
159
163
  }
160
164
  }));
161
165
 
162
- case 28:
166
+ case 29:
163
167
  serverFrame = _context.sent;
164
- _context.next = 31;
168
+ _context.next = 32;
165
169
  return regeneratorRuntime.awrap(serverFrame.listen());
166
170
 
167
- case 31:
171
+ case 32:
168
172
  spinner.stop();
169
173
  info = serverFrame.config.logger.info;
170
174
  info(chalk.green("Zalo Mini App dev server is running at:\n"));
171
175
  serverFrame.printUrls();
172
176
 
173
- case 35:
177
+ case 36:
174
178
  spinner.stop();
175
- _context.next = 38;
179
+ _context.next = 39;
176
180
  return regeneratorRuntime.awrap(new Promise(function () {
177
- var previewOnZaloURL = "https://zalo.me/app/link/zapps/".concat(appId, "/?env=TESTING_LOCAL&clientIp=https://").concat(host, ":").concat(app.config.server.port);
178
-
179
- if (isShowMobileUI) {
180
- var nw = require('nw');
181
-
182
- require('child_process').exec("".concat(nw.findpath(), " ").concat(path.join(__dirname, 'phone-app'), " url=https://").concat(host, ":").concat(port, " appId=").concat(appId, " cwd=").concat(process.cwd(), " previewOnZalo=").concat(previewOnZalo)).unref();
183
- } else if (previewOnZalo) {
181
+ var previewOnZaloURL = "https://zalo.me/app/link/zapps/".concat(appId, "/?env=TESTING_LOCAL&clientIp=").concat(isIOS ? 'http' : 'https', "://").concat(host, ":").concat(app.config.server.port); // if (isShowMobileUI) {
182
+ // const nw = require('nw');
183
+ // require('child_process')
184
+ // .exec(
185
+ // `${nw.findpath()} ${path.join(
186
+ // __dirname,
187
+ // 'phone-app'
188
+ // )} url=https://${host}:${port} appId=${appId} cwd=${process.cwd()} previewOnZalo=${previewOnZalo}`
189
+ // )
190
+ // .unref();
191
+ // } else
192
+
193
+ if (previewOnZalo) {
184
194
  qrcode.generate(previewOnZaloURL, {
185
195
  small: true
186
196
  }, function (qrcode) {
187
197
  logger.text(chalk.green("".concat(logSymbols.info, " ").concat(chalk.bold("Zalo Mini App dev server is running at: ".concat(host, ":").concat(app.config.server.port)))));
188
198
  logger.text(chalk.green("".concat(logSymbols.info, " ").concat(chalk.bold("Trying reverse socket connection"))));
189
199
 
190
- var processAdbReverse = require('child_process').spawn("adb", ['reverse', "tcp:".concat(app.config.server.port), "tcp:".concat(app.config.server.port)]);
191
-
192
- processAdbReverse.stderr.on('data', function (data) {
193
- logger.error(data.toString());
194
- });
195
- processAdbReverse.on('exit', function (code) {
196
- if (code !== 0) {
197
- throw new Error("adb reverse error: ".concat(code));
198
- } else {
199
- var qrCode = "".concat(logSymbols.info, " ").concat(chalk.bold("Scan the QR code with Zalo app:\n".concat(qrcode)));
200
- logger.text(qrCode);
201
-
202
- var processAdbDevices = require('child_process').spawn("adb", ['devices']);
203
-
204
- processAdbDevices.stdout.on('data', function (data) {
205
- logger.text("".concat(chalk.yellow(data.toString())));
206
- });
207
- }
208
- });
200
+ if (isIOS) {
201
+ var qrCode = "".concat(logSymbols.info, " ").concat(chalk.bold("Scan the QR code with Zalo app:\n".concat(qrcode)));
202
+ logger.text(qrCode);
203
+ } else {
204
+ var processAdbReverse = require('child_process').spawn("adb", ['reverse', "tcp:".concat(app.config.server.port), "tcp:".concat(app.config.server.port)]);
205
+
206
+ processAdbReverse.stderr.on('data', function (data) {
207
+ logger.error(data.toString());
208
+ });
209
+ processAdbReverse.on('exit', function (code) {
210
+ if (code !== 0) {
211
+ throw new Error("adb reverse error: ".concat(code));
212
+ } else {
213
+ var _qrCode = "".concat(logSymbols.info, " ").concat(chalk.bold("Scan the QR code with Zalo app:\n".concat(qrcode)));
214
+
215
+ logger.text(_qrCode);
216
+
217
+ var processAdbDevices = require('child_process').spawn("adb", ['devices']);
218
+
219
+ processAdbDevices.stdout.on('data', function (data) {
220
+ logger.text("".concat(chalk.yellow(data.toString())));
221
+ });
222
+ }
223
+ });
224
+ }
209
225
  });
210
226
  }
211
227
  }));
212
228
 
213
- case 38:
229
+ case 39:
214
230
  return _context.abrupt("return", _context.sent);
215
231
 
216
- case 41:
217
- _context.prev = 41;
218
- _context.t0 = _context["catch"](12);
232
+ case 42:
233
+ _context.prev = 42;
234
+ _context.t0 = _context["catch"](13);
219
235
  logger.statusError('Error starting project'); // if (err) logger.error(err.stderr || err);
220
236
 
221
237
  logger.error(_context.t0);
222
238
  errorExit(_context.t0);
223
239
  return _context.abrupt("return");
224
240
 
225
- case 47:
241
+ case 48:
226
242
  case "end":
227
243
  return _context.stop();
228
244
  }
229
245
  }
230
- }, null, null, [[12, 41]]);
246
+ }, null, null, [[13, 42]]);
231
247
  };
package/start/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const chalk = require('chalk');
4
4
  const ora = require('ora');
5
5
  const path = require('path');
6
+ const os = require('os');
6
7
  const qrcode = require('qrcode-terminal');
7
8
  const logSymbols = require('log-symbols');
8
9
  const { createServer } = require('vite');
@@ -32,9 +33,10 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
32
33
  spinner.start();
33
34
  const cwd = options.cwd || process.cwd();
34
35
  const appId = options.appId || envUtils.getEnv(config.env.appId);
35
- const isShowMobileUI = options.showMobileUI;
36
36
  const previewOnZalo = options.previewOnZalo;
37
- const host = 'localhost';
37
+ const isIOS = options.ios;
38
+ const iosHostName = options.iosHostName;
39
+ const host = isIOS ? iosHostName : 'localhost';
38
40
  const port = options.port;
39
41
  try {
40
42
  if (previewOnZalo) {
@@ -56,8 +58,8 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
56
58
  const localServer = {};
57
59
 
58
60
  const publicServer = {
59
- // host: '0.0.0.0',
60
- https: true,
61
+ host: '0.0.0.0',
62
+ https: !isIOS,
61
63
  hmr: {
62
64
  host: host,
63
65
  },
@@ -108,18 +110,21 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
108
110
 
109
111
  spinner.stop();
110
112
  return await new Promise(() => {
111
- const previewOnZaloURL = `https://zalo.me/app/link/zapps/${appId}/?env=TESTING_LOCAL&clientIp=https://${host}:${app.config.server.port}`;
112
- if (isShowMobileUI) {
113
- const nw = require('nw');
114
- require('child_process')
115
- .exec(
116
- `${nw.findpath()} ${path.join(
117
- __dirname,
118
- 'phone-app'
119
- )} url=https://${host}:${port} appId=${appId} cwd=${process.cwd()} previewOnZalo=${previewOnZalo}`
120
- )
121
- .unref();
122
- } else if (previewOnZalo) {
113
+ const previewOnZaloURL = `https://zalo.me/app/link/zapps/${appId}/?env=TESTING_LOCAL&clientIp=${
114
+ isIOS ? 'http' : 'https'
115
+ }://${host}:${app.config.server.port}`;
116
+ // if (isShowMobileUI) {
117
+ // const nw = require('nw');
118
+ // require('child_process')
119
+ // .exec(
120
+ // `${nw.findpath()} ${path.join(
121
+ // __dirname,
122
+ // 'phone-app'
123
+ // )} url=https://${host}:${port} appId=${appId} cwd=${process.cwd()} previewOnZalo=${previewOnZalo}`
124
+ // )
125
+ // .unref();
126
+ // } else
127
+ if (previewOnZalo) {
123
128
  qrcode.generate(previewOnZaloURL, { small: true }, function (qrcode) {
124
129
  logger.text(
125
130
  chalk.green(
@@ -135,33 +140,41 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
135
140
  )}`
136
141
  )
137
142
  );
138
- const processAdbReverse = require('child_process').spawn(`adb`, [
139
- 'reverse',
140
- `tcp:${app.config.server.port}`,
141
- `tcp:${app.config.server.port}`,
142
- ]);
143
+ if (isIOS) {
144
+ const qrCode = `${logSymbols.info} ${chalk.bold(
145
+ `Scan the QR code with Zalo app:\n${qrcode}`
146
+ )}`;
147
+ logger.text(qrCode);
148
+ } else {
149
+ const processAdbReverse = require('child_process').spawn(`adb`, [
150
+ 'reverse',
151
+ `tcp:${app.config.server.port}`,
152
+ `tcp:${app.config.server.port}`,
153
+ ]);
143
154
 
144
- processAdbReverse.stderr.on('data', function (data) {
145
- logger.error(data.toString());
146
- });
155
+ processAdbReverse.stderr.on('data', function (data) {
156
+ logger.error(data.toString());
157
+ });
147
158
 
148
- processAdbReverse.on('exit', function (code) {
149
- if (code !== 0) {
150
- throw new Error(`adb reverse error: ${code}`);
151
- } else {
152
- const qrCode = `${logSymbols.info} ${chalk.bold(
153
- `Scan the QR code with Zalo app:\n${qrcode}`
154
- )}`;
155
- logger.text(qrCode);
156
- const processAdbDevices = require('child_process').spawn(`adb`, [
157
- 'devices',
158
- ]);
159
+ processAdbReverse.on('exit', function (code) {
160
+ if (code !== 0) {
161
+ throw new Error(`adb reverse error: ${code}`);
162
+ } else {
163
+ const qrCode = `${logSymbols.info} ${chalk.bold(
164
+ `Scan the QR code with Zalo app:\n${qrcode}`
165
+ )}`;
166
+ logger.text(qrCode);
167
+ const processAdbDevices = require('child_process').spawn(
168
+ `adb`,
169
+ ['devices']
170
+ );
159
171
 
160
- processAdbDevices.stdout.on('data', function (data) {
161
- logger.text(`${chalk.yellow(data.toString())}`);
162
- });
163
- }
164
- });
172
+ processAdbDevices.stdout.on('data', function (data) {
173
+ logger.text(`${chalk.yellow(data.toString())}`);
174
+ });
175
+ }
176
+ });
177
+ }
165
178
  });
166
179
  }
167
180
  });