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