This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.versionrc.js
66 lines (60 loc) · 1.72 KB
/
.versionrc.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
const fs = require("fs-extra")
const yaml = require("js-yaml")
const getDirectoriesSync = (source) =>
fs
.readdirSync(source, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory() || dirent.isSymbolicLink())
.map((dirent) => dirent.name)
const chartsUpdater = {
readVersion: (contents) => {
let chart;
try {
chart = yaml.load(contents, 'utf-8');
} catch (e) {
console.error(e);
throw e;
}
return chart.version;
},
writeVersion: (contents, version) => {
let chart = yaml.load(contents, 'utf8');
chart.version = version;
chart.appVersion = version;
const { dependencies } = chart
if (dependencies) {
for (const dependency of dependencies) {
if (dependency.repository.startsWith("file://./charts/")) {
dependency.version = version
}
}
}
return yaml.dump(chart, { indent: 2 });
}
}
const bumpFiles = [{ filename: "package.json", type: "json" }]
const packageDirs = getDirectoriesSync("packages")
for (const dir of packageDirs){
const filename = `packages/${dir}/package.json`
if(fs.pathExistsSync(filename)){
bumpFiles.push({ filename, type: "json" })
}
}
const getChartsRecursive = (dir = "packages", list=[])=>{
const chartList = getDirectoriesSync(dir)
list.push(...chartList.map(c => fs.realpathSync(`${dir}/${c}`)))
for (const chartName of chartList){
const childDir = `${dir}/${chartName}/charts`
if (fs.pathExistsSync(childDir)){
list.push(...getChartsRecursive(childDir))
}
}
return list
}
const charts = getChartsRecursive()
bumpFiles.push(...charts.map((chartDir) => ({
filename: `${chartDir}/Chart.yaml`,
updater: chartsUpdater
})))
module.exports = {
bumpFiles,
}