|
| 1 | +const {defaultTo} = require('lodash'); |
| 2 | +const AggregateError = require('aggregate-error'); |
| 3 | +const verifyPluginConfig = require('./lib/verify-config'); |
| 4 | +const verifyPodAuth = require('./lib/verify-auth'); |
| 5 | +const verifyCliInstalled = require('./lib/verify-cli-installed'); |
| 6 | +const verifyPodLint = require('./lib/verify-pod-lint'); |
| 7 | +const preparePod = require('./lib/prepare'); |
| 8 | +const publishPod = require('./lib/publish'); |
| 9 | + |
| 10 | +// Let verified; |
| 11 | +let prepared; |
| 12 | + |
| 13 | +async function verifyConditions(pluginConfig, context) { |
| 14 | + // Set default values for config |
| 15 | + pluginConfig.podLint = defaultTo(pluginConfig.podLint, true); |
| 16 | + pluginConfig.podLintArgs = defaultTo(pluginConfig.podLintArgs, ''); |
| 17 | + pluginConfig.podPushArgs = defaultTo(pluginConfig.podPushArgs, ''); |
| 18 | + |
| 19 | + const errors = verifyPluginConfig(pluginConfig); |
| 20 | + |
| 21 | + try { |
| 22 | + // 1. Verify `pod` command exists |
| 23 | + await verifyCliInstalled(pluginConfig); |
| 24 | + |
| 25 | + // 2. Verify `COCOAPODS_TRUNK_TOKEN` environment variable exists |
| 26 | + // 3. Verify `pod trunk me` is successful. |
| 27 | + await verifyPodAuth(context); |
| 28 | + |
| 29 | + // 4. Verify `pod lib lint` is successful |
| 30 | + await verifyPodLint(pluginConfig, context); |
| 31 | + } catch (error) { |
| 32 | + errors.push(...error); |
| 33 | + } |
| 34 | + |
| 35 | + if (errors.length > 0) { |
| 36 | + throw new AggregateError(errors); |
| 37 | + } |
| 38 | + |
| 39 | + // Verified = true; |
| 40 | +} |
| 41 | + |
| 42 | +async function prepare(pluginConfig, context) { |
| 43 | + await preparePod(pluginConfig, context); |
| 44 | + prepared = true; |
| 45 | +} |
| 46 | + |
| 47 | +async function publish(pluginConfig, context) { |
| 48 | + if (!prepared) { |
| 49 | + await preparePod(pluginConfig, context); |
| 50 | + } |
| 51 | + |
| 52 | + await publishPod(pluginConfig, context); |
| 53 | + |
| 54 | + return true; |
| 55 | +} |
| 56 | + |
| 57 | +module.exports = {verifyConditions, prepare, publish}; |
0 commit comments