zmp-cli 3.9.0 → 3.10.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/assets/index.js +0 -0
- package/build/index.js +1 -1
- package/config/index.js +0 -0
- package/create/index.js +0 -0
- package/create/utils/generate-package-json.js +8 -3
- package/deploy/index.js +0 -0
- package/index.js +3 -3
- package/login/index.js +2 -6
- package/login/utils/zalo-login.js +3 -1
- package/migrate/index.js +0 -0
- package/package.json +3 -4
- package/start/index.js +25 -18
- package/utils/env.js +8 -1
- package/create/templates/dist/generate-styles.dev.js +0 -46
- package/create/templates/react/dist/generate-scripts.dev.js +0 -23
- package/create/templates/react-typescript/dist/generate-scripts.dev.js +0 -23
package/assets/index.js
CHANGED
|
File without changes
|
package/build/index.js
CHANGED
|
@@ -14,7 +14,7 @@ const envUtils = require('../utils/env');
|
|
|
14
14
|
const config = require('../config');
|
|
15
15
|
const generatePagesMap = require('../utils/generate-pages-map');
|
|
16
16
|
|
|
17
|
-
const env =
|
|
17
|
+
const env = envUtils.getEnv('NODE_ENV') || 'production';
|
|
18
18
|
|
|
19
19
|
const waitText = chalk.gray('Building... (Please wait, it can take a while)');
|
|
20
20
|
const frameworkWarning = chalk.yellow(
|
package/config/index.js
CHANGED
|
File without changes
|
package/create/index.js
CHANGED
|
File without changes
|
|
@@ -2,7 +2,8 @@ const generateNpmScripts = require('./generate-npm-scripts');
|
|
|
2
2
|
const { generateTailWindScripts } = require('./generate-npm-scripts');
|
|
3
3
|
|
|
4
4
|
module.exports = function generatePackageJson(options) {
|
|
5
|
-
const { name, framework, cssPreProcessor, includeTailwind, stateManagement } =
|
|
5
|
+
const { name, framework, cssPreProcessor, includeTailwind, stateManagement } =
|
|
6
|
+
options;
|
|
6
7
|
|
|
7
8
|
// Dependencies
|
|
8
9
|
const dependencies = ['zmp-framework', 'zmp-sdk', 'swiper'];
|
|
@@ -29,7 +30,11 @@ module.exports = function generatePackageJson(options) {
|
|
|
29
30
|
if (framework === 'react-typescript') {
|
|
30
31
|
dependencies.push(...dependenciesReactTs);
|
|
31
32
|
}
|
|
32
|
-
const devDependencies = [
|
|
33
|
+
const devDependencies = [
|
|
34
|
+
'cross-env',
|
|
35
|
+
'postcss-preset-env@6.7.0',
|
|
36
|
+
'vite@2.6.14',
|
|
37
|
+
];
|
|
33
38
|
// CSS PreProcessor
|
|
34
39
|
if (cssPreProcessor === 'stylus') devDependencies.push(...['stylus']);
|
|
35
40
|
else if (cssPreProcessor === 'less') devDependencies.push(...['less']);
|
|
@@ -38,7 +43,7 @@ module.exports = function generatePackageJson(options) {
|
|
|
38
43
|
// DevDependencies
|
|
39
44
|
const devDependenciesCore = ['zmp-loader'];
|
|
40
45
|
const devDependenciesReact = ['@vitejs/plugin-react-refresh'];
|
|
41
|
-
const devDependenciesVue = ['@vitejs/plugin-vue', '@vue/compiler-sfc'];
|
|
46
|
+
const devDependenciesVue = ['@vitejs/plugin-vue@2.3.3', '@vue/compiler-sfc'];
|
|
42
47
|
|
|
43
48
|
if (framework === 'react' || framework === 'react-typescript')
|
|
44
49
|
devDependencies.push(
|
package/deploy/index.js
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
@@ -26,8 +26,6 @@ const os = require('os');
|
|
|
26
26
|
const pkg = require('./package.json');
|
|
27
27
|
const config = require('./config');
|
|
28
28
|
|
|
29
|
-
require('dotenv').config({ path: config.root_env() });
|
|
30
|
-
|
|
31
29
|
const cwd = process.cwd();
|
|
32
30
|
|
|
33
31
|
const logger = {
|
|
@@ -117,8 +115,9 @@ program
|
|
|
117
115
|
'Specify server port. By default it is 3000',
|
|
118
116
|
parseInt
|
|
119
117
|
)
|
|
120
|
-
.option('-Z, --zalo-app', 'Preview on
|
|
118
|
+
.option('-Z, --zalo-app', 'Preview on Zalo')
|
|
121
119
|
.option('-ios, --ios', 'Run on ios')
|
|
120
|
+
.option('-nF, --no-frame', 'Run without Zalo frame')
|
|
122
121
|
.option('-D, --dev', 'Development environment')
|
|
123
122
|
.description('Start a ZMP project')
|
|
124
123
|
.action(async (options) => {
|
|
@@ -147,6 +146,7 @@ program
|
|
|
147
146
|
showMobileUI: (options && options.showMobileUi) || false,
|
|
148
147
|
previewOnZalo: (options && options.zaloApp) || false,
|
|
149
148
|
ios: (options && options.ios) || false,
|
|
149
|
+
frame: (options && options.frame) ?? true,
|
|
150
150
|
},
|
|
151
151
|
logger
|
|
152
152
|
);
|
package/login/index.js
CHANGED
|
@@ -11,16 +11,12 @@ const envUtils = require('../utils/env');
|
|
|
11
11
|
const log = require('../utils/log');
|
|
12
12
|
const zaloLogin = require('./utils/zalo-login');
|
|
13
13
|
|
|
14
|
-
const env =
|
|
14
|
+
const env = envUtils.getEnv('NODE_ENV') || 'production';
|
|
15
15
|
|
|
16
16
|
const waitText = chalk.gray('Login...');
|
|
17
17
|
const spinner = ora(waitText);
|
|
18
18
|
|
|
19
|
-
module.exports = async (
|
|
20
|
-
options = {},
|
|
21
|
-
logger,
|
|
22
|
-
{ exitOnError = true, iconFile = null } = {}
|
|
23
|
-
) => {
|
|
19
|
+
module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
|
|
24
20
|
function errorExit(err) {
|
|
25
21
|
log.error(err.stderr || err);
|
|
26
22
|
if (exitOnError) process.exit(1);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const axios = require('axios');
|
|
2
|
+
const envUtils = require('../../utils/env');
|
|
2
3
|
const config = require('../../config');
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
const env = envUtils.getEnv('NODE_ENV') || 'production';
|
|
4
6
|
|
|
5
7
|
module.exports = (function () {
|
|
6
8
|
const apiRequestLogin =
|
package/migrate/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zmp-cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "ZMP command line utility (CLI)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
"copy-webpack-plugin": "^7.0.0",
|
|
56
56
|
"cpy": "^7.3.0",
|
|
57
57
|
"css-minimizer-webpack-plugin": "^1.2.0",
|
|
58
|
-
"dotenv": "^8.2.0",
|
|
59
58
|
"envfile": "^6.14.0",
|
|
60
59
|
"exec-sh": "^0.3.2",
|
|
61
60
|
"express": "^4.17.1",
|
|
@@ -94,7 +93,7 @@
|
|
|
94
93
|
},
|
|
95
94
|
"devDependencies": {
|
|
96
95
|
"babel-eslint": "^10.1.0",
|
|
97
|
-
"eslint": "^
|
|
96
|
+
"eslint": "^7.32.0",
|
|
98
97
|
"eslint-config-airbnb-base": "^14.0.0",
|
|
99
98
|
"eslint-config-prettier": "^7.2.0",
|
|
100
99
|
"eslint-plugin-import": "^2.18.2",
|
|
@@ -103,4 +102,4 @@
|
|
|
103
102
|
"eslint-plugin-promise": "^4.2.1",
|
|
104
103
|
"eslint-plugin-standard": "^5.0.0"
|
|
105
104
|
}
|
|
106
|
-
}
|
|
105
|
+
}
|
package/start/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const ora = require('ora');
|
|
5
5
|
const path = require('path');
|
|
6
|
-
const os = require('os');
|
|
7
6
|
const qrcode = require('qrcode-terminal');
|
|
8
7
|
const logSymbols = require('log-symbols');
|
|
9
8
|
const { createServer } = require('vite');
|
|
@@ -36,6 +35,7 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
|
|
|
36
35
|
const previewOnZalo = options.previewOnZalo;
|
|
37
36
|
const isIOS = options.ios;
|
|
38
37
|
const iosHostName = options.iosHostName;
|
|
38
|
+
const usingFrame = options.frame;
|
|
39
39
|
const host = isIOS ? iosHostName : 'localhost';
|
|
40
40
|
const port = options.port;
|
|
41
41
|
try {
|
|
@@ -84,29 +84,36 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
|
|
|
84
84
|
'process.env.previewOnZalo': previewOnZalo,
|
|
85
85
|
},
|
|
86
86
|
server: {
|
|
87
|
-
port: port - 1,
|
|
87
|
+
port: usingFrame ? port - 1 : port,
|
|
88
88
|
...(previewOnZalo ? publicServer : localServer),
|
|
89
89
|
},
|
|
90
90
|
});
|
|
91
91
|
const app = await server.listen();
|
|
92
92
|
|
|
93
93
|
if (!previewOnZalo) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
if (usingFrame) {
|
|
95
|
+
//run frame server
|
|
96
|
+
const serverFrame = await createServer({
|
|
97
|
+
// any valid user config options, plus `mode` and `configFile`
|
|
98
|
+
configFile: false,
|
|
99
|
+
root: __dirname + '/frame',
|
|
100
|
+
server: {
|
|
101
|
+
port: app.httpServer.address().port + 1,
|
|
102
|
+
strictPort: true,
|
|
103
|
+
open: true,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
spinner.stop();
|
|
107
|
+
await serverFrame.listen();
|
|
108
|
+
const info = serverFrame.config.logger.info;
|
|
109
|
+
info(chalk.green(`Zalo Mini App dev server is running at:\n`));
|
|
110
|
+
serverFrame.printUrls();
|
|
111
|
+
} else {
|
|
112
|
+
spinner.stop();
|
|
113
|
+
const info = server.config.logger.info;
|
|
114
|
+
info(chalk.green(`Zalo Mini App dev server is running at:\n`));
|
|
115
|
+
server.printUrls();
|
|
116
|
+
}
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
spinner.stop();
|
package/utils/env.js
CHANGED
|
@@ -9,7 +9,14 @@ const { parse, stringify } = require('envfile');
|
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
11
|
function getEnv(key) {
|
|
12
|
-
|
|
12
|
+
const value = process.env[key];
|
|
13
|
+
if (value) return value;
|
|
14
|
+
const rootENV = config.root_env();
|
|
15
|
+
const exists = fse.existsSync(rootENV);
|
|
16
|
+
if (!exists) return undefined;
|
|
17
|
+
const data = fse.readFileSync(rootENV, 'utf8');
|
|
18
|
+
const result = parse(data);
|
|
19
|
+
return result[key];
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
/**
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var indent = require('../utils/indent');
|
|
4
|
-
|
|
5
|
-
var _require = require('../utils/colors'),
|
|
6
|
-
colorThemeCSSProperties = _require.colorThemeCSSProperties;
|
|
7
|
-
|
|
8
|
-
module.exports = function (options) {
|
|
9
|
-
var template = options.template,
|
|
10
|
-
theming = options.theming;
|
|
11
|
-
var customColor = theming.customColor,
|
|
12
|
-
color = theming.color,
|
|
13
|
-
fillBars = theming.fillBars;
|
|
14
|
-
var styles = '';
|
|
15
|
-
var themeRgb = [0, 122, 255];
|
|
16
|
-
|
|
17
|
-
if (customColor && color) {
|
|
18
|
-
var customProps = colorThemeCSSProperties("".concat(color));
|
|
19
|
-
themeRgb = customProps['--zmp-theme-color-rgb'].split(',').map(function (n) {
|
|
20
|
-
return n.trim();
|
|
21
|
-
});
|
|
22
|
-
styles += indent(0, "\n /* Custom color theme properties */\n :root {\n ".concat(Object.keys(customProps).filter(function (prop) {
|
|
23
|
-
return prop !== '--zmp-tabbar-fill-link-active-color' && prop !== '--zmp-tabbar-fill-link-active-border-color';
|
|
24
|
-
}).map(function (prop) {
|
|
25
|
-
return "".concat(prop, ": ").concat(customProps[prop], ";");
|
|
26
|
-
}).join('\n '), "\n }\n :root.theme-dark,:root .theme-dark {\n ").concat(Object.keys(customProps).map(function (prop) {
|
|
27
|
-
return "".concat(prop, ": ").concat(customProps[prop], ";");
|
|
28
|
-
}).join('\n '), "\n }\n "));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (fillBars) {
|
|
32
|
-
styles += indent(0, "\n /* Invert navigation bars to fill style */\n ");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (includeTailwind) {
|
|
36
|
-
styles += indent(0, "\n @import \"./tailwind.css\";\n ");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (template === 'split-view') {
|
|
40
|
-
styles += indent(0, "\n /* Left Panel right border when it is visible by breakpoint */\n .panel-left.panel-in-breakpoint:before {\n position: absolute;\n right: 0;\n top: 0;\n height: 100%;\n width: 1px;\n background: rgba(0,0,0,0.1);\n content: '';\n z-index: 6000;\n }\n\n /* Hide navbar link which opens left panel when it is visible by breakpoint */\n .panel-left.panel-in-breakpoint ~ .view .navbar .panel-open[data-panel=\"left\"] {\n display: none;\n }\n\n /*\n Extra borders for main view and left panel for iOS theme when it behaves as panel (before breakpoint size)\n */\n .ios .panel-left:not(.panel-in-breakpoint).panel-in ~ .view-main:before,\n .ios .panel-left:not(.panel-in-breakpoint).panel-closing ~ .view-main:before {\n position: absolute;\n left: 0;\n top: 0;\n height: 100%;\n width: 1px;\n background: rgba(0,0,0,0.1);\n content: '';\n z-index: 6000;\n }\n ");
|
|
41
|
-
} else {
|
|
42
|
-
styles += indent(0, "\n /* Your app custom styles here */\n ");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return styles.trim();
|
|
46
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var templateIf = require('../../utils/template-if');
|
|
4
|
-
|
|
5
|
-
var indent = require('../../utils/indent');
|
|
6
|
-
|
|
7
|
-
var stylesExtension = require('../../utils/styles-extension');
|
|
8
|
-
|
|
9
|
-
module.exports = function (options) {
|
|
10
|
-
var cssPreProcessor = options.cssPreProcessor,
|
|
11
|
-
theming = options.theming,
|
|
12
|
-
customBuild = options.customBuild,
|
|
13
|
-
includeTailwind = options.includeTailwind;
|
|
14
|
-
var scripts = '';
|
|
15
|
-
scripts += indent(0, "\n // Import React and ReactDOM\n import React from 'react';\n import { createRoot } from 'react-dom/client';\n\n // Import ZMP\n import ZMP from '".concat(customBuild ? './zmp-custom.js' : 'zmp-framework/core/lite-bundle', "';\n\n // Import ZMP-React Plugin\n import ZMPReact from 'zmp-framework/react';").concat(includeTailwind ? "\n\n // Import tailwind styles\n import './css/tailwind.css';\n " : '', "\n\n // Import ZMP Styles\n ").concat(templateIf(customBuild, function () {
|
|
16
|
-
return "\n import './css/zmp-custom.less';\n ";
|
|
17
|
-
}, function () {
|
|
18
|
-
return "\n import 'zmp-framework/".concat(theming.useUiKits ? 'zmp-bundle.min.css' : 'zmp.min.css', "';\n ");
|
|
19
|
-
}), "\n\n // Import Icons and App Custom Styles\n ").concat(templateIf(theming.iconFonts, function () {
|
|
20
|
-
return "\n import './css/icons.css';\n ";
|
|
21
|
-
}), "\n import './css/app.").concat(stylesExtension(cssPreProcessor), "';\n\n // Import App Component\n import App from './components/app.jsx';\n import appConfig from '../app-config.json';\n\n if (!window.APP_CONFIG) {\n window.APP_CONFIG = appConfig;\n }\n\n // Init ZMP React Plugin\n ZMP.use(ZMPReact)\n\n // Mount React App\n const root = createRoot(document.getElementById('app'));\n root.render(React.createElement(App));\n "));
|
|
22
|
-
return scripts.trim();
|
|
23
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var templateIf = require('../../utils/template-if');
|
|
4
|
-
|
|
5
|
-
var indent = require('../../utils/indent');
|
|
6
|
-
|
|
7
|
-
var stylesExtension = require('../../utils/styles-extension');
|
|
8
|
-
|
|
9
|
-
module.exports = function (options) {
|
|
10
|
-
var cssPreProcessor = options.cssPreProcessor,
|
|
11
|
-
theming = options.theming,
|
|
12
|
-
customBuild = options.customBuild,
|
|
13
|
-
includeTailwind = options.includeTailwind;
|
|
14
|
-
var scripts = '';
|
|
15
|
-
scripts += indent(0, "\n // Import React and ReactDOM\n import React from 'react';\n import { createRoot } from 'react-dom/client';\n\n // Import ZMP\n import ZMP from '".concat(customBuild ? './zmp-custom.js' : 'zmp-framework/core/lite-bundle', "';\n\n // Import ZMP-React Plugin\n import ZMPReact from 'zmp-framework/react';").concat(includeTailwind ? "\n\n // Import tailwind styles\n import './css/tailwind.css';\n " : '', "\n\n // Import ZMP Styles\n ").concat(templateIf(customBuild, function () {
|
|
16
|
-
return "\n import './css/zmp-custom.less';\n ";
|
|
17
|
-
}, function () {
|
|
18
|
-
return "\n import 'zmp-framework/".concat(theming.useUiKits ? 'zmp-bundle.min.css' : 'zmp.min.css', "';\n ");
|
|
19
|
-
}), "\n\n // Import Icons and App Custom Styles\n ").concat(templateIf(theming.iconFonts, function () {
|
|
20
|
-
return "\n import './css/icons.css';\n ";
|
|
21
|
-
}), "\n import './css/app.").concat(stylesExtension(cssPreProcessor), "';\n\n // Import App Component\n import App from './components/app';\n import appConfig from '../app-config.json';\n\n if (!(window as any).APP_CONFIG) {\n (window as any).APP_CONFIG = appConfig\n }\n\n // Init ZMP React Plugin\n ZMP.use(ZMPReact)\n\n // Mount React App\n const root = createRoot(document.getElementById('app')!);\n root.render(React.createElement(App));\n "));
|
|
22
|
-
return scripts.trim();
|
|
23
|
-
};
|