summaryrefslogtreecommitdiff
path: root/platform/ios/scripts/lint-podspecs.js
blob: c5e1c6d49be9e1ca64bcea96d6e0ae021131e0f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env node

const fs = require('fs');
const execSync = require('child_process').execSync;
const _ = require('lodash');
const semver = require('semver');

console.step = _.partial(console.log, '\n\033[1m\033[36m*', _, '\033[0m');

const podspecsPath = 'platform/ios';

/*
    ------------------------
*/
console.step(`Running CocoaPods linter against podspecs in '${podspecsPath}'`)
execSync(`pod spec lint ${podspecsPath}/*.podspec --quick`, {stdio: 'inherit'});

/*
    ------------------------
*/
console.step('Checking Mapbox SDK version strings in podspecs')
const podspecs = fs.readdirSync(podspecsPath).filter(fn => fn.endsWith('.podspec'));

let matchedVersions = [];

for (const podspecFilename of podspecs) {
    console.log(podspecFilename);
    const podspecContents = fs.readFileSync(`${podspecsPath}/${podspecFilename}`, 'utf8');

    /*
      This regular expression:
        - Matches single lines in the format: version = '9.9.9'
        - Groups the version number inside the single quotes.
        - Ignores whitespace at the start of the line and between parts of the definition using: \s*?
    */
    const regex = /^\s*?version\s*?=\s*?'(.*)'$/gmi;

    const match = regex.exec(podspecContents);
    if (!match) {
        console.error('  ❌ No version string found');
        process.exitCode = 1;
        continue;
    }

    const matchedVersion = match[1];
    matchedVersions.push(matchedVersion);

    const semanticVersion = semver.valid(matchedVersion);
    if (!semanticVersion) {
        console.error(`  ❌ ${matchedVersion} is not a valid semantic version`);
        process.exitCode = 1;
        continue;
    }

    console.log(`  ✅ ${matchedVersion} is a valid semantic version`);
}

/*
    ------------------------
*/
console.step('Checking version consistency')
const uniqueVersions = _.uniq(matchedVersions);
if (uniqueVersions.length != 1) {
    console.error('❌ Versions in podspecs do not match:', uniqueVersions);
    process.exitCode = 1;
} else {
    console.log(`✅ ${uniqueVersions[0]} is set in all podspecs`);
}