Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
POS/scripts/sync-version.js at develop · Posnic/POS · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Posnic
POS
Repository navigation
Code
Issues
396
(396)
Pull requests
12
(12)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
POS
/
scripts
/
sync-version.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
116 lines (105 loc) · 4.38 KB
develop
Breadcrumbs
POS
/
scripts
/
sync-version.js
Copy path
Top
File metadata and controls
Code
Blame
116 lines (105 loc) · 4.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"use strict"
;
/*
* One version, written everywhere it is stated.
*
* package.json is not the only file that names the release. codemeta.json
* states it twice (version and softwareVersion), CITATION.cff states it again,
* and the generated OpenAPI spec carries it in info.version. Three separate
* tests assert they all agree, and
* CI regenerates the docs and fails on any diff.
*
* The first real run of `release:ship` bumped package.json alone and CI
* refused the release a minute later - correctly, and after the tag had
* already been pushed. Bumping is therefore not an edit to one file; it is
* this script, and release-ship.js calls it before committing.
*
* node scripts/sync-version.js # sync every file to package.json
* node scripts/sync-version.js --check # fail if any of them disagree
*/
const
fs
=
require
(
"fs"
)
;
const
path
=
require
(
"path"
)
;
const
{
execFileSync
}
=
require
(
"child_process"
)
;
const
ROOT
=
path
.
join
(
__dirname
,
".."
)
;
const
CHECK
=
process
.
argv
.
includes
(
"--check"
)
;
const
version
=
require
(
path
.
join
(
ROOT
,
"package.json"
)
)
.
version
;
const
changed
=
[
]
;
const
wrong
=
[
]
;
/* Rewritten as text, not JSON.stringify: these files are read by people and
reformatting them whole would bury a one-line change in a thousand. */
function
edit
(
file
,
replacements
)
{
const
p
=
path
.
join
(
ROOT
,
file
)
;
const
before
=
fs
.
readFileSync
(
p
,
"utf8"
)
;
let
after
=
before
;
for
(
const
[
pattern
,
replacement
]
of
replacements
)
{
if
(
!
pattern
.
test
(
after
)
)
{
throw
new
Error
(
`
${
file
}
: nothing matched
${
pattern
}
- the file's shape changed`
,
)
;
}
after
=
after
.
replace
(
pattern
,
replacement
)
;
}
if
(
after
===
before
)
return
;
if
(
CHECK
)
{
wrong
.
push
(
file
)
;
return
;
}
fs
.
writeFileSync
(
p
,
after
)
;
changed
.
push
(
file
)
;
}
edit
(
"codemeta.json"
,
[
[
/
^
(
\s
*
"
v
e
r
s
i
o
n
"
:
\s
*
"
)
[
^
"
]
+
(
"
)
/
m
,
`$1
${
version
}
$2`
]
,
[
/
^
(
\s
*
"
s
o
f
t
w
a
r
e
V
e
r
s
i
o
n
"
:
\s
*
"
)
[
^
"
]
+
(
"
)
/
m
,
`$1
${
version
}
$2`
]
,
]
)
;
edit
(
"codemeta.json"
,
[
[
/
(
"
r
e
l
e
a
s
e
N
o
t
e
s
"
:
\s
*
"
)
[
^
"
]
+
(
"
\s
*
,
?
)
/
,
`$1https://github.com/Posnic/POS/releases/tag/v
${
version
}
$2`
]
]
)
;
edit
(
"frontend/login.html"
,
[
[
/
(
"
s
o
f
t
w
a
r
e
V
e
r
s
i
o
n
"
:
\s
*
"
)
[
^
"
]
+
(
"
)
/
,
`$1
${
version
}
$2`
]
]
)
;
for
(
const
file
of
[
"package-lock.json"
,
"api/package-lock.json"
]
)
{
edit
(
file
,
[
[
/
^
(
"
v
e
r
s
i
o
n
"
:
\s
*
"
)
[
^
"
]
+
(
"
)
/
m
,
`$1
${
version
}
$2`
]
,
[
/
^
(
"
v
e
r
s
i
o
n
"
:
\s
*
"
)
[
^
"
]
+
(
"
)
/
m
,
`$1
${
version
}
$2`
]
,
]
)
;
}
const
citation
=
fs
.
readFileSync
(
path
.
join
(
ROOT
,
"CITATION.cff"
)
,
"utf8"
)
;
const
releaseDate
=
/
^
d
a
t
e
-
r
e
l
e
a
s
e
d
:
\s
*
(
\d
{
4
}
-
\d
{
2
}
-
\d
{
2
}
)
$
/
m
.
exec
(
citation
)
?.
[
1
]
;
if
(
!
releaseDate
)
throw
new
Error
(
"CITATION.cff must specify the release date"
)
;
edit
(
"builds/linux/com.posnic.app.metainfo.xml"
,
[
[
/
(
<
r
e
l
e
a
s
e
s
>
\s
*
)
(
<
r
e
l
e
a
s
e
v
e
r
s
i
o
n
=
"
(
[
^
"
]
+
)
"
d
a
t
e
=
"
[
^
"
]
+
"
\s
*
\/
>
)
/
,
(
_match
,
prefix
,
existing
,
previousVersion
)
=>
prefix
+
`<release version="
${
version
}
" date="
${
releaseDate
}
"/>`
+
(
previousVersion
===
version
?
""
:
"\n "
+
existing
)
,
]
]
)
;
edit
(
"CITATION.cff"
,
[
[
/
^
(
v
e
r
s
i
o
n
:
\s
*
)
.
+
$
/
m
,
`$1
${
version
}
`
]
]
)
;
/*
* The OpenAPI spec takes its version from api/package.json, so that file has
* to move too - and the spec is then regenerated rather than hand-edited,
* because CI regenerates it and compares.
*/
edit
(
"api/package.json"
,
[
[
/
^
(
\s
*
"
v
e
r
s
i
o
n
"
:
\s
*
"
)
[
^
"
]
+
(
"
)
/
m
,
`$1
${
version
}
$2`
]
]
)
;
if
(
!
CHECK
)
{
/*
* The generator is invoked directly rather than through `npm run docs:api`.
* Going via npm on Windows means spawning npm.cmd, which modern Node refuses
* without a shell (CVE-2024-27980), and a shell with an args array earns a
* DeprecationWarning on every run. Node running a .js file needs neither.
* api/package.json's docs:api is exactly this command.
*/
execFileSync
(
process
.
execPath
,
[
"scripts/generate-api-docs.js"
]
,
{
cwd
:
path
.
join
(
ROOT
,
"api"
)
,
stdio
:
"pipe"
,
}
)
;
changed
.
push
(
"docs/API.md + docs/openapi.json (regenerated)"
)
;
}
if
(
CHECK
)
{
const
spec
=
JSON
.
parse
(
fs
.
readFileSync
(
path
.
join
(
ROOT
,
"docs"
,
"openapi.json"
)
,
"utf8"
)
,
)
;
if
(
spec
.
info
.
version
!==
version
)
wrong
.
push
(
"docs/openapi.json"
)
;
if
(
wrong
.
length
)
{
console
.
error
(
`\n These still name a different version than
${
version
}
:`
)
;
for
(
const
f
of
wrong
)
console
.
error
(
`
${
f
}
`
)
;
console
.
error
(
"\n Run: node scripts/sync-version.js\n"
)
;
process
.
exit
(
1
)
;
}
console
.
log
(
`every version-bearing file agrees on
${
version
}
`
)
;
}
else
{
console
.
log
(
`version
${
version
}
written to:`
)
;
for
(
const
f
of
changed
)
console
.
log
(
`
${
f
}
`
)
;
}
You can’t perform that action at this time.