forked from react-native-maps/react-native-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-version.js
executable file
·70 lines (57 loc) · 1.56 KB
/
update-version.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
#!/usr/bin/env node
/**
* Script that runs as part of `npm version`. It updates any files that have a
* reference to the current package version:
*
* - gradle.properties
* x react-native-maps.podspec // <-- this is now dynamic
* x react-native-google-maps.podspec // <-- this is now dynamic
*
* And `git add`s them.
*/
const { exec } = require('child_process');
const pkg = require('../package.json');
const filesToUpdate = ['gradle.properties'];
function doExec(cmdString) {
return new Promise((resolve, reject) => {
exec(cmdString, (err, stdout) => {
if (err) {
reject(err);
return;
}
resolve(stdout);
});
});
}
function updateVersionInFile(currentVersion, nextVersion, relativePath) {
process.stdout.write(`• ${relativePath}\n`);
return doExec(
`sed -i '' 's/${escapeDots(currentVersion)}/${escapeDots(
nextVersion
)}/g' ./${relativePath}`
);
}
function escapeDots(version) {
return version.replace(/\./g, '\\.');
}
function run() {
const currentVersion = pkg.version;
const nextVersion = process.env.npm_package_version;
Promise.resolve()
.then(() => updateFiles(currentVersion, nextVersion))
.then(() => gitAdd());
}
// Tasks
function updateFiles(currentVersion, nextVersion) {
process.stdout.write(`Updating ${currentVersion} ➞ ${nextVersion}:\n`);
return Promise.all(
filesToUpdate.map(relativePath =>
updateVersionInFile(currentVersion, nextVersion, relativePath)
)
);
}
function gitAdd() {
return doExec(`git add ${filesToUpdate.join(' ')}`);
}
// Do it.
run();