UNPKG

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