forked from gustarus/react-native-version-up
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
147 lines (120 loc) · 4.97 KB
/
index.js
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
144
145
146
147
'use strict';
const fs = require('fs');
const argv = require('yargs').argv;
const readlineSync = require('readline-sync');
const helpers = require('./lib/helpers');
const log = require('./lib/log');
const pathToRoot = process.cwd();
const pathToPackage = argv.pathToPackage || `${pathToRoot}/package.json`;
const pathToAppJson = `${pathToRoot}/app.json`;
const info = helpers.getPackageInfo(pathToPackage);
const pathToPlist = argv.pathToPlist || `${pathToRoot}/ios/${info.name}/Info.plist`;
const pathToGradle = argv.pathToGradle || `${pathToRoot}/android/app/build.gradle`;
// getting next version
const versionCurrent = info.version;
const versions = helpers.versions(versionCurrent);
let major = helpers.version(versions[0], argv.major);
let minor = helpers.version(versions[1], argv.minor, argv.major);
let patch = helpers.version(versions[2], argv.patch, argv.major || argv.minor);
let buildOption = argv.build || false;
let jsBundle = argv.jsBundle || false;
if (jsBundle) {
const appJson = require(pathToAppJson);
let version = parseInt(appJson.jsBundleIdentifier, 10);
version += 1;
helpers.changeJsBundleVersionInAppJson(pathToAppJson, version);
console.log(`jsBundleIdentifier changed in app.json to ${version}`);
return;
}
// getting next build number
const buildCurrent = helpers.getBuildNumberFromPlist(pathToPlist);
const build = buildCurrent + 1;
if (buildOption) {
if (argv.ios) {
helpers.changeBuildInPlist(pathToPlist, build);
helpers.changeIosBuildNumberInAppJson(pathToAppJson, build);
console.log(`Build number in plist incremented from ${buildCurrent} to ${build}`);
return;
} else if (argv.android) {
helpers.changeBuildInGradle(pathToGradle, build);
helpers.changeAndroidVersionCodeInAppJson(pathToAppJson, build);
console.log(`Build number in gradle incremented from ${buildCurrent} to ${build}`);
} else {
helpers.changeBuildInPlist(pathToPlist, build);
helpers.changeBuildInGradle(pathToGradle, build);
helpers.changeIosBuildNumberInAppJson(pathToAppJson, build);
helpers.changeAndroidVersionCodeInAppJson(pathToAppJson, build);
console.log(`Build number incremented in plist and gradle from ${buildCurrent} to ${build}`);
}
return;
}
const version = `${major}.${minor}.${patch}`;
// getting commit message
const message = argv.m || argv.message || `release ${version}: increase versions and build numbers`;
log.info('\nI\'m going to increase the version in:');
log.info(`- package.json (${pathToPackage});`, 1);
log.info(`- ios project (${pathToPlist});`, 1);
log.info(`- android project (${pathToGradle}).`, 1);
log.notice(`\nThe 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}".`);
}
const question = log.info(`Use "${version}" as the next version? [y/n] `, 0, true);
const answer = readlineSync.question(question).toLowerCase();
answer === 'y' ? resolve() : reject('Process canceled.');
});
const update = chain.then(() => {
log.notice('\nUpdating versions');
}).then(() => {
log.info('Updating version in package.json...', 1);
helpers.changeVersionInPackage(pathToPackage, version);
if (fs.existsSync(pathToAppJson)) {
helpers.changeVersionInAppJson(pathToAppJson, version);
helpers.changeIosBuildNumberInAppJson(pathToAppJson, build);
helpers.changeAndroidVersionCodeInAppJson(pathToAppJson, build);
log.success(`Version and builds in app.json changed.`, 2)
}
log.success(`Version in package.json changed.`, 2);
}).then(() => {
log.info('Updating version in xcode project...', 1);
helpers.changeVersionAndBuildInPlist(pathToPlist, version, build);
log.success(`Version and build number in ios project (plist file) changed.`, 2);
}).then(() => {
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.notice(`\nI'm ready to cooperate with the git!`);
log.info('I want to make a commit with message:', 1);
log.info(`"${message}"`, 2);
log.info(`I want to add a tag:`, 1);
log.info(`"v${version}"`, 2);
const question = log.info(`Do you allow me to do this? [y/n] `, 1, true);
const answer = readlineSync.question(question).toLowerCase();
if (answer === 'y') {
return helpers.commitVersionIncrease(version, message, [
pathToPackage,
pathToPlist,
pathToGradle
]).then(() => {
log.success(`Commit with files added. Run "git push".`, 1);
});
} else {
log.warning(`Skipped.`, 1);
}
});
commit.then(() => {
log.success(`\nDone!`);
}).catch(e => {
log.line();
log.error(e)
});