-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.js
50 lines (43 loc) · 1.3 KB
/
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
/**
* Update version of all published packages
*/
import fs from 'node:fs/promises'
;(async () => {
const version = new Date().toISOString().slice(0, 10).replace(/-/g, '')
// Version number with dots should have no zero padding 1.02.03 -> 1.2.3
const versionWithDots =
[
version.slice(0, 4),
version.slice(4, 6),
version.slice(6, 8)
].map(i => parseInt(i, 10).toString()).join('.')
console.log('Version', versionWithDots)
for (const file of [
'index.php',
'date/index.php',
'plugin.php',
'package.json',
'env/package.json'
]) {
console.log('Update', file)
// YYYYMMDD
const content = (await fs.readFile(file, 'utf8'))
.replace(/return '[0-9]{8}'/, `return '${version}'`)
.replace(/'version' => '[0-9]{8}'/, `'version' => '${version}'`)
.replace(
/'version' => '[0-9]{4}\.[0-9]+\.[0-9]+'/,
`'version' => '${versionWithDots}'`,
)
.replace(/\$version = '[0-9]{8}'/, `$version = '${version}'`)
.replace(
/"version": "[0-9]{4}\.[0-9]+\.[0-9]+"/,
`"version": "${versionWithDots}"`,
)
.replace(
/Version: [0-9]{4}\.[0-9]+\.[0-9]+/,
`Version: ${versionWithDots}`,
)
// console.log(content)
await fs.writeFile(file, content)
}
})().catch(console.error)