@codeleap/cli 3.14.1 → 3.14.3
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/dist/commands/convertorWebp.js +225 -0
- package/dist/constants.js +2 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.convertorWebpCommand = void 0;
|
|
54
|
+
var Command_1 = require("../lib/Command");
|
|
55
|
+
var fs_1 = __importDefault(require("fs"));
|
|
56
|
+
var path_1 = __importDefault(require("path"));
|
|
57
|
+
var sharp_1 = __importDefault(require("sharp"));
|
|
58
|
+
var lib_1 = require("../lib");
|
|
59
|
+
require("../lib/firebase");
|
|
60
|
+
var constants_1 = require("../constants");
|
|
61
|
+
var commandName = 'convertor-webp';
|
|
62
|
+
exports.convertorWebpCommand = (0, Command_1.codeleapCommand)({
|
|
63
|
+
name: commandName,
|
|
64
|
+
parameters: [],
|
|
65
|
+
help: {
|
|
66
|
+
description: 'Command for easily convertor to webp, compression and resize images.',
|
|
67
|
+
examples: [
|
|
68
|
+
"codeleap ".concat(commandName),
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
}, function (argv) { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
+
var flags, _, settingsPath, settingsJSON, 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) {
|
|
77
|
+
case 0:
|
|
78
|
+
flags = argv.flags, _ = argv._;
|
|
79
|
+
settingsPath = constants_1.CODELEAP_CLI_SETTINGS_PATH;
|
|
80
|
+
if (!fs_1.default.existsSync(settingsPath)) {
|
|
81
|
+
console.error('Settings not found, check path:', settingsPath);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
settingsJSON = fs_1.default.readFileSync(settingsPath).toString();
|
|
86
|
+
settings = JSON.parse(settingsJSON)['convertor-webp'];
|
|
87
|
+
isMultipleConversion = settings.mode === 'multi';
|
|
88
|
+
isSingleConversion = settings.mode === 'single';
|
|
89
|
+
filename = null;
|
|
90
|
+
if (!isSingleConversion) return [3 /*break*/, 2];
|
|
91
|
+
return [4 /*yield*/, lib_1.inquirer.prompt([
|
|
92
|
+
{
|
|
93
|
+
message: "Please insert the filename",
|
|
94
|
+
name: 'filename',
|
|
95
|
+
},
|
|
96
|
+
])];
|
|
97
|
+
case 1:
|
|
98
|
+
answers = _h.sent();
|
|
99
|
+
filename = answers.filename;
|
|
100
|
+
_h.label = 2;
|
|
101
|
+
case 2:
|
|
102
|
+
console.log('Starting conversion', settings);
|
|
103
|
+
if (!fs_1.default.existsSync(settings.output)) {
|
|
104
|
+
try {
|
|
105
|
+
fs_1.default.mkdirSync(settings.output);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
console.error('Error on create output folder, check settings', {
|
|
109
|
+
settings: settings,
|
|
110
|
+
error: e,
|
|
111
|
+
});
|
|
112
|
+
process.exit(1);
|
|
113
|
+
return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
files = [];
|
|
117
|
+
if (fs_1.default.existsSync(settings.input)) {
|
|
118
|
+
inputFiles = fs_1.default.readdirSync(settings.input);
|
|
119
|
+
if (isMultipleConversion) {
|
|
120
|
+
_loop_1 = function (inputFile) {
|
|
121
|
+
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); });
|
|
122
|
+
var isIgnoredFile = settings.convertor.ignoreFiles.includes(inputFile === null || inputFile === void 0 ? void 0 : inputFile.split('.')[0]);
|
|
123
|
+
if (isCorrectFormat && !isIgnoredFile) {
|
|
124
|
+
files.push(inputFile);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
try {
|
|
128
|
+
for (inputFiles_1 = __values(inputFiles), inputFiles_1_1 = inputFiles_1.next(); !inputFiles_1_1.done; inputFiles_1_1 = inputFiles_1.next()) {
|
|
129
|
+
inputFile = inputFiles_1_1.value;
|
|
130
|
+
_loop_1(inputFile);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
134
|
+
finally {
|
|
135
|
+
try {
|
|
136
|
+
if (inputFiles_1_1 && !inputFiles_1_1.done && (_a = inputFiles_1.return)) _a.call(inputFiles_1);
|
|
137
|
+
}
|
|
138
|
+
finally { if (e_2) throw e_2.error; }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
if (!!fs_1.default.existsSync(settings.input + '/' + filename)) {
|
|
143
|
+
files.push(filename);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
console.error('File not found, check filename', filename);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
console.error('Input folder not found, check settings', settings);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
return [2 /*return*/];
|
|
156
|
+
}
|
|
157
|
+
console.log('Files to convert', files);
|
|
158
|
+
_loop_2 = function (file) {
|
|
159
|
+
var inputPath, outputPath, img, img_metadata, imageProcessing, needResize, newWidth, newHeight, hasAlfaChannels;
|
|
160
|
+
return __generator(this, function (_j) {
|
|
161
|
+
switch (_j.label) {
|
|
162
|
+
case 0:
|
|
163
|
+
inputPath = path_1.default.join(settings.input, file);
|
|
164
|
+
outputPath = path_1.default.join(settings.output, path_1.default.parse(file).name + '.webp');
|
|
165
|
+
if (fs_1.default.existsSync(outputPath)) {
|
|
166
|
+
fs_1.default.unlinkSync(outputPath);
|
|
167
|
+
}
|
|
168
|
+
img = (0, sharp_1.default)(inputPath);
|
|
169
|
+
return [4 /*yield*/, img.metadata()];
|
|
170
|
+
case 1:
|
|
171
|
+
img_metadata = _j.sent();
|
|
172
|
+
imageProcessing = img.webp({ quality: Number((_e = settings === null || settings === void 0 ? void 0 : settings.convertor) === null || _e === void 0 ? void 0 : _e.compressionQuality) });
|
|
173
|
+
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);
|
|
174
|
+
if (needResize) {
|
|
175
|
+
newWidth = parseInt(String((_g = settings === null || settings === void 0 ? void 0 : settings.convertor) === null || _g === void 0 ? void 0 : _g.resizeWidth));
|
|
176
|
+
newHeight = parseInt(String(img_metadata.height * (newWidth / img_metadata.width)));
|
|
177
|
+
imageProcessing = imageProcessing.resize({ width: newWidth, height: newHeight });
|
|
178
|
+
}
|
|
179
|
+
hasAlfaChannels = img_metadata.channels && img_metadata.channels >= 4;
|
|
180
|
+
if (hasAlfaChannels && !!settings.convertor.processColorChannels) {
|
|
181
|
+
imageProcessing = imageProcessing.toColorspace('srgb');
|
|
182
|
+
}
|
|
183
|
+
imageProcessing.toFile(outputPath, function (err, info) {
|
|
184
|
+
if (err) {
|
|
185
|
+
console.error("Error converting ".concat(file, " to webP"), err);
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.log("Image ".concat(file, " converted to webP"), info);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return [2 /*return*/];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
_h.label = 3;
|
|
197
|
+
case 3:
|
|
198
|
+
_h.trys.push([3, 8, 9, 10]);
|
|
199
|
+
files_1 = __values(files), files_1_1 = files_1.next();
|
|
200
|
+
_h.label = 4;
|
|
201
|
+
case 4:
|
|
202
|
+
if (!!files_1_1.done) return [3 /*break*/, 7];
|
|
203
|
+
file = files_1_1.value;
|
|
204
|
+
return [5 /*yield**/, _loop_2(file)];
|
|
205
|
+
case 5:
|
|
206
|
+
_h.sent();
|
|
207
|
+
_h.label = 6;
|
|
208
|
+
case 6:
|
|
209
|
+
files_1_1 = files_1.next();
|
|
210
|
+
return [3 /*break*/, 4];
|
|
211
|
+
case 7: return [3 /*break*/, 10];
|
|
212
|
+
case 8:
|
|
213
|
+
e_1_1 = _h.sent();
|
|
214
|
+
e_1 = { error: e_1_1 };
|
|
215
|
+
return [3 /*break*/, 10];
|
|
216
|
+
case 9:
|
|
217
|
+
try {
|
|
218
|
+
if (files_1_1 && !files_1_1.done && (_b = files_1.return)) _b.call(files_1);
|
|
219
|
+
}
|
|
220
|
+
finally { if (e_1) throw e_1.error; }
|
|
221
|
+
return [7 /*endfinally*/];
|
|
222
|
+
case 10: return [2 /*return*/];
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}); });
|
package/dist/constants.js
CHANGED
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.MOBILE_TEMPLATE_URL = exports.USER_CONFIG = exports.orgName = exports.cliConfigPath = exports.cwd = exports.isDev = void 0;
|
|
17
|
+
exports.CODELEAP_CLI_SETTINGS_PATH = exports.MOBILE_TEMPLATE_URL = exports.USER_CONFIG = exports.orgName = exports.cliConfigPath = exports.cwd = exports.isDev = void 0;
|
|
18
18
|
var path_1 = __importDefault(require("path"));
|
|
19
19
|
var fs_1 = __importDefault(require("fs"));
|
|
20
20
|
var os_1 = __importDefault(require("os"));
|
|
@@ -32,3 +32,4 @@ catch (e) {
|
|
|
32
32
|
exports.orgName = 'codeleap-uk';
|
|
33
33
|
exports.USER_CONFIG = __assign({ SHELL: true }, _userConf);
|
|
34
34
|
exports.MOBILE_TEMPLATE_URL = "git@github.com:".concat(exports.orgName, "/mobile-template.git");
|
|
35
|
+
exports.CODELEAP_CLI_SETTINGS_PATH = './codeleapcli.config.json';
|
package/dist/index.js
CHANGED
|
@@ -8,6 +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
|
+
var convertorWebp_1 = require("./commands/convertorWebp");
|
|
11
12
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
12
13
|
var packageJson = require('../package.json');
|
|
13
14
|
(0, cleye_1.cli)({
|
|
@@ -18,7 +19,8 @@ var packageJson = require('../package.json');
|
|
|
18
19
|
createApp_1.createAppCommand,
|
|
19
20
|
configure_1.configureCommand,
|
|
20
21
|
downloadKeystores_1.downloadKeystores,
|
|
21
|
-
syncIcons_1.syncIconsCommand
|
|
22
|
+
syncIcons_1.syncIconsCommand,
|
|
23
|
+
convertorWebp_1.convertorWebpCommand
|
|
22
24
|
],
|
|
23
25
|
version: packageJson.version,
|
|
24
26
|
});
|