@zimbra/zimlet-cli 13.0.0 → 14.0.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.
@@ -37,13 +37,12 @@ var _default = (0, _asyncCommand.default)({
37
37
  description: {
38
38
  alias: 'desc',
39
39
  description: 'Description for your zimlet',
40
- demandOption: true,
41
- requiresArg: true
40
+ default: null
42
41
  },
43
42
  label: {
44
43
  alias: 'l',
45
44
  description: 'Display name for your zimlet',
46
- demandOption: true
45
+ default: null
47
46
  },
48
47
  zimbraXVersion: {
49
48
  description: 'https://semver.org version range of Zimbra X that the Zimlet is compatible with.',
@@ -68,11 +67,21 @@ var _default = (0, _asyncCommand.default)({
68
67
 
69
68
  let builddir = _path.default.resolve(cwd, argv.builddir || 'build');
70
69
 
71
- let dest = _path.default.resolve(cwd, argv.dest || 'pkg', `${argv.name}.zip`); // Create the xml descriptor file for the zimlet
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
72
81
 
73
82
 
74
83
  let xmlFile = `${argv.name}.xml`;
75
- let zimletXML = `<zimlet name="${argv.name}" version="${argv.pkgVersion}" description="${argv.description}" label="${argv.label}" zimbraXZimletCompatibleSemVer="${argv.zimbraXVersion}">`;
84
+ let zimletXML = `<zimlet name="${argv.name}" version="${argv.pkgVersion}" description="${description}" label="${label}" zimbraXZimletCompatibleSemVer="${argv.zimbraXVersion}">`;
76
85
  let files;
77
86
 
78
87
  try {
@@ -81,7 +90,7 @@ var _default = (0, _asyncCommand.default)({
81
90
  return (0, _util.error)(`Failed to read ${builddir}: ${err}`, 1);
82
91
  }
83
92
 
84
- files.forEach(file => {
93
+ files.filter(file => !file.match(/\.properties$/)).forEach(file => {
85
94
  if (file.match(/\.js$/)) {
86
95
  zimletXML += `\n\t<include>${file}</include>`;
87
96
  } else if (file.match(/\.css$/)) {
@@ -96,21 +105,9 @@ var _default = (0, _asyncCommand.default)({
96
105
  _fs.default.writeFileSync(_path.default.resolve(builddir, xmlFile), zimletXML);
97
106
  } catch (err) {
98
107
  return (0, _util.error)(`Failed to write XML file: ${err}`, 1);
99
- } // Add properties file for description and label
100
- // As admin console requires properties file to display label and desciption
101
-
102
-
103
- let propertiesFile = `${argv.name}.properties`;
104
- let zimletProperties = '\n';
105
- zimletProperties += `label = ${argv.label}\n`;
106
- zimletProperties += `description = ${argv.description}\n`;
107
-
108
- try {
109
- _fs.default.writeFileSync(_path.default.resolve(builddir, propertiesFile), zimletProperties);
110
- } catch (err) {
111
- return (0, _util.error)(`Failed to write properties file: ${err}`, 1);
112
- } //Zip up the contents of the build dir along with the xml file as the final zimlet deliverable
108
+ }
113
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
114
111
 
115
112
  let zipFile = new _admZip.default();
116
113
  zipFile.addLocalFolder(builddir, '');
@@ -121,4 +118,86 @@ var _default = (0, _asyncCommand.default)({
121
118
  });
122
119
 
123
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
+
124
203
  module.exports = exports.default;
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zimbra/zimlet-cli",
3
- "version": "13.0.0",
3
+ "version": "14.0.0",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zimbra/zimlet-cli",
3
- "version": "13.0.0",
3
+ "version": "14.0.0",
4
4
  "description": "Develop, Build, and Package Zimbra X compatible zimlets for development and production.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {