underpost 3.2.9 → 3.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/.github/workflows/npmpkg.ci.yml +1 -0
  2. package/.github/workflows/pwa-microservices-template-test.ci.yml +1 -1
  3. package/.github/workflows/release.cd.yml +1 -0
  4. package/.vscode/extensions.json +9 -9
  5. package/.vscode/settings.json +20 -4
  6. package/CHANGELOG.md +195 -1
  7. package/CLI-HELP.md +92 -23
  8. package/README.md +38 -9
  9. package/bin/build.js +27 -7
  10. package/bin/build.template.js +187 -0
  11. package/bin/deploy.js +12 -2
  12. package/bin/index.js +2 -1
  13. package/bump.config.js +26 -0
  14. package/conf.js +20 -7
  15. package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +1 -1
  16. package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +1 -1
  17. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  18. package/manifests/deployment/dd-test-development/deployment.yaml +4 -2
  19. package/manifests/kind-config-dev.yaml +8 -0
  20. package/manifests/lxd/lxd-admin-profile.yaml +12 -3
  21. package/manifests/mongodb/pv-pvc.yaml +44 -8
  22. package/manifests/mongodb/statefulset.yaml +55 -68
  23. package/manifests/mongodb-4.4/headless-service.yaml +10 -0
  24. package/manifests/mongodb-4.4/kustomization.yaml +3 -1
  25. package/manifests/mongodb-4.4/mongodb-nodeport.yaml +17 -0
  26. package/manifests/mongodb-4.4/pv-pvc.yaml +10 -14
  27. package/manifests/mongodb-4.4/statefulset.yaml +79 -0
  28. package/manifests/mongodb-4.4/storage-class.yaml +9 -0
  29. package/manifests/valkey/statefulset.yaml +1 -1
  30. package/manifests/valkey/valkey-nodeport.yaml +17 -0
  31. package/package.json +27 -12
  32. package/scripts/ipxe-setup.sh +52 -49
  33. package/scripts/k3s-node-setup.sh +81 -46
  34. package/scripts/lxd-vm-setup.sh +193 -8
  35. package/scripts/maas-nat-firewalld.sh +145 -0
  36. package/src/api/core/core.router.js +19 -14
  37. package/src/api/core/core.service.js +5 -5
  38. package/src/api/default/default.router.js +22 -18
  39. package/src/api/default/default.service.js +5 -5
  40. package/src/api/document/document.router.js +28 -23
  41. package/src/api/document/document.service.js +100 -23
  42. package/src/api/file/file.router.js +19 -13
  43. package/src/api/file/file.service.js +9 -7
  44. package/src/api/test/test.router.js +17 -12
  45. package/src/api/types.js +24 -0
  46. package/src/api/user/guest.service.js +5 -4
  47. package/src/api/user/user.router.js +297 -288
  48. package/src/api/user/user.service.js +100 -35
  49. package/src/cli/baremetal.js +132 -101
  50. package/src/cli/cluster.js +700 -232
  51. package/src/cli/db.js +59 -60
  52. package/src/cli/deploy.js +216 -137
  53. package/src/cli/fs.js +13 -3
  54. package/src/cli/index.js +80 -15
  55. package/src/cli/ipfs.js +4 -6
  56. package/src/cli/kubectl.js +4 -1
  57. package/src/cli/lxd.js +1099 -223
  58. package/src/cli/monitor.js +9 -3
  59. package/src/cli/release.js +334 -140
  60. package/src/cli/repository.js +68 -23
  61. package/src/cli/run.js +191 -47
  62. package/src/cli/secrets.js +11 -2
  63. package/src/cli/test.js +9 -3
  64. package/src/client/Default.index.js +9 -3
  65. package/src/client/components/core/Auth.js +5 -0
  66. package/src/client/components/core/ClientEvents.js +76 -0
  67. package/src/client/components/core/EventBus.js +4 -0
  68. package/src/client/components/core/Modal.js +82 -41
  69. package/src/client/components/core/PanelForm.js +56 -52
  70. package/src/client/components/core/Worker.js +162 -363
  71. package/src/client/sw/core.sw.js +174 -112
  72. package/src/db/DataBaseProvider.js +115 -15
  73. package/src/db/mariadb/MariaDB.js +2 -1
  74. package/src/db/mongo/MongoBootstrap.js +657 -0
  75. package/src/db/mongo/MongooseDB.js +129 -21
  76. package/src/index.js +1 -1
  77. package/src/runtime/express/Express.js +2 -2
  78. package/src/runtime/wp/Wp.js +8 -5
  79. package/src/server/auth.js +2 -2
  80. package/src/server/client-build-docs.js +1 -1
  81. package/src/server/client-build.js +94 -129
  82. package/src/server/conf.js +81 -79
  83. package/src/server/process.js +180 -19
  84. package/src/server/proxy.js +9 -2
  85. package/src/server/runtime.js +1 -1
  86. package/src/server/start.js +16 -4
  87. package/src/server/valkey.js +2 -0
  88. package/src/ws/IoInterface.js +16 -16
  89. package/src/ws/core/channels/core.ws.chat.js +11 -11
  90. package/src/ws/core/channels/core.ws.mailer.js +29 -29
  91. package/src/ws/core/channels/core.ws.stream.js +19 -19
  92. package/src/ws/core/core.ws.connection.js +8 -8
  93. package/src/ws/core/core.ws.server.js +6 -5
  94. package/src/ws/default/channels/default.ws.main.js +10 -10
  95. package/src/ws/default/default.ws.connection.js +4 -4
  96. package/src/ws/default/default.ws.server.js +4 -3
  97. package/bin/file.js +0 -202
  98. package/bin/vs.js +0 -74
  99. package/bin/zed.js +0 -84
  100. package/src/client/ssr/email/DefaultRecoverEmail.js +0 -21
  101. package/src/client/ssr/email/DefaultVerifyEmail.js +0 -17
  102. /package/src/client/ssr/{offline → views}/Maintenance.js +0 -0
  103. /package/src/client/ssr/{offline → views}/NoNetworkConnection.js +0 -0
  104. /package/src/client/ssr/{pages → views}/Test.js +0 -0
@@ -4,7 +4,13 @@
4
4
  * @namespace UnderpostMonitor
5
5
  */
6
6
 
7
- import { loadReplicas, pathPortAssignmentFactory, loadConfServerJson, loadCronDeployEnv } from '../server/conf.js';
7
+ import {
8
+ loadReplicas,
9
+ pathPortAssignmentFactory,
10
+ loadConfServerJson,
11
+ loadCronDeployEnv,
12
+ etcHostFactory,
13
+ } from '../server/conf.js';
8
14
  import { loggerFactory } from '../server/logger.js';
9
15
  import axios from 'axios';
10
16
  import fs from 'fs-extra';
@@ -144,7 +150,7 @@ class UnderpostMonitor {
144
150
  if (path.match('peer') || path.match('socket')) continue;
145
151
  const urlTest = `http${env === 'development' ? '' : 's'}://${host}${path}`;
146
152
  if (env === 'development') {
147
- const { renderHosts } = Underpost.deploy.etcHostFactory([host]);
153
+ const { renderHosts } = etcHostFactory([host]);
148
154
  logger.info('renderHosts', renderHosts);
149
155
  }
150
156
  await axios.get(urlTest, { timeout: 10000 }).catch((error) => {
@@ -200,7 +206,7 @@ class UnderpostMonitor {
200
206
  let monitorPodName;
201
207
  const monitorCallBack = (resolve, reject) => {
202
208
  if (env === 'development') {
203
- const { renderHosts } = Underpost.deploy.etcHostFactory([]);
209
+ const { renderHosts } = etcHostFactory([]);
204
210
  logger.info('renderHosts', renderHosts);
205
211
  }
206
212
  const envMsTimeout = Underpost.env.get(`${deployId}-${env}-monitor-ms`);
@@ -10,26 +10,297 @@
10
10
  */
11
11
 
12
12
  import fs from 'fs-extra';
13
+ import path from 'path';
13
14
  import dotenv from 'dotenv';
14
15
  import { pbcopy, shellCd, shellExec } from '../server/process.js';
16
+ import { Dns } from '../server/dns.js';
15
17
  import { loggerFactory } from '../server/logger.js';
16
18
  import { timer } from '../client/components/core/CommonJs.js';
17
19
  import Underpost from '../index.js';
18
20
 
19
21
  const logger = loggerFactory(import.meta);
20
22
 
23
+ /**
24
+ * Files that must never be touched by a version bump, even if they happen to contain a
25
+ * literal version string. CHANGELOG is historical; logs/ and node_modules/ are runtime
26
+ * outputs; engine-private/.env.* and secrets must not be rewritten by regex.
27
+ */
28
+ const VERSION_BUMP_SKIP = [
29
+ /(^|\/)CHANGELOG\.md$/i,
30
+ /(^|\/)logs\//,
31
+ /(^|\/)node_modules\//,
32
+ /(^|\/)\.git\//,
33
+ /(^|\/)engine-private\/.*\.env(\..*)?$/,
34
+ ];
35
+
36
+ const isSkipped = (filePath) => VERSION_BUMP_SKIP.some((re) => re.test(filePath));
37
+
38
+ /**
39
+ * Declarative regex-based version bump targets for files bumpp cannot handle natively
40
+ * (image tags, doc strings, README badges, build-args, etc.).
41
+ *
42
+ * Each target is one of:
43
+ * - { file: 'path/to/file', patterns: RegExp | RegExp[] }
44
+ * - { dir: 'dir', match: RegExp, patterns: RegExp | RegExp[], recursive?: boolean }
45
+ *
46
+ * Every pattern MUST have exactly one capture group: the prefix to preserve. The replacement
47
+ * is `$1<newVersion>`. Use a lookahead `(?=...)` to anchor a trailing context (closing quote,
48
+ * backtick, etc.) without consuming it. This keeps the callback signature trivial.
49
+ *
50
+ * The walker iterates targets, applies patterns to each matching file, and reports the
51
+ * number of substitutions per file. Files that match nothing are silently skipped.
52
+ */
53
+ const buildVersionBumpTargets = () => [
54
+ // ── src/index.js — anchored to the static class field, never a bare replaceAll. ──
55
+ {
56
+ file: 'src/index.js',
57
+ patterns: /(static version = ['"]v)\d+\.\d+\.\d+(?=['"])/g,
58
+ },
59
+
60
+ // ── README + CLI-HELP fallbacks. CLI-HELP is regenerated by `deploy cli-docs`, but bump
61
+ // it too so the file is consistent if the regeneration step is skipped. ──
62
+ {
63
+ file: 'README.md',
64
+ patterns: [
65
+ /(socket\.dev\/api\/badge\/npm\/package\/underpost\/)\d+\.\d+\.\d+/g,
66
+ /(socket\.dev\/npm\/package\/underpost\/overview\/)\d+\.\d+\.\d+/g,
67
+ /(ci\/cd cli v)\d+\.\d+\.\d+/gi,
68
+ ],
69
+ },
70
+ {
71
+ file: 'CLI-HELP.md',
72
+ patterns: /(ci\/cd cli v)\d+\.\d+\.\d+/gi,
73
+ optional: true,
74
+ },
75
+
76
+ // ── Cyberia + nexodev docs. ──
77
+ {
78
+ dir: 'src/client/public/cyberia-docs',
79
+ match: /\.md$/,
80
+ patterns: [/(\*\*(?:Current )?[Vv]ersion:\*\* )\d+\.\d+\.\d+/g, /(underpost\/[a-z0-9-]+:v)\d+\.\d+\.\d+/g],
81
+ recursive: true,
82
+ },
83
+ {
84
+ dir: 'src/client/public/nexodev/docs/references',
85
+ match: /\.md$/,
86
+ patterns: [
87
+ /(underpost\/[a-z0-9-]+:v)\d+\.\d+\.\d+/g,
88
+ /(UNDERPOST_VERSION=)\d+\.\d+\.\d+/g,
89
+ /(ci\/cd cli v)\d+\.\d+\.\d+/gi,
90
+ // version tag bumps inside markdown narrative, e.g. `v3.2.9`, `v3.2.10`, …
91
+ /(`v)\d+\.\d+\.\d+(?=`)/g,
92
+ ],
93
+ recursive: true,
94
+ },
95
+
96
+ // ── Kubernetes manifests. Covers deployment.yaml + cronjob yamls under dd-cron. ──
97
+ {
98
+ dir: 'manifests/deployment',
99
+ match: /deployment\.yaml$/,
100
+ patterns: [/(underpost\/[a-z0-9-]+:v)\d+\.\d+\.\d+/g, /(engine\.version: )\d+\.\d+\.\d+/g],
101
+ recursive: true,
102
+ },
103
+ {
104
+ dir: 'manifests/cronjobs',
105
+ match: /\.yaml$/,
106
+ patterns: /(underpost\/[a-z0-9-]+:v)\d+\.\d+\.\d+/g,
107
+ recursive: true,
108
+ },
109
+
110
+ // ── GitHub Actions workflows. Single sweep across docker-image.*.ci.yml, engine-*.cd.yml,
111
+ // and the root docker-image.ci.yml — replaces previous three separate loops. ──
112
+ {
113
+ dir: '.github/workflows',
114
+ match: /\.(yml|yaml)$/,
115
+ patterns: [
116
+ /(underpost\/[a-z0-9-]+:v)\d+\.\d+\.\d+/g,
117
+ /(underpost-engine:v)\d+\.\d+\.\d+/g,
118
+ /(type=raw,value=v)\d+\.\d+\.\d+/g,
119
+ /(UNDERPOST_VERSION=)\d+\.\d+\.\d+/g,
120
+ ],
121
+ },
122
+
123
+ // ── engine-private confs (gitignored — bumped only if present). ──
124
+ {
125
+ dir: 'engine-private/conf',
126
+ match: /(?:deployment\.yaml|conf\.instances\.json)$/,
127
+ patterns: [
128
+ /(underpost\/[a-z0-9-]+:v)\d+\.\d+\.\d+/g,
129
+ /(underpost-engine:v)\d+\.\d+\.\d+/g,
130
+ /(engine\.version: )\d+\.\d+\.\d+/g,
131
+ /(v)\d+\.\d+\.\d+/g,
132
+ ],
133
+ recursive: true,
134
+ optional: true,
135
+ },
136
+ ];
137
+
138
+ /**
139
+ * Walks a directory (optionally recursively) and returns paths matching `match`.
140
+ */
141
+ const walkDir = (dir, match, recursive) => {
142
+ if (!fs.existsSync(dir)) return [];
143
+ const out = [];
144
+ const stack = [dir];
145
+ while (stack.length) {
146
+ const cur = stack.pop();
147
+ let entries;
148
+ try {
149
+ entries = fs.readdirSync(cur, { withFileTypes: true });
150
+ } catch {
151
+ continue;
152
+ }
153
+ for (const ent of entries) {
154
+ const full = path.join(cur, ent.name);
155
+ if (ent.isDirectory()) {
156
+ if (recursive) stack.push(full);
157
+ } else if (ent.isFile() && match.test(ent.name) && !isSkipped(full)) {
158
+ out.push(full);
159
+ }
160
+ }
161
+ }
162
+ return out;
163
+ };
164
+
165
+ /**
166
+ * Applies an array of regex patterns to a single file in place. Substitutes only when the
167
+ * matched version literally equals `oldVersion` — narrative references to other versions
168
+ * (e.g. example tags `(v3.2.9, v3.2.10, …)`) are left untouched.
169
+ *
170
+ * Returns the substitution count (0 if nothing matched).
171
+ */
172
+ const bumpFile = (filePath, patterns, oldVersion, newVersion, { dryRun }) => {
173
+ if (isSkipped(filePath)) return 0;
174
+ if (!fs.existsSync(filePath)) return 0;
175
+ const original = fs.readFileSync(filePath, 'utf8');
176
+ const regexes = Array.isArray(patterns) ? patterns : [patterns];
177
+ let updated = original;
178
+ let count = 0;
179
+ for (const re of regexes) {
180
+ updated = updated.replace(re, (m, prefix) => {
181
+ const matchedVersion = m.match(/\d+\.\d+\.\d+/)?.[0];
182
+ if (matchedVersion !== oldVersion) return m;
183
+ count += 1;
184
+ return `${prefix}${newVersion}`;
185
+ });
186
+ }
187
+ if (count > 0 && updated !== original && !dryRun) {
188
+ fs.writeFileSync(filePath, updated, 'utf8');
189
+ }
190
+ return count;
191
+ };
192
+
193
+ /**
194
+ * Bumps every non-canonical file declared in VERSION_BUMP_TARGETS.
195
+ * Returns a per-file report so callers can print a summary.
196
+ *
197
+ * @param {string} oldVersion - The version currently in the files (pre-bump).
198
+ * @param {string} newVersion - The version to write.
199
+ * @param {{dryRun?: boolean}} [opts]
200
+ * @returns {Array<{file: string, count: number}>}
201
+ */
202
+ const bumpAuxiliaryFiles = (oldVersion, newVersion, { dryRun = false } = {}) => {
203
+ const report = [];
204
+ if (oldVersion === newVersion) return report;
205
+ for (const target of buildVersionBumpTargets()) {
206
+ const files = target.file ? [target.file] : walkDir(target.dir, target.match, target.recursive ?? false);
207
+ for (const file of files) {
208
+ if (target.optional && !fs.existsSync(file)) continue;
209
+ const count = bumpFile(file, target.patterns, oldVersion, newVersion, { dryRun });
210
+ if (count > 0) report.push({ file, count });
211
+ }
212
+ }
213
+ return report;
214
+ };
215
+
216
+ /**
217
+ * Prints a per-file change summary table.
218
+ */
219
+ const printBumpReport = (report, { dryRun }) => {
220
+ const header = dryRun ? 'Version bump (dry-run) — would change:' : 'Version bump — files updated:';
221
+ logger.info(header);
222
+ if (!report.length) {
223
+ console.log(' (no files matched)');
224
+ return;
225
+ }
226
+ const maxLen = Math.max(...report.map((r) => r.file.length));
227
+ for (const { file, count } of report) {
228
+ console.log(` ${file.padEnd(maxLen + 2)} ${count} match${count === 1 ? '' : 'es'}`);
229
+ }
230
+ console.log(` Total: ${report.length} file(s), ${report.reduce((s, r) => s + r.count, 0)} substitution(s)`);
231
+ };
232
+
21
233
  /**
22
234
  * Kills any Node.js dev-server or nodemon processes that may hold file locks
23
235
  * (e.g. overwriting package.json). Skips VSCode internals and the current process.
24
236
  */
25
237
  function killDevServers() {
26
- // shellExec(
27
- // `kill -9 $(pgrep -f 'nodemon|node.*src/server|node.*dev' | grep -v '^${process.pid}$') 2>/dev/null || true`,
28
- // );
29
- shellExec(`node bin run kill 4001`);
30
- shellExec(`node bin run kill 4002`);
31
- shellExec(`node bin run kill 4003`);
32
- shellExec(`node bin run kill 3000`);
238
+ for (const port of [4001, 4002, 4003, 3000]) shellExec(`node bin run kill ${port}`);
239
+ }
240
+
241
+ const TEMPLATE_PATH = '../pwa-microservices-template';
242
+
243
+ /**
244
+ * Runs a command in an ISOLATED environment. `release build` loads the engine's
245
+ * `dd-cron/.env.production` (DEPLOY_ID=dd-cron, DB creds, secrets, …) into its own `process.env`,
246
+ * which `shellExec` children would otherwise inherit — and the template's `dotenv.config()` runs
247
+ * without override, so it could never reclaim those keys. `env -i` starts the child with an empty
248
+ * environment; only PATH/HOME-class essentials are re-added so node/npm/git still resolve. The
249
+ * template then reads only its own `.env`, resolving `dd-default` exactly like a fresh clone.
250
+ */
251
+ const ISOLATED_ENV = 'env -i HOME="$HOME" PATH="$PATH" USER="$USER" LOGNAME="$LOGNAME" TERM="$TERM" LANG="$LANG"';
252
+
253
+ /**
254
+ * Builds the pwa-microservices-template from scratch and smoke-tests its default workflow.
255
+ *
256
+ * 1. Cleans the engine, pulls latest, and rebuilds the template via `bin/build.template`.
257
+ * 2. Derives `.env` + `.env.example` from the template `.env.example` (DHCP host IP + file
258
+ * logs), both written from the same `dd-default` content so the default startup workflow
259
+ * bootstraps `engine-private` from scratch out of them. `.env` is rewritten because it is
260
+ * gitignored (git clean never removes it) and may otherwise hold a stale `dd-cron`.
261
+ * 3. Installs deps, then builds + runs the template `dev` server in an ISOLATED env
262
+ * (see `ISOLATED_ENV`) so it resolves `dd-default` like a fresh clone, and asserts the
263
+ * startup log is error-free.
264
+ *
265
+ * @returns {boolean} true when the template started cleanly, false otherwise.
266
+ */
267
+ async function buildAndTestTemplate() {
268
+ killDevServers();
269
+ Underpost.repo.clean({ paths: ['/home/dd/engine', '/home/dd/engine/engine-private '] });
270
+ shellExec(`node bin pull . ${process.env.GITHUB_USERNAME}/engine`);
271
+ shellExec(`npm run update:template`);
272
+ shellExec(`node bin run shared-dir ${TEMPLATE_PATH}`);
273
+
274
+ const dhcpHostIp = Dns.getLocalIPv4Address();
275
+ logger.info(`DHCP host IP for template test: ${dhcpHostIp}`);
276
+ let envContent = fs.readFileSync(`${TEMPLATE_PATH}/.env.example`, 'utf8');
277
+ if (dhcpHostIp) envContent = envContent.replace(/127\.0\.0\.1/g, dhcpHostIp);
278
+ envContent = envContent.replace(/^ENABLE_FILE_LOGS=.*/m, 'ENABLE_FILE_LOGS=true');
279
+ // fs.writeFileSync(`${TEMPLATE_PATH}/.env`, envContent, 'utf8');
280
+ fs.writeFileSync(`${TEMPLATE_PATH}/.env.example`, envContent, 'utf8');
281
+ shellExec(`cd ${TEMPLATE_PATH} && npm install`);
282
+ shellExec(`cd ${TEMPLATE_PATH} && node bin env clean`);
283
+ // Build + run in an isolated env so the template resolves dd-default from its own .env and
284
+ // never inherits the engine's dd-cron deploy selection. See ISOLATED_ENV above.
285
+ //
286
+ // ENABLE_FILE_LOGS must be passed inline: src/server.js builds start.js's logger at import
287
+ // time, before Config.build() loads the template .env, so the var has to be present in the
288
+ // process env from the start for logs/start.js/all.log (the success probe below) to be written.
289
+ shellExec(`cd ${TEMPLATE_PATH} && ${ISOLATED_ENV} npm run build`);
290
+ shellExec(`cd ${TEMPLATE_PATH} && ${ISOLATED_ENV} ENABLE_FILE_LOGS=true timeout 5s npm run dev`, { async: true });
291
+ await timer(5500);
292
+
293
+ const templateLogPath = `${TEMPLATE_PATH}/logs/start.js/all.log`;
294
+ const runnerResult = fs.existsSync(templateLogPath) ? fs.readFileSync(templateLogPath, 'utf8') : '';
295
+ logger.info('Test template runner result');
296
+ killDevServers();
297
+ shellCd(`/home/dd/engine`);
298
+ Underpost.repo.clean({ paths: ['/home/dd/engine', '/home/dd/engine/engine-private '] });
299
+ if (!runnerResult || runnerResult.toLowerCase().match('error')) {
300
+ logger.error('Test template runner result failed');
301
+ return false;
302
+ }
303
+ return true;
33
304
  }
34
305
 
35
306
  /**
@@ -46,154 +317,76 @@ class UnderpostRelease {
46
317
  * Builds a new version of the Underpost engine.
47
318
  *
48
319
  * Performs the full version build pipeline:
49
- * 1. Loads production environment and pulls latest code.
50
- * 2. Kills running dev servers on ports 4001-4003.
51
- * 3. Builds and tests the pwa-microservices-template.
52
- * 4. Bumps version in package.json, package-lock.json, and all conf package files.
53
- * 5. Updates deployment YAML manifests and Docker image CI workflow with new version.
54
- * 6. Updates src/index.js version string.
55
- * 7. Rebuilds CLI docs, dependencies, client builds, deploy manifests, and default confs.
56
- * 8. Syncs cron setup-start scripts and builds changelog.
320
+ * 1. Loads production env and pulls latest code; kills dev servers on ports 4001-4003.
321
+ * 2. Builds and smoke-tests the pwa-microservices-template (aborts on error).
322
+ * 3. Canonical version files: delegates to `bumpp` (driven by `bump.config.js`). Bumps
323
+ * package.json, package-lock.json (root + packages['']), and every
324
+ * engine-private/conf/**\/package.json.
325
+ * 4. Auxiliary files: anchored-regex walker over VERSION_BUMP_TARGETS — covers
326
+ * src/index.js, README, cyberia-docs, nexodev docs, manifests (deployment + cronjobs),
327
+ * .github/workflows (image tags, type=raw, UNDERPOST_VERSION build-args), and
328
+ * engine-private confs (deployment.yaml + conf.instances.json). Files in
329
+ * VERSION_BUMP_SKIP (CHANGELOG, logs/, .env.*, node_modules/) are never touched.
330
+ * The walker only rewrites occurrences whose version literally equals the pre-bump
331
+ * version — narrative references like `(v3.2.9, v3.2.10, …)` are preserved.
332
+ * 5. Rebuilds CLI docs, deps, client bundle, deploy manifests, default confs.
333
+ * 6. Syncs cron setup-start scripts and builds the changelog.
334
+ *
335
+ * With `options.dryRun: true`, steps 3–4 print a per-file substitution report and exit
336
+ * without writing files or running steps 5–6.
57
337
  *
58
338
  * @method build
59
339
  * @param {string} [newVersion] - The new version string to set. Defaults to current version if not provided.
60
- * @param {object} [options] - Commander options object (unused, reserved for future flags).
340
+ * @param {{dryRun?: boolean}} [options] - Commander options. `--dry-run` previews changes.
61
341
  * @memberof UnderpostRelease
62
342
  */
63
- async build(newVersion, options) {
343
+ async build(newVersion, options = {}) {
344
+ const dryRun = !!options.dryRun;
64
345
  dotenv.config({ path: `./engine-private/conf/dd-cron/.env.production`, override: true });
65
346
  shellCd(`/home/dd/engine`);
66
- killDevServers();
67
- Underpost.repo.clean({ paths: ['/home/dd/engine', '/home/dd/engine/engine-private '] });
68
- shellExec(`node bin pull . ${process.env.GITHUB_USERNAME}/engine`);
69
- shellExec(`npm run update:template`);
70
- shellExec(`cd ../pwa-microservices-template && npm install && npm run build`);
71
- console.log(fs.existsSync(`../pwa-microservices-template/engine-private/conf/dd-default`));
72
- shellExec(`cd ../pwa-microservices-template && ENABLE_FILE_LOGS=true timeout 5s npm run dev`, {
73
- async: true,
74
- });
75
- await timer(5500);
76
- const templateRunnerResult = fs.readFileSync(`../pwa-microservices-template/logs/start.js/all.log`, 'utf8');
77
- logger.info('Test template runner result');
78
- console.log(templateRunnerResult);
79
- if (!templateRunnerResult || templateRunnerResult.toLowerCase().match('error')) {
80
- logger.error('Test template runner result failed');
81
- return;
82
- }
83
- killDevServers();
84
- shellCd(`/home/dd/engine`);
85
- Underpost.repo.clean({ paths: ['/home/dd/engine', '/home/dd/engine/engine-private '] });
347
+
348
+ // ── Resolve from/to versions up front. Used by every bump step + downstream commands. ──
86
349
  const originPackageJson = JSON.parse(fs.readFileSync(`package.json`, 'utf8'));
87
- if (!newVersion) newVersion = originPackageJson.version;
88
350
  const { version } = originPackageJson;
89
- originPackageJson.version = newVersion;
90
- fs.writeFileSync(`package.json`, JSON.stringify(originPackageJson, null, 4), 'utf8');
91
-
92
- const originPackageLockJson = JSON.parse(fs.readFileSync(`package-lock.json`, 'utf8'));
93
- originPackageLockJson.version = newVersion;
94
- originPackageLockJson.packages[''].version = newVersion;
95
- fs.writeFileSync(`package-lock.json`, JSON.stringify(originPackageLockJson, null, 4), 'utf8');
96
-
97
- if (fs.existsSync(`./engine-private/conf`)) {
98
- const files = await fs.readdir(`./engine-private/conf`, { recursive: true });
99
- for (const relativePath of files) {
100
- const filePah = `./engine-private/conf/${relativePath.replaceAll(`\\`, '/')}`;
101
- if (filePah.split('/').pop() === 'package.json') {
102
- const originPackage = JSON.parse(fs.readFileSync(filePah, 'utf8'));
103
- originPackage.version = newVersion;
104
- fs.writeFileSync(filePah, JSON.stringify(originPackage, null, 4), 'utf8');
105
- }
106
- if (filePah.split('/').pop() === 'deployment.yaml') {
107
- fs.writeFileSync(
108
- filePah,
109
- fs
110
- .readFileSync(filePah, 'utf8')
111
- .replaceAll(`v${version}`, `v${newVersion}`)
112
- .replaceAll(`engine.version: ${version}`, `engine.version: ${newVersion}`),
113
- 'utf8',
114
- );
115
- }
116
- }
117
- }
118
-
119
- fs.writeFileSync(
120
- `./manifests/deployment/dd-default-development/deployment.yaml`,
121
- fs
122
- .readFileSync(`./manifests/deployment/dd-default-development/deployment.yaml`, 'utf8')
123
- .replaceAll(`underpost-engine:v${version}`, `underpost-engine:v${newVersion}`),
124
- 'utf8',
125
- );
351
+ if (!newVersion) newVersion = version;
352
+ logger.info(`Release build bumping ${version} → ${newVersion}${dryRun ? ' (dry-run)' : ''}`);
126
353
 
127
- if (fs.existsSync(`./.github/workflows/docker-image.ci.yml`))
128
- fs.writeFileSync(
129
- `./.github/workflows/docker-image.ci.yml`,
130
- fs
131
- .readFileSync(`./.github/workflows/docker-image.ci.yml`, 'utf8')
132
- .replaceAll(`underpost-engine:v${version}`, `underpost-engine:v${newVersion}`),
133
- 'utf8',
134
- );
135
-
136
- // Update underpost/* image versions in all engine-*.cd.yml workflows.
137
- for (const wf of fs.readdirSync(`./.github/workflows`)) {
138
- if (!wf.match(/^engine-.+\.cd\.yml$/)) continue;
139
- const wfPath = `./.github/workflows/${wf}`;
140
- const updated = fs
141
- .readFileSync(wfPath, 'utf8')
142
- .replace(/underpost\/([^:'"]+):v[0-9]+\.[0-9]+\.[0-9]+/g, `underpost/$1:v${newVersion}`);
143
- fs.writeFileSync(wfPath, updated, 'utf8');
144
- }
145
-
146
- // Update version tag in all runtime docker image workflows (type=raw,value=v<version>).
147
- for (const wf of fs.readdirSync(`./.github/workflows`)) {
148
- if (!wf.match(/^docker-image\..+\.ci\.yml$/) || wf === 'docker-image.ci.yml') continue;
149
- const wfPath = `./.github/workflows/${wf}`;
150
- fs.writeFileSync(
151
- wfPath,
152
- fs.readFileSync(wfPath, 'utf8').replaceAll(`type=raw,value=v${version}`, `type=raw,value=v${newVersion}`),
153
- 'utf8',
154
- );
354
+ if (!dryRun) {
355
+ const templateOk = await buildAndTestTemplate();
356
+ if (!templateOk) return;
155
357
  }
156
358
 
157
- // Update image version in all conf.instances.json files for underpost/* images.
158
- if (fs.existsSync(`./engine-private/conf`)) {
159
- const confFiles = await fs.readdir(`./engine-private/conf`, { recursive: true });
160
- for (const relativePath of confFiles) {
161
- const filePath = `./engine-private/conf/${relativePath.replaceAll('\\', '/')}`;
162
- if (filePath.split('/').pop() !== 'conf.instances.json' || !fs.existsSync(filePath)) continue;
163
-
164
- let instances;
165
- try {
166
- instances = JSON.parse(fs.readFileSync(filePath, 'utf8'));
167
- } catch {
168
- logger.warn(`Skipping invalid JSON file: ${filePath}`);
169
- continue;
170
- }
171
-
172
- if (!Array.isArray(instances)) continue;
173
-
174
- let updated = false;
175
- for (const instance of instances) {
176
- if (!instance || typeof instance !== 'object') continue;
177
- if (!instance.image || typeof instance.image !== 'string') continue;
178
- if (!instance.image.startsWith('underpost/')) continue;
359
+ // ── Canonical version files: delegate to bumpp (package.json, package-lock.json,
360
+ // engine-private/conf/**/package.json). bumpp owns lockfile semantics (root version
361
+ // + packages[''].version) so we don't reimplement them. ──
362
+ const { versionBump } = await import('bumpp');
363
+ const bumppResult = await versionBump({
364
+ release: newVersion,
365
+ files: [
366
+ 'package.json',
367
+ 'package-lock.json',
368
+ ...(fs.existsSync('./engine-private/conf') ? ['engine-private/conf/**/package.json'] : []),
369
+ ],
370
+ commit: false,
371
+ tag: false,
372
+ push: false,
373
+ confirm: false,
374
+ recursive: false,
375
+ ignoreScripts: true,
376
+ dry: dryRun,
377
+ });
378
+ logger.info(`bumpp updated ${bumppResult?.files?.length ?? 0} canonical file(s).`);
179
379
 
180
- const baseImage = instance.image.split('@')[0].split(':')[0];
181
- const nextImage = `${baseImage}:v${newVersion}`;
182
- if (instance.image !== nextImage) {
183
- instance.image = nextImage;
184
- updated = true;
185
- }
186
- }
380
+ // ── Auxiliary files: anchored-regex walker over VERSION_BUMP_TARGETS. ──
381
+ const report = bumpAuxiliaryFiles(version, newVersion, { dryRun });
382
+ printBumpReport(report, { dryRun });
187
383
 
188
- if (updated) fs.writeFileSync(filePath, JSON.stringify(instances, null, 2), 'utf8');
189
- }
384
+ if (dryRun) {
385
+ logger.info('Dry-run complete. No files modified. Re-run without --dry-run to apply.');
386
+ return { from: version, to: newVersion, files: report.map((r) => r.file), dryRun: true };
190
387
  }
191
388
 
192
- fs.writeFileSync(
193
- `./src/index.js`,
194
- fs.readFileSync(`./src/index.js`, 'utf8').replaceAll(`${version}`, `${newVersion}`),
195
- 'utf8',
196
- );
389
+ // ── Downstream regenerations and manifest sync (unchanged from previous flow). ──
197
390
  shellExec(`node bin/deploy cli-docs ${version} ${newVersion}`);
198
391
  shellExec(`node bin/deploy update-dependencies`);
199
392
  shellExec(`node bin/build dd`);
@@ -206,6 +399,7 @@ class UnderpostRelease {
206
399
  shellExec(`sudo rm -rf ./engine-private/conf/dd-default`);
207
400
  shellExec(`node bin cron --kubeadm --setup-start --git`); // --apply
208
401
  shellExec(`node bin cmt --changelog-build`);
402
+ return { from: version, to: newVersion, files: report.map((r) => r.file), dryRun: false };
209
403
  },
210
404
 
211
405
  /**
@@ -266,7 +460,7 @@ class UnderpostRelease {
266
460
  * Runs the pwa-microservices-template update and push flow locally.
267
461
  *
268
462
  * Always removes and re-clones pwa-microservices-template, then:
269
- * 1. Runs update:template (node bin/file update-template) to sync engine sources.
463
+ * 1. Runs update:template (node bin/build.template) to sync engine sources.
270
464
  * 2. Installs dependencies and builds the template.
271
465
  * 3. Commits and pushes to the pwa-microservices-template remote repository.
272
466
  *