forked from gustarus/react-native-version-up
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
143 lines (118 loc) · 3.85 KB
/
index.js
File metadata and controls
143 lines (118 loc) · 3.85 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"use strict";
const fs = require("fs");
const readlineSync = require("readline-sync");
const helpers = require("./lib/helpers");
const log = require("./lib/log");
const getCurrentInfo = config => {
const pathToPackage =
config.pathToPackage || `${config.pathToRoot}/package.json`;
return {
info: helpers.getPackageInfo(pathToPackage),
pathToPackage
};
};
const versionUp = async config => {
const { info, pathToPackage } = getCurrentInfo(config);
const pathToPlist =
config.pathToPlist || `${config.pathToRoot}/ios/${info.name}/Info.plist`;
const pathToGradle =
config.pathToGradle || `${config.pathToRoot}/android/app/build.gradle`;
// handle case of several plist files
const pathsToPlists = Array.isArray(pathToPlist)
? pathToPlist
: [pathToPlist];
// getting next version
const versionCurrent = info.version;
const versions = helpers.versions(versionCurrent);
let major = helpers.version(versions[0], config.major);
let minor = helpers.version(versions[1], config.minor, config.major);
let patch = helpers.version(
versions[2],
config.patch,
config.major || config.minor
);
const version = `${major}.${minor}.${patch}`;
// getting next build number
const buildCurrent = helpers.getBuildNumberFromPlist(pathsToPlists[0]);
const build = buildCurrent + 1;
// getting commit message
const messageTemplate =
config.m ||
config.message ||
"Release ${version}: increase versions and build numbers";
const message = messageTemplate.replace("${version}", version);
log.info("\nI'm going to increase the version in:");
log.info(`- package.json (${pathToPackage});`, 1);
log.info(`- ios project (${pathsToPlists.join(", ")});`, 1);
log.info(`- android project (${pathToGradle}).`, 1);
log.notice(`\nThe build version will be changed:`);
log.notice(`- from: ${versionCurrent} (${buildCurrent});`, 1);
log.notice(`- to: ${version} (${build}).`, 1);
if (version === versionCurrent) {
log.warning("\nNothing to change in the version. Canceled.");
process.exit();
}
const chain = new Promise((resolve, reject) => {
log.line();
if (versions.length !== 3) {
log.warning(
`I can\'t understand format of the version "${versionCurrent}".`
);
}
resolve();
});
const update = chain
.then(() => {
log.notice("\nUpdating versions");
})
.then(() => {
log.info("Updating version in package.json...", 1);
helpers.changeVersionInPackage(pathToPackage, version);
log.success(`Version in package.json changed.`, 2);
})
.then(() => {
log.info("Updating version in xcode project...", 1);
pathsToPlists.forEach(pathToPlist => {
helpers.changeVersionAndBuildInPlist(pathToPlist, version, build);
});
log.success(
`Version and build number in ios project (plist file) changed.`,
2
);
})
.then(() => {
if (config.skipBuildIncrease) {
return log.info("Skipping build increase...");
}
log.info("Updating version in android project...", 1);
helpers.changeVersionAndBuildInGradle(pathToGradle, version, build);
log.success(
`Version and build number in android project (gradle file) changed.`,
2
);
});
const commit = update.then(() => {
log.info("Commiting version bump", 1);
log.info(`"${message} v${version}"`, 2);
return helpers
.commitVersionIncrease(version, message, [
pathToPackage,
...pathsToPlists,
pathToGradle
])
.then(() => {
log.success(`Commit with files added. Run "git push".`, 1);
});
});
await commit
.then(() => {
log.success(`\nDone!`);
})
.catch(e => {
log.line();
log.error(e);
});
return { version, build };
};
module.exports = versionUp;
module.exports.getCurrentInfo = getCurrentInfo;