1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.createCordovaResNotFoundMessage = exports.createCordovaResNotFoundError = exports.findCordovaRes = exports.checkCordovaRes = exports.runCordovaRes = exports.createCordovaResArgs = exports.SUPPORTED_PLATFORMS = void 0;
|
4 | const utils_subprocess_1 = require("@ionic/utils-subprocess");
|
5 | const color_1 = require("./color");
|
6 | const errors_1 = require("./errors");
|
7 | const logger_1 = require("./utils/logger");
|
8 | const npm_1 = require("./utils/npm");
|
9 | exports.SUPPORTED_PLATFORMS = ['ios', 'android'];
|
10 | function createCordovaResArgs({ platform }, options) {
|
11 | const args = [];
|
12 | if (platform) {
|
13 | args.push(platform);
|
14 | }
|
15 | if (options['icon']) {
|
16 | args.push('--type', 'icon');
|
17 | }
|
18 | else if (options['splash']) {
|
19 | args.push('--type', 'splash');
|
20 | }
|
21 | if (options['verbose']) {
|
22 | args.push('--verbose');
|
23 | }
|
24 | return args;
|
25 | }
|
26 | exports.createCordovaResArgs = createCordovaResArgs;
|
27 | async function runCordovaRes({ config, log, shell }, args, options = {}) {
|
28 | const stream = logger_1.createPrefixedWriteStream(log, color_1.weak(`[cordova-res]`));
|
29 | try {
|
30 | await shell.run('cordova-res', args, { showCommand: true, fatalOnNotFound: false, stream, ...options });
|
31 | }
|
32 | catch (e) {
|
33 | if (e instanceof utils_subprocess_1.SubprocessError && e.code === utils_subprocess_1.ERROR_COMMAND_NOT_FOUND) {
|
34 | throw await createCordovaResNotFoundError(config.get('npmClient'));
|
35 | }
|
36 | throw e;
|
37 | }
|
38 | }
|
39 | exports.runCordovaRes = runCordovaRes;
|
40 | async function checkCordovaRes({ config }) {
|
41 | const p = await findCordovaRes();
|
42 | if (!p) {
|
43 | throw await createCordovaResNotFoundError(config.get('npmClient'));
|
44 | }
|
45 | }
|
46 | exports.checkCordovaRes = checkCordovaRes;
|
47 | async function findCordovaRes() {
|
48 | try {
|
49 | return await utils_subprocess_1.which('cordova-res');
|
50 | }
|
51 | catch (e) {
|
52 | if (e.code !== 'ENOENT') {
|
53 | throw e;
|
54 | }
|
55 | }
|
56 | }
|
57 | exports.findCordovaRes = findCordovaRes;
|
58 | async function createCordovaResNotFoundError(npmClient) {
|
59 | return new errors_1.FatalException(await createCordovaResNotFoundMessage(npmClient));
|
60 | }
|
61 | exports.createCordovaResNotFoundError = createCordovaResNotFoundError;
|
62 | async function createCordovaResNotFoundMessage(npmClient) {
|
63 | const installArgs = await npm_1.pkgManagerArgs(npmClient, { command: 'install', pkg: 'cordova-res', global: true });
|
64 | return (`${color_1.input('cordova-res')} was not found on your PATH. Please install it globally:\n\n` +
|
65 | `${color_1.input(installArgs.join(' '))}\n`);
|
66 | }
|
67 | exports.createCordovaResNotFoundMessage = createCordovaResNotFoundMessage;
|