diff --git a/plugins/cocoapods/README.md b/plugins/cocoapods/README.md index 9e17f4fa5..d68e607d9 100644 --- a/plugins/cocoapods/README.md +++ b/plugins/cocoapods/README.md @@ -1,6 +1,6 @@ # Cocoapods Plugin -Use auto to version your [Cocoapod](https://cocoapods.org/), and push to your specs repository! +Use `auto` to version your [Cocoapod](https://cocoapods.org/), and push to your specs repository! ## Installation @@ -27,10 +27,7 @@ yarn add -D @auto-it/cocoapods } ] // other plugins - ], - // THIS IS REQUIRED - // Cocoapods cannot work with tags in the format v1.0.0 - "noVersionPrefix": true + ] } ``` @@ -42,10 +39,6 @@ yarn add -D @auto-it/cocoapods - Your `podspec` file must pass `pod lib lint` in order for publishing to a Specs repository to work. -### Versioning - -[Cocoapods](https://cocoapods.org/) does not work with the version prefix of `v1.0.0` so all versions must be the plain semver number (`1.0.0`). You are required to set the `noVersionPrefix` setting in your auto configuration. - ### Pushing to the Cocoapods Trunk If a `specsRepo` is not provided in the plugin options, this plugin will push to the cocoapods trunk repository. This requires that the machine running this has followed the steps for pushing to trunk, the guide for that can be found [here](https://guides.cocoapods.org/making/getting-setup-with-trunk.html#getting-started). diff --git a/plugins/cocoapods/__tests__/cocoapods.test.ts b/plugins/cocoapods/__tests__/cocoapods.test.ts index f7dd27fd2..ab7f6ff99 100644 --- a/plugins/cocoapods/__tests__/cocoapods.test.ts +++ b/plugins/cocoapods/__tests__/cocoapods.test.ts @@ -113,6 +113,14 @@ describe('Cocoapods Plugin', () => { expect(mock).lastCalledWith(expect.any(String), specWithVersion('0.0.2')); }); }); + describe('modifyConfig hook', () => { + test('should set noVersionPrefix to true', () => { + const config = {}; + expect(hooks.modifyConfig.call(config as any)).toStrictEqual({ + noVersionPrefix: true + }); + }); + }); describe('getPreviousVersion hook', () => { test('should get previous version from podspec', async () => { mockPodspec(specWithVersion('0.0.1')); diff --git a/plugins/cocoapods/package.json b/plugins/cocoapods/package.json index 7a0ae889c..077019bd6 100644 --- a/plugins/cocoapods/package.json +++ b/plugins/cocoapods/package.json @@ -37,6 +37,9 @@ }, "dependencies": { "@auto-it/core": "link:../../packages/core", + "fp-ts": "^2.5.3", + "io-ts": "^2.1.2", + "semver": "^7.1.3", "tslib": "1.10.0" } } diff --git a/plugins/cocoapods/src/index.ts b/plugins/cocoapods/src/index.ts index e1f6424ea..e34ec1a02 100644 --- a/plugins/cocoapods/src/index.ts +++ b/plugins/cocoapods/src/index.ts @@ -1,7 +1,14 @@ -import { Auto, IPlugin, execPromise } from '@auto-it/core'; +import { + Auto, + IPlugin, + execPromise, + validatePluginConfiguration +} from '@auto-it/core'; import { inc, ReleaseType } from 'semver'; +import * as t from 'io-ts'; + import { getPodspecContents, writePodspecContents } from './utilities'; const logPrefix = '[Cocoapods-Plugin]'; @@ -16,13 +23,18 @@ const versionRegex = /\.version\s*=\s*['|"](?\d+\.\d+\.\d+)['|"]/; */ const logMessage = (msg: string): string => `${logPrefix} ${msg}`; -export interface ICocoapodsPluginOptions { - /** path to podspec file */ - podspecPath: string; +const required = t.interface({ + /** Relative path to podspec file */ + podspecPath: t.string +}); - /** the Cocoapods repo to publish to */ - specsRepo?: string; -} +const optional = t.partial({ + /** The Cocoapods repo to publish to */ + specsRepo: t.string +}); + +const pluginOptions = t.intersection([required, optional]); +export type ICocoapodsPluginOptions = t.TypeOf; /** * Returns the regex'd version of the podspec file @@ -108,6 +120,17 @@ export default class CocoapodsPlugin implements IPlugin { /** Tap into auto plugin points. */ apply(auto: Auto) { + auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => { + if (name === this.name || name === `@auto-it/${this.name}`) { + return validatePluginConfiguration(this.name, pluginOptions, options); + } + }); + + auto.hooks.modifyConfig.tap(this.name, (config: any) => { + config.noVersionPrefix = true; + return config; + }); + auto.hooks.getPreviousVersion.tapPromise(this.name, async () => { return auto.prefixRelease(getVersion(this.options.podspecPath)); }); diff --git a/yarn.lock b/yarn.lock index 54aef269b..5fc71a243 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6944,8 +6944,8 @@ forwarded@~0.1.2: fp-ts@^2.5.3: version "2.5.3" - resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-2.5.3.tgz#7f09cc7f3e09623c6ade303d98a2cccdb2cc861f" - integrity sha512-lQd+hahLd8cygNoXbEHDjH/cbF6XVWlEPb8h5GXXlozjCSDxWgclvkpOoTRfBA0P+r69l9VvW1nEsSGIJRQpWw== + resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/fp-ts/-/fp-ts-2.5.3.tgz#7f09cc7f3e09623c6ade303d98a2cccdb2cc861f" + integrity sha1-fwnMfz4JYjxq3jA9mKLMzbLMhh8= fragment-cache@^0.2.1: version "0.2.1" @@ -8305,8 +8305,8 @@ invert-kv@^1.0.0: io-ts@^2.1.2: version "2.1.2" - resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.1.2.tgz#8ea4439c902c3d15cda343900bed7ee5a9977f42" - integrity sha512-whVRGaNBZSrkPrg1y+sSy/kv/fDjweQPP1UCLhKwJUHWGD6rFgbZ44FBF98JlY/FFzTA0MkhGeHWZ/aFhF42eA== + resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/io-ts/-/io-ts-2.1.2.tgz#8ea4439c902c3d15cda343900bed7ee5a9977f42" + integrity sha1-jqRDnJAsPRXNo0OQC+1+5amXf0I= ip-regex@^1.0.1: version "1.0.3" @@ -13382,6 +13382,11 @@ semver@^7.0.0, semver@^7.1.1: resolved "https://registry.yarnpkg.com/semver/-/semver-7.1.3.tgz#e4345ce73071c53f336445cfc19efb1c311df2a6" integrity sha512-ekM0zfiA9SCBlsKa2X1hxyxiI4L3B6EbVJkkdgQXnSEEaHlGdvyodMruTiulSRWMMB4NeIuYNMC9rTKTz97GxA== +semver@^7.1.3: + version "7.1.3" + resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/semver/-/semver-7.1.3.tgz#e4345ce73071c53f336445cfc19efb1c311df2a6" + integrity sha1-5DRc5zBxxT8zZEXPwZ77HDEd8qY= + semver@~5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"