-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.js
113 lines (89 loc) · 3.7 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
'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 info = helpers.getPackageInfo(pathToPackage);
const pathToPlist = argv.pathToPlist || `${pathToRoot}/ios/${info.name}/Info.plist`;
const pathToGradle = argv.pathToGradle || `${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], argv.major);
let minor = helpers.version(versions[1], argv.minor, argv.major);
let patch = helpers.version(versions[2], argv.patch, argv.major || argv.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 = argv.m || argv.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 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);
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(() => {
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,
...pathsToPlists,
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)
});