@codeleap/cli 5.8.20 → 5.8.21

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.
@@ -53,7 +53,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
53
53
  exports.convertorWebpCommand = void 0;
54
54
  var Command_1 = require("../lib/Command");
55
55
  var fs_1 = __importDefault(require("fs"));
56
- // import sharp from 'sharp'
56
+ var path_1 = __importDefault(require("path"));
57
+ var sharp_1 = __importDefault(require("sharp"));
57
58
  var lib_1 = require("../lib");
58
59
  require("../lib/firebase");
59
60
  var constants_1 = require("../constants");
@@ -68,11 +69,11 @@ exports.convertorWebpCommand = (0, Command_1.codeleapCommand)({
68
69
  ],
69
70
  },
70
71
  }, function (argv) { return __awaiter(void 0, void 0, void 0, function () {
71
- var flags, _, settings, isMultipleConversion, isSingleConversion, filename, answers, files, inputFiles, _loop_1, inputFiles_1, inputFiles_1_1, inputFile;
72
- var e_1, _a;
73
- var _b, _c;
74
- return __generator(this, function (_d) {
75
- switch (_d.label) {
72
+ var flags, _, settings, isMultipleConversion, isSingleConversion, filename, answers, files, inputFiles, _loop_1, inputFiles_1, inputFiles_1_1, inputFile, _loop_2, files_1, files_1_1, file, e_1_1;
73
+ var e_2, _a, e_1, _b;
74
+ var _c, _d, _e, _f, _g;
75
+ return __generator(this, function (_h) {
76
+ switch (_h.label) {
76
77
  case 0:
77
78
  flags = argv.flags, _ = argv._;
78
79
  settings = constants_1.USER_CONFIG['convertor-webp'];
@@ -87,9 +88,9 @@ exports.convertorWebpCommand = (0, Command_1.codeleapCommand)({
87
88
  },
88
89
  ])];
89
90
  case 1:
90
- answers = _d.sent();
91
+ answers = _h.sent();
91
92
  filename = answers.filename;
92
- _d.label = 2;
93
+ _h.label = 2;
93
94
  case 2:
94
95
  console.log('Starting conversion', settings);
95
96
  if (!fs_1.default.existsSync(settings.output)) {
@@ -109,7 +110,7 @@ exports.convertorWebpCommand = (0, Command_1.codeleapCommand)({
109
110
  inputFiles = fs_1.default.readdirSync(settings.input);
110
111
  if (isMultipleConversion) {
111
112
  _loop_1 = function (inputFile) {
112
- var isCorrectFormat = (_c = (_b = settings === null || settings === void 0 ? void 0 : settings.convertor) === null || _b === void 0 ? void 0 : _b.inputFormats) === null || _c === void 0 ? void 0 : _c.some(function (_format) { return inputFile === null || inputFile === void 0 ? void 0 : inputFile.endsWith(_format); });
113
+ var isCorrectFormat = (_d = (_c = settings === null || settings === void 0 ? void 0 : settings.convertor) === null || _c === void 0 ? void 0 : _c.inputFormats) === null || _d === void 0 ? void 0 : _d.some(function (_format) { return inputFile === null || inputFile === void 0 ? void 0 : inputFile.endsWith(_format); });
113
114
  var isIgnoredFile = settings.convertor.ignoreFiles.includes(inputFile === null || inputFile === void 0 ? void 0 : inputFile.split('.')[0]);
114
115
  if (isCorrectFormat && !isIgnoredFile) {
115
116
  files.push(inputFile);
@@ -121,12 +122,12 @@ exports.convertorWebpCommand = (0, Command_1.codeleapCommand)({
121
122
  _loop_1(inputFile);
122
123
  }
123
124
  }
124
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
125
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
125
126
  finally {
126
127
  try {
127
128
  if (inputFiles_1_1 && !inputFiles_1_1.done && (_a = inputFiles_1.return)) _a.call(inputFiles_1);
128
129
  }
129
- finally { if (e_1) throw e_1.error; }
130
+ finally { if (e_2) throw e_2.error; }
130
131
  }
131
132
  }
132
133
  else {
@@ -144,7 +145,71 @@ exports.convertorWebpCommand = (0, Command_1.codeleapCommand)({
144
145
  process.exit(1);
145
146
  }
146
147
  console.log('Files to convert', files);
147
- return [2 /*return*/];
148
+ _loop_2 = function (file) {
149
+ var inputPath, outputPath, img, img_metadata, imageProcessing, needResize, newWidth, newHeight, hasAlfaChannels;
150
+ return __generator(this, function (_j) {
151
+ switch (_j.label) {
152
+ case 0:
153
+ inputPath = path_1.default.join(settings.input, file);
154
+ outputPath = path_1.default.join(settings.output, path_1.default.parse(file).name + '.webp');
155
+ if (fs_1.default.existsSync(outputPath)) {
156
+ fs_1.default.unlinkSync(outputPath);
157
+ }
158
+ img = (0, sharp_1.default)(inputPath);
159
+ return [4 /*yield*/, img.metadata()];
160
+ case 1:
161
+ img_metadata = _j.sent();
162
+ imageProcessing = img.webp({ quality: Number((_e = settings === null || settings === void 0 ? void 0 : settings.convertor) === null || _e === void 0 ? void 0 : _e.compressionQuality) });
163
+ needResize = (img_metadata === null || img_metadata === void 0 ? void 0 : img_metadata.width) && (img_metadata === null || img_metadata === void 0 ? void 0 : img_metadata.width) > ((_f = settings === null || settings === void 0 ? void 0 : settings.convertor) === null || _f === void 0 ? void 0 : _f.resizeWidth);
164
+ if (needResize) {
165
+ newWidth = parseInt(String((_g = settings === null || settings === void 0 ? void 0 : settings.convertor) === null || _g === void 0 ? void 0 : _g.resizeWidth));
166
+ newHeight = parseInt(String(img_metadata.height * (newWidth / img_metadata.width)));
167
+ imageProcessing = imageProcessing.resize({ width: newWidth, height: newHeight });
168
+ }
169
+ hasAlfaChannels = img_metadata.channels && img_metadata.channels >= 4;
170
+ if (hasAlfaChannels && !!settings.convertor.processColorChannels) {
171
+ imageProcessing = imageProcessing.toColorspace('srgb');
172
+ }
173
+ imageProcessing.toFile(outputPath, function (err, info) {
174
+ if (err) {
175
+ console.error("Error converting ".concat(file, " to webP"), err);
176
+ process.exit(1);
177
+ }
178
+ else {
179
+ console.log("Image ".concat(file, " converted to webP"), info);
180
+ }
181
+ });
182
+ return [2 /*return*/];
183
+ }
184
+ });
185
+ };
186
+ _h.label = 3;
187
+ case 3:
188
+ _h.trys.push([3, 8, 9, 10]);
189
+ files_1 = __values(files), files_1_1 = files_1.next();
190
+ _h.label = 4;
191
+ case 4:
192
+ if (!!files_1_1.done) return [3 /*break*/, 7];
193
+ file = files_1_1.value;
194
+ return [5 /*yield**/, _loop_2(file)];
195
+ case 5:
196
+ _h.sent();
197
+ _h.label = 6;
198
+ case 6:
199
+ files_1_1 = files_1.next();
200
+ return [3 /*break*/, 4];
201
+ case 7: return [3 /*break*/, 10];
202
+ case 8:
203
+ e_1_1 = _h.sent();
204
+ e_1 = { error: e_1_1 };
205
+ return [3 /*break*/, 10];
206
+ case 9:
207
+ try {
208
+ if (files_1_1 && !files_1_1.done && (_b = files_1.return)) _b.call(files_1);
209
+ }
210
+ finally { if (e_1) throw e_1.error; }
211
+ return [7 /*endfinally*/];
212
+ case 10: return [2 /*return*/];
148
213
  }
149
214
  });
150
215
  }); });
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ var downloadKeystores_1 = require("./commands/downloadKeystores");
8
8
  var keystoresAndroid_1 = require("./commands/keystoresAndroid");
9
9
  var rename_1 = require("./commands/rename");
10
10
  var syncIcons_1 = require("./commands/syncIcons");
11
- // import { convertorWebpCommand } from './commands/convertorWebp'
11
+ var convertorWebp_1 = require("./commands/convertorWebp");
12
12
  var configureTheme_1 = require("./commands/configureTheme");
13
13
  var linguiTranslate_1 = require("./commands/linguiTranslate");
14
14
  var configureSplash_1 = require("./commands/configureSplash");
@@ -25,7 +25,7 @@ var packageJson = require('../package.json');
25
25
  configure_1.configureCommand,
26
26
  downloadKeystores_1.downloadKeystores,
27
27
  syncIcons_1.syncIconsCommand,
28
- // convertorWebpCommand,
28
+ convertorWebp_1.convertorWebpCommand,
29
29
  configureTheme_1.configureThemeCommand,
30
30
  linguiTranslate_1.linguiTranslateCommand,
31
31
  configureSplash_1.configureSplashCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/cli",
3
- "version": "5.8.20",
3
+ "version": "5.8.21",
4
4
  "main": "./dist/index.js",
5
5
  "repository": "git@github.com:codeleap-uk/codeleap-lib.git",
6
6
  "author": "Paulo Henrique De Souza <paulosouza300272@gmail.com>",
@@ -10,7 +10,7 @@
10
10
  "codeleap-cli": "./dist/index.js"
11
11
  },
12
12
  "devDependencies": {
13
- "@codeleap/config": "5.8.20",
13
+ "@codeleap/config": "5.8.21",
14
14
  "@types/inquirer": "^8.2.0",
15
15
  "@types/libsodium-wrappers": "^0.7.10",
16
16
  "cross-env": "^7.0.3"
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/cli",
3
- "version": "5.8.20",
3
+ "version": "5.8.21",
4
4
  "main": "./dist/index.js",
5
5
  "repository": "git@github.com:codeleap-uk/codeleap-lib.git",
6
6
  "author": "Paulo Henrique De Souza <paulosouza300272@gmail.com>",