UNPKG

2.46 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const utils_subprocess_1 = require("@ionic/utils-subprocess");
4const color_1 = require("./color");
5const errors_1 = require("./errors");
6const logger_1 = require("./utils/logger");
7const npm_1 = require("./utils/npm");
8exports.SUPPORTED_PLATFORMS = ['ios', 'android'];
9function 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}
25exports.createCordovaResArgs = createCordovaResArgs;
26async 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}
38exports.runCordovaRes = runCordovaRes;
39async function checkCordovaRes({ config }) {
40 const p = await findCordovaRes();
41 if (!p) {
42 throw await createCordovaResNotFoundError(config.get('npmClient'));
43 }
44}
45exports.checkCordovaRes = checkCordovaRes;
46async 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}
56exports.findCordovaRes = findCordovaRes;
57async function createCordovaResNotFoundError(npmClient) {
58 return new errors_1.FatalException(await createCordovaResNotFoundMessage(npmClient));
59}
60exports.createCordovaResNotFoundError = createCordovaResNotFoundError;
61async 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}
66exports.createCordovaResNotFoundMessage = createCordovaResNotFoundMessage;