@zimbra/zimlet-cli 12.13.0 → 14.2.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.
Files changed (45) hide show
  1. package/.browserslistrc +1 -0
  2. package/dist/cli.js +11 -17
  3. package/dist/commands/create.js +206 -324
  4. package/dist/commands/package.js +144 -93
  5. package/dist/entry.js +14 -12
  6. package/dist/index.js +89 -114
  7. package/dist/lib/async-command.js +8 -14
  8. package/dist/lib/setup.js +55 -133
  9. package/dist/lib/webpack/transform-config.js +8 -8
  10. package/dist/shims/@apollo/client/index.js +92 -82
  11. package/dist/shims/@apollo/client/react/components/index.js +6 -6
  12. package/dist/shims/@apollo/client/react/hoc/index.js +8 -8
  13. package/dist/shims/@apollo/client/react/index.js +16 -16
  14. package/dist/shims/@zimbra-client/blocks/index.js +28 -28
  15. package/dist/shims/@zimbra-client/browser/index.js +4 -4
  16. package/dist/shims/@zimbra-client/components/index.js +53 -51
  17. package/dist/shims/@zimbra-client/constants/index.js +7 -7
  18. package/dist/shims/@zimbra-client/enhancers/index.js +10 -10
  19. package/dist/shims/@zimbra-client/errors/index.js +5 -5
  20. package/dist/shims/@zimbra-client/graphql/index.js +29 -29
  21. package/dist/shims/@zimbra-client/hooks/graphql/index.js +8 -8
  22. package/dist/shims/@zimbra-client/hooks/index.js +8 -8
  23. package/dist/shims/@zimbra-client/platform/index.js +5 -5
  24. package/dist/shims/@zimbra-client/util/contacts/index.js +4 -4
  25. package/dist/shims/@zimbra-client/util/index.js +15 -13
  26. package/dist/shims/@zimbra-client/util/redux/index.js +8 -8
  27. package/dist/shims/clipboard-polyfill/index.js +4 -4
  28. package/dist/shims/index.js +2 -2
  29. package/dist/shims/moment/index.js +43 -43
  30. package/dist/shims/preact/compat/index.js +40 -52
  31. package/dist/shims/preact/hooks/index.js +14 -14
  32. package/dist/shims/preact/index.js +15 -15
  33. package/dist/shims/preact-context-provider/index.js +6 -6
  34. package/dist/shims/preact-i18n/index.js +12 -12
  35. package/dist/shims/preact-pwa-install/index.js +3 -3
  36. package/dist/shims/preact-render-to-string/index.js +5 -5
  37. package/dist/shims/preact-router/index.js +9 -9
  38. package/dist/shims/preact-router/match/index.js +4 -4
  39. package/dist/shims/react-redux/index.js +16 -16
  40. package/dist/shims/recompose/index.js +46 -46
  41. package/dist/shims/redux-actions/index.js +9 -9
  42. package/dist/util.js +11 -11
  43. package/dist/zimlet-style-loader.js +8 -4
  44. package/package-lock.json +6400 -6926
  45. package/package.json +41 -44
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = void 0;
6
+ exports.default = void 0;
7
7
 
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
 
@@ -15,13 +15,9 @@ var _util = require("../util");
15
15
 
16
16
  var _asyncCommand = _interopRequireDefault(require("../lib/async-command"));
17
17
 
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
-
22
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
23
-
24
- var _default = (0, _asyncCommand["default"])({
20
+ var _default = (0, _asyncCommand.default)({
25
21
  command: 'package',
26
22
  desc: 'Package a zimlet for deployment',
27
23
  builder: {
@@ -41,22 +37,21 @@ var _default = (0, _asyncCommand["default"])({
41
37
  description: {
42
38
  alias: 'desc',
43
39
  description: 'Description for your zimlet',
44
- demandOption: true,
45
- requiresArg: true
40
+ default: null
46
41
  },
47
42
  label: {
48
43
  alias: 'l',
49
44
  description: 'Display name for your zimlet',
50
- demandOption: true
45
+ default: null
51
46
  },
52
47
  zimbraXVersion: {
53
48
  description: 'https://semver.org version range of Zimbra X that the Zimlet is compatible with.',
54
- "default": '>=1.0.0',
49
+ default: '>=1.0.0',
55
50
  requiresArg: true
56
51
  },
57
52
  builddir: {
58
53
  alias: 'b',
59
- "default": './build',
54
+ default: './build',
60
55
  description: 'Source directory of built artifacts to publish'
61
56
  },
62
57
  dest: {
@@ -65,88 +60,144 @@ var _default = (0, _asyncCommand["default"])({
65
60
  description: 'Directory for packaged artifacts'
66
61
  }
67
62
  },
68
- handler: function handler(argv) {
69
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
70
- var cwd, builddir, dest, xmlFile, zimletXML, files, propertiesFile, zimletProperties, zipFile;
71
- return regeneratorRuntime.wrap(function _callee$(_context) {
72
- while (1) {
73
- switch (_context.prev = _context.next) {
74
- case 0:
75
- // normalize built files source directory and desination package dir
76
- cwd = process.cwd();
77
- builddir = _path["default"].resolve(cwd, argv.builddir || 'build');
78
- dest = _path["default"].resolve(cwd, argv.dest || 'pkg', "".concat(argv.name, ".zip")); // Create the xml descriptor file for the zimlet
79
-
80
- xmlFile = "".concat(argv.name, ".xml");
81
- zimletXML = "<zimlet name=\"".concat(argv.name, "\" version=\"").concat(argv.pkgVersion, "\" description=\"").concat(argv.description, "\" label=\"").concat(argv.label, "\" zimbraXZimletCompatibleSemVer=\"").concat(argv.zimbraXVersion, "\">");
82
- _context.prev = 5;
83
- files = _fs["default"].readdirSync(builddir);
84
- _context.next = 12;
85
- break;
86
-
87
- case 9:
88
- _context.prev = 9;
89
- _context.t0 = _context["catch"](5);
90
- return _context.abrupt("return", (0, _util.error)("Failed to read ".concat(builddir, ": ").concat(_context.t0), 1));
91
-
92
- case 12:
93
- files.forEach(function (file) {
94
- if (file.match(/\.js$/)) {
95
- zimletXML += "\n\t<include>".concat(file, "</include>");
96
- } else if (file.match(/\.css$/)) {
97
- zimletXML += "\n\t<includeCSS>".concat(file, "</includeCSS>");
98
- } else if (file !== xmlFile) {
99
- zimletXML += "\n\t<resource>".concat(file, "</resource>");
100
- }
101
- });
102
- zimletXML += '\n</zimlet>';
103
- _context.prev = 14;
104
-
105
- _fs["default"].writeFileSync(_path["default"].resolve(builddir, xmlFile), zimletXML);
106
-
107
- _context.next = 21;
108
- break;
109
-
110
- case 18:
111
- _context.prev = 18;
112
- _context.t1 = _context["catch"](14);
113
- return _context.abrupt("return", (0, _util.error)("Failed to write XML file: ".concat(_context.t1), 1));
114
-
115
- case 21:
116
- // Add properties file for description and label
117
- // As admin console requires properties file to display label and desciption
118
- propertiesFile = "".concat(argv.name, ".properties");
119
- zimletProperties = '\n';
120
- zimletProperties += "label = ".concat(argv.label, "\n");
121
- zimletProperties += "description = ".concat(argv.description, "\n");
122
- _context.prev = 25;
123
-
124
- _fs["default"].writeFileSync(_path["default"].resolve(builddir, propertiesFile), zimletProperties);
125
-
126
- _context.next = 32;
127
- break;
128
-
129
- case 29:
130
- _context.prev = 29;
131
- _context.t2 = _context["catch"](25);
132
- return _context.abrupt("return", (0, _util.error)("Failed to write properties file: ".concat(_context.t2), 1));
133
-
134
- case 32:
135
- //Zip up the contents of the build dir along with the xml file as the final zimlet deliverable
136
- zipFile = new _admZip["default"]();
137
- zipFile.addLocalFolder(builddir, '');
138
- zipFile.writeZip(dest);
139
- return _context.abrupt("return", "Successfully packaged zimlet to: ".concat(dest, "\n"));
140
-
141
- case 36:
142
- case "end":
143
- return _context.stop();
144
- }
145
- }
146
- }, _callee, null, [[5, 9], [14, 18], [25, 29]]);
147
- }))();
63
+
64
+ async handler(argv) {
65
+ // normalize built files source directory and desination package dir
66
+ let cwd = process.cwd();
67
+
68
+ let builddir = _path.default.resolve(cwd, argv.builddir || 'build');
69
+
70
+ let dest = _path.default.resolve(cwd, argv.dest || 'pkg', `${argv.name}.zip`); // Get label and description from src/intl/en_US.json or from argument
71
+
72
+
73
+ const {
74
+ label,
75
+ description
76
+ } = getZimletLabelDescription() || argv;
77
+
78
+ if (!(label && description)) {
79
+ return (0, _util.error)('label and description string are not provided as argument');
80
+ } // Create the xml descriptor file for the zimlet
81
+
82
+
83
+ let xmlFile = `${argv.name}.xml`;
84
+ let zimletXML = `<zimlet name="${argv.name}" version="${argv.pkgVersion}" description="${description}" label="${label}" zimbraXZimletCompatibleSemVer="${argv.zimbraXVersion}">`;
85
+ let files;
86
+
87
+ try {
88
+ files = _fs.default.readdirSync(builddir);
89
+ } catch (err) {
90
+ return (0, _util.error)(`Failed to read ${builddir}: ${err}`, 1);
91
+ }
92
+
93
+ files.filter(file => !file.match(/\.properties$/)).forEach(file => {
94
+ if (file.match(/\.js$/)) {
95
+ zimletXML += `\n\t<include>${file}</include>`;
96
+ } else if (file.match(/\.css$/)) {
97
+ zimletXML += `\n\t<includeCSS>${file}</includeCSS>`;
98
+ } else if (file !== xmlFile) {
99
+ zimletXML += `\n\t<resource>${file}</resource>`;
100
+ }
101
+ });
102
+ zimletXML += '\n</zimlet>';
103
+
104
+ try {
105
+ _fs.default.writeFileSync(_path.default.resolve(builddir, xmlFile), zimletXML);
106
+ } catch (err) {
107
+ return (0, _util.error)(`Failed to write XML file: ${err}`, 1);
108
+ }
109
+
110
+ createLocalizationFiles(argv.name, label, description); //Zip up the contents of the build dir along with the xml file as the final zimlet deliverable
111
+
112
+ let zipFile = new _admZip.default();
113
+ zipFile.addLocalFolder(builddir, '');
114
+ zipFile.writeZip(dest);
115
+ return `Successfully packaged zimlet to: ${dest}\n`;
148
116
  }
117
+
149
118
  });
150
119
 
151
- exports["default"] = _default;
120
+ exports.default = _default;
121
+
122
+ function getZimletLabelDescription() {
123
+ const intlDir = _path.default.resolve(process.cwd(), 'src', 'intl');
124
+
125
+ try {
126
+ const content = JSON.parse(_fs.default.readFileSync(_path.default.resolve(intlDir, 'en_US.json')));
127
+
128
+ if (!(content.zimlet?.label && content.zimlet?.description)) {
129
+ throw new Error('label or description not found');
130
+ }
131
+
132
+ return {
133
+ label: content.zimlet.label,
134
+ description: content.zimlet.description
135
+ };
136
+ } catch (err) {
137
+ (0, _util.warn)(`Failed to read src/intl/en_US.json file: ${err}. \nMake sure below content present in src/intl/en_US.json file \n
138
+ "zimlet": {
139
+ "label": "<zimlet label>",
140
+ "description": "<zimlet description>"
141
+ } \nAs a fallback we are using strings from package.json which is deprecated.\n`);
142
+ return null;
143
+ }
144
+ } // Add properties file for description and label
145
+ // As admin console requires properties file to display label and desciption
146
+
147
+
148
+ function createLocalizationFiles(zimletName, label, description) {
149
+ const cwd = process.cwd();
150
+
151
+ const intlDir = _path.default.resolve(cwd, 'src', 'intl');
152
+
153
+ let intlFiles;
154
+ createPropertyFile(zimletName, label, description);
155
+
156
+ try {
157
+ intlFiles = _fs.default.readdirSync(intlDir);
158
+ } catch (err) {
159
+ console.error(`Failed to read ${intlDir}: ${err}`, 1);
160
+ }
161
+
162
+ intlFiles.filter(file => file.match(/\.json$/) && !file.includes('en_US')).forEach(intl => {
163
+ try {
164
+ const content = JSON.parse(_fs.default.readFileSync(_path.default.resolve(intlDir, intl)));
165
+ const propertiesFileName = `${zimletName}_${intl.replace('.json', '')}`;
166
+ const labelValue = getUnicode(content.zimlet?.label || '');
167
+ const descriptionValue = getUnicode(content.zimlet?.description || '');
168
+ createPropertyFile(propertiesFileName, labelValue, descriptionValue);
169
+ } catch (ex) {
170
+ (0, _util.error)(`Error while reading file: ${ex}`, 1);
171
+ }
172
+ });
173
+ }
174
+
175
+ function createPropertyFile(fileName, label, description) {
176
+ const builddir = _path.default.resolve(process.cwd(), 'build');
177
+
178
+ const propertiesFile = `${fileName}.properties`;
179
+ let zimletProperties = '\n';
180
+ zimletProperties += `label = ${label}\n`;
181
+ zimletProperties += `description = ${description}\n`;
182
+
183
+ try {
184
+ _fs.default.writeFileSync(_path.default.resolve(builddir, propertiesFile), zimletProperties);
185
+ } catch (err) {
186
+ return (0, _util.error)(`Failed to write properties file: ${err}`, 1);
187
+ }
188
+ }
189
+
190
+ function getUnicode(txt) {
191
+ let hex = '';
192
+ if (txt.length === 0) return;
193
+
194
+ for (let i = 0; i < txt.length; i++) {
195
+ const h = txt.codePointAt(i).toString(16);
196
+ hex += '\\u' + h.padStart(4, 0);
197
+ if (h.length > 4) i++;
198
+ }
199
+
200
+ return hex;
201
+ }
202
+
152
203
  module.exports = exports.default;
package/dist/entry.js CHANGED
@@ -3,16 +3,18 @@
3
3
  /** This is the real webpack entry file. It manages setting up the zimlet and HMR.
4
4
  * The user-defined entry file (index.js) is imported here via a `zimlet-cli-entrypoint` alias.
5
5
  */
6
- (function () {
6
+ (() => {
7
7
  function init() {
8
- zimlet(function (context) {
9
- var zimbra = context.zimbra,
10
- config = context.config,
11
- plugins = context.plugins,
12
- shims = context.shims,
13
- components = context.components,
14
- store = context.store,
15
- meta = context.meta; // Add shims to the global scope to expose dependencies to Zimlets
8
+ zimlet(context => {
9
+ let {
10
+ zimbra,
11
+ config,
12
+ plugins,
13
+ shims,
14
+ components,
15
+ store,
16
+ meta
17
+ } = context; // Add shims to the global scope to expose dependencies to Zimlets
16
18
  // Shimmed dependencies include preact, preact-router, react-apollo
17
19
 
18
20
  global.shims = shims;
@@ -24,11 +26,11 @@
24
26
  global.ZIMLET_STYLES = [];
25
27
  global.meta = meta;
26
28
 
27
- var entry = require('zimlet-cli-entrypoint');
29
+ let entry = require('zimlet-cli-entrypoint');
28
30
 
29
- var r = entry && entry["default"] || entry; // If export is a factory, pass it context. Otherwise it's a singleton.
31
+ let r = entry && entry.default || entry; // If export is a factory, pass it context. Otherwise it's a singleton.
30
32
 
31
- var instance = typeof r === 'function' ? r(context) : r;
33
+ let instance = typeof r === 'function' ? r(context) : r;
32
34
  context.styles.set(global.ZIMLET_STYLES.join('\n'));
33
35
  return instance;
34
36
  });