@foxford/cli 1.0.0-beta-6f7848f0-20250318
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/README.mdx +38 -0
- package/cli.png +0 -0
- package/fox.js +1812 -0
- package/fox.js.map +1 -0
- package/opt.png +0 -0
- package/package.json +64 -0
package/fox.js
ADDED
|
@@ -0,0 +1,1812 @@
|
|
|
1
|
+
#!/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defProps = Object.defineProperties;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __esm = (fn, res) => function __init() {
|
|
27
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
28
|
+
};
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
32
|
+
};
|
|
33
|
+
var __copyProps = (to, from, except, desc) => {
|
|
34
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
35
|
+
for (let key of __getOwnPropNames(from))
|
|
36
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
37
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
38
|
+
}
|
|
39
|
+
return to;
|
|
40
|
+
};
|
|
41
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
42
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
43
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
44
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
45
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
46
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
47
|
+
mod
|
|
48
|
+
));
|
|
49
|
+
var __async = (__this, __arguments, generator) => {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
var fulfilled = (value) => {
|
|
52
|
+
try {
|
|
53
|
+
step(generator.next(value));
|
|
54
|
+
} catch (e) {
|
|
55
|
+
reject(e);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var rejected = (value) => {
|
|
59
|
+
try {
|
|
60
|
+
step(generator.throw(value));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
reject(e);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
66
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/logger/index.ts
|
|
71
|
+
var import_logger, logger;
|
|
72
|
+
var init_logger = __esm({
|
|
73
|
+
"src/logger/index.ts"() {
|
|
74
|
+
"use strict";
|
|
75
|
+
import_logger = require("@foxford/logger");
|
|
76
|
+
logger = import_logger.log.getLogger("cli");
|
|
77
|
+
logger.setLevel("info");
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// src/program/abstract.action.ts
|
|
82
|
+
var AbstractAction;
|
|
83
|
+
var init_abstract_action = __esm({
|
|
84
|
+
"src/program/abstract.action.ts"() {
|
|
85
|
+
"use strict";
|
|
86
|
+
AbstractAction = class {
|
|
87
|
+
constructor(program) {
|
|
88
|
+
this.program = program;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// src/program/abstract.command.ts
|
|
95
|
+
var AbstractCommand;
|
|
96
|
+
var init_abstract_command = __esm({
|
|
97
|
+
"src/program/abstract.command.ts"() {
|
|
98
|
+
"use strict";
|
|
99
|
+
AbstractCommand = class {
|
|
100
|
+
constructor(action) {
|
|
101
|
+
this.action = action;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// src/lib/runners/runner.ts
|
|
108
|
+
var init_runner = __esm({
|
|
109
|
+
"src/lib/runners/runner.ts"() {
|
|
110
|
+
"use strict";
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// src/lib/runners/ffmpeg.runner.ts
|
|
115
|
+
var import_node_path, import_chalk, import_fluent_ffmpeg, FFMpegRunner;
|
|
116
|
+
var init_ffmpeg_runner = __esm({
|
|
117
|
+
"src/lib/runners/ffmpeg.runner.ts"() {
|
|
118
|
+
"use strict";
|
|
119
|
+
import_node_path = __toESM(require("path"));
|
|
120
|
+
import_chalk = __toESM(require("chalk"));
|
|
121
|
+
import_fluent_ffmpeg = __toESM(require("fluent-ffmpeg"));
|
|
122
|
+
FFMpegRunner = class {
|
|
123
|
+
constructor(options) {
|
|
124
|
+
this.options = options != null ? options : {};
|
|
125
|
+
}
|
|
126
|
+
run(payload) {
|
|
127
|
+
return __async(this, null, function* () {
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
(0, import_fluent_ffmpeg.default)(payload.resource).output((_a = payload.output) != null ? _a : import_node_path.default.basename(payload.resource)).outputOptions([
|
|
131
|
+
"-hide_banner",
|
|
132
|
+
"-movflags +faststart",
|
|
133
|
+
"-pix_fmt yuv420p",
|
|
134
|
+
"-c:v libx264",
|
|
135
|
+
"-preset:v veryslow",
|
|
136
|
+
"-profile:v high",
|
|
137
|
+
"-level 3.1",
|
|
138
|
+
"-tune:v ssim",
|
|
139
|
+
"-r 30",
|
|
140
|
+
"-g 180",
|
|
141
|
+
"-keyint_min 180",
|
|
142
|
+
"-sc_threshold 0",
|
|
143
|
+
"-max_muxing_queue_size 1024",
|
|
144
|
+
// '-vf scale=1920:-1',
|
|
145
|
+
"-f mp4",
|
|
146
|
+
...(_b = payload.extraFlags) != null ? _b : []
|
|
147
|
+
]).on("end", function() {
|
|
148
|
+
resolve(payload.resource);
|
|
149
|
+
}).on("error", function(err) {
|
|
150
|
+
console.log();
|
|
151
|
+
console.log(import_chalk.default.redBright("Cannot process video: " + err.message));
|
|
152
|
+
reject(err);
|
|
153
|
+
}).run();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// src/lib/runners/shell.runner.ts
|
|
162
|
+
var import_child_process, import_chalk2, ShellRunner;
|
|
163
|
+
var init_shell_runner = __esm({
|
|
164
|
+
"src/lib/runners/shell.runner.ts"() {
|
|
165
|
+
"use strict";
|
|
166
|
+
import_child_process = require("child_process");
|
|
167
|
+
import_chalk2 = __toESM(require("chalk"));
|
|
168
|
+
ShellRunner = class {
|
|
169
|
+
constructor(binary, options) {
|
|
170
|
+
this.binary = binary;
|
|
171
|
+
this.options = options != null ? options : { cwd: process.cwd() };
|
|
172
|
+
}
|
|
173
|
+
run(_0) {
|
|
174
|
+
return __async(this, arguments, function* (command, args = [], options = {}, collect = false) {
|
|
175
|
+
const spawnOptions = __spreadValues({
|
|
176
|
+
cwd: this.options.cwd,
|
|
177
|
+
stdio: collect ? "pipe" : "inherit",
|
|
178
|
+
shell: true
|
|
179
|
+
}, options);
|
|
180
|
+
return new Promise((resolve, reject) => {
|
|
181
|
+
const child = (0, import_child_process.spawn)(`${this.binary}`, [command, ...args], spawnOptions);
|
|
182
|
+
if (collect && child.stdout) {
|
|
183
|
+
child.stdout.on("data", (data) => resolve(data.toString().replace(/\r\n|\n/, "")));
|
|
184
|
+
}
|
|
185
|
+
child.on("close", (code) => {
|
|
186
|
+
if (code === 0) {
|
|
187
|
+
resolve(child.stdout);
|
|
188
|
+
} else {
|
|
189
|
+
console.error(import_chalk2.default.red(`
|
|
190
|
+
\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0432\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C \u043A\u043E\u043C\u0430\u043D\u0434\u0443: ${this.binary} ${command} ${args} `));
|
|
191
|
+
reject(code);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
runSync(command) {
|
|
198
|
+
const spawnOptions = {
|
|
199
|
+
cwd: this.options.cwd,
|
|
200
|
+
encoding: "utf-8"
|
|
201
|
+
};
|
|
202
|
+
return (0, import_child_process.execSync)(`${this.binary} ${command}`, spawnOptions);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @param command
|
|
206
|
+
* @returns The entire command that will be ran when calling `run(command)`.
|
|
207
|
+
*/
|
|
208
|
+
rawFullCommand(command) {
|
|
209
|
+
const commandArgs = [command];
|
|
210
|
+
return `${this.binary} ${commandArgs.join(" ")}`;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// src/lib/runners/node.runner.ts
|
|
217
|
+
var NodeRunner;
|
|
218
|
+
var init_node_runner = __esm({
|
|
219
|
+
"src/lib/runners/node.runner.ts"() {
|
|
220
|
+
"use strict";
|
|
221
|
+
init_shell_runner();
|
|
222
|
+
NodeRunner = class extends ShellRunner {
|
|
223
|
+
constructor(options) {
|
|
224
|
+
super("node", options);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// src/lib/runners/npm.runner.ts
|
|
231
|
+
var NpmRunner;
|
|
232
|
+
var init_npm_runner = __esm({
|
|
233
|
+
"src/lib/runners/npm.runner.ts"() {
|
|
234
|
+
"use strict";
|
|
235
|
+
init_shell_runner();
|
|
236
|
+
NpmRunner = class extends ShellRunner {
|
|
237
|
+
constructor(options) {
|
|
238
|
+
super("npm", options);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// src/lib/runners/pnpm.runner.ts
|
|
245
|
+
var PnpmRunner;
|
|
246
|
+
var init_pnpm_runner = __esm({
|
|
247
|
+
"src/lib/runners/pnpm.runner.ts"() {
|
|
248
|
+
"use strict";
|
|
249
|
+
init_shell_runner();
|
|
250
|
+
PnpmRunner = class extends ShellRunner {
|
|
251
|
+
constructor(options) {
|
|
252
|
+
super("pnpm", options);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// src/helpers/env.ts
|
|
259
|
+
function truthy(value) {
|
|
260
|
+
return !!value;
|
|
261
|
+
}
|
|
262
|
+
function loadEnv(pkgPath) {
|
|
263
|
+
const dotenvFiles = [
|
|
264
|
+
Boolean("production") && import_node_path2.default.join(pkgPath, `.env.${"production"}.local`),
|
|
265
|
+
Boolean("production") && import_node_path2.default.join(pkgPath, `.env.${"production"}`),
|
|
266
|
+
Boolean("production") === false && import_node_path2.default.join(pkgPath, `.env.development`),
|
|
267
|
+
import_node_path2.default.join(pkgPath, `.env.local`),
|
|
268
|
+
import_node_path2.default.join(pkgPath, ".env")
|
|
269
|
+
].filter(truthy);
|
|
270
|
+
dotenvFiles.forEach((dotenvFile) => {
|
|
271
|
+
if (import_fs_extra.default.existsSync(dotenvFile)) {
|
|
272
|
+
import_dotenv_expand.default.expand(
|
|
273
|
+
import_dotenv.default.config({
|
|
274
|
+
path: dotenvFile
|
|
275
|
+
})
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
return dotenvFiles;
|
|
280
|
+
}
|
|
281
|
+
var import_node_path2, import_dotenv, import_dotenv_expand, import_fs_extra;
|
|
282
|
+
var init_env = __esm({
|
|
283
|
+
"src/helpers/env.ts"() {
|
|
284
|
+
"use strict";
|
|
285
|
+
import_node_path2 = __toESM(require("path"));
|
|
286
|
+
import_dotenv = __toESM(require("dotenv"));
|
|
287
|
+
import_dotenv_expand = __toESM(require("dotenv-expand"));
|
|
288
|
+
import_fs_extra = __toESM(require("fs-extra"));
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// src/helpers/logger.ts
|
|
293
|
+
var label;
|
|
294
|
+
var init_logger2 = __esm({
|
|
295
|
+
"src/helpers/logger.ts"() {
|
|
296
|
+
"use strict";
|
|
297
|
+
label = (chalk13, label2) => chalk13.black(` ${label2} `);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// src/lib/runners/script.runner.ts
|
|
302
|
+
var import_chalk3, getLabel, getFailLabel, ScriptRunner;
|
|
303
|
+
var init_script_runner = __esm({
|
|
304
|
+
"src/lib/runners/script.runner.ts"() {
|
|
305
|
+
"use strict";
|
|
306
|
+
import_chalk3 = __toESM(require("chalk"));
|
|
307
|
+
init_pnpm_runner();
|
|
308
|
+
init_env();
|
|
309
|
+
init_logger2();
|
|
310
|
+
getLabel = (pkgName) => {
|
|
311
|
+
return label(import_chalk3.default.bgGreen, pkgName) + import_chalk3.default.white(" ");
|
|
312
|
+
};
|
|
313
|
+
getFailLabel = (pkgName) => {
|
|
314
|
+
return label(import_chalk3.default.bgRed, pkgName) + import_chalk3.default.white(" ");
|
|
315
|
+
};
|
|
316
|
+
ScriptRunner = class {
|
|
317
|
+
constructor(options) {
|
|
318
|
+
this.options = options != null ? options : {};
|
|
319
|
+
}
|
|
320
|
+
run(_0, _1) {
|
|
321
|
+
return __async(this, arguments, function* (script, { pkg }) {
|
|
322
|
+
const label2 = getLabel(pkg.localName.toUpperCase());
|
|
323
|
+
const failLabel = getFailLabel(pkg.localName.toUpperCase());
|
|
324
|
+
console.log(label2 + import_chalk3.default.blue(`Start ${import_chalk3.default.white.underline(script)} process`));
|
|
325
|
+
if (this.options.verbose) {
|
|
326
|
+
console.log(label2 + import_chalk3.default.blue(`Print typescript config`));
|
|
327
|
+
console.log();
|
|
328
|
+
}
|
|
329
|
+
console.log(
|
|
330
|
+
label2 + import_chalk3.default.blue(`Env ${import_chalk3.default.magenta("process.env.NODE_ENV")} is ${import_chalk3.default.yellow("production")}`)
|
|
331
|
+
);
|
|
332
|
+
console.log(
|
|
333
|
+
label2 + import_chalk3.default.blue(`Env ${import_chalk3.default.magenta("process.env.NODE_OPTIONS")} is ${import_chalk3.default.yellow(process.env.NODE_OPTIONS)}`)
|
|
334
|
+
);
|
|
335
|
+
try {
|
|
336
|
+
console.log(label2 + import_chalk3.default.blue(`Load .env files`));
|
|
337
|
+
const envFiles = loadEnv(pkg.path);
|
|
338
|
+
console.log(JSON.stringify(envFiles, null, 2));
|
|
339
|
+
} catch (err) {
|
|
340
|
+
if (err instanceof Error) {
|
|
341
|
+
console.log(failLabel + import_chalk3.default.red(err.message));
|
|
342
|
+
process.exit(1);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const pnpmRunner = new PnpmRunner();
|
|
346
|
+
pnpmRunner.run("run", [`--filter ${pkg.localName}`, script], {
|
|
347
|
+
env: Object.assign(process.env, { FORCE_COLOR: "1" }),
|
|
348
|
+
cwd: pkg.path
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// src/lib/runners/tinypng.runner.ts
|
|
357
|
+
var import_chalk4, import_tinify, TinyPngRunner;
|
|
358
|
+
var init_tinypng_runner = __esm({
|
|
359
|
+
"src/lib/runners/tinypng.runner.ts"() {
|
|
360
|
+
"use strict";
|
|
361
|
+
import_chalk4 = __toESM(require("chalk"));
|
|
362
|
+
import_tinify = __toESM(require("tinify"));
|
|
363
|
+
TinyPngRunner = class {
|
|
364
|
+
constructor(options) {
|
|
365
|
+
this.options = options != null ? options : {};
|
|
366
|
+
if (!(options == null ? void 0 : options.token)) throw new Error("You must specify process.env.TINIFY_API_KEY env variable with tinify key");
|
|
367
|
+
}
|
|
368
|
+
run(payload) {
|
|
369
|
+
return __async(this, null, function* () {
|
|
370
|
+
var _a, _b, _c;
|
|
371
|
+
const source = import_tinify.default.fromFile(payload.resource);
|
|
372
|
+
import_tinify.default.key = (_b = (_a = this.options) == null ? void 0 : _a.token) != null ? _b : "";
|
|
373
|
+
try {
|
|
374
|
+
yield source.toFile((_c = payload.output) != null ? _c : payload.resource);
|
|
375
|
+
} catch (err) {
|
|
376
|
+
if (err instanceof Error) console.log(import_chalk4.default.redBright("Cannot compress resource with tinify: " + err.message));
|
|
377
|
+
}
|
|
378
|
+
return payload.resource;
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
runSync() {
|
|
382
|
+
throw new TypeError("this method not implemented");
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// src/lib/runners/runner.factory.ts
|
|
389
|
+
var RunnerMap, RunnerFactory;
|
|
390
|
+
var init_runner_factory = __esm({
|
|
391
|
+
"src/lib/runners/runner.factory.ts"() {
|
|
392
|
+
"use strict";
|
|
393
|
+
init_ffmpeg_runner();
|
|
394
|
+
init_node_runner();
|
|
395
|
+
init_npm_runner();
|
|
396
|
+
init_pnpm_runner();
|
|
397
|
+
init_runner();
|
|
398
|
+
init_script_runner();
|
|
399
|
+
init_tinypng_runner();
|
|
400
|
+
RunnerMap = {
|
|
401
|
+
["NPM" /* NPM */]: NpmRunner,
|
|
402
|
+
["PNPM" /* PNPM */]: PnpmRunner,
|
|
403
|
+
["NODE" /* NODE */]: NodeRunner,
|
|
404
|
+
["PACKAGE_JSON_SCRIPT" /* PACKAGE_JSON_SCRIPT */]: ScriptRunner,
|
|
405
|
+
["FFMPEG" /* FFMPEG */]: FFMpegRunner,
|
|
406
|
+
["TINYPNG" /* TINYPNG */]: TinyPngRunner
|
|
407
|
+
};
|
|
408
|
+
RunnerFactory = class {
|
|
409
|
+
static create(runner, options) {
|
|
410
|
+
const RunnerClass = RunnerMap[runner];
|
|
411
|
+
if (!RunnerClass) {
|
|
412
|
+
throw new Error(`Unknown runner ${runner}`);
|
|
413
|
+
}
|
|
414
|
+
return new RunnerClass(options);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
// src/lib/runners/index.ts
|
|
421
|
+
var init_runners = __esm({
|
|
422
|
+
"src/lib/runners/index.ts"() {
|
|
423
|
+
"use strict";
|
|
424
|
+
init_runner();
|
|
425
|
+
init_runner_factory();
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
// src/program/program.ts
|
|
430
|
+
var import_node_path3, import_commander, import_detect_package_manager, import_dotenv2, import_fs_extra2, import_zx, Program;
|
|
431
|
+
var init_program = __esm({
|
|
432
|
+
"src/program/program.ts"() {
|
|
433
|
+
"use strict";
|
|
434
|
+
import_node_path3 = __toESM(require("path"));
|
|
435
|
+
import_commander = require("commander");
|
|
436
|
+
import_detect_package_manager = require("detect-package-manager");
|
|
437
|
+
import_dotenv2 = __toESM(require("dotenv"));
|
|
438
|
+
import_fs_extra2 = require("fs-extra");
|
|
439
|
+
import_zx = require("zx");
|
|
440
|
+
init_runners();
|
|
441
|
+
Program = class extends import_commander.Command {
|
|
442
|
+
constructor() {
|
|
443
|
+
super();
|
|
444
|
+
this.rootPath = process.cwd();
|
|
445
|
+
this.commandList = [];
|
|
446
|
+
import_zx.$.verbose = false;
|
|
447
|
+
const dotenvFiles = [
|
|
448
|
+
import_node_path3.default.resolve("./.env.local"),
|
|
449
|
+
import_node_path3.default.resolve("./.env"),
|
|
450
|
+
import_node_path3.default.resolve(__dirname, "../.env.local"),
|
|
451
|
+
import_node_path3.default.resolve(__dirname, "../.env")
|
|
452
|
+
];
|
|
453
|
+
dotenvFiles.forEach((dotenvFile) => {
|
|
454
|
+
if ((0, import_fs_extra2.existsSync)(dotenvFile)) {
|
|
455
|
+
import_dotenv2.default.config({
|
|
456
|
+
path: dotenvFile
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
this.determineRootPath().then((path10) => this.rootPath = path10);
|
|
461
|
+
}
|
|
462
|
+
determineRootPath() {
|
|
463
|
+
return __async(this, null, function* () {
|
|
464
|
+
const packageManager = yield (0, import_detect_package_manager.detect)();
|
|
465
|
+
switch (packageManager) {
|
|
466
|
+
case "npm":
|
|
467
|
+
return import_node_path3.default.dirname(RunnerFactory.create("NPM" /* NPM */).runSync("root"));
|
|
468
|
+
case "pnpm":
|
|
469
|
+
return import_node_path3.default.dirname(RunnerFactory.create("PNPM" /* PNPM */).runSync("root"));
|
|
470
|
+
default:
|
|
471
|
+
return process.cwd();
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
defineCommand(command) {
|
|
476
|
+
this.commandList.push(command);
|
|
477
|
+
}
|
|
478
|
+
getCommands() {
|
|
479
|
+
return this.commandList;
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// src/program/index.ts
|
|
486
|
+
var init_program2 = __esm({
|
|
487
|
+
"src/program/index.ts"() {
|
|
488
|
+
"use strict";
|
|
489
|
+
init_abstract_action();
|
|
490
|
+
init_abstract_command();
|
|
491
|
+
init_program();
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// src/lib/ui/banner.ts
|
|
496
|
+
var BANNER;
|
|
497
|
+
var init_banner = __esm({
|
|
498
|
+
"src/lib/ui/banner.ts"() {
|
|
499
|
+
"use strict";
|
|
500
|
+
BANNER = `
|
|
501
|
+
\xB7\u2584\u2584\u2584 \u2590\u2584\u2022 \u2584 \xB7\u2584\u2584\u2584 \u2584\u2584\u2584 \xB7\u2584\u2584\u2584\u2584
|
|
502
|
+
\u2590\u2584\u2584\xB7\u25AA \u2588\u258C\u2588\u258C\u25AA\u2590\u2584\u2584\xB7\u25AA \u2580\u2584 \u2588\xB7\u2588\u2588\u25AA \u2588\u2588
|
|
503
|
+
\u2588\u2588\u25AA \u2584\u2588\u2580\u2584 \xB7\u2588\u2588\xB7 \u2588\u2588\u25AA \u2584\u2588\u2580\u2584 \u2590\u2580\u2580\u2584 \u2590\u2588\xB7 \u2590\u2588\u258C
|
|
504
|
+
\u2588\u2588\u258C.\u2590\u2588\u258C.\u2590\u258C\u25AA\u2590\u2588\xB7\u2588\u258C\u2588\u2588\u258C.\u2590\u2588\u258C.\u2590\u258C\u2590\u2588\u2022\u2588\u258C\u2588\u2588. \u2588\u2588
|
|
505
|
+
\u2580\u2580\u2580 \u2580\u2588\u2584\u2580\u25AA\u2022\u2580\u2580 \u2580\u2580\u2580\u2580\u2580 \u2580\u2588\u2584\u2580\u25AA.\u2580 \u2580\u2580\u2580\u2580\u2580\u2580\u2022
|
|
506
|
+
`;
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
// src/lib/ui/prefixes.ts
|
|
511
|
+
var import_chalk5, ERROR_PREFIX, INFO_PREFIX;
|
|
512
|
+
var init_prefixes = __esm({
|
|
513
|
+
"src/lib/ui/prefixes.ts"() {
|
|
514
|
+
"use strict";
|
|
515
|
+
import_chalk5 = __toESM(require("chalk"));
|
|
516
|
+
ERROR_PREFIX = import_chalk5.default.bgRgb(210, 0, 75).bold.rgb(0, 0, 0)(" Error ");
|
|
517
|
+
INFO_PREFIX = import_chalk5.default.bgRgb(60, 190, 100).bold.rgb(0, 0, 0)(" Info ");
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// src/lib/ui/index.ts
|
|
522
|
+
var init_ui = __esm({
|
|
523
|
+
"src/lib/ui/index.ts"() {
|
|
524
|
+
"use strict";
|
|
525
|
+
init_banner();
|
|
526
|
+
init_prefixes();
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
// src/processes/codegen/index.ts
|
|
531
|
+
var codegen_exports = {};
|
|
532
|
+
__export(codegen_exports, {
|
|
533
|
+
default: () => codegen_default
|
|
534
|
+
});
|
|
535
|
+
var codegen_default;
|
|
536
|
+
var init_codegen = __esm({
|
|
537
|
+
"src/processes/codegen/index.ts"() {
|
|
538
|
+
"use strict";
|
|
539
|
+
codegen_default = (_program) => {
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
// src/processes/codemod/action.ts
|
|
545
|
+
var CodemodAction;
|
|
546
|
+
var init_action = __esm({
|
|
547
|
+
"src/processes/codemod/action.ts"() {
|
|
548
|
+
"use strict";
|
|
549
|
+
init_runners();
|
|
550
|
+
init_program2();
|
|
551
|
+
CodemodAction = class extends AbstractAction {
|
|
552
|
+
handle(options) {
|
|
553
|
+
return __async(this, null, function* () {
|
|
554
|
+
const flags = [];
|
|
555
|
+
if (options.dry) flags.push("--dry");
|
|
556
|
+
if (options.verbose) flags.push("--verbose");
|
|
557
|
+
console.log("options", options);
|
|
558
|
+
console.log("flags", flags);
|
|
559
|
+
console.log("extra", options.extra);
|
|
560
|
+
const runner = RunnerFactory.create("NODE" /* NODE */, {
|
|
561
|
+
verbose: options.verbose
|
|
562
|
+
});
|
|
563
|
+
runner.run("", [], {
|
|
564
|
+
cwd: process.cwd()
|
|
565
|
+
});
|
|
566
|
+
return;
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
// src/lib/collection/collection.ts
|
|
574
|
+
var init_collection = __esm({
|
|
575
|
+
"src/lib/collection/collection.ts"() {
|
|
576
|
+
"use strict";
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
// src/lib/collection/abstract.collection.ts
|
|
581
|
+
var AbstractCollection;
|
|
582
|
+
var init_abstract_collection = __esm({
|
|
583
|
+
"src/lib/collection/abstract.collection.ts"() {
|
|
584
|
+
"use strict";
|
|
585
|
+
AbstractCollection = class {
|
|
586
|
+
constructor(collection) {
|
|
587
|
+
this.collection = collection;
|
|
588
|
+
}
|
|
589
|
+
execute(_name, _inputs, _extraFlags, _cwd) {
|
|
590
|
+
return __async(this, null, function* () {
|
|
591
|
+
return;
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
// src/lib/utils/formatting.ts
|
|
599
|
+
function normalizeToKebabOrSnakeCase(str) {
|
|
600
|
+
const STRING_DASHERIZE_REGEXP = /\s/g;
|
|
601
|
+
const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
|
|
602
|
+
return str.replace(STRING_DECAMELIZE_REGEXP, "$1-$2").toLowerCase().replace(STRING_DASHERIZE_REGEXP, "-");
|
|
603
|
+
}
|
|
604
|
+
var init_formatting = __esm({
|
|
605
|
+
"src/lib/utils/formatting.ts"() {
|
|
606
|
+
"use strict";
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
// src/lib/collection/fox-codemod.collection.ts
|
|
611
|
+
var import_node_path4, import_chalk6, import_fs_extra3, FoxCodemodCollection;
|
|
612
|
+
var init_fox_codemod_collection = __esm({
|
|
613
|
+
"src/lib/collection/fox-codemod.collection.ts"() {
|
|
614
|
+
"use strict";
|
|
615
|
+
import_node_path4 = __toESM(require("path"));
|
|
616
|
+
import_chalk6 = __toESM(require("chalk"));
|
|
617
|
+
import_fs_extra3 = __toESM(require("fs-extra"));
|
|
618
|
+
init_abstract_collection();
|
|
619
|
+
init_collection();
|
|
620
|
+
init_formatting();
|
|
621
|
+
FoxCodemodCollection = class extends AbstractCollection {
|
|
622
|
+
constructor() {
|
|
623
|
+
var _a;
|
|
624
|
+
super("@foxford/codemods" /* FOX_CODEMODS */);
|
|
625
|
+
this.codemods = [];
|
|
626
|
+
const pathCollection = require.resolve("@foxford/codemods" /* FOX_CODEMODS */);
|
|
627
|
+
const pkgJson = require(import_node_path4.default.join(import_node_path4.default.dirname(pathCollection), "package.json"));
|
|
628
|
+
if (!pkgJson.codemods) {
|
|
629
|
+
console.log(
|
|
630
|
+
import_chalk6.default.red('May be you must specify "codemods" section in your package.json with path to collection.json')
|
|
631
|
+
);
|
|
632
|
+
process.exit(1);
|
|
633
|
+
}
|
|
634
|
+
const collectionPath = import_node_path4.default.join(import_node_path4.default.dirname(pathCollection), (_a = pkgJson.codemods) != null ? _a : "");
|
|
635
|
+
if (!import_fs_extra3.default.existsSync(collectionPath)) {
|
|
636
|
+
console.log(
|
|
637
|
+
import_chalk6.default.red('Collection path specified in "codemods" section in your package.json is not valid: ', collectionPath)
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
try {
|
|
641
|
+
const collectionJson = require(collectionPath);
|
|
642
|
+
this.codemods = collectionJson.codemods.map((codemod) => __spreadProps(__spreadValues({}, codemod), {
|
|
643
|
+
name: normalizeToKebabOrSnakeCase(codemod.name)
|
|
644
|
+
}));
|
|
645
|
+
} catch (e) {
|
|
646
|
+
console.log(import_chalk6.default.red("Collection json is not valid"));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
getItems() {
|
|
650
|
+
return this.codemods;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
// src/lib/collection/collection.factory.ts
|
|
657
|
+
var CollectionFactory;
|
|
658
|
+
var init_collection_factory = __esm({
|
|
659
|
+
"src/lib/collection/collection.factory.ts"() {
|
|
660
|
+
"use strict";
|
|
661
|
+
init_collection();
|
|
662
|
+
init_fox_codemod_collection();
|
|
663
|
+
CollectionFactory = class {
|
|
664
|
+
static create(collection) {
|
|
665
|
+
if (collection === "@foxford/codemods" /* FOX_CODEMODS */) {
|
|
666
|
+
return new FoxCodemodCollection();
|
|
667
|
+
}
|
|
668
|
+
return new FoxCodemodCollection();
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
// src/lib/collection/index.ts
|
|
675
|
+
var init_collection2 = __esm({
|
|
676
|
+
"src/lib/collection/index.ts"() {
|
|
677
|
+
"use strict";
|
|
678
|
+
init_collection_factory();
|
|
679
|
+
init_collection();
|
|
680
|
+
init_abstract_collection();
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
// src/processes/codemod/command.ts
|
|
685
|
+
var import_chalk7, import_cli_table3, import_commander2, CodemodCommand;
|
|
686
|
+
var init_command = __esm({
|
|
687
|
+
"src/processes/codemod/command.ts"() {
|
|
688
|
+
"use strict";
|
|
689
|
+
import_chalk7 = __toESM(require("chalk"));
|
|
690
|
+
import_cli_table3 = __toESM(require("cli-table3"));
|
|
691
|
+
import_commander2 = require("commander");
|
|
692
|
+
init_collection2();
|
|
693
|
+
init_program2();
|
|
694
|
+
CodemodCommand = class extends AbstractCommand {
|
|
695
|
+
constructor() {
|
|
696
|
+
super(...arguments);
|
|
697
|
+
this.id = "codemod";
|
|
698
|
+
this.items = [];
|
|
699
|
+
}
|
|
700
|
+
buildRunCommand() {
|
|
701
|
+
const verbose = new import_commander2.Option("--verbose", "\u0412\u044B\u0432\u043E\u0434 \u0434\u0430\u043D\u043D\u044B\u0445");
|
|
702
|
+
const dry = new import_commander2.Option("--dry", "\u041F\u0440\u043E\u0433\u043E\u043D \u0431\u0435\u0437 \u0438\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0439");
|
|
703
|
+
const run = new import_commander2.Command("run");
|
|
704
|
+
run.description("\u0417\u0430\u043F\u0443\u0441\u0438\u0442\u044C \u043A\u043E\u0434\u043C\u043E\u0434 \u0441 \u0438\u043C\u0435\u043D\u0435\u043C <name>").argument("<name>", "\u0418\u043C\u044F \u043A\u043E\u0434\u043C\u043E\u0434\u0430 (codemod --list)").argument("<input...>", "Glob \u043F\u0430\u0442\u0442\u0435\u0440\u043D \u0444\u0430\u0439\u043B\u043E\u0432 \u0434\u043B\u044F \u043A\u043E\u0442\u043E\u0440\u044B\u0445 \u0431\u0443\u0434\u0435\u0442 \u043F\u0440\u0438\u043C\u0435\u043D\u0438\u043C \u043A\u043E\u0434\u043C\u043E\u0434").addOption(verbose).addOption(dry).allowUnknownOption(true).showHelpAfterError().action((name, input, options, command) => __async(this, null, function* () {
|
|
705
|
+
var _a, _b;
|
|
706
|
+
if (!this.items.filter((item) => item.name === name)) {
|
|
707
|
+
console.error("Name not found");
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
const unknownOptions = (_b = (_a = command.parseOptions(command.args)) == null ? void 0 : _a.unknown) != null ? _b : [];
|
|
711
|
+
const paths = input.filter((item) => !unknownOptions.includes(item));
|
|
712
|
+
if (unknownOptions.length) {
|
|
713
|
+
options.extra = unknownOptions;
|
|
714
|
+
}
|
|
715
|
+
options.paths = paths;
|
|
716
|
+
yield this.action.handle(options);
|
|
717
|
+
}));
|
|
718
|
+
return run;
|
|
719
|
+
}
|
|
720
|
+
buildListCommand() {
|
|
721
|
+
const run = new import_commander2.Command("list");
|
|
722
|
+
run.description("\u0412\u044B\u0432\u0435\u0441\u0442\u0438 \u043F\u043E\u043B\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u044B\u0445 \u043A\u043E\u0434\u043C\u043E\u0434\u043E\u0432").showHelpAfterError().action(() => __async(this, null, function* () {
|
|
723
|
+
const list = yield this.getCollectionItems();
|
|
724
|
+
console.log(
|
|
725
|
+
`\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u044B\u0435 \u043A\u043E\u0434\u043C\u043E\u0434\u044B \u0438\u0437 ${import_chalk7.default.bold(this.getCollection())}:
|
|
726
|
+
` + this.buildSchematicsListAsTable(list)
|
|
727
|
+
);
|
|
728
|
+
}));
|
|
729
|
+
return run;
|
|
730
|
+
}
|
|
731
|
+
getCollectionItems() {
|
|
732
|
+
return __async(this, null, function* () {
|
|
733
|
+
const list = yield this.getItems(this.getCollection());
|
|
734
|
+
this.items = list;
|
|
735
|
+
return list;
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
load(program) {
|
|
739
|
+
return __async(this, null, function* () {
|
|
740
|
+
const codemod = new import_commander2.Command("codemod");
|
|
741
|
+
codemod.addHelpText(
|
|
742
|
+
"before",
|
|
743
|
+
`
|
|
744
|
+
---------------------------------------
|
|
745
|
+
${import_chalk7.default.greenBright(
|
|
746
|
+
"\u{1F6E0} Codemod manager"
|
|
747
|
+
)}
|
|
748
|
+
---------------------------------------
|
|
749
|
+
`
|
|
750
|
+
).usage("<command>").helpOption(false).description(yield this.buildDescription()).summary("\u0423\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u0435 \u043A\u043E\u0434\u043C\u043E\u0434\u0430\u043C\u0438").addCommand(this.buildRunCommand()).addCommand(this.buildListCommand()).action((options) => __async(this, null, function* () {
|
|
751
|
+
if (!options || Object.keys(options).length === 0) {
|
|
752
|
+
codemod.outputHelp();
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
yield this.action.handle(options);
|
|
756
|
+
}));
|
|
757
|
+
program.addCommand(codemod);
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
buildSchematicsListAsTable(items) {
|
|
761
|
+
const leftMargin = " ";
|
|
762
|
+
const tableConfig = {
|
|
763
|
+
head: ["name", "description"],
|
|
764
|
+
chars: {
|
|
765
|
+
left: leftMargin.concat("\u2502"),
|
|
766
|
+
"top-left": leftMargin.concat("\u250C"),
|
|
767
|
+
"bottom-left": leftMargin.concat("\u2514"),
|
|
768
|
+
mid: "",
|
|
769
|
+
"left-mid": "",
|
|
770
|
+
"mid-mid": "",
|
|
771
|
+
"right-mid": ""
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
const table = new import_cli_table3.default(tableConfig);
|
|
775
|
+
for (const item of items) {
|
|
776
|
+
table.push([import_chalk7.default.green(item.name), item.description]);
|
|
777
|
+
}
|
|
778
|
+
return table.toString();
|
|
779
|
+
}
|
|
780
|
+
getCollection() {
|
|
781
|
+
return "@foxford/codemods" /* FOX_CODEMODS */;
|
|
782
|
+
}
|
|
783
|
+
getItems(collection) {
|
|
784
|
+
return __async(this, null, function* () {
|
|
785
|
+
const abstractCollection = CollectionFactory.create(collection);
|
|
786
|
+
this.items = yield abstractCollection.getItems();
|
|
787
|
+
return this.items;
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
buildDescription() {
|
|
791
|
+
return __async(this, null, function* () {
|
|
792
|
+
const list = yield this.getCollectionItems();
|
|
793
|
+
const shortList = list.slice(0, 20);
|
|
794
|
+
return `\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u044B\u0435 \u043A\u043E\u0434\u043C\u043E\u0434\u044B \u0438\u0437 ${import_chalk7.default.bold(this.getCollection())}:
|
|
795
|
+
` + this.buildSchematicsListAsTable(shortList) + import_chalk7.default.yellowBright(`
|
|
796
|
+
|
|
797
|
+
\u0427\u0442\u043E\u0431\u044B \u0443\u0432\u0438\u0434\u0435\u0442\u044C \u043F\u043E\u043B\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A \u043A\u043E\u0434\u043C\u043E\u0434\u043E\u0432 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u043A\u043E\u043C\u0430\u043D\u0434\u0443 `) + import_chalk7.default.greenBright(`codemod list`);
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
// src/processes/codemod/index.ts
|
|
805
|
+
var codemod_exports = {};
|
|
806
|
+
__export(codemod_exports, {
|
|
807
|
+
default: () => codemod_default
|
|
808
|
+
});
|
|
809
|
+
var codemod_default;
|
|
810
|
+
var init_codemod = __esm({
|
|
811
|
+
"src/processes/codemod/index.ts"() {
|
|
812
|
+
"use strict";
|
|
813
|
+
init_action();
|
|
814
|
+
init_command();
|
|
815
|
+
codemod_default = (program) => {
|
|
816
|
+
program.defineCommand(new CodemodCommand(new CodemodAction(program)));
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
// src/processes/deploy/providers/abstract.provider.ts
|
|
822
|
+
var import_zx2, DeployProvider;
|
|
823
|
+
var init_abstract_provider = __esm({
|
|
824
|
+
"src/processes/deploy/providers/abstract.provider.ts"() {
|
|
825
|
+
"use strict";
|
|
826
|
+
import_zx2 = require("zx");
|
|
827
|
+
init_logger();
|
|
828
|
+
DeployProvider = class {
|
|
829
|
+
constructor(providerName) {
|
|
830
|
+
this.providerName = providerName;
|
|
831
|
+
this.cwd = process.cwd();
|
|
832
|
+
this.logger = logger.getLogger(providerName);
|
|
833
|
+
this.buildDir = "./build";
|
|
834
|
+
this.packageJson = this.readPackageJson();
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Читает и парсит файл package.json из текущей рабочей директории.
|
|
838
|
+
*
|
|
839
|
+
* Эта функция пытается найти и прочитать файл package.json в текущей
|
|
840
|
+
* рабочей директории. Если файл найден, он читается синхронно и парсится как JSON.
|
|
841
|
+
*
|
|
842
|
+
* @throws {Error} Выбрасывает ошибку, если файл package.json не найден в текущей директории
|
|
843
|
+
* или если возникла ошибка при чтении/парсинге файла.
|
|
844
|
+
* @returns {FoxfordTools.PackageJson} Распарсенное содержимое файла package.json.
|
|
845
|
+
*/
|
|
846
|
+
readPackageJson(rootPath = this.cwd) {
|
|
847
|
+
const packageJsonPath = import_zx2.path.resolve(rootPath, "package.json");
|
|
848
|
+
console.log(packageJsonPath);
|
|
849
|
+
if (!import_zx2.fs.existsSync(packageJsonPath)) {
|
|
850
|
+
throw new Error("package.json \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D \u0432 \u0442\u0435\u043A\u0443\u0449\u0435\u0439 \u0434\u0438\u0440\u0435\u043A\u0442\u043E\u0440\u0438\u0438");
|
|
851
|
+
}
|
|
852
|
+
try {
|
|
853
|
+
const packageJsonContent = import_zx2.fs.readFileSync(packageJsonPath, "utf-8");
|
|
854
|
+
return JSON.parse(packageJsonContent);
|
|
855
|
+
} catch (error) {
|
|
856
|
+
throw new Error(`\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0447\u0442\u0435\u043D\u0438\u0438 \u0438\u043B\u0438 \u043F\u0430\u0440\u0441\u0438\u043D\u0433\u0435 package.json: ${error.message}`);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
// src/processes/deploy/providers/cdn.ts
|
|
864
|
+
var import_zx3, CdnDeploy;
|
|
865
|
+
var init_cdn = __esm({
|
|
866
|
+
"src/processes/deploy/providers/cdn.ts"() {
|
|
867
|
+
"use strict";
|
|
868
|
+
import_zx3 = require("zx");
|
|
869
|
+
init_abstract_provider();
|
|
870
|
+
init_logger();
|
|
871
|
+
CdnDeploy = class extends DeployProvider {
|
|
872
|
+
constructor() {
|
|
873
|
+
super("cdn");
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Определяет цель развертывания на основе текущей ветки Git.
|
|
877
|
+
*
|
|
878
|
+
* @returns {'latest' | 'beta'} 'latest' для ветки master, 'beta' для всех остальных.
|
|
879
|
+
*/
|
|
880
|
+
getTarget() {
|
|
881
|
+
const { GITHUB_REF_NAME } = process.env;
|
|
882
|
+
if (GITHUB_REF_NAME === "master") return "latest";
|
|
883
|
+
return "beta";
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Формирует удаленный путь для версии пакета.
|
|
887
|
+
*
|
|
888
|
+
* @param {string} bucket - Имя бакета.
|
|
889
|
+
* @param {string} packageName - Имя пакета.
|
|
890
|
+
* @returns {string} Полный путь для версии пакета.
|
|
891
|
+
*/
|
|
892
|
+
getRemoteDirByVersion(bucket, packageName) {
|
|
893
|
+
return `${bucket}/libs/${packageName}/${this.packageJson.version}/`;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Формирует удаленный путь для цели развертывания.
|
|
897
|
+
*
|
|
898
|
+
* @param {string} bucket - Имя бакета.
|
|
899
|
+
* @param {string} packageName - Имя пакета.
|
|
900
|
+
* @param {string} target - Цель развертывания ('latest' или 'beta').
|
|
901
|
+
* @returns {string} Полный путь для цели развертывания.
|
|
902
|
+
*/
|
|
903
|
+
getRemoteDirByTarget(bucket, packageName, target) {
|
|
904
|
+
return `${bucket}/libs/${packageName}/${target}/`;
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Выполняет процесс развертывания на CDN.
|
|
908
|
+
*
|
|
909
|
+
* Этот метод копирует файлы из локальной директории в удаленные директории CDN,
|
|
910
|
+
* используя rclone. Он обрабатывает как версионные, так и целевые пути.
|
|
911
|
+
*
|
|
912
|
+
* @param {DeployCdnOptions} params - Параметры развертывания.
|
|
913
|
+
* @param {string} [params.localDir] - Локальная директория для копирования (по умолчанию this.buildDir).
|
|
914
|
+
* @param {string} [params.bucket] - Имя бакета CDN (по умолчанию из env или 'dist.ngcdn.ru').
|
|
915
|
+
* @param {string} [params.packageName] - Имя пакета (по умолчанию из package.json).
|
|
916
|
+
* @param {'latest' | 'beta'} [params.target] - Цель развертывания (по умолчанию определяется автоматически).
|
|
917
|
+
* @param {boolean} [params.dry] - Если true, выполняет пробный запуск без фактической загрузки.
|
|
918
|
+
*
|
|
919
|
+
* @throws Завершает процесс, если локальная директория не существует.
|
|
920
|
+
*/
|
|
921
|
+
deploy(params) {
|
|
922
|
+
return __async(this, null, function* () {
|
|
923
|
+
var _a, _b, _c, _d, _e;
|
|
924
|
+
const { OS_USERNAME, OS_PASSWORD } = process.env;
|
|
925
|
+
if (!OS_USERNAME || !OS_PASSWORD) {
|
|
926
|
+
this.logger.warn("\u041D\u0435 \u0443\u043A\u0430\u0437\u0430\u043D\u044B \u043F\u0435\u0440\u0435\u043C\u0435\u043D\u043D\u044B\u0435 \u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u044F OS_USERNAME \u0438\u043B\u0438 OS_PASSWORD");
|
|
927
|
+
}
|
|
928
|
+
const localDir = import_zx3.path.join(process.cwd(), (_a = params.localDir) != null ? _a : this.buildDir);
|
|
929
|
+
this.packageJson = this.readPackageJson(localDir);
|
|
930
|
+
const bucket = (_c = (_b = params.bucket) != null ? _b : process.env.BUCKET) != null ? _c : "dist.ngcdn.ru";
|
|
931
|
+
const remoteDirs = [];
|
|
932
|
+
const packageName = (_d = params.packageName) != null ? _d : this.packageJson.name;
|
|
933
|
+
const target = (_e = params.target) != null ? _e : this.getTarget();
|
|
934
|
+
remoteDirs.push(this.getRemoteDirByVersion(bucket, packageName));
|
|
935
|
+
remoteDirs.push(this.getRemoteDirByTarget(bucket, packageName, target));
|
|
936
|
+
if (!import_zx3.fs.existsSync(localDir)) {
|
|
937
|
+
logger.error(`\u0414\u0438\u0440\u0435\u043A\u0442\u043E\u0440\u0438\u044F "${localDir}" \u043D\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442`);
|
|
938
|
+
process.exit(1);
|
|
939
|
+
}
|
|
940
|
+
yield Promise.allSettled(
|
|
941
|
+
remoteDirs.map((remoteDir) => __async(this, null, function* () {
|
|
942
|
+
const rclone = `rclone copy ${localDir} myremote:${remoteDir} --progress --error-on-no-transfer`;
|
|
943
|
+
logger.log(`\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u043F\u0430\u043A\u0435\u0442\u0430 \u0432 ${remoteDir} \u0441 \u043A\u043E\u043C\u0430\u043D\u0434\u043E\u0439:
|
|
944
|
+
`, rclone);
|
|
945
|
+
yield import_zx3.$`rclone copy ${localDir} myremote:${remoteDir} --progress --error-on-no-transfer ${params.dry ? "--dry-run" : ""}`;
|
|
946
|
+
}))
|
|
947
|
+
);
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
// src/processes/deploy/providers/npm.ts
|
|
955
|
+
function sleep(ms) {
|
|
956
|
+
if (false) {
|
|
957
|
+
return Promise.resolve();
|
|
958
|
+
}
|
|
959
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
960
|
+
}
|
|
961
|
+
var import_zx4, NpmDeploy;
|
|
962
|
+
var init_npm = __esm({
|
|
963
|
+
"src/processes/deploy/providers/npm.ts"() {
|
|
964
|
+
"use strict";
|
|
965
|
+
import_zx4 = require("zx");
|
|
966
|
+
init_abstract_provider();
|
|
967
|
+
init_logger();
|
|
968
|
+
NpmDeploy = class extends DeployProvider {
|
|
969
|
+
constructor() {
|
|
970
|
+
super("npm");
|
|
971
|
+
this.versionLists = [];
|
|
972
|
+
this.dry = "";
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Возвращает сообщение об устаревании с текущим SHA коммита.
|
|
976
|
+
*
|
|
977
|
+
* @returns Промис, который разрешается строкой сообщения об устаревании.
|
|
978
|
+
*/
|
|
979
|
+
getDeprecationMessage() {
|
|
980
|
+
return __async(this, null, function* () {
|
|
981
|
+
const commitSha = (yield import_zx4.$`git rev-parse --short HEAD`).toString().trim();
|
|
982
|
+
return `deprecated by ${commitSha}`;
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Создает или обновляет файл .npmrc с токеном аутентификации для реестра npm.
|
|
987
|
+
*
|
|
988
|
+
* Этот метод добавляет конфигурацию аутентификации в файл .npmrc,
|
|
989
|
+
* обеспечивая безопасный доступ к реестру npm для публикации пакетов.
|
|
990
|
+
* Он использует переменную окружения NPM_TOKEN для аутентификации.
|
|
991
|
+
*
|
|
992
|
+
* @returns Промис, который разрешается, когда файл .npmrc успешно обновлен.
|
|
993
|
+
* @throws Выбрасывает ошибку, если операция с файлом не удалась или если NPM_TOKEN не установлен.
|
|
994
|
+
*/
|
|
995
|
+
touchNpmrc() {
|
|
996
|
+
return __async(this, null, function* () {
|
|
997
|
+
yield import_zx4.$`echo "//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}" >> .npmrc`;
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Генерирует строку версии пакета на основе цели и SHA коммита.
|
|
1002
|
+
*
|
|
1003
|
+
* @param target - Цель развертывания. Может быть 'beta' или 'latest'.
|
|
1004
|
+
* Определяет, возвращать ли бета-версию или текущую версию пакета.
|
|
1005
|
+
* @param sha - Короткий SHA коммита, используемый в строке бета-версии.
|
|
1006
|
+
* @returns Строка, представляющая версию пакета.
|
|
1007
|
+
* Для цели 'latest' возвращает текущую версию пакета.
|
|
1008
|
+
* Для цели 'beta' возвращает строку версии в формате:
|
|
1009
|
+
* "<текущая_версия>-beta-<sha>-<текущая_дата>"
|
|
1010
|
+
*/
|
|
1011
|
+
getBetaPackageVersion(sha) {
|
|
1012
|
+
const now = /* @__PURE__ */ new Date();
|
|
1013
|
+
const year = now.getFullYear();
|
|
1014
|
+
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
1015
|
+
const day = String(now.getDate()).padStart(2, "0");
|
|
1016
|
+
const date = `${year}${month}${day}`;
|
|
1017
|
+
return `${this.packageJson.version}-beta-${sha}-${date}`;
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Фильтрует устаревшие версии из заданного списка версий пакета.
|
|
1021
|
+
*
|
|
1022
|
+
* Этот метод проверяет каждую версию в реестре npm, чтобы определить, является ли она устаревшей.
|
|
1023
|
+
* Он использует команду `npm view` для получения статуса устаревания каждой версии.
|
|
1024
|
+
*
|
|
1025
|
+
* @param versions - Массив строк версий для проверки на устаревание.
|
|
1026
|
+
* @returns Промис, который разрешается в массив строк версий, которые не являются устаревшими.
|
|
1027
|
+
*/
|
|
1028
|
+
getNotDeprecatedVersions(versions) {
|
|
1029
|
+
return __async(this, null, function* () {
|
|
1030
|
+
const notDeprecatedVersions = [];
|
|
1031
|
+
for (const ver of versions) {
|
|
1032
|
+
const cmd = ["npm", "view", `${this.packageJson.name}@${ver}`, "deprecated"];
|
|
1033
|
+
const result = yield import_zx4.$`${cmd}`;
|
|
1034
|
+
if (!result.toString().trim().includes("deprecated by")) {
|
|
1035
|
+
notDeprecatedVersions.push(ver);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
return notDeprecatedVersions;
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Получает список всех версий текущего пакета из реестра npm.
|
|
1043
|
+
*
|
|
1044
|
+
* Этот метод выполняет команду npm для получения всех версий пакета,
|
|
1045
|
+
* указанного в файле package.json. Затем он парсит JSON-ответ
|
|
1046
|
+
* и сохраняет результат в свойстве `versionLists` класса.
|
|
1047
|
+
*
|
|
1048
|
+
* @returns Промис, который разрешается в массив строк, где каждая строка
|
|
1049
|
+
* представляет версию пакета. Если парсинг не удался, возвращает
|
|
1050
|
+
* пустой массив.
|
|
1051
|
+
*
|
|
1052
|
+
* @throws Записывает ошибку в консоль, если парсинг JSON не удался, но не
|
|
1053
|
+
* выбрасывает исключение.
|
|
1054
|
+
*/
|
|
1055
|
+
getVersionsList() {
|
|
1056
|
+
return __async(this, null, function* () {
|
|
1057
|
+
logger.info("Getting versions list...");
|
|
1058
|
+
const outputProcess = yield import_zx4.$`npm view ${this.packageJson.name} versions --json`;
|
|
1059
|
+
const versionsListPo = outputProcess.toString();
|
|
1060
|
+
logger.info("Versions list recieved", versionsListPo);
|
|
1061
|
+
try {
|
|
1062
|
+
const parsed = JSON.parse(versionsListPo);
|
|
1063
|
+
if (Array.isArray(parsed)) {
|
|
1064
|
+
return parsed;
|
|
1065
|
+
} else {
|
|
1066
|
+
return [parsed];
|
|
1067
|
+
}
|
|
1068
|
+
} catch (e) {
|
|
1069
|
+
logger.error("Error parsing versions list");
|
|
1070
|
+
return [];
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Получает список бэта версий на текущую версию из списка всех версий.
|
|
1076
|
+
*
|
|
1077
|
+
* @param currentVersion - Строка текущей версии для сравнения.
|
|
1078
|
+
* @returns Массив строк похожих версий.
|
|
1079
|
+
*/
|
|
1080
|
+
getBetaVersions(currentVersion) {
|
|
1081
|
+
return this.versionLists.filter((ver) => {
|
|
1082
|
+
var _a;
|
|
1083
|
+
if (!ver.includes("beta")) return false;
|
|
1084
|
+
if (ver === currentVersion) return false;
|
|
1085
|
+
const semverFromVersion = currentVersion.match(/^[0-9]{1,9}.[0-9]{1,9}.[0-9]{1,9}/gi);
|
|
1086
|
+
if (!semverFromVersion) return false;
|
|
1087
|
+
const matchedVersion = (_a = semverFromVersion[0]) != null ? _a : null;
|
|
1088
|
+
if (!matchedVersion) return false;
|
|
1089
|
+
return ver.includes(matchedVersion);
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Помечает предыдущие похожие версии пакета как устаревшие.
|
|
1094
|
+
*
|
|
1095
|
+
* Этот метод находит похожие версии на текущую версию, фильтрует уже устаревшие версии,
|
|
1096
|
+
* а затем помечает оставшиеся версии как устаревшие, используя команду npm deprecate.
|
|
1097
|
+
*
|
|
1098
|
+
* @param currentVersion - Текущая версия пакета для сравнения при поиске похожих версий.
|
|
1099
|
+
* @returns Промис, который разрешается, когда все похожие, не устаревшие версии были помечены как устаревшие или была попытка их пометить.
|
|
1100
|
+
*/
|
|
1101
|
+
deprecatePrevBetaVersions(currentVersion) {
|
|
1102
|
+
return __async(this, null, function* () {
|
|
1103
|
+
logger.info("Set previous beta versions as deprecated");
|
|
1104
|
+
this.versionLists = yield this.getVersionsList();
|
|
1105
|
+
const betaVersions = this.getBetaVersions(currentVersion);
|
|
1106
|
+
logger.info("Founded beta versions:", betaVersions);
|
|
1107
|
+
const notDeprecatedVersions = yield this.getNotDeprecatedVersions(betaVersions);
|
|
1108
|
+
logger.info("Not deprecated versions:", notDeprecatedVersions);
|
|
1109
|
+
const deprecationMessage = yield this.getDeprecationMessage();
|
|
1110
|
+
for (const ver of notDeprecatedVersions) {
|
|
1111
|
+
yield sleep(500);
|
|
1112
|
+
try {
|
|
1113
|
+
if (!this.dry) {
|
|
1114
|
+
const cmd = ["npm", "deprecate", `${this.packageJson.name}@${ver}`, deprecationMessage];
|
|
1115
|
+
logger.info("Deprecate version:", cmd);
|
|
1116
|
+
yield import_zx4.$`${cmd}`;
|
|
1117
|
+
}
|
|
1118
|
+
} catch (error) {
|
|
1119
|
+
logger.error(error);
|
|
1120
|
+
continue;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Удаляет бета-версии пакета, которые похожи на текущую версию.
|
|
1127
|
+
*
|
|
1128
|
+
* Этот метод получает все версии пакета, находит похожие версии на текущую,
|
|
1129
|
+
* и удаляет те, которые являются бета-версиями. Он использует команду npm unpublish с флагом --force.
|
|
1130
|
+
*
|
|
1131
|
+
* @param currentVersion - Текущая версия пакета для сравнения при поиске похожих версий.
|
|
1132
|
+
* @returns Промис, который разрешается, когда все бета-версии были удалены или была попытка их удалить.
|
|
1133
|
+
* @throws Записывает ошибки в консоль, если удаление не удалось для какой-либо версии, но продолжает со следующей версией.
|
|
1134
|
+
*/
|
|
1135
|
+
unpublishBetaVersions(currentVersion) {
|
|
1136
|
+
return __async(this, null, function* () {
|
|
1137
|
+
logger.info("Unpublish beta versions");
|
|
1138
|
+
this.versionLists = yield this.getVersionsList();
|
|
1139
|
+
logger.info("Version list: ", this.versionLists);
|
|
1140
|
+
const betaVersions = this.getBetaVersions(currentVersion);
|
|
1141
|
+
logger.info("List for unpublish & deprecating: ", betaVersions);
|
|
1142
|
+
const deprecationMessage = yield this.getDeprecationMessage();
|
|
1143
|
+
for (const ver of betaVersions) {
|
|
1144
|
+
if (!ver.includes("beta")) continue;
|
|
1145
|
+
try {
|
|
1146
|
+
const deprecate = ["npm", "deprecate", `${this.packageJson.name}@${ver}`, deprecationMessage];
|
|
1147
|
+
logger.info("Deprecate version:", deprecate);
|
|
1148
|
+
yield import_zx4.$`${deprecate}`;
|
|
1149
|
+
const unpublish = ["npm", "unpublish", `${this.packageJson.name}@${ver}`, "--force", this.dry];
|
|
1150
|
+
logger.info("Unpublish version:", unpublish);
|
|
1151
|
+
yield import_zx4.$`${unpublish}`;
|
|
1152
|
+
} catch (error) {
|
|
1153
|
+
logger.error(error);
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
yield sleep(500);
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Разворачивает пакет в реестре npm.
|
|
1162
|
+
*
|
|
1163
|
+
* Этот метод обрабатывает весь процесс развертывания, включая управление версиями,
|
|
1164
|
+
* обновление package.json, публикацию npm и пост-публикационные действия, такие как пометка
|
|
1165
|
+
* предыдущих версий как устаревших или удаление бета-версий.
|
|
1166
|
+
*
|
|
1167
|
+
* @param params - Параметры развертывания.
|
|
1168
|
+
* @param params.dry - Если true, выполняет пробный запуск без фактической публикации.
|
|
1169
|
+
* @param params.target - Цель развертывания, либо 'beta', либо 'latest'. По умолчанию 'beta'.
|
|
1170
|
+
*
|
|
1171
|
+
* @throws Завершает процесс, если директория сборки не найдена.
|
|
1172
|
+
* @returns Промис, который разрешается, когда процесс развертывания завершен.
|
|
1173
|
+
*/
|
|
1174
|
+
deploy(params) {
|
|
1175
|
+
return __async(this, null, function* () {
|
|
1176
|
+
var _a, _b;
|
|
1177
|
+
logger.info("Start deploy process to npm", params);
|
|
1178
|
+
const localDir = import_zx4.path.join(process.cwd(), (_a = params.localDir) != null ? _a : this.buildDir);
|
|
1179
|
+
if (!import_zx4.fs.existsSync(localDir)) {
|
|
1180
|
+
logger.error(`\u0414\u0438\u0440\u0435\u043A\u0442\u043E\u0440\u0438\u044F "${localDir}" \u043D\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442`);
|
|
1181
|
+
process.exit(1);
|
|
1182
|
+
}
|
|
1183
|
+
this.packageJson = this.readPackageJson(localDir);
|
|
1184
|
+
if (params.dry === true) this.dry = "--dry-run";
|
|
1185
|
+
logger.info("Change directory to", localDir);
|
|
1186
|
+
(0, import_zx4.cd)(localDir);
|
|
1187
|
+
logger.info("Get commit sha");
|
|
1188
|
+
const commitSha = (yield import_zx4.$`git rev-parse --short HEAD`).toString().replace("\n", "");
|
|
1189
|
+
logger.info("Commit sha:", commitSha);
|
|
1190
|
+
const target = (_b = params.target) != null ? _b : "beta";
|
|
1191
|
+
logger.info("Target is:", target);
|
|
1192
|
+
yield this.touchNpmrc();
|
|
1193
|
+
logger.info("Touch .npmrc");
|
|
1194
|
+
if (target === "beta") {
|
|
1195
|
+
this.packageJson.version = this.packageJson.version.includes("beta") ? this.packageJson.version : this.getBetaPackageVersion(commitSha);
|
|
1196
|
+
}
|
|
1197
|
+
this.packageJson.sha = commitSha;
|
|
1198
|
+
logger.info("Target version is:", this.packageJson.version);
|
|
1199
|
+
if (this.packageJson.scripts && this.packageJson.scripts.postinstall) {
|
|
1200
|
+
this.packageJson.scripts = {
|
|
1201
|
+
postinstall: this.packageJson.scripts.postinstall
|
|
1202
|
+
};
|
|
1203
|
+
} else {
|
|
1204
|
+
this.packageJson.scripts = {};
|
|
1205
|
+
}
|
|
1206
|
+
if (this.packageJson.devDependencies) {
|
|
1207
|
+
delete this.packageJson.devDependencies;
|
|
1208
|
+
}
|
|
1209
|
+
logger.info("Resulted package.json", this.packageJson);
|
|
1210
|
+
yield import_zx4.fs.writeJson("package.json", this.packageJson, {
|
|
1211
|
+
spaces: 2
|
|
1212
|
+
});
|
|
1213
|
+
const cmd = ["npm", "publish", "--access=public", `--tag=${target}`, this.dry];
|
|
1214
|
+
logger.info("Publish with args:", cmd);
|
|
1215
|
+
yield import_zx4.$`${cmd}`;
|
|
1216
|
+
if (target === "beta") {
|
|
1217
|
+
yield this.deprecatePrevBetaVersions(this.packageJson.version);
|
|
1218
|
+
} else {
|
|
1219
|
+
yield this.unpublishBetaVersions(this.packageJson.version);
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
});
|
|
1226
|
+
|
|
1227
|
+
// src/processes/deploy/action.ts
|
|
1228
|
+
var DeployAction;
|
|
1229
|
+
var init_action2 = __esm({
|
|
1230
|
+
"src/processes/deploy/action.ts"() {
|
|
1231
|
+
"use strict";
|
|
1232
|
+
init_program2();
|
|
1233
|
+
init_cdn();
|
|
1234
|
+
init_npm();
|
|
1235
|
+
DeployAction = class extends AbstractAction {
|
|
1236
|
+
handle(params) {
|
|
1237
|
+
return __async(this, null, function* () {
|
|
1238
|
+
let provider;
|
|
1239
|
+
switch (params.provider) {
|
|
1240
|
+
case "npm":
|
|
1241
|
+
provider = new NpmDeploy();
|
|
1242
|
+
break;
|
|
1243
|
+
case "cdn":
|
|
1244
|
+
provider = new CdnDeploy();
|
|
1245
|
+
break;
|
|
1246
|
+
default:
|
|
1247
|
+
throw new Error(`Unsupported deploy provider: ${params.provider}`);
|
|
1248
|
+
}
|
|
1249
|
+
yield provider.deploy(params);
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
|
|
1256
|
+
// src/processes/deploy/command.ts
|
|
1257
|
+
var import_commander3, DeployCommand;
|
|
1258
|
+
var init_command2 = __esm({
|
|
1259
|
+
"src/processes/deploy/command.ts"() {
|
|
1260
|
+
"use strict";
|
|
1261
|
+
import_commander3 = require("commander");
|
|
1262
|
+
init_program2();
|
|
1263
|
+
DeployCommand = class extends AbstractCommand {
|
|
1264
|
+
constructor() {
|
|
1265
|
+
super(...arguments);
|
|
1266
|
+
this.id = "deploy";
|
|
1267
|
+
}
|
|
1268
|
+
load(program) {
|
|
1269
|
+
return __async(this, null, function* () {
|
|
1270
|
+
const deployCommand = new import_commander3.Command("deploy").description("\u0417\u0430\u0434\u0435\u043F\u043B\u043E\u0438\u0442\u044C \u043F\u0430\u043A\u0435\u0442");
|
|
1271
|
+
const targetOption = new import_commander3.Option("--target <target>", "\u0420\u0435\u043B\u0438\u0437 beta \u0438\u043B\u0438 latest").choices(["beta", "latest"]).default("beta");
|
|
1272
|
+
const localDirOption = new import_commander3.Option("--localDir <path>", "\u0418\u0437 \u043A\u0430\u043A\u043E\u0439 \u043B\u043E\u043A\u0430\u043B\u044C\u043D\u043E\u0439 \u0434\u0438\u0440\u0435\u043A\u0442\u043E\u0440\u0438\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0435");
|
|
1273
|
+
const dryOption = new import_commander3.Option("--dry", "\u0417\u0430\u043F\u0443\u0441\u043A \u0431\u0435\u0437 \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u044F \u043E\u043F\u0435\u0440\u0430\u0446\u0438\u0438").default(false);
|
|
1274
|
+
const cdnCommand = new import_commander3.Command("cdn").description("\u0414\u0435\u043F\u043B\u043E\u0439 \u043F\u0430\u043A\u0435\u0442\u0430 \u0432 cdn").option("--bucket <name>", "\u0412 \u043A\u0430\u043A\u043E\u0439 \u0431\u0430\u043A\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044C \u043F\u0430\u043A\u0435\u0442").option("--packageName <name>", "\u0418\u043C\u044F \u043F\u0430\u043A\u0435\u0442\u0430 \u0432\u043C\u0435\u0441\u0442\u043E packageJson.name").action((params) => __async(this, null, function* () {
|
|
1275
|
+
yield this.action.handle(__spreadProps(__spreadValues({}, params), { provider: "cdn" }));
|
|
1276
|
+
}));
|
|
1277
|
+
cdnCommand.addOption(targetOption);
|
|
1278
|
+
cdnCommand.addOption(localDirOption);
|
|
1279
|
+
cdnCommand.addOption(dryOption);
|
|
1280
|
+
const npmCommand = new import_commander3.Command("npm").description("\u0414\u0435\u043F\u043B\u043E\u0439 \u043F\u0430\u043A\u0435\u0442\u0430 \u0432 npm").action((params) => __async(this, null, function* () {
|
|
1281
|
+
yield this.action.handle(__spreadProps(__spreadValues({}, params), { provider: "npm" }));
|
|
1282
|
+
}));
|
|
1283
|
+
npmCommand.addOption(targetOption);
|
|
1284
|
+
npmCommand.addOption(localDirOption);
|
|
1285
|
+
npmCommand.addOption(dryOption);
|
|
1286
|
+
deployCommand.addCommand(cdnCommand);
|
|
1287
|
+
deployCommand.addCommand(npmCommand);
|
|
1288
|
+
program.addCommand(deployCommand);
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
|
|
1295
|
+
// src/processes/deploy/index.ts
|
|
1296
|
+
var deploy_exports = {};
|
|
1297
|
+
__export(deploy_exports, {
|
|
1298
|
+
default: () => deploy_default
|
|
1299
|
+
});
|
|
1300
|
+
var deploy_default;
|
|
1301
|
+
var init_deploy = __esm({
|
|
1302
|
+
"src/processes/deploy/index.ts"() {
|
|
1303
|
+
"use strict";
|
|
1304
|
+
init_action2();
|
|
1305
|
+
init_command2();
|
|
1306
|
+
deploy_default = (program) => {
|
|
1307
|
+
program.defineCommand(new DeployCommand(new DeployAction(program)));
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
// src/processes/info/action.ts
|
|
1313
|
+
var import_os, import_chalk8, import_filesize, import_os_name, import_systeminformation, import_zx5, InfoAction;
|
|
1314
|
+
var init_action3 = __esm({
|
|
1315
|
+
"src/processes/info/action.ts"() {
|
|
1316
|
+
"use strict";
|
|
1317
|
+
import_os = require("os");
|
|
1318
|
+
import_chalk8 = __toESM(require("chalk"));
|
|
1319
|
+
import_filesize = require("filesize");
|
|
1320
|
+
import_os_name = __toESM(require("os-name"));
|
|
1321
|
+
import_systeminformation = __toESM(require("systeminformation"));
|
|
1322
|
+
import_zx5 = require("zx");
|
|
1323
|
+
init_ui();
|
|
1324
|
+
init_program2();
|
|
1325
|
+
InfoAction = class extends AbstractAction {
|
|
1326
|
+
handle() {
|
|
1327
|
+
return __async(this, null, function* () {
|
|
1328
|
+
this.displayBanner();
|
|
1329
|
+
yield this.displaySystemInformation();
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
displayBanner() {
|
|
1333
|
+
console.info(import_chalk8.default.red(BANNER));
|
|
1334
|
+
}
|
|
1335
|
+
displaySystemInformation() {
|
|
1336
|
+
return __async(this, null, function* () {
|
|
1337
|
+
console.info(import_chalk8.default.green("[System Information]"));
|
|
1338
|
+
console.info("OS Version :", import_chalk8.default.blue((0, import_os_name.default)((0, import_os.platform)(), (0, import_os.release)())));
|
|
1339
|
+
console.info("NodeJS Version :", import_chalk8.default.blue(process.version));
|
|
1340
|
+
const where = yield import_zx5.$`which node`;
|
|
1341
|
+
console.info("NodeJS path :", where.toString());
|
|
1342
|
+
console.info("NODE_OPTIONS :", import_chalk8.default.blue(process.env.NODE_OPTIONS));
|
|
1343
|
+
if (where.toString().includes("nvm")) {
|
|
1344
|
+
console.info("NVM_DIR :", import_chalk8.default.blue(process.env.NVM_DIR));
|
|
1345
|
+
}
|
|
1346
|
+
console.log();
|
|
1347
|
+
const cpu = yield import_systeminformation.default.cpu();
|
|
1348
|
+
const mem = yield import_systeminformation.default.mem();
|
|
1349
|
+
console.info("CPU Family:", import_chalk8.default.blue(`${cpu.vendor} ${cpu.brand}`));
|
|
1350
|
+
console.info("CPU Ph Cores:", import_chalk8.default.blue(cpu.cores));
|
|
1351
|
+
console.info("CPU Speed:", import_chalk8.default.blue(`${cpu.speed}GHz`));
|
|
1352
|
+
console.info("Memory:", import_chalk8.default.blue(`${(0, import_filesize.filesize)(mem.total)}`));
|
|
1353
|
+
console.info("Memory Free:", import_chalk8.default.blue(`${(0, import_filesize.filesize)(mem.free)}`));
|
|
1354
|
+
console.info("Memory Used:", import_chalk8.default.blue(`${(0, import_filesize.filesize)(mem.used)}`));
|
|
1355
|
+
console.info("Memory Available:", import_chalk8.default.blue(`${(0, import_filesize.filesize)(mem.available)}`));
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
rightPad(name, length) {
|
|
1359
|
+
while (name.length < length) {
|
|
1360
|
+
name = name.concat(" ");
|
|
1361
|
+
}
|
|
1362
|
+
return name;
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
|
|
1368
|
+
// src/processes/info/command.ts
|
|
1369
|
+
var InfoCommand;
|
|
1370
|
+
var init_command3 = __esm({
|
|
1371
|
+
"src/processes/info/command.ts"() {
|
|
1372
|
+
"use strict";
|
|
1373
|
+
init_program2();
|
|
1374
|
+
InfoCommand = class extends AbstractCommand {
|
|
1375
|
+
constructor() {
|
|
1376
|
+
super(...arguments);
|
|
1377
|
+
this.id = "info";
|
|
1378
|
+
}
|
|
1379
|
+
load(program) {
|
|
1380
|
+
return __async(this, null, function* () {
|
|
1381
|
+
program.command("info").alias("i").description("\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0438\u043D\u0444\u043E").action(() => __async(this, null, function* () {
|
|
1382
|
+
yield this.action.handle();
|
|
1383
|
+
}));
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
|
|
1390
|
+
// src/processes/info/index.ts
|
|
1391
|
+
var info_exports = {};
|
|
1392
|
+
__export(info_exports, {
|
|
1393
|
+
default: () => info_default
|
|
1394
|
+
});
|
|
1395
|
+
var info_default;
|
|
1396
|
+
var init_info = __esm({
|
|
1397
|
+
"src/processes/info/index.ts"() {
|
|
1398
|
+
"use strict";
|
|
1399
|
+
init_action3();
|
|
1400
|
+
init_command3();
|
|
1401
|
+
info_default = (program) => {
|
|
1402
|
+
program.defineCommand(new InfoCommand(new InfoAction(program)));
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
|
|
1407
|
+
// src/processes/optimize/action.ts
|
|
1408
|
+
var import_fs, import_node_path5, import_chalk9, import_cli_progress, import_cli_table32, import_filesize2, import_glob, import_inquirer, OptimizeAction;
|
|
1409
|
+
var init_action4 = __esm({
|
|
1410
|
+
"src/processes/optimize/action.ts"() {
|
|
1411
|
+
"use strict";
|
|
1412
|
+
import_fs = __toESM(require("fs"));
|
|
1413
|
+
import_node_path5 = __toESM(require("path"));
|
|
1414
|
+
import_chalk9 = __toESM(require("chalk"));
|
|
1415
|
+
import_cli_progress = __toESM(require("cli-progress"));
|
|
1416
|
+
import_cli_table32 = __toESM(require("cli-table3"));
|
|
1417
|
+
import_filesize2 = require("filesize");
|
|
1418
|
+
import_glob = require("glob");
|
|
1419
|
+
import_inquirer = __toESM(require("inquirer"));
|
|
1420
|
+
init_runners();
|
|
1421
|
+
init_program2();
|
|
1422
|
+
OptimizeAction = class extends AbstractAction {
|
|
1423
|
+
constructor() {
|
|
1424
|
+
super(...arguments);
|
|
1425
|
+
this.buildStatusTable = (results) => {
|
|
1426
|
+
const success = results.filter((item) => item.status === true);
|
|
1427
|
+
const failed = results.filter((item) => item.status === false);
|
|
1428
|
+
const leftMargin = "";
|
|
1429
|
+
const table = new import_cli_table32.default({
|
|
1430
|
+
head: ["\u041E\u0431\u0440\u0430\u0431\u043E\u0442\u0430\u043D\u043E", "\u041D\u0435 \u043E\u0431\u0440\u0430\u0431\u043E\u0442\u0430\u043D\u043E", "\u0418\u0437\u043C\u0435\u043D\u0435\u043D\u0438\u0435 \u0440\u0430\u0437\u043C\u0435\u0440\u0430"],
|
|
1431
|
+
chars: {
|
|
1432
|
+
left: leftMargin.concat("\u2502"),
|
|
1433
|
+
"top-left": leftMargin.concat("\u250C"),
|
|
1434
|
+
"bottom-left": leftMargin.concat("\u2514"),
|
|
1435
|
+
mid: "",
|
|
1436
|
+
"left-mid": "",
|
|
1437
|
+
"mid-mid": "",
|
|
1438
|
+
"right-mid": ""
|
|
1439
|
+
}
|
|
1440
|
+
});
|
|
1441
|
+
const sumFilesize = results.reduce((acc, task) => {
|
|
1442
|
+
if (task.__originalStat && task.__optimizedStat) {
|
|
1443
|
+
acc += task.__originalStat.size - task.__optimizedStat.size;
|
|
1444
|
+
}
|
|
1445
|
+
return acc;
|
|
1446
|
+
}, 0);
|
|
1447
|
+
const sumPrefix = sumFilesize >= 0 ? "-" : "+";
|
|
1448
|
+
table.push([
|
|
1449
|
+
import_chalk9.default.greenBright(success.length),
|
|
1450
|
+
import_chalk9.default.redBright(failed.length),
|
|
1451
|
+
sumFilesize >= 0 ? import_chalk9.default.greenBright(`${sumPrefix}${(0, import_filesize2.filesize)(sumFilesize)}`) : import_chalk9.default.redBright(`${sumPrefix}${(0, import_filesize2.filesize)(Math.abs(sumFilesize))}`)
|
|
1452
|
+
]);
|
|
1453
|
+
return table.toString();
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
handle(_0) {
|
|
1457
|
+
return __async(this, arguments, function* (options, extraFlags = []) {
|
|
1458
|
+
const resources = yield (0, import_glob.glob)(import_node_path5.default.join(process.cwd(), options.filePath), { ignore: "node_modules/**" });
|
|
1459
|
+
console.log(import_chalk9.default.white(`\u041D\u0430\u0439\u0434\u0435\u043D\u043E ${import_chalk9.default.green(resources.length)} \u0440\u0435\u0441\u0443\u0440\u0441\u043E\u0432 \u0434\u043B\u044F \u043E\u043F\u0442\u0438\u043C\u0438\u0437\u0430\u0446\u0438\u0438`));
|
|
1460
|
+
console.log(
|
|
1461
|
+
import_chalk9.default.yellowBright(`\u0415\u0441\u043B\u0438 \u0432\u044B \u0445\u043E\u0442\u0438\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044C \u0441\u043F\u0438\u0441\u043E\u043A \u0440\u0435\u0441\u0443\u0440\u0441\u043E\u0432, \u0432\u043E\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435\u0441\u044C \u043E\u043F\u0446\u0438\u0435\u0439 ${import_chalk9.default.green("--list")}`)
|
|
1462
|
+
);
|
|
1463
|
+
if (options.list) console.log(resources);
|
|
1464
|
+
const answers = yield import_inquirer.default.prompt([
|
|
1465
|
+
{
|
|
1466
|
+
type: "list",
|
|
1467
|
+
message: "\u041F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442\u044C?",
|
|
1468
|
+
choices: [
|
|
1469
|
+
{ name: "Yes", value: 1 },
|
|
1470
|
+
{ name: "No", value: 0 }
|
|
1471
|
+
],
|
|
1472
|
+
default: 0,
|
|
1473
|
+
name: "continue"
|
|
1474
|
+
}
|
|
1475
|
+
]);
|
|
1476
|
+
if (!answers.continue) return;
|
|
1477
|
+
console.log();
|
|
1478
|
+
const bar = new import_cli_progress.default.SingleBar({ fps: 25 }, import_cli_progress.default.Presets.shades_classic);
|
|
1479
|
+
bar.start(resources.length, 0);
|
|
1480
|
+
const ft = yield import("file-type");
|
|
1481
|
+
const promises = resources.map((resource) => __async(this, null, function* () {
|
|
1482
|
+
var _a, _b;
|
|
1483
|
+
const fileType = yield ft.fileTypeFromFile(resource);
|
|
1484
|
+
if (!fileType)
|
|
1485
|
+
return {
|
|
1486
|
+
__originalPath: resource,
|
|
1487
|
+
__optimizedPath: resource,
|
|
1488
|
+
status: false
|
|
1489
|
+
};
|
|
1490
|
+
const { mime } = fileType;
|
|
1491
|
+
let runner;
|
|
1492
|
+
const outputPath = options.replace ? resource : import_node_path5.default.join(import_node_path5.default.dirname(resource), `${(_a = options.prefix) != null ? _a : ""}${import_node_path5.default.basename(resource)}`);
|
|
1493
|
+
switch (mime) {
|
|
1494
|
+
case "image/png":
|
|
1495
|
+
case "image/jpeg":
|
|
1496
|
+
runner = RunnerFactory.create("TINYPNG" /* TINYPNG */, {
|
|
1497
|
+
token: (_b = process.env.TINIFY_API_KEY) != null ? _b : "",
|
|
1498
|
+
verbose: true
|
|
1499
|
+
});
|
|
1500
|
+
break;
|
|
1501
|
+
case "video/mp4":
|
|
1502
|
+
runner = RunnerFactory.create("FFMPEG" /* FFMPEG */, {
|
|
1503
|
+
verbose: true
|
|
1504
|
+
});
|
|
1505
|
+
break;
|
|
1506
|
+
default:
|
|
1507
|
+
console.log(import_chalk9.default.yellowBright(`Unsupported mime type for ${import_chalk9.default.white(resource)}`));
|
|
1508
|
+
}
|
|
1509
|
+
if (!runner) {
|
|
1510
|
+
return {
|
|
1511
|
+
__originalPath: resource,
|
|
1512
|
+
__optimizedPath: resource,
|
|
1513
|
+
status: false
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
try {
|
|
1517
|
+
const beforeStat = import_fs.default.statSync(resource);
|
|
1518
|
+
yield runner.run({
|
|
1519
|
+
resource,
|
|
1520
|
+
output: outputPath,
|
|
1521
|
+
extraFlags
|
|
1522
|
+
});
|
|
1523
|
+
const afterStat = import_fs.default.statSync(outputPath);
|
|
1524
|
+
return {
|
|
1525
|
+
__originalPath: resource,
|
|
1526
|
+
__originalStat: beforeStat,
|
|
1527
|
+
__optimizedPath: resource,
|
|
1528
|
+
__optimizedStat: afterStat,
|
|
1529
|
+
status: true
|
|
1530
|
+
};
|
|
1531
|
+
} catch (err) {
|
|
1532
|
+
return {
|
|
1533
|
+
__originalPath: resource,
|
|
1534
|
+
__optimizedPath: resource,
|
|
1535
|
+
status: false,
|
|
1536
|
+
err
|
|
1537
|
+
};
|
|
1538
|
+
} finally {
|
|
1539
|
+
bar.increment();
|
|
1540
|
+
}
|
|
1541
|
+
}));
|
|
1542
|
+
yield Promise.all(promises).then((result) => {
|
|
1543
|
+
bar.stop();
|
|
1544
|
+
this.printResult(result);
|
|
1545
|
+
});
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
printResult(result) {
|
|
1549
|
+
const statusTable = this.buildStatusTable(result);
|
|
1550
|
+
console.log(statusTable);
|
|
1551
|
+
this.showUncompletedFiles(result);
|
|
1552
|
+
}
|
|
1553
|
+
showUncompletedFiles(results) {
|
|
1554
|
+
const failed = results.filter((item) => item.status === false);
|
|
1555
|
+
if (failed.length > 0) {
|
|
1556
|
+
console.log(import_chalk9.default.redBright("\u0421\u043F\u0438\u0441\u043E\u043A \u043D\u0435\u043E\u0431\u0440\u0430\u0431\u043E\u0442\u0430\u043D\u043D\u044B\u0445 \u0444\u0430\u0439\u043B\u043E\u0432"));
|
|
1557
|
+
console.log(failed.map((item) => item.__originalPath));
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
// src/processes/optimize/command.ts
|
|
1565
|
+
var import_chalk10, OptimizeCommand;
|
|
1566
|
+
var init_command4 = __esm({
|
|
1567
|
+
"src/processes/optimize/command.ts"() {
|
|
1568
|
+
"use strict";
|
|
1569
|
+
import_chalk10 = __toESM(require("chalk"));
|
|
1570
|
+
init_program2();
|
|
1571
|
+
OptimizeCommand = class extends AbstractCommand {
|
|
1572
|
+
constructor() {
|
|
1573
|
+
super(...arguments);
|
|
1574
|
+
this.id = "optimize";
|
|
1575
|
+
}
|
|
1576
|
+
load(program) {
|
|
1577
|
+
return __async(this, null, function* () {
|
|
1578
|
+
program.command("optimize [path] [extraFlags...]").alias("opt").option("-l, --list", "\u0412\u044B\u0432\u0435\u0441\u0442\u0438 \u0441\u043F\u0438\u0441\u043E\u043A \u0444\u0430\u0439\u043B\u043E\u0432 \u0434\u043B\u044F \u043E\u043F\u0442\u0438\u043C\u0438\u0437\u0430\u0446\u0438\u0438", false).option("-r, --replace", "\u0417\u0430\u043C\u0435\u043D\u0438\u0442\u044C \u0438\u0441\u0445\u043E\u0434\u043D\u044B\u0439 \u0444\u0430\u0439\u043B", false).option("-p, --prefix", "\u041F\u0440\u0435\u0444\u0438\u043A\u0441 \u0432 \u0438\u043C\u0435\u043D\u0438 \u043E\u043F\u0442\u0438\u043C\u0430\u0439\u0437\u043D\u0443\u0442\u043E\u0433\u043E \u0444\u0430\u0439\u043B\u0430", "__").description("\u041E\u043F\u0442\u0438\u043C\u0438\u0437\u0438\u0440\u043E\u0432\u0430\u0442\u044C \u0440\u0435\u0441\u0443\u0440\u0441(jpg,png,mp4)").action((path10, extraFlags, option) => __async(this, null, function* () {
|
|
1579
|
+
if (!path10) {
|
|
1580
|
+
console.log(import_chalk10.default.yellow("\u0423\u043A\u0430\u0436\u0438\u0442\u0435 \u043F\u0443\u0442\u044C \u0434\u043E \u0440\u0435\u0441\u0443\u0440\u0441\u0430(\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F glob)"));
|
|
1581
|
+
process.exit(1);
|
|
1582
|
+
}
|
|
1583
|
+
yield this.action.handle(
|
|
1584
|
+
{
|
|
1585
|
+
filePath: path10,
|
|
1586
|
+
list: option.list,
|
|
1587
|
+
replace: option.replace,
|
|
1588
|
+
prefix: option.prefix
|
|
1589
|
+
},
|
|
1590
|
+
extraFlags
|
|
1591
|
+
);
|
|
1592
|
+
}));
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
});
|
|
1598
|
+
|
|
1599
|
+
// src/processes/optimize/index.ts
|
|
1600
|
+
var optimize_exports = {};
|
|
1601
|
+
__export(optimize_exports, {
|
|
1602
|
+
default: () => optimize_default
|
|
1603
|
+
});
|
|
1604
|
+
var optimize_default;
|
|
1605
|
+
var init_optimize = __esm({
|
|
1606
|
+
"src/processes/optimize/index.ts"() {
|
|
1607
|
+
"use strict";
|
|
1608
|
+
init_action4();
|
|
1609
|
+
init_command4();
|
|
1610
|
+
optimize_default = (program) => {
|
|
1611
|
+
program.defineCommand(new OptimizeCommand(new OptimizeAction(program)));
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
// src/bin/fox.ts
|
|
1617
|
+
var import_chalk12 = __toESM(require("chalk"));
|
|
1618
|
+
|
|
1619
|
+
// package.json
|
|
1620
|
+
var package_default = {
|
|
1621
|
+
name: "@foxford/cli",
|
|
1622
|
+
version: "1.0.0",
|
|
1623
|
+
description: "Foxford Cli",
|
|
1624
|
+
keywords: [
|
|
1625
|
+
"foxford",
|
|
1626
|
+
"cli",
|
|
1627
|
+
"tool"
|
|
1628
|
+
],
|
|
1629
|
+
homepage: "https://github.com/foxford/stoege",
|
|
1630
|
+
bugs: "https://github.com/foxford/stoege/issues",
|
|
1631
|
+
repository: {
|
|
1632
|
+
type: "git",
|
|
1633
|
+
url: "git+https://github.com/foxford/stoege.git"
|
|
1634
|
+
},
|
|
1635
|
+
license: "MIT",
|
|
1636
|
+
author: "Foxford Co",
|
|
1637
|
+
maintainers: [
|
|
1638
|
+
{
|
|
1639
|
+
name: "Roman Olin",
|
|
1640
|
+
email: "r.v.olin@foxford.ru",
|
|
1641
|
+
team: "@frontend/core"
|
|
1642
|
+
}
|
|
1643
|
+
],
|
|
1644
|
+
main: "./README.mdx",
|
|
1645
|
+
exports: {
|
|
1646
|
+
"./README.mdx": "./README.mdx"
|
|
1647
|
+
},
|
|
1648
|
+
bin: {
|
|
1649
|
+
"fox-dev": "./scripts/dev.js",
|
|
1650
|
+
fox: "./scripts/prod.js"
|
|
1651
|
+
},
|
|
1652
|
+
scripts: {
|
|
1653
|
+
"============================ BUILD =============================": "",
|
|
1654
|
+
build: "tsup",
|
|
1655
|
+
prebuild: 'pnpm -w run build:workspace-deps "$PWD"',
|
|
1656
|
+
"============================ DEPLOY =============================": "",
|
|
1657
|
+
deploy: "fox deploy npm",
|
|
1658
|
+
"============================ LINT =============================": "",
|
|
1659
|
+
"lint:type-check": "tsc --noEmit --pretty",
|
|
1660
|
+
"lint:eslint": "eslint --cache --cache-strategy content --max-warnings=0 ./",
|
|
1661
|
+
"============================ TEST =============================": "",
|
|
1662
|
+
test: "vitest run",
|
|
1663
|
+
"test:watch": "vitest"
|
|
1664
|
+
},
|
|
1665
|
+
dependencies: {
|
|
1666
|
+
"@foxford/logger": "workspace:*",
|
|
1667
|
+
"@tsconfig/node16": "16.1.3",
|
|
1668
|
+
"@types/cli-progress": "3.11.5",
|
|
1669
|
+
"@types/fluent-ffmpeg": "2.1.24",
|
|
1670
|
+
chalk: "4.1.0",
|
|
1671
|
+
"cli-progress": "3.12.0",
|
|
1672
|
+
"cli-table3": "0.6.5",
|
|
1673
|
+
commander: "13.1.0",
|
|
1674
|
+
"detect-package-manager": "3.0.2",
|
|
1675
|
+
dotenv: "16.4.5",
|
|
1676
|
+
"dotenv-expand": "11.0.6",
|
|
1677
|
+
"file-type": "19.0.0",
|
|
1678
|
+
filesize: "10.1.2",
|
|
1679
|
+
"fluent-ffmpeg": "2.1.2",
|
|
1680
|
+
"fs-extra": "11.2.0",
|
|
1681
|
+
glob: "10.4.2",
|
|
1682
|
+
inquirer: "12.4.3",
|
|
1683
|
+
"os-name": "4.0.1",
|
|
1684
|
+
systeminformation: "5.25.11",
|
|
1685
|
+
tinify: "1.7.1",
|
|
1686
|
+
tsx: "4.15.7",
|
|
1687
|
+
typescript: "5.6.3",
|
|
1688
|
+
yaml: "2.4.5",
|
|
1689
|
+
zx: "8.1.3"
|
|
1690
|
+
},
|
|
1691
|
+
devDependencies: {
|
|
1692
|
+
"@foxford/eslint-config": "workspace:*",
|
|
1693
|
+
"@foxford/typescript-config": "workspace:*",
|
|
1694
|
+
tsup: "8.4.0"
|
|
1695
|
+
}
|
|
1696
|
+
};
|
|
1697
|
+
|
|
1698
|
+
// src/bin/fox.ts
|
|
1699
|
+
init_logger();
|
|
1700
|
+
init_program2();
|
|
1701
|
+
|
|
1702
|
+
// src/program/loader.ts
|
|
1703
|
+
var import_node_path6 = __toESM(require("path"));
|
|
1704
|
+
var import_chalk11 = __toESM(require("chalk"));
|
|
1705
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
1706
|
+
init_ui();
|
|
1707
|
+
init_logger();
|
|
1708
|
+
var log2 = logger.getLogger("command-loader");
|
|
1709
|
+
var _CommandLoader = class _CommandLoader {
|
|
1710
|
+
static load(program) {
|
|
1711
|
+
return __async(this, null, function* () {
|
|
1712
|
+
if (true) {
|
|
1713
|
+
yield this.loadProductionProcesses(program);
|
|
1714
|
+
} else {
|
|
1715
|
+
yield this.loadDevelopmentProcesses(program);
|
|
1716
|
+
}
|
|
1717
|
+
yield Promise.all(program.getCommands().map((command) => __async(this, null, function* () {
|
|
1718
|
+
return yield command.load(program);
|
|
1719
|
+
})));
|
|
1720
|
+
this.handleInvalidCommand(program);
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
static loadProductionProcesses(program) {
|
|
1724
|
+
return __async(this, null, function* () {
|
|
1725
|
+
try {
|
|
1726
|
+
for (const [processName, moduleLoader] of Object.entries({
|
|
1727
|
+
codegen: () => Promise.resolve().then(() => (init_codegen(), codegen_exports)),
|
|
1728
|
+
codemod: () => Promise.resolve().then(() => (init_codemod(), codemod_exports)),
|
|
1729
|
+
deploy: () => Promise.resolve().then(() => (init_deploy(), deploy_exports)),
|
|
1730
|
+
info: () => Promise.resolve().then(() => (init_info(), info_exports)),
|
|
1731
|
+
optimize: () => Promise.resolve().then(() => (init_optimize(), optimize_exports))
|
|
1732
|
+
})) {
|
|
1733
|
+
try {
|
|
1734
|
+
log2.debug(`\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043C \u043C\u043E\u0434\u0443\u043B\u044C: ${import_chalk11.default.cyan(processName)}`);
|
|
1735
|
+
const module2 = yield moduleLoader();
|
|
1736
|
+
module2.default(program);
|
|
1737
|
+
} catch (err) {
|
|
1738
|
+
log2.error(`\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0435 \u043C\u043E\u0434\u0443\u043B\u044F "${processName}":`, err);
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
} catch (err) {
|
|
1742
|
+
log2.error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0435 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u043E\u0432:", err);
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
}
|
|
1746
|
+
static loadDevelopmentProcesses(program) {
|
|
1747
|
+
return __async(this, null, function* () {
|
|
1748
|
+
try {
|
|
1749
|
+
if (!(yield import_fs_extra4.default.pathExists(_CommandLoader.PROCESSES_DIR))) {
|
|
1750
|
+
log2.error(`\u0414\u0438\u0440\u0435\u043A\u0442\u043E\u0440\u0438\u044F \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u043E\u0432 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430: ${_CommandLoader.PROCESSES_DIR}`);
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
const processes = yield this.getProcesses(_CommandLoader.PROCESSES_DIR);
|
|
1754
|
+
for (const processName of processes) {
|
|
1755
|
+
try {
|
|
1756
|
+
log2.debug(`\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043C \u043C\u043E\u0434\u0443\u043B\u044C: ${import_chalk11.default.cyan(processName)}`);
|
|
1757
|
+
const modulePath = import_node_path6.default.join(_CommandLoader.PROCESSES_DIR, processName);
|
|
1758
|
+
const module2 = require(modulePath);
|
|
1759
|
+
module2.default(program);
|
|
1760
|
+
} catch (err) {
|
|
1761
|
+
log2.error(`\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0435 \u043C\u043E\u0434\u0443\u043B\u044F "${processName}":`, err);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
} catch (err) {
|
|
1765
|
+
log2.error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u0438 \u0447\u0442\u0435\u043D\u0438\u0438 \u0434\u0438\u0440\u0435\u043A\u0442\u043E\u0440\u0438\u0438 \u043F\u0440\u043E\u0446\u0435\u0441\u0441\u043E\u0432:", err);
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
static getProcesses(processesPath) {
|
|
1770
|
+
return __async(this, null, function* () {
|
|
1771
|
+
const files = yield import_fs_extra4.default.readdir(processesPath);
|
|
1772
|
+
return files.filter((file) => {
|
|
1773
|
+
const filePath = import_node_path6.default.join(processesPath, file, "index.ts");
|
|
1774
|
+
const stat = import_fs_extra4.default.statSync(filePath);
|
|
1775
|
+
return stat.isFile();
|
|
1776
|
+
}).map((file) => import_node_path6.default.parse(file).name);
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
static handleInvalidCommand(program) {
|
|
1780
|
+
program.on("command:*", () => {
|
|
1781
|
+
console.error(`
|
|
1782
|
+
${ERROR_PREFIX} \u041D\u0435\u0432\u0435\u0440\u043D\u0430\u044F \u043A\u043E\u043C\u0430\u043D\u0434\u0430: ${import_chalk11.default.red("%s")}`, program.args.join(" "));
|
|
1783
|
+
console.log(`\u0421\u043C\u043E\u0442\u0440\u0438 ${import_chalk11.default.red("--help")} \u0434\u043B\u044F \u0432\u044B\u0432\u043E\u0434\u0430 \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u043E\u0433\u043E \u0441\u043F\u0438\u0441\u043A\u0430 \u043A\u043E\u043C\u0430\u043D\u0434.
|
|
1784
|
+
`);
|
|
1785
|
+
process.exit(1);
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
_CommandLoader.PROCESSES_DIR = import_node_path6.default.resolve(__dirname, "..", "processes");
|
|
1790
|
+
var CommandLoader = _CommandLoader;
|
|
1791
|
+
|
|
1792
|
+
// src/bin/fox.ts
|
|
1793
|
+
var PROGRAM_NAME = "fox";
|
|
1794
|
+
var welcomeText = `${import_chalk12.default.green(`\u041F\u0440\u0438\u0432\u0435\u0442\u270C\uFE0F , Foxford \u0440\u0430\u0437\u0440\u0430\u0431\u043E\u0442\u0447\u0438\u043A\u{1F913}`)}
|
|
1795
|
+
${import_chalk12.default.magenta(`\u042D\u0442\u0430 \u0448\u0442\u0443\u043A\u0430 \u043F\u0440\u0438\u0437\u0432\u0430\u043D\u0430 \u043F\u043E\u043C\u043E\u0447\u044C \u0442\u0435\u0431\u0435 \u0432 \u043A\u043E\u0434\u043E\u0433\u0435\u043D\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 \u0432 \u0447\u0435\u043C-\u043D\u0438\u0431\u0443\u0434\u044C \u0435\u0449\u0451\u{1F37F}`)}
|
|
1796
|
+
${import_chalk12.default.yellowBright("\u0427\u0430\u0439 \u043D\u0430\u043B\u0438\u0432\u0430\u0439 \u0441\u0435\u0431\u0435 \u0441\u0430\u043C \u{1F36E}\u{1F36A}")}
|
|
1797
|
+
`;
|
|
1798
|
+
var bootstrap = () => __async(exports, null, function* () {
|
|
1799
|
+
logger.debug("Start program");
|
|
1800
|
+
const program = new Program();
|
|
1801
|
+
program.version(package_default.version, "-v, --version", "\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u0442\u0435\u043A\u0443\u0449\u0443\u044E \u0432\u0435\u0440\u0441\u0438\u044E \u0442\u0443\u043B\u0437\u044B").name(PROGRAM_NAME).description(welcomeText).usage("<command> [options]").helpOption(false).addHelpCommand(false);
|
|
1802
|
+
logger.debug("Load processes");
|
|
1803
|
+
yield CommandLoader.load(program);
|
|
1804
|
+
logger.debug("Loading complete");
|
|
1805
|
+
logger.debug("Parse process.argv", process.argv);
|
|
1806
|
+
yield program.parseAsync(process.argv);
|
|
1807
|
+
if (!process.argv.slice(2).length) {
|
|
1808
|
+
program.outputHelp();
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
bootstrap();
|
|
1812
|
+
//# sourceMappingURL=fox.js.map
|