zmp-cli 3.4.0 → 3.5.1

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/build/index.js CHANGED
@@ -91,7 +91,9 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
91
91
  ZMP_IMPORT_PAGES: () => generatePagesMap(cwd),
92
92
  },
93
93
  }),
94
- dynamicImportVars(),
94
+ dynamicImportVars({
95
+ warnOnError: true,
96
+ }),
95
97
  ],
96
98
  output: {
97
99
  entryFileNames: 'assets/[name].[hash].module.js',
@@ -1,29 +1,60 @@
1
1
  "use strict";
2
2
 
3
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
4
+
5
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
6
+
7
+ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
8
+
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
10
+
3
11
  var generateNpmScripts = require('./generate-npm-scripts');
4
12
 
13
+ var _require = require('./generate-npm-scripts'),
14
+ generateTailWindScripts = _require.generateTailWindScripts;
15
+
5
16
  module.exports = function generatePackageJson(options) {
6
17
  var name = options.name,
7
18
  framework = options.framework,
8
- cssPreProcessor = options.cssPreProcessor; // Dependencies
19
+ cssPreProcessor = options.cssPreProcessor,
20
+ includeTailwind = options.includeTailwind; // Dependencies
9
21
 
10
22
  var dependencies = ['zmp-framework', 'zmp-sdk', 'swiper'];
11
23
  var dependenciesVue = ['vue@3'];
12
24
  var dependenciesReact = ['react', 'react-dom', 'prop-types'];
13
- if (framework === 'vue') dependencies.push.apply(dependencies, dependenciesVue);else if (framework === 'react') dependencies.push.apply(dependencies, dependenciesReact);
14
- var devDependencies = ['cross-env', 'postcss-preset-env', 'vite']; // CSS PreProcessor
25
+ var dependenciesReactTs = ['@types/react', '@types/react-dom'];
26
+ var tailwindDependencies = ['autoprefixer', 'tailwindcss', 'postcss@^8', 'postcss-cli@^8'];
27
+
28
+ if (framework === 'vue') {
29
+ dependencies.push.apply(dependencies, dependenciesVue);
30
+ } else if (framework === 'react' || framework === 'react-typescript') {
31
+ dependencies.push.apply(dependencies, dependenciesReact);
32
+ }
33
+
34
+ if (framework === 'react-typescript') {
35
+ dependencies.push.apply(dependencies, dependenciesReactTs);
36
+ }
37
+
38
+ var devDependencies = ['cross-env', 'postcss-preset-env@6.7.0', 'vite']; // CSS PreProcessor
15
39
 
16
40
  if (cssPreProcessor === 'stylus') devDependencies.push.apply(devDependencies, ['stylus']);else if (cssPreProcessor === 'less') devDependencies.push.apply(devDependencies, ['less']);else if (cssPreProcessor === 'scss') devDependencies.push.apply(devDependencies, ['sass']); // DevDependencies
17
41
 
18
42
  var devDependenciesCore = ['zmp-loader'];
19
43
  var devDependenciesReact = ['@vitejs/plugin-react-refresh'];
20
44
  var devDependenciesVue = ['@vitejs/plugin-vue', '@vue/compiler-sfc'];
21
- if (framework === 'react') devDependencies.push.apply(devDependencies, [devDependenciesReact]);else if (framework === 'vue') devDependencies.push.apply(devDependencies, [devDependenciesVue]);else if (framework === 'core') devDependencies.push.apply(devDependencies, [devDependenciesCore]); // Scripts
45
+ if (framework === 'react' || framework === 'react-typescript') devDependencies.push.apply(devDependencies, [devDependenciesReact].concat(_toConsumableArray(includeTailwind ? tailwindDependencies : [])));else if (framework === 'vue') devDependencies.push.apply(devDependencies, [devDependenciesVue]);else if (framework === 'core') devDependencies.push.apply(devDependencies, [devDependenciesCore]); // Scripts
22
46
 
23
47
  var scripts = {};
24
48
  generateNpmScripts().forEach(function (s) {
25
49
  scripts[s.name] = s.script;
26
50
  });
51
+
52
+ if (includeTailwind) {
53
+ generateTailWindScripts().forEach(function (s) {
54
+ scripts[s.name] = s.script;
55
+ });
56
+ }
57
+
27
58
  var postInstall = [];
28
59
 
29
60
  if (postInstall.length) {
@@ -25,7 +25,7 @@ module.exports = function generatePackageJson(options) {
25
25
  if (framework === 'react-typescript') {
26
26
  dependencies.push(...dependenciesReactTs);
27
27
  }
28
- const devDependencies = ['cross-env', 'postcss-preset-env', 'vite'];
28
+ const devDependencies = ['cross-env', 'postcss-preset-env@6.7.0', 'vite'];
29
29
  // CSS PreProcessor
30
30
  if (cssPreProcessor === 'stylus') devDependencies.push(...['stylus']);
31
31
  else if (cssPreProcessor === 'less') devDependencies.push(...['less']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmp-cli",
3
- "version": "3.4.0",
3
+ "version": "3.5.1",
4
4
  "description": "ZMP command line utility (CLI)",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -72,7 +72,6 @@
72
72
  "mini-css-extract-plugin": "^1.3.7",
73
73
  "minimist": "^1.2.5",
74
74
  "multer": "^1.4.2",
75
- "node-blob": "^0.0.2",
76
75
  "normalize-path": "^3.0.0",
77
76
  "opn": "^6.0.0",
78
77
  "ora": "^3.4.0",
@@ -87,7 +86,7 @@
87
86
  "terser-webpack-plugin": "^5.1.1",
88
87
  "toastr": "^2.1.4",
89
88
  "touch": "^3.1.0",
90
- "vite": "^2.1.5",
89
+ "vite": "^2.6.14",
91
90
  "vite-plugin-replace": "^0.1.1",
92
91
  "xhr2": "^0.2.1",
93
92
  "xmlhttprequest": "^1.8.0",
@@ -1,143 +1,156 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta
6
- http-equiv="Content-Security-Policy"
7
- content="default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content:"
8
- />
9
- <meta
10
- name="viewport"
11
- content="width=device-width, initial-scale=1, viewport-fit=cover"
12
- />
13
-
14
- <meta name="theme-color" content="#007aff" />
15
- <meta name="format-detection" content="telephone=no" />
16
- <meta name="msapplication-tap-highlight" content="no" />
17
- <link rel="icon" href="/src/static/icons/favicon.png" />
18
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" integrity="sha512-1ycn6IcaQQ40/MKBW2W4Rhis/DbILU74C1vSrLJxCq57o941Ym01SwNsOMqvEBFlcgUa6xLiPY/NS5R+E6ztJQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
19
- <script>
20
- fetch('http://localhost:3000/app-config.json')
21
- .then(response => response.json())
22
- .then(data => {
23
- if (data.app.title) {
24
- document.getElementById('title').innerHTML = data.app.title;
25
- document.title = data.app.title;
26
- }
27
- if (data.app.headerColor) {
28
- document.getElementById('header').style.backgroundColor = data.app.headerColor;
29
- }
30
- if (data.app.statusBarColor) {
31
- document.getElementById('statusbar').style.backgroundColor = data.app.statusBarColor;
32
- }
33
- if (data.app.textColor) {
34
- document.getElementById('statusbar').style.color = data.app.textColor;
35
- document.getElementById('header').style.color = data.app.textColor;
36
- }
37
- });
38
- </script>
39
-
40
- <title>Water Reminder1</title>
41
- <style>
42
- body {
43
- font-family: -apple-system, BlinkMacSystemFont, sans-serif;
44
- margin: 0px;
45
- }
46
- #zalo-frame {
47
- width: 100%;
48
- height: calc(100vh - 74px);
49
- border: none;
50
- overflow: auto;
51
- cursor: grab;
52
- }
53
- .wrapper-frame {
54
- width: 100%;
55
- height: 100vh;
56
- background-color: black;
57
- margin: auto;
58
- }
59
- .status-bar {
60
- height: 30px;
61
- background-color: #0068FF;
62
- color: white;
63
- font-size: 13px;
64
- }
65
- .status-bar .right {
66
- float: right;
67
- padding: 6px;
68
- }
69
- .status-bar .left {
70
- float: left;
71
- padding: 6px;
72
- margin-left: 5px;
73
- }
74
- .status-bar .right i {
75
- margin-right: 5px;
76
- }
77
- .header {
78
- position: relative;
79
- height: 32px;
80
- background-color: #0068FF;
81
- text-align: center;
82
- color: #fff;
83
- padding-top: 12px;
84
- }
85
- .header .home {
86
- font-size: 14px;
87
- position: absolute;
88
- left: 6px;
89
- top: 6px;
90
- padding-top: 6px;
91
- height: 24px;
92
- width: 30px;
93
- background-color: rgba(0, 0, 0, 0.15);
94
- border-radius: 100%;
95
- border: 1px solid rgba(255, 255, 255, 0.25);
96
- }
97
3
 
98
- .header .setting {
99
- font-size: 14px;
100
- position: absolute;
101
- right: 6px;
102
- top: 6px;
103
- padding-top: 6px;
104
- height: 24px;
105
- width: 85px;
106
- background-color: rgba(0, 0, 0, 0.15);
107
- border-radius: 16px;
108
- border: 1px solid rgba(255, 255, 255, 0.25);
109
- }
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta http-equiv="Content-Security-Policy"
7
+ content="default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content:" />
8
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
110
9
 
111
- .header .setting i:first-child {
112
- border-right: 1px solid rgba(255, 255, 255, 0.25);
113
- padding-right: 12px;
114
- margin-right: 12px;
115
- }
116
- </style>
117
- </head>
118
- <body>
119
- <div class="wrapper-frame">
120
- <div id="statusbar" class="status-bar">
121
- <div class="right">
122
- <i class="fas fa-wifi"></i>
123
- <i class="fas fa-battery-full"></i>
124
- </div>
125
- <div class="left">
126
- 12:00
127
- </div>
10
+ <meta name="theme-color" content="#007aff" />
11
+ <meta name="format-detection" content="telephone=no" />
12
+ <meta name="msapplication-tap-highlight" content="no" />
13
+ <link rel="icon" href="/src/static/icons/favicon.png" />
14
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"
15
+ integrity="sha512-1ycn6IcaQQ40/MKBW2W4Rhis/DbILU74C1vSrLJxCq57o941Ym01SwNsOMqvEBFlcgUa6xLiPY/NS5R+E6ztJQ=="
16
+ crossorigin="anonymous" referrerpolicy="no-referrer" />
17
+
18
+ <title>Water Reminder1</title>
19
+ <style>
20
+ body {
21
+ font-family: -apple-system, BlinkMacSystemFont, sans-serif;
22
+ margin: 0px;
23
+ }
24
+
25
+ #zalo-frame {
26
+ width: 100%;
27
+ height: calc(100vh - 74px);
28
+ border: none;
29
+ overflow: auto;
30
+ cursor: grab;
31
+ }
32
+
33
+ .wrapper-frame {
34
+ width: 100%;
35
+ height: 100vh;
36
+ background-color: black;
37
+ margin: auto;
38
+ overflow: hidden;
39
+ }
40
+
41
+ .status-bar {
42
+ height: 30px;
43
+ background-color: #0068FF;
44
+ color: white;
45
+ font-size: 13px;
46
+ }
47
+
48
+ .status-bar .right {
49
+ float: right;
50
+ padding: 6px;
51
+ }
52
+
53
+ .status-bar .left {
54
+ float: left;
55
+ padding: 6px;
56
+ margin-left: 5px;
57
+ }
58
+
59
+ .status-bar .right i {
60
+ margin-right: 5px;
61
+ }
62
+
63
+ .header {
64
+ position: relative;
65
+ height: 32px;
66
+ background-color: #0068FF;
67
+ text-align: center;
68
+ color: #fff;
69
+ padding-top: 12px;
70
+ }
71
+
72
+ .header .home {
73
+ font-size: 14px;
74
+ position: absolute;
75
+ left: 6px;
76
+ top: 6px;
77
+ padding-top: 6px;
78
+ height: 24px;
79
+ width: 30px;
80
+ background-color: rgba(0, 0, 0, 0.15);
81
+ border-radius: 100%;
82
+ border: 1px solid rgba(255, 255, 255, 0.25);
83
+ }
84
+
85
+ .header .setting {
86
+ font-size: 14px;
87
+ position: absolute;
88
+ right: 6px;
89
+ top: 6px;
90
+ padding-top: 6px;
91
+ height: 24px;
92
+ width: 85px;
93
+ background-color: rgba(0, 0, 0, 0.15);
94
+ border-radius: 16px;
95
+ border: 1px solid rgba(255, 255, 255, 0.25);
96
+ }
97
+
98
+ .header .setting i:first-child {
99
+ border-right: 1px solid rgba(255, 255, 255, 0.25);
100
+ padding-right: 12px;
101
+ margin-right: 12px;
102
+ }
103
+ </style>
104
+ </head>
105
+
106
+ <body>
107
+ <div class="wrapper-frame">
108
+ <div id="statusbar" class="status-bar">
109
+ <div class="right">
110
+ <i class="fas fa-wifi"></i>
111
+ <i class="fas fa-battery-full"></i>
112
+ </div>
113
+ <div class="left">
114
+ 12:00
128
115
  </div>
116
+ </div>
129
117
 
130
- <div id="header" class="header">
131
- <div class="home">
132
- <i class="fas fa-home"></i>
133
- </div>
134
- <div class="setting">
135
- <i class="fas fa-ellipsis-h"></i>
136
- <i class="fas fa-power-off"></i>
137
- </div>
138
- <span id="title"></span>
118
+ <div id="header" class="header">
119
+ <div class="home">
120
+ <i class="fas fa-home"></i>
121
+ </div>
122
+ <div class="setting">
123
+ <i class="fas fa-ellipsis-h"></i>
124
+ <i class="fas fa-power-off"></i>
139
125
  </div>
140
- <iframe id="zalo-frame" src="http://localhost:3000"></iframe>
126
+ <span id="title"></span>
141
127
  </div>
142
- </body>
128
+ </div>
129
+ </body>
130
+
131
+ <script>
132
+ fetch(`http://localhost:${window.location.port - 1}/app-config.json`)
133
+ .then(response => response.json())
134
+ .then(data => {
135
+ if (data.app.title) {
136
+ document.getElementById('title').innerHTML = data.app.title;
137
+ document.title = data.app.title;
138
+ }
139
+ if (data.app.headerColor) {
140
+ document.getElementById('header').style.backgroundColor = data.app.headerColor;
141
+ }
142
+ if (data.app.statusBarColor) {
143
+ document.getElementById('statusbar').style.backgroundColor = data.app.statusBarColor;
144
+ }
145
+ if (data.app.textColor) {
146
+ document.getElementById('statusbar').style.color = data.app.textColor;
147
+ document.getElementById('header').style.color = data.app.textColor;
148
+ }
149
+ });
150
+ const iframe = document.createElement('iframe');
151
+ iframe.id = 'zalo-frame'
152
+ iframe.src = `http://localhost:${window.location.port - 1}`
153
+ document.body.firstElementChild.appendChild(iframe);
154
+ </script>
155
+
143
156
  </html>
package/start/index.js CHANGED
@@ -6,13 +6,11 @@ const path = require('path');
6
6
  const qrcode = require('qrcode-terminal');
7
7
  const logSymbols = require('log-symbols');
8
8
  const { createServer } = require('vite');
9
- const { replaceCodePlugin } = require('vite-plugin-replace');
10
9
 
11
10
  const config = require('../config');
12
11
  const envUtils = require('../utils/env');
13
12
  const fs = require('../utils/fs-extra');
14
13
  const fse = require('../utils/fs-extra');
15
- const generatePagesMap = require('../utils/generate-pages-map');
16
14
 
17
15
  const spinner = ora('Starting mini app...');
18
16
 
@@ -82,22 +80,8 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
82
80
  previewOnZalo ? 'production' : 'development'
83
81
  ),
84
82
  },
85
- optimizeDeps: {
86
- exclude: ['zmp-import-pages'],
87
- },
88
- plugins: [
89
- replaceCodePlugin({
90
- replacements: [
91
- {
92
- from: 'ZMP_IMPORT_PAGES',
93
- to: () => generatePagesMap(cwd),
94
- },
95
- ],
96
- }),
97
- ],
98
83
  server: {
99
- port: port,
100
- strictPort: true,
84
+ port: port - 1,
101
85
  ...(previewOnZalo ? publicServer : localServer),
102
86
  },
103
87
  });
@@ -110,10 +94,16 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
110
94
  configFile: false,
111
95
  root: __dirname + '/frame',
112
96
  server: {
113
- port: port + 1,
97
+ port: app.httpServer.address().port + 1,
98
+ strictPort: true,
99
+ open: true,
114
100
  },
115
101
  });
116
- serverFrame.listen();
102
+ await serverFrame.listen();
103
+ spinner.stop();
104
+ const info = serverFrame.config.logger.info;
105
+ info(chalk.green(`Zalo Mini App dev server is running at:\n`));
106
+ serverFrame.printUrls();
117
107
  }
118
108
 
119
109
  spinner.stop();
@@ -0,0 +1,106 @@
1
+ // Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
2
+ // (MIT licensed)
3
+ // Also based on https://github.com/modulesio/window-fetch/blob/master/src/blob.js
4
+
5
+ const TYPE = Symbol('type');
6
+ const CLOSED = Symbol('closed');
7
+
8
+ class Blob {
9
+ constructor() {
10
+ Object.defineProperty(this, Symbol.toStringTag, {
11
+ value: 'Blob',
12
+ writable: false,
13
+ enumerable: false,
14
+ configurable: true
15
+ });
16
+
17
+ this[CLOSED] = false;
18
+ this[TYPE] = '';
19
+
20
+ const blobParts = arguments[0];
21
+ const options = arguments[1];
22
+
23
+ const buffers = [];
24
+
25
+ if (blobParts) {
26
+ const a = blobParts;
27
+ const length = Number(a.length);
28
+ for (let i = 0; i < length; i++) {
29
+ const element = a[i];
30
+ let buffer;
31
+ if (element instanceof Buffer) {
32
+ buffer = element;
33
+ } else if (ArrayBuffer.isView(element)) {
34
+ buffer = Buffer.from(element.buffer, element.byteOffset, element.byteLength);
35
+ } else if (element instanceof ArrayBuffer) {
36
+ buffer = Buffer.from(element);
37
+ } else if (element instanceof Blob) {
38
+ buffer = element.buffer;
39
+ } else {
40
+ buffer = Buffer.from(typeof element === 'string' ? element : String(element));
41
+ }
42
+ buffers.push(buffer);
43
+ }
44
+ }
45
+
46
+ this.buffer = Buffer.concat(buffers);
47
+
48
+ let type = options && options.type !== undefined && String(options.type).toLowerCase();
49
+ if (type && !/[^\u0020-\u007E]/.test(type)) {
50
+ this[TYPE] = type;
51
+ }
52
+ }
53
+ get size() {
54
+ return this[CLOSED] ? 0 : this.buffer.length;
55
+ }
56
+ get type() {
57
+ return this[TYPE];
58
+ }
59
+ get isClosed() {
60
+ return this[CLOSED];
61
+ }
62
+ slice() {
63
+ const size = this.size;
64
+
65
+ const start = arguments[0];
66
+ const end = arguments[1];
67
+ let relativeStart, relativeEnd;
68
+ if (start === undefined) {
69
+ relativeStart = 0;
70
+ } else if (start < 0) {
71
+ relativeStart = Math.max(size + start, 0);
72
+ } else {
73
+ relativeStart = Math.min(start, size);
74
+ }
75
+ if (end === undefined) {
76
+ relativeEnd = size;
77
+ } else if (end < 0) {
78
+ relativeEnd = Math.max(size + end, 0);
79
+ } else {
80
+ relativeEnd = Math.min(end, size);
81
+ }
82
+ const span = Math.max(relativeEnd - relativeStart, 0);
83
+
84
+ const buffer = this.buffer;
85
+ const slicedBuffer = buffer.slice(
86
+ relativeStart,
87
+ relativeStart + span
88
+ );
89
+ const blob = new Blob([], { type: arguments[2] });
90
+ blob.buffer = slicedBuffer;
91
+ blob[CLOSED] = this[CLOSED];
92
+ return blob;
93
+ }
94
+ close() {
95
+ this[CLOSED] = true;
96
+ }
97
+ };
98
+
99
+ Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
100
+ value: 'BlobPrototype',
101
+ writable: false,
102
+ enumerable: false,
103
+ configurable: true
104
+ });
105
+
106
+ module.exports = Blob;
@@ -1,5 +1,5 @@
1
1
  const FileAPI = require('file-api');
2
- const Blob = require('node-blob');
2
+ const Blob = require('./node-blob');
3
3
  const XMLHttpRequest = require('xhr2');
4
4
 
5
5
  const File = FileAPI.File;