-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincrementVersions.js
40 lines (31 loc) · 1.35 KB
/
incrementVersions.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
const fs = require('fs')
const packagePath = './package.json';
const solutionPath = './config/package-solution.json';
const versiony = require('versiony')
const updateFile = (file, version, nestedObject, arrayProperty) => {
const newVersion = `${version}.0`;
const targetName = `${file}${nestedObject ? '.' + nestedObject : '' }`;
console.log(`Updating ${targetName}.version=${newVersion}`);
const fileContent = require(file);
const target = nestedObject ? fileContent[nestedObject] : fileContent;
target.version = newVersion;
if( typeof target[arrayProperty] === 'object' ) {
console.log(`Updating ${target[arrayProperty].length} in ${targetName}.${arrayProperty} `);
for( const item of target[arrayProperty]) {
console.log(`Updating ${targetName}.${arrayProperty}[${item['title'] ?? item['id']}]`);
item['version'] = newVersion;
}
} else {
console.error(`${targetName}.${arrayProperty} is of type ${typeof target[arrayProperty]}`)
}
fs.writeFileSync(file, JSON.stringify(fileContent, null, 4))
}
function main() {
const newVersion = versiony
.patch()
.with(packagePath)
.end({quiet: true});
console.log(`Updated ${packagePath} to ${newVersion.version}`);
updateFile( solutionPath, newVersion.version, 'solution', 'features' );
}
main();