-
Notifications
You must be signed in to change notification settings - Fork 12
/
setVersion.js
185 lines (153 loc) · 9.3 KB
/
setVersion.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const fs = require('fs')
const readline = require('readline-sync');
function replaceVersionLine(content, version, prefix = 'version = ', suffix = '') {
const lines = content.split('\n')
const versionLineIndex = lines.findIndex(line => line.startsWith(prefix))
if (versionLineIndex === -1) throw new Error(`Could not find version line in ${content}`)
const scope = lines[versionLineIndex].substring(prefix.length)
const oldVersion = scope.split('"')[1]
const newVersionLine = `${prefix}"${version}"${suffix}`
lines[versionLineIndex] = newVersionLine
const newContent = lines.join('\n')
return { oldVersion, newContent }
}
let isPreRelease = false;
const answer = readline.question('Is this a pre-release version? (y/n) ');
isPreRelease = answer === 'y' || answer === 'Y';
if (isPreRelease) {
console.log('Setting versions for pre-release (will not add pre-release prefix to launcher version)');
}
let VERSION = process.argv[2]
let RUST_VERSION = process.argv[2]
if (isPreRelease) {
VERSION = VERSION + "-prerelease";
RUST_VERSION = VERSION + ".0";
}
const RAW_VERSION = process.argv[2];
console.log("Setting all sub-project versions to: " + VERSION + " with tauri still being set to: " + RAW_VERSION);
const rootRepo = JSON.parse(fs.readFileSync('package.json', 'utf8'))
console.log("Root repo version: " + rootRepo.version + " -> " + VERSION)
rootRepo.version = VERSION
fs.writeFileSync('package.json', JSON.stringify(rootRepo, null, 2) + '\n')
let ad4mClient;
if (isPreRelease) {
cli = replaceVersionLine(fs.readFileSync('cli/Cargo.toml', 'utf8'), RUST_VERSION)
console.log("CLI version: " + cli.oldVersion + " -> " + RUST_VERSION)
// ad4mClient = replaceVersionLine(cli.newContent, RUST_VERSION, `ad4m-client = { path = "../rust-client", version = `, ` }`)
// console.log(`CLI ad4m-client dep: ${ad4mClient.oldVersion} -> ${RUST_VERSION}`)
} else {
cli = replaceVersionLine(fs.readFileSync('cli/Cargo.toml', 'utf8'), RAW_VERSION)
console.log("CLI version: " + cli.oldVersion + " -> " + RAW_VERSION)
// ad4mClient = replaceVersionLine(cli.newContent, RAW_VERSION, `ad4m-client = { path = "../rust-client", version = `, ` }`)
// console.log(`CLI ad4m-client dep: ${ad4mClient.oldVersion} -> ${RAW_VERSION}`)
}
fs.writeFileSync('cli/Cargo.toml', cli.newContent)
const connect = JSON.parse(fs.readFileSync('connect/package.json', 'utf8'))
console.log("Connect version: " + connect.version + " -> " + VERSION)
connect.version = VERSION
fs.writeFileSync('connect/package.json', JSON.stringify(connect, null, 2) + '\n')
const core = JSON.parse(fs.readFileSync('core/package.json', 'utf8'))
console.log("Core version: " + core.version + " -> " + VERSION)
core.version = VERSION
fs.writeFileSync('core/package.json', JSON.stringify(core, null, 2) + '\n')
const hookHelpers = JSON.parse(fs.readFileSync('ad4m-hooks/helpers/package.json', 'utf8'))
console.log("Hook Helpers version: " + core.version + " -> " + VERSION)
hookHelpers.version = VERSION
fs.writeFileSync('ad4m-hooks/helpers/package.json', JSON.stringify(hookHelpers, null, 2) + '\n')
const reactHooks = JSON.parse(fs.readFileSync('ad4m-hooks/react/package.json', 'utf8'))
console.log("Ad4m React hook version: " + reactHooks.version + " -> " + VERSION)
reactHooks.version = VERSION
fs.writeFileSync('ad4m-hooks/react/package.json', JSON.stringify(reactHooks, null, 2) + '\n')
const vueHooks = JSON.parse(fs.readFileSync('ad4m-hooks/vue/package.json', 'utf8'))
console.log("Ad4m Vue hook version: " + vueHooks.version + " -> " + VERSION)
vueHooks.version = VERSION
fs.writeFileSync('ad4m-hooks/vue/package.json', JSON.stringify(vueHooks, null, 2) + '\n')
const executor = JSON.parse(fs.readFileSync('executor/package.json', 'utf8'))
console.log("Executor version: " + executor.version + " -> " + VERSION)
executor.version = VERSION
fs.writeFileSync('executor/package.json', JSON.stringify(executor, null, 2) + '\n')
const rustExecutor = JSON.parse(fs.readFileSync('rust-executor/package.json', 'utf8'))
console.log("Executor version: " + rustExecutor.version + " -> " + VERSION)
rustExecutor.version = VERSION
fs.writeFileSync('rust-executor/package.json', JSON.stringify(rustExecutor, null, 2) + '\n')
const tests = JSON.parse(fs.readFileSync('tests/js/package.json', 'utf8'))
console.log("Executor version: " + tests.version + " -> " + VERSION)
tests.version = VERSION
fs.writeFileSync('tests/js/package.json', JSON.stringify(tests, null, 2) + '\n')
const executorHardWired = replaceVersionLine(
fs.readFileSync('executor/src/core/Config.ts', 'utf8'),
VERSION,
'export let ad4mExecutorVersion = ',
';')
console.log("Hard-wired version string in executor's Config.ts: " + executorHardWired.oldVersion + " -> " + VERSION)
fs.writeFileSync('executor/src/core/Config.ts', executorHardWired.newContent)
const rustClient = replaceVersionLine(fs.readFileSync('rust-client/Cargo.toml', 'utf8'), VERSION)
console.log("rust-client version: " + rustClient.oldVersion + " -> " + VERSION)
fs.writeFileSync('rust-client/Cargo.toml', rustClient.newContent)
const rustExecutorCargo = replaceVersionLine(fs.readFileSync('rust-executor/Cargo.toml', 'utf8'), VERSION)
console.log("rust-executor version: " + rustExecutorCargo.oldVersion + " -> " + VERSION)
fs.writeFileSync('rust-executor/Cargo.toml', rustExecutorCargo.newContent)
const globalsRs = replaceVersionLine(
fs.readFileSync('rust-executor/src/globals.rs', 'utf8'),
VERSION,
` pub static ref AD4M_VERSION: String = String::from(`,
`);`
)
console.log("globals.rs version: " + globalsRs.oldVersion + " -> " + VERSION)
fs.writeFileSync('rust-executor/src/globals.rs', globalsRs.newContent)
const uiPackage = JSON.parse(fs.readFileSync('ui/package.json', 'utf8'))
if (isPreRelease) {
console.log("UI version: " + uiPackage.version + " -> " + VERSION)
uiPackage.version = VERSION
} else {
console.log("UI version: " + uiPackage.version + " -> " + RAW_VERSION)
uiPackage.version = RAW_VERSION
}
fs.writeFileSync('ui/package.json', JSON.stringify(uiPackage, null, 2) + '\n')
const uiTauri = JSON.parse(fs.readFileSync('ui/src-tauri/tauri.conf.json', 'utf8'))
if (isPreRelease) {
console.log("UI Tauri version: " + uiTauri.version + " -> " + VERSION)
uiTauri.version = VERSION
} else {
console.log("UI Tauri version: " + uiTauri.version + " -> " + RAW_VERSION)
uiTauri.version = RAW_VERSION
}
fs.writeFileSync('ui/src-tauri/tauri.conf.json', JSON.stringify(uiTauri, null, 2) + '\n')
let uiTauriCargo;
if (isPreRelease) {
uiTauriCargo = replaceVersionLine(fs.readFileSync('ui/src-tauri/Cargo.toml', 'utf8'), RUST_VERSION)
console.log("UI Cargo version: " + uiTauriCargo.oldVersion + " -> " + RUST_VERSION)
} else {
uiTauriCargo = replaceVersionLine(fs.readFileSync('ui/src-tauri/Cargo.toml', 'utf8'), RAW_VERSION)
console.log("UI Cargo version: " + uiTauriCargo.oldVersion + " -> " + VERSION)
}
fs.writeFileSync('ui/src-tauri/Cargo.toml', uiTauriCargo.newContent)
const book = JSON.parse(fs.readFileSync('docs/package.json', 'utf8'))
console.log("Docs version: " + book.version + " -> " + VERSION)
book.version = VERSION
fs.writeFileSync('docs/package.json', JSON.stringify(book, null, 2) + '\n')
const testRunner = JSON.parse(fs.readFileSync('test-runner/package.json', 'utf8'))
console.log("Test runner version: " + testRunner.version + " -> " + VERSION)
testRunner.version = VERSION
fs.writeFileSync('test-runner/package.json', JSON.stringify(testRunner, null, 2) + '\n')
const perspectiveDiffSync = JSON.parse(fs.readFileSync('bootstrap-languages/p-diff-sync/package.json', 'utf8'))
console.log("Perspective diff sync: " + perspectiveDiffSync.version + " -> " + VERSION)
perspectiveDiffSync.version = VERSION
fs.writeFileSync('bootstrap-languages/p-diff-sync/package.json', JSON.stringify(perspectiveDiffSync, null, 2) + '\n')
const agentLanguage = JSON.parse(fs.readFileSync('bootstrap-languages/agent-language/package.json', 'utf8'))
console.log("Agent language: " + agentLanguage.version + " -> " + VERSION)
agentLanguage.version = VERSION
fs.writeFileSync('bootstrap-languages/agent-language/package.json', JSON.stringify(agentLanguage, null, 2) + '\n')
const directMessageLanguage = JSON.parse(fs.readFileSync('bootstrap-languages/direct-message-language/package.json', 'utf8'))
console.log("Direct message language: " + directMessageLanguage.version + " -> " + VERSION)
directMessageLanguage.version = VERSION
fs.writeFileSync('bootstrap-languages/direct-message-language/package.json', JSON.stringify(directMessageLanguage, null, 2) + '\n')
const neighbourhoodLanguage = JSON.parse(fs.readFileSync('bootstrap-languages/neighbourhood-language/package.json', 'utf8'))
console.log("Neighbourhood language: " + neighbourhoodLanguage.version + " -> " + VERSION)
neighbourhoodLanguage.version = VERSION
fs.writeFileSync('bootstrap-languages/neighbourhood-language/package.json', JSON.stringify(neighbourhoodLanguage, null, 2) + '\n')
const perspectiveLanguage = JSON.parse(fs.readFileSync('bootstrap-languages/perspective-language/package.json', 'utf8'))
console.log("Perspective language: " + perspectiveLanguage.version + " -> " + VERSION)
perspectiveLanguage.version = VERSION
fs.writeFileSync('bootstrap-languages/perspective-language/package.json', JSON.stringify(perspectiveLanguage, null, 2) + '\n')
fs.writeFileSync('bootstrap-languages/p-diff-sync/package.json', JSON.stringify(perspectiveDiffSync, null, 2) + '\n')