zmp-cli 3.9.1 → 3.10.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/assets/index.js CHANGED
File without changes
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env node
2
+
3
+ /* eslint no-console: off */
4
+ "use strict";
5
+
6
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
7
+
8
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
9
+
10
+ function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
11
+
12
+ 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; } }
13
+
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
15
+
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
20
+ var chalk = require('chalk');
21
+
22
+ var ora = require('ora');
23
+
24
+ var path = require('path');
25
+
26
+ var _require = require('vite'),
27
+ build = _require.build;
28
+
29
+ var dynamicImportVars = require('@rollup/plugin-dynamic-import-vars')["default"];
30
+
31
+ var _ = require('lodash');
32
+
33
+ var replace = require('@rollup/plugin-replace');
34
+
35
+ var log = require('../utils/log');
36
+
37
+ var fse = require('../utils/fs-extra');
38
+
39
+ var getAppInfo = require('../utils/get-app-info');
40
+
41
+ var envUtils = require('../utils/env');
42
+
43
+ var config = require('../config');
44
+
45
+ var generatePagesMap = require('../utils/generate-pages-map');
46
+
47
+ var env = envUtils.getEnv('NODE_ENV') || 'production';
48
+ var waitText = chalk.gray('Building... (Please wait, it can take a while)');
49
+ var frameworkWarning = chalk.yellow('Warning: This CLI version will work better with zmp-framework version 1.5.0 or higher');
50
+ var spinner = ora(env === 'production' ? 'Building for production...' : 'Building development version...');
51
+
52
+ module.exports = function _callee() {
53
+ var options,
54
+ logger,
55
+ _ref,
56
+ _ref$exitOnError,
57
+ exitOnError,
58
+ cwd,
59
+ resolvePath,
60
+ appConfig,
61
+ errorExit,
62
+ appId,
63
+ nextVersion,
64
+ appInfo,
65
+ currentVersion,
66
+ viteConfig,
67
+ isTypeScriptProject,
68
+ res,
69
+ output,
70
+ jsFiles,
71
+ cssFiles,
72
+ appConfigJson,
73
+ _args = arguments;
74
+
75
+ return regeneratorRuntime.async(function _callee$(_context) {
76
+ while (1) {
77
+ switch (_context.prev = _context.next) {
78
+ case 0:
79
+ errorExit = function _ref2(err) {
80
+ log.error(err.stderr || err);
81
+ if (exitOnError) process.exit(1);
82
+ };
83
+
84
+ options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
85
+ logger = _args.length > 1 ? _args[1] : undefined;
86
+ _ref = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, _ref$exitOnError = _ref.exitOnError, exitOnError = _ref$exitOnError === void 0 ? true : _ref$exitOnError;
87
+ cwd = options.cwd || process.cwd();
88
+
89
+ resolvePath = function resolvePath(dir) {
90
+ return path.join(cwd, dir);
91
+ };
92
+
93
+ appConfig = options.appConfigJson || require(resolvePath(config.filename.appConfig));
94
+
95
+ if (!logger) {
96
+ // eslint-disable-next-line
97
+ logger = {
98
+ statusStart: function statusStart() {},
99
+ statusDone: function statusDone() {},
100
+ statusError: function statusError() {},
101
+ text: function text() {},
102
+ error: function error() {}
103
+ };
104
+ }
105
+
106
+ logger.text(frameworkWarning);
107
+ spinner.start();
108
+ logger.statusStart(waitText);
109
+ _context.prev = 11;
110
+ appId = envUtils.getEnv(config.env.appId);
111
+ nextVersion = options.nextVersion;
112
+
113
+ if (nextVersion) {
114
+ _context.next = 21;
115
+ break;
116
+ }
117
+
118
+ _context.next = 17;
119
+ return regeneratorRuntime.awrap(getAppInfo(appId, options));
120
+
121
+ case 17:
122
+ appInfo = _context.sent;
123
+ currentVersion = appInfo && appInfo.latestVersion && Number(appInfo.latestVersion);
124
+
125
+ if (currentVersion === undefined || currentVersion === null) {
126
+ currentVersion = 0;
127
+ }
128
+
129
+ nextVersion = currentVersion + 1;
130
+
131
+ case 21:
132
+ viteConfig = 'vite.config.js';
133
+ isTypeScriptProject = fse.existsSync(path.join(cwd, 'vite.config.ts'));
134
+
135
+ if (isTypeScriptProject) {
136
+ viteConfig = 'vite.config.ts';
137
+ } // eslint-disable-next-line
138
+
139
+
140
+ _context.next = 26;
141
+ return regeneratorRuntime.awrap(build({
142
+ configFile: path.join(cwd, viteConfig),
143
+ root: cwd,
144
+ base: "".concat(config.zdn_url).concat(appId, "/").concat(nextVersion, "/"),
145
+ css: {
146
+ modules: {
147
+ scopeBehaviour: 'local'
148
+ }
149
+ },
150
+ build: {
151
+ target: 'es2015',
152
+ outDir: path.join(cwd, 'www'),
153
+ assetsInlineLimit: 0,
154
+ cssCodeSplit: false,
155
+ cssTarget: ['es2015', 'safari13.1'],
156
+ rollupOptions: {
157
+ plugins: [replace({
158
+ values: {
159
+ ZMP_IMPORT_PAGES: function ZMP_IMPORT_PAGES() {
160
+ return generatePagesMap(cwd);
161
+ }
162
+ }
163
+ }), dynamicImportVars({
164
+ warnOnError: true
165
+ })],
166
+ output: {
167
+ entryFileNames: 'assets/[name].[hash].module.js',
168
+ chunkFileNames: 'assets/[name].[hash].module.js'
169
+ }
170
+ }
171
+ },
172
+ logLevel: 'error'
173
+ }));
174
+
175
+ case 26:
176
+ res = _context.sent;
177
+ output = res.output.map(function (obj) {
178
+ return _.pick(obj, ['fileName', 'type', 'isEntry', 'isImplicitEntry', 'isDynamicEntry']);
179
+ });
180
+ jsFiles = output.filter(function (file) {
181
+ if (file.type !== 'chunk') return false;
182
+ return file.isEntry || !file.isDynamicEntry;
183
+ });
184
+ cssFiles = output.filter(function (file) {
185
+ if (file.type !== 'asset' || !file.fileName.endsWith('.css')) return false; // const name = file.fileName.replace(/\.([a-z0-9]{8})\.css$/, '');
186
+ // if (!jsFiles.find((js) => js.fileName.startsWith(name))) return false;
187
+
188
+ return true;
189
+ });
190
+ appConfigJson = _objectSpread({}, appConfig, {
191
+ listCSS: [].concat(_toConsumableArray(Array.isArray(appConfig.listCSS) ? appConfig.listCSS : []), _toConsumableArray(cssFiles.map(function (f) {
192
+ return f.fileName;
193
+ }))),
194
+ listSyncJS: [].concat(_toConsumableArray(Array.isArray(appConfig.listSyncJS) ? appConfig.listSyncJS : []), _toConsumableArray(jsFiles.map(function (f) {
195
+ return f.fileName;
196
+ }))),
197
+ listAsyncJS: _toConsumableArray(Array.isArray(appConfig.listAsyncJS) ? appConfig.listAsyncJS : [])
198
+ });
199
+ fse.writeFileSync(resolvePath("www/".concat(config.filename.appConfig)), JSON.stringify(appConfigJson));
200
+ logger.statusDone("".concat(chalk.bold.green('Build Done!\n')));
201
+ return _context.abrupt("return", appConfigJson);
202
+
203
+ case 36:
204
+ _context.prev = 36;
205
+ _context.t0 = _context["catch"](11);
206
+ logger.statusError('Error building project'); // if (err) logger.error(err.stderr || err);
207
+
208
+ errorExit(_context.t0);
209
+ return _context.abrupt("return");
210
+
211
+ case 41:
212
+ case "end":
213
+ return _context.stop();
214
+ }
215
+ }
216
+ }, null, null, [[11, 36]]);
217
+ };
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 = process.env.NODE_ENV || 'production';
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(
@@ -74,9 +74,7 @@ module.exports = async (options = {}, logger, { exitOnError = true } = {}) => {
74
74
  const res = await build({
75
75
  configFile: path.join(cwd, viteConfig),
76
76
  root: cwd,
77
- base: `${
78
- config.zdn_url[options && options.dev ? 'dev' : 'prod']
79
- }${appId}/${nextVersion}/`,
77
+ base: `${config.zdn_url}${appId}/${nextVersion}/`,
80
78
  css: {
81
79
  modules: {
82
80
  scopeBehaviour: 'local',
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ filename: {
5
+ appConfig: 'app-config.json',
6
+ zmpConfig: 'zmp-cli.json',
7
+ packageJson: 'package.json'
8
+ },
9
+ api_domain: 'https://zmp-api.developers.zalo.me/',
10
+ zdn_url: '//h5.zdn.vn/zapps/',
11
+ path: {
12
+ login: 'admin/login',
13
+ requestLogin: 'admin/request-login',
14
+ checkLoginStatus: 'admin/get-login-status',
15
+ // uploadApp: 'admin/upload-app',
16
+ uploadAppByChunk: 'app/upload-chunk',
17
+ requestUploadResumable: 'app/request-upload',
18
+ getAppInfo: 'app/get-info'
19
+ },
20
+ dirname: __dirname,
21
+ root_env: function root_env() {
22
+ return "".concat(process.cwd(), "/.env");
23
+ },
24
+ env: {
25
+ appId: 'APP_ID',
26
+ token: 'ZMP_TOKEN',
27
+ accessToken: 'VITE_ACCESS_TOKEN'
28
+ },
29
+ error_code: {
30
+ app_config_not_found: -1400,
31
+ permission_denied: -2001,
32
+ request_timeout: -2003
33
+ },
34
+ error_msg: {
35
+ app_config_not_found: "App config not found. Please re-init project. (Tips: Run 'zmp init')",
36
+ permission_denied: "Permission denied. Please login again. (Tips: Run 'zmp login')",
37
+ request_timeout: 'Request Timeout'
38
+ },
39
+ resumable_option: {
40
+ chunkSize: 512 * 1000,
41
+ // bytes -> 512kb/chunk
42
+ simultaneousUploads: 4,
43
+ testChunks: true,
44
+ throttleProgressCallbacks: 1,
45
+ method: 'octet',
46
+ forceChunkSize: false
47
+ }
48
+ };
package/config/index.js CHANGED
@@ -2,15 +2,10 @@ module.exports = {
2
2
  filename: {
3
3
  appConfig: 'app-config.json',
4
4
  zmpConfig: 'zmp-cli.json',
5
+ packageJson: 'package.json',
5
6
  },
6
- api_domain: {
7
- dev: 'https://dev-zmp-api.developers.zalo.me/',
8
- prod: 'https://zmp-api.developers.zalo.me/',
9
- },
10
- zdn_url: {
11
- dev: '//dev.h5.zalo.me/zapps/',
12
- prod: '//h5.zdn.vn/zapps/',
13
- },
7
+ api_domain: 'https://zmp-api.developers.zalo.me/',
8
+ zdn_url: '//h5.zdn.vn/zapps/',
14
9
  path: {
15
10
  login: 'admin/login',
16
11
  requestLogin: 'admin/request-login',
@@ -25,6 +20,7 @@ module.exports = {
25
20
  env: {
26
21
  appId: 'APP_ID',
27
22
  token: 'ZMP_TOKEN',
23
+ accessToken: 'VITE_ACCESS_TOKEN',
28
24
  },
29
25
  error_code: {
30
26
  app_config_not_found: -1400,
package/create/index.js CHANGED
File without changes
@@ -0,0 +1,46 @@
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
+ };
@@ -0,0 +1,23 @@
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
+ };
@@ -0,0 +1,23 @@
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
+ };
@@ -43,7 +43,7 @@ module.exports = function generatePackageJson(options) {
43
43
  // DevDependencies
44
44
  const devDependenciesCore = ['zmp-loader'];
45
45
  const devDependenciesReact = ['@vitejs/plugin-react-refresh'];
46
- const devDependenciesVue = ['@vitejs/plugin-vue', '@vue/compiler-sfc'];
46
+ const devDependenciesVue = ['@vitejs/plugin-vue@2.3.3', '@vue/compiler-sfc'];
47
47
 
48
48
  if (framework === 'react' || framework === 'react-typescript')
49
49
  devDependencies.push(
@@ -0,0 +1,227 @@
1
+ #!/usr/bin/env node
2
+
3
+ /* eslint no-console: off */
4
+ "use strict";
5
+
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
7
+
8
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
9
+
10
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+
12
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
13
+
14
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
15
+
16
+ function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
17
+
18
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+
20
+ var chalk = require('chalk');
21
+
22
+ var path = require('path');
23
+
24
+ var zipper = require('zip-local');
25
+
26
+ var logSymbols = require('log-symbols');
27
+
28
+ var qrcode = require('qrcode-terminal');
29
+
30
+ var config = require('../config');
31
+
32
+ var buildApp = require('../build/index');
33
+
34
+ var envUtils = require('../utils/env');
35
+
36
+ var uploadApp = require('./utils/upload-app');
37
+
38
+ var fse = require('../utils/fs-extra');
39
+
40
+ var requestUpload = require('./utils/request-upload');
41
+
42
+ var waitText = chalk.gray('(Please wait, it can take a while)');
43
+ var defaultLogger = {
44
+ statusStart: function statusStart() {},
45
+ statusDone: function statusDone() {},
46
+ statusText: function statusText() {},
47
+ statusError: function statusError() {},
48
+ text: function text() {},
49
+ error: function error() {},
50
+ showOnUI: function showOnUI() {}
51
+ };
52
+
53
+ module.exports = function _callee() {
54
+ var options,
55
+ logger,
56
+ _ref,
57
+ _ref$exitOnError,
58
+ exitOnError,
59
+ cwd,
60
+ outputDir,
61
+ apiDomain,
62
+ resolvePath,
63
+ errorExit,
64
+ token,
65
+ appConfigFilename,
66
+ packageJsonFilename,
67
+ appConfigJson,
68
+ packageJson,
69
+ frameworkVersions,
70
+ dependencies,
71
+ dataRequest,
72
+ nextVersion,
73
+ identifier,
74
+ urlRequestUpload,
75
+ requestUploadData,
76
+ flag,
77
+ buffer,
78
+ uploadData,
79
+ uploadRes,
80
+ appURL,
81
+ _args = arguments;
82
+
83
+ return regeneratorRuntime.async(function _callee$(_context) {
84
+ while (1) {
85
+ switch (_context.prev = _context.next) {
86
+ case 0:
87
+ errorExit = function _ref4(err) {
88
+ logger.error(err.stderr || err);
89
+ if (exitOnError) process.exit(1);
90
+ };
91
+
92
+ options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
93
+ logger = _args.length > 1 && _args[1] !== undefined ? _args[1] : defaultLogger;
94
+ _ref = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, _ref$exitOnError = _ref.exitOnError, exitOnError = _ref$exitOnError === void 0 ? true : _ref$exitOnError;
95
+ cwd = options.cwd || process.cwd();
96
+ outputDir = options.outputDir || 'www';
97
+ apiDomain = config.api_domain;
98
+
99
+ resolvePath = function resolvePath(dir) {
100
+ return path.join(cwd, dir);
101
+ };
102
+
103
+ token = envUtils.getEnv(config.env.token);
104
+ appConfigFilename = config.filename.appConfig;
105
+ packageJsonFilename = config.filename.packageJson;
106
+
107
+ try {
108
+ appConfigJson = require(resolvePath(appConfigFilename));
109
+ } catch (err) {
110
+ errorExit(new Error(config.error_msg.app_config_not_found));
111
+ }
112
+
113
+ frameworkVersions = {};
114
+
115
+ try {
116
+ packageJson = require(resolvePath(packageJsonFilename));
117
+ dependencies = packageJson.dependencies;
118
+ Object.entries(dependencies).forEach(function (_ref2) {
119
+ var _ref3 = _slicedToArray(_ref2, 2),
120
+ key = _ref3[0],
121
+ value = _ref3[1];
122
+
123
+ if (key.includes('zmp') || key.includes('react')) {
124
+ frameworkVersions[key] = value;
125
+ }
126
+ });
127
+ } catch (err) {// pass
128
+ }
129
+
130
+ dataRequest = {
131
+ appName: appConfigJson.app.title,
132
+ appDesc: options.desc || 'Update app with new version',
133
+ appConfig: JSON.stringify(appConfigJson),
134
+ frameworkVersions: JSON.stringify(frameworkVersions)
135
+ };
136
+ _context.prev = 15;
137
+ urlRequestUpload = "".concat(apiDomain).concat(config.path.requestUploadResumable);
138
+ _context.next = 19;
139
+ return regeneratorRuntime.awrap(requestUpload(urlRequestUpload, dataRequest, options.versionStatus, token));
140
+
141
+ case 19:
142
+ requestUploadData = _context.sent;
143
+ nextVersion = requestUploadData.nextVersion;
144
+ identifier = requestUploadData.identifier;
145
+ _context.next = 27;
146
+ break;
147
+
148
+ case 24:
149
+ _context.prev = 24;
150
+ _context.t0 = _context["catch"](15);
151
+ errorExit(_context.t0);
152
+
153
+ case 27:
154
+ if (!options.customProject) {
155
+ _context.next = 35;
156
+ break;
157
+ }
158
+
159
+ flag = 0;
160
+ if (appConfigJson.listSyncJS && appConfigJson.listSyncJS.length > 0) flag += 1;
161
+ if (appConfigJson.listAsyncJS && appConfigJson.listAsyncJS.length > 0) flag += 1;
162
+
163
+ if (flag === 0) {
164
+ errorExit(new Error('Please define your assets output at app-config.json. Read more: https:/'));
165
+ }
166
+
167
+ fse.writeFileSync(resolvePath("".concat(outputDir, "/").concat(config.filename.appConfig)), JSON.stringify(appConfigJson));
168
+ _context.next = 38;
169
+ break;
170
+
171
+ case 35:
172
+ _context.next = 37;
173
+ return regeneratorRuntime.awrap(buildApp(_objectSpread({}, options, {
174
+ appConfigJson: appConfigJson,
175
+ nextVersion: nextVersion
176
+ }), logger));
177
+
178
+ case 37:
179
+ appConfigJson = _context.sent;
180
+
181
+ case 38:
182
+ logger.statusStart("Deploying Your App ".concat(waitText));
183
+ _context.prev = 39;
184
+ _context.next = 42;
185
+ return regeneratorRuntime.awrap(new Promise(function (resolve, reject) {
186
+ zipper.zip(resolvePath(outputDir), function (zipError, zipped) {
187
+ if (zipError) return reject(zipError);
188
+ zipped.compress();
189
+ return resolve(zipped.memory());
190
+ });
191
+ }));
192
+
193
+ case 42:
194
+ buffer = _context.sent;
195
+ uploadData = _objectSpread({}, dataRequest, {
196
+ appBuffer: buffer,
197
+ identifier: identifier
198
+ });
199
+ _context.next = 46;
200
+ return regeneratorRuntime.awrap(uploadApp(uploadData, options, logger));
201
+
202
+ case 46:
203
+ uploadRes = _context.sent;
204
+ appURL = uploadRes && uploadRes.data && uploadRes.data.appUrl;
205
+ qrcode.generate(appURL, {
206
+ small: true
207
+ }, function (qrcode) {
208
+ var qrCode = "".concat(chalk.bold("".concat(logSymbols.info, " View app at:\n").concat(qrcode)));
209
+ logger.statusDone("".concat(chalk.bold.green('Deploy Done!'), " \uD83D\uDCAA"));
210
+ logger.text(qrCode);
211
+ });
212
+ _context.next = 55;
213
+ break;
214
+
215
+ case 51:
216
+ _context.prev = 51;
217
+ _context.t1 = _context["catch"](39);
218
+ logger.statusError('Error deploying your app');
219
+ errorExit(_context.t1);
220
+
221
+ case 55:
222
+ case "end":
223
+ return _context.stop();
224
+ }
225
+ }
226
+ }, null, null, [[15, 24], [39, 51]]);
227
+ };