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/prepare-sync-agent.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
14
(14)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
POS
/
scripts
/
prepare-sync-agent.js
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
91 lines (87 loc) · 4.29 KB
develop
Breadcrumbs
POS
/
scripts
/
prepare-sync-agent.js
Copy path
Top
File metadata and controls
Code
Blame
91 lines (87 loc) · 4.29 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
/**
* Optional build step: bundle the POSNIC Cloud sync agent into the installer.
*
* The agent is proprietary and lives in the private Cloud repo. If a sibling
* checkout exists (../Cloud/apps/sync-agent, or SYNC_AGENT_DIR env), it is
* copied (with production node_modules) into builds/sync-agent so
* electron-builder ships it under resources/sync-agent.
*
* Open-source builds: the folder is absent → an empty placeholder is created
* and the app simply runs without cloud sync.
*/
const
fs
=
require
(
'fs'
)
;
const
path
=
require
(
'path'
)
;
const
target
=
path
.
join
(
__dirname
,
'..'
,
'builds'
,
'sync-agent'
)
;
const
source
=
process
.
env
.
SYNC_AGENT_DIR
||
path
.
join
(
__dirname
,
'..'
,
'..'
,
'Gateway'
,
'apps'
,
'sync-agent'
)
;
fs
.
rmSync
(
target
,
{
recursive
:
true
,
force
:
true
}
)
;
fs
.
mkdirSync
(
target
,
{
recursive
:
true
}
)
;
if
(
fs
.
existsSync
(
path
.
join
(
source
,
'src'
,
'index.js'
)
)
)
{
fs
.
cpSync
(
source
,
target
,
{
recursive
:
true
,
filter
:
(
src
)
=>
!
/
[
\\
/
]
\.
e
n
v
$
/
.
test
(
src
)
&&
!
/
[
\\
/
]
a
g
e
n
t
-
s
m
o
k
e
\.
l
o
g
$
/
.
test
(
src
)
,
}
)
;
/*
* NO node_modules IS THE NORMAL CASE, not a mistake, and the old warning
* here said the opposite.
*
* The agent declares bson, dotenv and mongodb, and ships with none of them.
* It works because it is spawned from the Electron main process, which
* inherits NODE_PATH pointing at the API's own node_modules - see
* src/server.js, where that is set up for the in-process API. The agent
* needs the same three packages the API already carries, so a second copy
* would be dead weight in the installer.
*
* The old text told whoever saw it to run npm install in the Cloud agent,
* which would have made every installer larger to fix nothing. A warning
* that fires on every correct build is a warning people learn to scroll
* past, and then the real one goes past too.
*
* Said out loud rather than deleted, because the coupling is invisible from
* here and somebody should know it exists. tests/the-sync-agent-finds-its-
* modules.test.js pins it.
*/
if
(
!
fs
.
existsSync
(
path
.
join
(
target
,
'node_modules'
)
)
)
{
console
.
log
(
'[prepare-sync-agent] no node_modules, as expected: the agent resolves bson, dotenv and mongodb through NODE_PATH from the API runtime'
)
;
}
console
.
log
(
'[prepare-sync-agent] bundled sync agent from'
,
source
)
;
/*
* THE TWO LISTS MUST AGREE, or a collection syncs on paper only.
*
* api/src/sync/collections.json is what this app says must travel between
* the cloud and a till. The agent's sync-config.json, bundled just above,
* is what the till will actually push and pull. The restaurant's tables
* were in neither, and nothing compared them, so a shop ran with two
* different floors for as long as sync has existed.
*
* A bundle that would sync less than the app promises, or more than the
* app has decided, does not get built. Fixing it is a line in one file
* or the other, and a decision; that is the point.
*/
const
decisions
=
JSON
.
parse
(
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'..'
,
'api'
,
'src'
,
'sync'
,
'collections.json'
)
,
'utf8'
)
)
;
const
bundled
=
JSON
.
parse
(
fs
.
readFileSync
(
path
.
join
(
target
,
'sync-config.json'
)
,
'utf8'
)
)
.
collections
||
{
}
;
const
promised
=
Object
.
keys
(
decisions
.
synced
||
{
}
)
;
const
missing
=
promised
.
filter
(
(
name
)
=>
!
bundled
[
name
]
)
;
const
extra
=
Object
.
keys
(
bundled
)
.
filter
(
(
name
)
=>
!
decisions
.
synced
[
name
]
)
;
if
(
missing
.
length
||
extra
.
length
)
{
if
(
missing
.
length
)
{
console
.
error
(
'[prepare-sync-agent] the bundled agent does NOT sync: '
+
missing
.
join
(
', '
)
)
;
console
.
error
(
' api/src/sync/collections.json marks these synced; the agent at '
+
source
+
' has no lane for them.'
)
;
}
if
(
extra
.
length
)
{
console
.
error
(
'[prepare-sync-agent] the bundled agent syncs collections this app has not decided on: '
+
extra
.
join
(
', '
)
)
;
console
.
error
(
' Add them to "synced" in api/src/sync/collections.json, or drop them from the agent.'
)
;
}
process
.
exit
(
1
)
;
}
console
.
log
(
'[prepare-sync-agent] the agent syncs every collection the app promises ('
+
promised
.
length
+
')'
)
;
}
else
{
fs
.
writeFileSync
(
path
.
join
(
target
,
'.placeholder'
)
,
'Sync agent not bundled in this build (open-source build).\n'
)
;
console
.
log
(
'[prepare-sync-agent] public build: a signed sync component is installed after cloud activation'
)
;
}
You can’t perform that action at this time.