(title, promiseOrAsyncFunction, env = this.defaultEnvWithPathsAdded(),
cwd = this.projectRoot)
| 822 | } |
| 823 | |
| 824 | runCommands(title, promiseOrAsyncFunction, env = this.defaultEnvWithPathsAdded(), |
| 825 | cwd = this.projectRoot) { |
| 826 | // Capitalize title for debug output |
| 827 | Console.debug(title[0].toUpperCase() + title.slice(1)); |
| 828 | |
| 829 | const oldCwd = process.cwd(); |
| 830 | if (cwd) { |
| 831 | process.chdir(files.convertToOSPath(cwd)); |
| 832 | } |
| 833 | |
| 834 | const oldEnv = process.env; |
| 835 | if (env) { |
| 836 | // this preserves case insensitivity for PATH on windows |
| 837 | Object.keys(env).forEach(key => { |
| 838 | process.env[key] = env[key]; |
| 839 | }); |
| 840 | } |
| 841 | |
| 842 | try { |
| 843 | const promise = (typeof promiseOrAsyncFunction === 'function') ? |
| 844 | promiseOrAsyncFunction() : promiseOrAsyncFunction; |
| 845 | return Promise.await(promise); |
| 846 | } catch (error) { |
| 847 | Console.arrowError('Errors executing Cordova commands:'); |
| 848 | Console.error(); |
| 849 | const consoleOptions = Console.options({ indent: 3 }); |
| 850 | Console.error(`While ${title}:`, consoleOptions); |
| 851 | |
| 852 | if (error instanceof CordovaError) { |
| 853 | // Only print the message for errors thrown by cordova-lib, because |
| 854 | // these are meant for end-user consumption. |
| 855 | // But warn that they may not completely apply to our situation. |
| 856 | // (We do print the stack trace if we are in verbose mode.) |
| 857 | const errorMessage = Console.verbose ? (error.stack || error.message) : |
| 858 | error.message; |
| 859 | Console.error(`Cordova error: ${errorMessage}`, consoleOptions); |
| 860 | Console.error(chalk.green(`(If the error message contains suggestions \ |
| 861 | for a fix, note that this may not apply to the Meteor integration. You can try \ |
| 862 | running again with the --verbose option to help diagnose the issue.)`), |
| 863 | consoleOptions); |
| 864 | } else { |
| 865 | // Print stack trace for other errors by default, because the message |
| 866 | // usually does not give us enough information to know what is going on |
| 867 | const errorMessage = error && error.stack || error; |
| 868 | Console.error(errorMessage, consoleOptions); |
| 869 | }; |
| 870 | throw new main.ExitWithCode(1); |
| 871 | } finally { |
| 872 | if (cwd && oldCwd) { |
| 873 | process.chdir(oldCwd); |
| 874 | } |
| 875 | if (env && oldEnv) { |
| 876 | process.env = oldEnv; |
| 877 | } |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 |
no test coverage detected