hazo_env 0.15.3 → 0.17.0
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.
- package/CHANGE_LOG.md +120 -0
- package/README.md +333 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +17 -0
- package/dist/cli.js +178 -17
- package/dist/deploy/build.d.ts +1 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +51 -14
- package/dist/deploy/clean.d.ts +2 -1
- package/dist/deploy/clean.d.ts.map +1 -1
- package/dist/deploy/clean.js +36 -6
- package/dist/deploy/generate-readme-cli.d.ts +3 -0
- package/dist/deploy/generate-readme-cli.d.ts.map +1 -0
- package/dist/deploy/generate-readme-cli.js +40 -0
- package/dist/deploy/help.d.ts +55 -0
- package/dist/deploy/help.d.ts.map +1 -0
- package/dist/deploy/help.js +545 -0
- package/dist/deploy/idle-slots.d.ts +42 -0
- package/dist/deploy/idle-slots.d.ts.map +1 -0
- package/dist/deploy/idle-slots.js +136 -0
- package/dist/deploy/index.d.ts +5 -0
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/index.js +5 -0
- package/dist/deploy/init.d.ts +14 -0
- package/dist/deploy/init.d.ts.map +1 -1
- package/dist/deploy/init.js +14 -1
- package/dist/deploy/preflight.d.ts +26 -0
- package/dist/deploy/preflight.d.ts.map +1 -0
- package/dist/deploy/preflight.js +91 -0
- package/dist/deploy/rollback.d.ts +10 -1
- package/dist/deploy/rollback.d.ts.map +1 -1
- package/dist/deploy/rollback.js +25 -1
- package/dist/deploy/share.d.ts +28 -0
- package/dist/deploy/share.d.ts.map +1 -0
- package/dist/deploy/share.js +53 -0
- package/dist/deploy/shared-dirs.d.ts +128 -0
- package/dist/deploy/shared-dirs.d.ts.map +1 -0
- package/dist/deploy/shared-dirs.js +486 -0
- package/dist/deploy/status.d.ts +8 -0
- package/dist/deploy/status.d.ts.map +1 -1
- package/dist/deploy/status.js +6 -0
- package/dist/deploy/switch.d.ts.map +1 -1
- package/dist/deploy/switch.js +25 -0
- package/dist/deploy/types.d.ts +18 -0
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/deploy/verify.d.ts.map +1 -1
- package/dist/deploy/verify.js +7 -1
- package/dist/envsync/engine.d.ts.map +1 -1
- package/dist/envsync/engine.js +21 -7
- package/dist/envsync/paths.d.ts +22 -0
- package/dist/envsync/paths.d.ts.map +1 -1
- package/dist/envsync/paths.js +55 -0
- package/dist/peer-hint.d.ts +8 -0
- package/dist/peer-hint.d.ts.map +1 -0
- package/dist/peer-hint.js +49 -0
- package/dist/resolve/config-hint.d.ts +2 -0
- package/dist/resolve/config-hint.d.ts.map +1 -0
- package/dist/resolve/config-hint.js +23 -0
- package/dist/resolve/connect.d.ts.map +1 -1
- package/dist/resolve/connect.js +2 -1
- package/dist/resolve/deploy.d.ts.map +1 -1
- package/dist/resolve/deploy.js +167 -1
- package/dist/resolve/envsync.d.ts +16 -0
- package/dist/resolve/envsync.d.ts.map +1 -1
- package/dist/resolve/envsync.js +19 -0
- package/package.json +4 -3
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,8 @@ import pc from 'picocolors';
|
|
|
4
4
|
import { getEnv } from './index.client.js';
|
|
5
5
|
import { describeEnv, getEnvRole, getPattern } from './env.server.js';
|
|
6
6
|
import { doctor } from './doctor.js';
|
|
7
|
+
import { DEPLOY_SUBCOMMAND_NAMES, renderDeploySummaryList, renderDeploySubcommandHelpText, renderDeployConfigHelpText, } from './deploy/help.js';
|
|
8
|
+
import { missingPeerMessage } from './peer-hint.js';
|
|
7
9
|
const [, , command, ...args] = process.argv;
|
|
8
10
|
function statusIcon(status) {
|
|
9
11
|
if (status === 'ok')
|
|
@@ -201,24 +203,20 @@ async function runServe() {
|
|
|
201
203
|
process.exit(1);
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
|
-
const DEPLOY_SUBCOMMANDS =
|
|
206
|
+
const DEPLOY_SUBCOMMANDS = DEPLOY_SUBCOMMAND_NAMES;
|
|
205
207
|
function printDeployHelp() {
|
|
206
208
|
console.log(`
|
|
207
209
|
${pc.bold('hazo-env deploy')} — blue-green deployment orchestration
|
|
208
210
|
|
|
209
|
-
|
|
210
|
-
hazo-env deploy init Create peer dir, clone repo, generate config, write state
|
|
211
|
-
hazo-env deploy build Run the full build pipeline on the standby dir
|
|
212
|
-
--stop-prod --branch=<b> --db=<env> --peer-dir=<path>
|
|
213
|
-
hazo-env deploy verify Re-run health/typecheck/migration checks on standby
|
|
214
|
-
hazo-env deploy switch Stop prod, start standby on the prod port, run post-switch hooks
|
|
215
|
-
--force Bypass the "standby must have a successful recent build" check
|
|
216
|
-
hazo-env deploy rollback Reverse the last switch
|
|
217
|
-
hazo-env deploy status Show live/standby dirs, ports, PM2 state, disk/memory
|
|
218
|
-
hazo-env deploy clean Reclaim disk space from old builds and caches
|
|
219
|
-
--aggressive Also suggest system-level cleanup commands
|
|
211
|
+
${renderDeploySummaryList()}
|
|
220
212
|
`);
|
|
221
213
|
}
|
|
214
|
+
function printDeploySubcommandHelp(name) {
|
|
215
|
+
console.log(`\n${renderDeploySubcommandHelpText(name)}\n`);
|
|
216
|
+
}
|
|
217
|
+
function printDeployConfigHelp() {
|
|
218
|
+
console.log(`\n${pc.bold('hazo-env deploy config')}\n\n${renderDeployConfigHelpText()}\n`);
|
|
219
|
+
}
|
|
222
220
|
function formatDirStatus(info) {
|
|
223
221
|
const indicator = info.running ? pc.green(`✓ running (pid ${info.pid})`) : pc.dim('✗ not running');
|
|
224
222
|
return ` ${pc.bold(info.role.padEnd(8))} ${info.dir} ${pc.dim(`port ${info.port}`)} ${indicator}`;
|
|
@@ -229,6 +227,25 @@ function formatSidecarStatus(info) {
|
|
|
229
227
|
const staleNote = info.stale ? ` ${pc.yellow('⚠ stale: pm_cwd mismatch')}` : '';
|
|
230
228
|
return ` ${pc.bold('sidecar'.padEnd(8))} ${info.name} ${indicator}${staleNote}`;
|
|
231
229
|
}
|
|
230
|
+
/** Render one slot's shared-dir state. */
|
|
231
|
+
function formatSharedDirSlotState(s) {
|
|
232
|
+
switch (s.state) {
|
|
233
|
+
case 'linked':
|
|
234
|
+
return pc.green('linked');
|
|
235
|
+
case 'missing':
|
|
236
|
+
return pc.yellow('missing');
|
|
237
|
+
case 'empty-dir':
|
|
238
|
+
return pc.yellow('empty-dir');
|
|
239
|
+
case 'real-dir':
|
|
240
|
+
return pc.red(`real-dir (${s.fileCount} file${s.fileCount === 1 ? '' : 's'})`);
|
|
241
|
+
case 'wrong-link':
|
|
242
|
+
return pc.red(`wrong-link -> ${s.linkTarget}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** One row of the shared-dirs table: a dir's state in both slots side by side. */
|
|
246
|
+
function formatSharedDirRow(entry) {
|
|
247
|
+
return ` ${pc.bold(entry.dir.padEnd(24))} live: ${formatSharedDirSlotState(entry.live)} standby: ${formatSharedDirSlotState(entry.standby)}`;
|
|
248
|
+
}
|
|
232
249
|
async function runDeployStatus() {
|
|
233
250
|
const { resolveDeployConfig } = await import('./resolve/deploy.js');
|
|
234
251
|
const { runStatus } = await import('./deploy/status.js');
|
|
@@ -247,6 +264,13 @@ async function runDeployStatus() {
|
|
|
247
264
|
for (const sidecar of result.sidecars) {
|
|
248
265
|
console.log(formatSidecarStatus(sidecar));
|
|
249
266
|
}
|
|
267
|
+
if (result.sharedDirs.length) {
|
|
268
|
+
console.log('');
|
|
269
|
+
console.log(` ${pc.bold('shared dirs')}`);
|
|
270
|
+
for (const entry of result.sharedDirs) {
|
|
271
|
+
console.log(formatSharedDirRow(entry));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
250
274
|
console.log('');
|
|
251
275
|
console.log(` last switch: ${result.lastSwitch ?? pc.dim('(none)')}`);
|
|
252
276
|
console.log(` last build: ${result.lastBuild ?? pc.dim('(none)')}${result.lastBuildStatus ? ` ${result.lastBuildStatus === 'success' ? pc.green(result.lastBuildStatus) : pc.red(result.lastBuildStatus)}` : ''}`);
|
|
@@ -281,6 +305,9 @@ async function runDeployInit() {
|
|
|
281
305
|
if (result.envFilesMissing.length) {
|
|
282
306
|
console.log(` ${pc.yellow('⚠')} Env files not found (copy manually): ${result.envFilesMissing.join(', ')}`);
|
|
283
307
|
}
|
|
308
|
+
if (result.configExcludedFrom.length) {
|
|
309
|
+
console.log(` ${pc.green('✓')} config/hazo_env_config.ini excluded from git in: ${result.configExcludedFrom.join(', ')}`);
|
|
310
|
+
}
|
|
284
311
|
console.log('');
|
|
285
312
|
console.log(` Next steps:`);
|
|
286
313
|
console.log(` cd ${result.peerDir}`);
|
|
@@ -302,7 +329,57 @@ function formatBytes(bytes) {
|
|
|
302
329
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
303
330
|
return `${bytes} B`;
|
|
304
331
|
}
|
|
332
|
+
async function runDeployCleanIdleSlots() {
|
|
333
|
+
const { runCleanIdleSlots, IdleSlotsAbortError } = await import('./deploy/idle-slots.js');
|
|
334
|
+
const { nodeCommandRunner } = await import('./deploy/runner.js');
|
|
335
|
+
const yes = args.includes('--yes');
|
|
336
|
+
console.log(`\n${pc.bold('hazo-env deploy clean --idle-slots')}${yes ? '' : pc.dim(' (dry run — re-run with --yes to delete)')}\n`);
|
|
337
|
+
let result;
|
|
338
|
+
try {
|
|
339
|
+
result = runCleanIdleSlots(nodeCommandRunner, { yes });
|
|
340
|
+
}
|
|
341
|
+
catch (e) {
|
|
342
|
+
if (e instanceof IdleSlotsAbortError) {
|
|
343
|
+
console.error(` ${pc.red('✗')} ${e.message}\n`);
|
|
344
|
+
process.exit(1);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
throw e;
|
|
348
|
+
}
|
|
349
|
+
if (result.slots.length === 0) {
|
|
350
|
+
console.log(` ${pc.dim('No deploy state files found in ~/.hazo-deploy — nothing to clean.')}\n`);
|
|
351
|
+
}
|
|
352
|
+
for (const slot of result.slots) {
|
|
353
|
+
if (!slot.eligible) {
|
|
354
|
+
console.log(` ${pc.dim('·')} ${slot.app_name.padEnd(16)} ${slot.slot_dir} ${pc.yellow(`skipped: ${slot.skipReason}`)}`);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
console.log(` ${pc.green('✓')} ${slot.app_name.padEnd(16)} ${slot.slot_dir} ${pc.bold(formatBytes(slot.bytes))}`);
|
|
358
|
+
for (const t of slot.targets) {
|
|
359
|
+
const status = t.error
|
|
360
|
+
? pc.red(t.error)
|
|
361
|
+
: t.skipped
|
|
362
|
+
? pc.dim(t.skipReason ?? 'skipped')
|
|
363
|
+
: t.removed
|
|
364
|
+
? `reclaimed ${formatBytes(t.bytes)}`
|
|
365
|
+
: `${formatBytes(t.bytes)} (would delete)`;
|
|
366
|
+
console.log(` ${t.name.padEnd(14)} ${status}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
console.log('');
|
|
370
|
+
console.log(` ${pc.bold(result.dryRun ? 'total reclaimable:' : 'total reclaimed:')} ${formatBytes(result.totalBytes)}`);
|
|
371
|
+
if (result.dryRun && result.totalBytes > 0) {
|
|
372
|
+
console.log(` ${pc.dim('Nothing was deleted. Re-run with --yes to delete node_modules/.next from the slots above.')}`);
|
|
373
|
+
}
|
|
374
|
+
for (const warning of result.warnings)
|
|
375
|
+
console.log(` ${pc.yellow('⚠')} ${warning}`);
|
|
376
|
+
console.log('');
|
|
377
|
+
}
|
|
305
378
|
async function runDeployClean() {
|
|
379
|
+
if (args.includes('--idle-slots')) {
|
|
380
|
+
await runDeployCleanIdleSlots();
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
306
383
|
const { resolveDeployConfig } = await import('./resolve/deploy.js');
|
|
307
384
|
const { runClean } = await import('./deploy/clean.js');
|
|
308
385
|
const { nodeCommandRunner } = await import('./deploy/runner.js');
|
|
@@ -366,9 +443,12 @@ async function runDeployBuild() {
|
|
|
366
443
|
console.log(`\n${pc.bold('hazo-env deploy build')} ${pc.dim(config.app_name)}\n`);
|
|
367
444
|
function printSteps(steps) {
|
|
368
445
|
for (const step of steps) {
|
|
369
|
-
const icon = step.status === 'pass' ? pc.green('✓') : pc.red('✗');
|
|
370
|
-
const
|
|
446
|
+
const icon = step.status === 'pass' ? pc.green('✓') : step.status === 'warn' ? pc.yellow('⚠') : pc.red('✗');
|
|
447
|
+
const [first = '', ...rest] = (step.detail ?? '').split('\n');
|
|
448
|
+
const detail = first ? ` ${step.status === 'pass' ? pc.dim(first) : first}` : '';
|
|
371
449
|
console.log(` ${icon} ${step.name.padEnd(16)}${detail}`);
|
|
450
|
+
for (const line of rest)
|
|
451
|
+
console.log(` ${line}`);
|
|
372
452
|
}
|
|
373
453
|
}
|
|
374
454
|
try {
|
|
@@ -388,7 +468,10 @@ async function runDeployBuild() {
|
|
|
388
468
|
console.log('');
|
|
389
469
|
printSteps(e.steps);
|
|
390
470
|
console.log('');
|
|
391
|
-
|
|
471
|
+
const failedStep = e.steps.find((s) => s.status === 'fail');
|
|
472
|
+
console.error(failedStep
|
|
473
|
+
? ` ${pc.red('✗ Build aborted')} at step "${failedStep.name}" — see its output above.\n`
|
|
474
|
+
: ` ${pc.red('✗ Build aborted:')} ${e.message}\n`);
|
|
392
475
|
process.exit(1);
|
|
393
476
|
return;
|
|
394
477
|
}
|
|
@@ -404,12 +487,19 @@ function verifyStatusIcon(status) {
|
|
|
404
487
|
return pc.yellow('–');
|
|
405
488
|
return pc.red('✗');
|
|
406
489
|
}
|
|
490
|
+
async function printCliDependencyWarning() {
|
|
491
|
+
const { cliDependencyWarning } = await import('./deploy/preflight.js');
|
|
492
|
+
const warning = cliDependencyWarning(process.cwd());
|
|
493
|
+
if (warning)
|
|
494
|
+
console.log(` ${pc.yellow('⚠')} ${warning}\n`);
|
|
495
|
+
}
|
|
407
496
|
async function runDeployVerify() {
|
|
408
497
|
const { resolveDeployConfig } = await import('./resolve/deploy.js');
|
|
409
498
|
const { runVerify } = await import('./deploy/verify.js');
|
|
410
499
|
const { nodeCommandRunner } = await import('./deploy/runner.js');
|
|
411
500
|
const config = resolveDeployConfig();
|
|
412
501
|
console.log(`\n${pc.bold('hazo-env deploy verify')} ${pc.dim(config.app_name)}\n`);
|
|
502
|
+
await printCliDependencyWarning();
|
|
413
503
|
const result = runVerify(config, nodeCommandRunner, { tscCmd: config.verify_tsc_cmd });
|
|
414
504
|
const nameWidth = Math.max(...result.checks.map((c) => c.name.length)) + 2;
|
|
415
505
|
for (const check of result.checks) {
|
|
@@ -432,6 +522,7 @@ async function runDeploySwitch() {
|
|
|
432
522
|
const force = args.includes('--force');
|
|
433
523
|
const config = resolveDeployConfig();
|
|
434
524
|
console.log(`\n${pc.bold('hazo-env deploy switch')} ${pc.dim(config.app_name)}\n`);
|
|
525
|
+
await printCliDependencyWarning();
|
|
435
526
|
try {
|
|
436
527
|
const result = runSwitch(config, nodeCommandRunner, { force });
|
|
437
528
|
console.log(` ${pc.green('✓')} deleted live PM2 registration "${config.app_name}" in ${result.previousLiveDir}`);
|
|
@@ -483,9 +574,10 @@ async function runDeployRollback() {
|
|
|
483
574
|
const { runRollback, RollbackAbortError } = await import('./deploy/rollback.js');
|
|
484
575
|
const { nodeCommandRunner } = await import('./deploy/runner.js');
|
|
485
576
|
const config = resolveDeployConfig();
|
|
577
|
+
const force = args.includes('--force');
|
|
486
578
|
console.log(`\n${pc.bold('hazo-env deploy rollback')} ${pc.dim(config.app_name)}\n`);
|
|
487
579
|
try {
|
|
488
|
-
const result = runRollback(config, nodeCommandRunner);
|
|
580
|
+
const result = runRollback(config, nodeCommandRunner, { force });
|
|
489
581
|
console.log(` ${pc.green('✓')} started "${config.app_name}" on port ${result.prodPort} in ${result.restoredLiveDir}`);
|
|
490
582
|
if (result.stagingDeleteWarning) {
|
|
491
583
|
console.log(` ${pc.yellow('⚠')} ${result.stagingDeleteWarning}`);
|
|
@@ -519,18 +611,78 @@ async function runDeployRollback() {
|
|
|
519
611
|
process.exit(1);
|
|
520
612
|
}
|
|
521
613
|
}
|
|
614
|
+
async function runDeployShare() {
|
|
615
|
+
const { resolveDeployConfig } = await import('./resolve/deploy.js');
|
|
616
|
+
const { runShare } = await import('./deploy/share.js');
|
|
617
|
+
const dryRun = args.includes('--dry-run');
|
|
618
|
+
const config = resolveDeployConfig();
|
|
619
|
+
console.log(`\n${pc.bold('hazo-env deploy share')} ${pc.dim(config.app_name)}${dryRun ? pc.dim(' (dry run — nothing will be written)') : ''}\n`);
|
|
620
|
+
if (config.shared_dirs.length === 0) {
|
|
621
|
+
console.log(` ${pc.yellow('⚠')} No shared_dirs configured — nothing to migrate.\n`);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
try {
|
|
625
|
+
const result = runShare(config, { dryRun });
|
|
626
|
+
if (!result.stateFound) {
|
|
627
|
+
console.log(` ${pc.yellow('⚠')} No deploy state found — treating ${result.liveDir} as the only slot (no peer).`);
|
|
628
|
+
}
|
|
629
|
+
console.log(` live: ${result.liveDir}`);
|
|
630
|
+
console.log(` standby: ${result.standbyDir ?? pc.dim('(no peer)')}`);
|
|
631
|
+
console.log('');
|
|
632
|
+
for (const entry of result.dirs) {
|
|
633
|
+
console.log(` ${pc.bold(entry.dir)}`);
|
|
634
|
+
console.log(` target: ${entry.target}`);
|
|
635
|
+
console.log(` live: ${entry.liveAction}${entry.liveBackupDir ? pc.dim(` (backup: ${entry.liveBackupDir})`) : ''}`);
|
|
636
|
+
console.log(` standby: ${entry.standbyAction}${entry.standbyBackupDir ? pc.dim(` (backup: ${entry.standbyBackupDir})`) : ''}`);
|
|
637
|
+
console.log(` files: ${entry.filesFromLive} from live, ${entry.filesFromStandby} from standby, ${entry.identical} identical, ${entry.conflicts} conflict(s)` +
|
|
638
|
+
`${entry.lateMergedFiles ? `, ${entry.lateMergedFiles} merged late` : ''}`);
|
|
639
|
+
if (entry.conflicts) {
|
|
640
|
+
console.log(` ${pc.yellow('⚠')} conflicts parked under:`);
|
|
641
|
+
for (const f of entry.conflictFiles)
|
|
642
|
+
console.log(` ${f}`);
|
|
643
|
+
}
|
|
644
|
+
for (const w of entry.warnings)
|
|
645
|
+
console.log(` ${pc.yellow('⚠')} ${w}`);
|
|
646
|
+
console.log('');
|
|
647
|
+
}
|
|
648
|
+
if (dryRun) {
|
|
649
|
+
console.log(` ${pc.yellow('Dry run only — nothing was written. Re-run without --dry-run to apply.')}\n`);
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
console.log(` ${pc.green('Share complete.')} Verify the report above, then delete the ".pre-share-*" backup dirs once you're satisfied.\n`);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
catch (e) {
|
|
656
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
657
|
+
console.error(`\n ${pc.red('✗')} ${msg}\n`);
|
|
658
|
+
process.exit(1);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
522
661
|
async function runDeploy() {
|
|
523
662
|
const subCmd = args[0];
|
|
663
|
+
const subArgs = args.slice(1);
|
|
524
664
|
if (!subCmd || subCmd === '--help' || subCmd === '-h') {
|
|
525
665
|
printDeployHelp();
|
|
526
666
|
return;
|
|
527
667
|
}
|
|
668
|
+
// `deploy config` is documentation-only — there is nothing else it could
|
|
669
|
+
// do, so it renders the same thing with or without --help.
|
|
670
|
+
if (subCmd === 'config') {
|
|
671
|
+
printDeployConfigHelp();
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
528
674
|
if (!DEPLOY_SUBCOMMANDS.includes(subCmd)) {
|
|
529
675
|
console.error(pc.red(`Error: unknown deploy subcommand "${subCmd}"`));
|
|
530
676
|
printDeployHelp();
|
|
531
677
|
process.exit(1);
|
|
532
678
|
return;
|
|
533
679
|
}
|
|
680
|
+
// `deploy <cmd> --help` / `-h` shows the detailed reference for that
|
|
681
|
+
// subcommand instead of running it.
|
|
682
|
+
if (subArgs.includes('--help') || subArgs.includes('-h')) {
|
|
683
|
+
printDeploySubcommandHelp(subCmd);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
534
686
|
if (subCmd === 'init') {
|
|
535
687
|
await runDeployInit();
|
|
536
688
|
return;
|
|
@@ -559,6 +711,10 @@ async function runDeploy() {
|
|
|
559
711
|
await runDeployRollback();
|
|
560
712
|
return;
|
|
561
713
|
}
|
|
714
|
+
if (subCmd === 'share') {
|
|
715
|
+
await runDeployShare();
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
562
718
|
}
|
|
563
719
|
function printHelp() {
|
|
564
720
|
console.log(`
|
|
@@ -582,7 +738,7 @@ Usage:
|
|
|
582
738
|
hazo-env serve Start the envsync HTTP service (HAZO_ENVSYNC_TOKEN required)
|
|
583
739
|
--port <n> --bind <host> Override HAZO_ENVSYNC_PORT / HAZO_ENVSYNC_BIND
|
|
584
740
|
hazo-env deploy [subcommand] Blue-green deployment orchestration (see "deploy --help")
|
|
585
|
-
|
|
741
|
+
${[...DEPLOY_SUBCOMMAND_NAMES, 'config'].join(' | ')}
|
|
586
742
|
`);
|
|
587
743
|
}
|
|
588
744
|
(async () => {
|
|
@@ -607,6 +763,11 @@ Usage:
|
|
|
607
763
|
}
|
|
608
764
|
}
|
|
609
765
|
catch (e) {
|
|
766
|
+
const peerMessage = missingPeerMessage(e);
|
|
767
|
+
if (peerMessage) {
|
|
768
|
+
console.error(`\n${peerMessage}\n`);
|
|
769
|
+
process.exit(1);
|
|
770
|
+
}
|
|
610
771
|
const msg = e instanceof Error ? e.message : String(e);
|
|
611
772
|
console.error(`\n${pc.red('Error:')} ${msg}\n`);
|
|
612
773
|
process.exit(1);
|
package/dist/deploy/build.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface RunBuildOptions {
|
|
|
15
15
|
/** Delay between health check retries, in ms. Default: 1500. */
|
|
16
16
|
healthCheckDelayMs?: number;
|
|
17
17
|
}
|
|
18
|
-
export type BuildStepStatus = 'pass' | 'fail';
|
|
18
|
+
export type BuildStepStatus = 'pass' | 'warn' | 'fail';
|
|
19
19
|
export interface BuildStepResult {
|
|
20
20
|
name: string;
|
|
21
21
|
status: BuildStepStatus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/deploy/build.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI9D,MAAM,WAAW,eAAe;IAC9B,gGAAgG;IAChG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gEAAgE;IAChE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,GAAG,QAAQ,CAAC;IACtC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,6FAA6F;AAC7F,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,CAAC;gBAEtB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE;CAKtD;AAKD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAMjF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAErE;AAiBD,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,iBAAiB,CASpH;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,GAAE,eAAoB,GAAG,cAAc,CAuWhH"}
|
package/dist/deploy/build.js
CHANGED
|
@@ -29,6 +29,8 @@ import { queryDiskFreeMb, queryMemoryFreeMb } from './status.js';
|
|
|
29
29
|
import { readState, updateState } from './state.js';
|
|
30
30
|
import { SWAP_INCREASE_SUGGESTIONS } from './clean.js';
|
|
31
31
|
import { startNamedPm2Process, isPm2ProcessNotFound } from './pm2-start.js';
|
|
32
|
+
import { ensureLinks } from './shared-dirs.js';
|
|
33
|
+
import { cliDependencyWarning, commandFailureDetail, isDeployConfigGitTracked, TRACKED_DEPLOY_CONFIG_MESSAGE, } from './preflight.js';
|
|
32
34
|
import { resolveConnectConfig } from '../resolve/connect.js';
|
|
33
35
|
/** Thrown when any pipeline step fails. Carries the steps completed so far for reporting. */
|
|
34
36
|
export class BuildAbortError extends Error {
|
|
@@ -146,6 +148,10 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
146
148
|
function pass(name, detail) {
|
|
147
149
|
steps.push({ name, status: 'pass', detail });
|
|
148
150
|
}
|
|
151
|
+
function warn(name, detail) {
|
|
152
|
+
steps.push({ name, status: 'warn', detail });
|
|
153
|
+
warnings.push(detail);
|
|
154
|
+
}
|
|
149
155
|
function abort(name, message) {
|
|
150
156
|
const finalMessage = productionStopped
|
|
151
157
|
? `${message}\n\n` +
|
|
@@ -173,8 +179,10 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
173
179
|
catch (e) {
|
|
174
180
|
if (e instanceof BuildAbortError)
|
|
175
181
|
throw e;
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
// commandFailureDetail appends the tail of the command's captured
|
|
183
|
+
// stdout+stderr — `next build` prints its tsc errors to stdout, which
|
|
184
|
+
// execSync keeps on the error object, not in its message.
|
|
185
|
+
return abort(name, commandFailureDetail(e));
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
let buildStatus = 'failed';
|
|
@@ -197,13 +205,20 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
197
205
|
: state
|
|
198
206
|
? path.resolve(state.live_dir)
|
|
199
207
|
: resolvePeerDir(cwd, undefined, config.dir_suffix);
|
|
208
|
+
// Warning only: hazo_env missing from package.json means this run's own
|
|
209
|
+
// `npm ci` (install step) removes it, breaking the NEXT `npx hazo_env`.
|
|
210
|
+
const dependencyWarning = cliDependencyWarning(cwd);
|
|
211
|
+
if (dependencyWarning)
|
|
212
|
+
warn('cli-dependency', dependencyWarning);
|
|
200
213
|
// Step 1: auto-clean, then check disk free against min_disk_mb.
|
|
201
214
|
const cleanResult = autoClean(config, runner);
|
|
202
215
|
pass('clean', `reclaimed ${cleanResult.totalBytesReclaimed} bytes across ${cleanResult.targets.length} targets`);
|
|
203
216
|
warnings.push(...cleanResult.warnings);
|
|
204
217
|
const diskFreeMb = queryDiskFreeMb(runner, cwd, warnings);
|
|
205
218
|
if (diskFreeMb !== undefined && diskFreeMb < config.min_disk_mb) {
|
|
206
|
-
abort('disk-check', `Disk free (${diskFreeMb} MB) is still below min_disk_mb (${config.min_disk_mb}) after cleanup
|
|
219
|
+
abort('disk-check', `Disk free (${diskFreeMb} MB) is still below min_disk_mb (${config.min_disk_mb}) after cleanup. ` +
|
|
220
|
+
`Run "hazo-env deploy clean --idle-slots" to reclaim space from other apps' idle standby slots ` +
|
|
221
|
+
`(dry run first; add --yes to delete).`);
|
|
207
222
|
}
|
|
208
223
|
pass('disk-check', diskFreeMb !== undefined ? `${diskFreeMb} MB free` : 'unknown — skipping check');
|
|
209
224
|
// Step 2/3: memory check, optionally freed by stopping the live PM2 process.
|
|
@@ -237,6 +252,30 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
237
252
|
abort('db-resolve', `db_strategy resolved to "copy" but the resolved db config is type "${dbConfig.type}", not sqlite.`);
|
|
238
253
|
}
|
|
239
254
|
pass('db-resolve', `strategy=${dbStrategyResolved}${opts.db ? ` db=${opts.db}` : ''}`);
|
|
255
|
+
// Shared dirs (ticket 03, deploy-shared-dirs spec): verify/self-heal the
|
|
256
|
+
// standby's shared-dir links BEFORE anything destructive happens (user
|
|
257
|
+
// story 23 — staging must never run against an empty private folder).
|
|
258
|
+
// Grouped with the other pre-flight checks above (disk/memory/db-resolve)
|
|
259
|
+
// for the same reason: it's read-mostly (a missing link is created, an
|
|
260
|
+
// empty real dir is replaced) and must never touch last_build on an
|
|
261
|
+
// early abort. `ensureLinks` throws its typed `SharedDirError` — whose
|
|
262
|
+
// message already carries the "run hazo-env deploy share" remediation
|
|
263
|
+
// hint — for a real non-empty dir or a wrong-link; `runStep` converts
|
|
264
|
+
// that into the same `BuildAbortError` path every other pre-flight
|
|
265
|
+
// failure above takes. A no-op when shared_dirs is empty (feature off).
|
|
266
|
+
if (config.shared_dirs.length > 0) {
|
|
267
|
+
const sharedDirResults = runStep('shared-dirs', () => ensureLinks(config, cwd, { allowCreate: true, allowReplaceEmpty: true }));
|
|
268
|
+
pass('shared-dirs', sharedDirResults.map((r) => `${r.dir}: ${r.action}`).join(', '));
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
pass('shared-dirs', 'no shared_dirs configured — skipping');
|
|
272
|
+
}
|
|
273
|
+
// Pre-flight (read-only, so before the destructive marker below): the
|
|
274
|
+
// per-slot INI must not be git-tracked — see preflight.ts's header.
|
|
275
|
+
if (runStep('config-untracked', () => isDeployConfigGitTracked(runner, cwd))) {
|
|
276
|
+
abort('config-untracked', TRACKED_DEPLOY_CONFIG_MESSAGE);
|
|
277
|
+
}
|
|
278
|
+
pass('config-untracked', 'config/hazo_env_config.ini is not tracked by git');
|
|
240
279
|
// Fix 3: write a provisional/pessimistic `last_build` marker right
|
|
241
280
|
// before the first DESTRUCTIVE step (git pull) — everything above this
|
|
242
281
|
// point (guard, disk/memory checks, db-resolve) is read-only, so an
|
|
@@ -258,18 +297,16 @@ export function runBuild(config, runner, opts = {}) {
|
|
|
258
297
|
catch {
|
|
259
298
|
// No state file yet — best-effort, same as the finally block below.
|
|
260
299
|
}
|
|
261
|
-
// Step 4a: stash any local changes so git pull doesn't fail.
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
300
|
+
// Step 4a: stash any local changes so git pull doesn't fail. The standby
|
|
301
|
+
// dir is a disposable clone; uncommitted edits there are leftover
|
|
302
|
+
// artifacts (npm-install-time package.json rewrites, hand patches), never
|
|
303
|
+
// intentional work. Best-effort: a failed stash just lets the pull
|
|
304
|
+
// report the real conflict. (Shipped in 0.15.3, lost in 0.16.0.)
|
|
305
|
+
const countStashes = () => (runner.spawn('git stash list', { cwd }).stdout ?? '').split('\n').filter((l) => l.trim().length > 0).length;
|
|
306
|
+
const stashesBefore = countStashes();
|
|
266
307
|
const stashResult = runner.spawn('git stash --quiet', { cwd });
|
|
267
|
-
if (stashResult.code === 0) {
|
|
268
|
-
|
|
269
|
-
const hasStash = (stashList.stdout ?? '').trim().length > 0;
|
|
270
|
-
if (hasStash) {
|
|
271
|
-
pass('git-stash', 'stashed local changes');
|
|
272
|
-
}
|
|
308
|
+
if (stashResult.code === 0 && countStashes() > stashesBefore) {
|
|
309
|
+
pass('git-stash', 'stashed local changes (recover with "git stash list" / "git stash pop")');
|
|
273
310
|
}
|
|
274
311
|
// Step 4b: git pull
|
|
275
312
|
runStep('git-pull', () => runner.exec(`git pull origin ${branch}`, { cwd }));
|
package/dist/deploy/clean.d.ts
CHANGED
|
@@ -50,8 +50,9 @@ export declare const SWAP_INCREASE_SUGGESTIONS: string[];
|
|
|
50
50
|
* Safe-targets-only cleanup, for reuse by `deploy build`'s auto-clean step
|
|
51
51
|
* (Task 5). Stable 2-arg signature — do not add parameters here; use
|
|
52
52
|
* `runClean` for anything CLI-specific (--aggressive, swap suggestions).
|
|
53
|
+
* `config.shared_dirs` (ticket 03) is read here — see `overlapsSharedDir`.
|
|
53
54
|
*/
|
|
54
|
-
export declare function autoClean(
|
|
55
|
+
export declare function autoClean(config: DeployConfig, runner: CommandRunner): AutoCleanResult;
|
|
55
56
|
/**
|
|
56
57
|
* Full `deploy clean` behavior: runs the same safe-target cleanup as
|
|
57
58
|
* `autoClean`, then adds the memory-triggered swap suggestion (independent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/deploy/clean.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,cAAc,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,UAAU,EAAE,OAAO,CAAC;IACpB,2IAA2I;IAC3I,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,8EAA8E;AAC9E,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,SAAS,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,iFAAiF;AACjF,eAAO,MAAM,0BAA0B,UAItC,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,yBAAyB,UAKrC,CAAC;
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/deploy/clean.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,cAAc,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,UAAU,EAAE,OAAO,CAAC;IACpB,2IAA2I;IAC3I,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,8EAA8E;AAC9E,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,SAAS,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,iFAAiF;AACjF,eAAO,MAAM,0BAA0B,UAItC,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,yBAAyB,UAKrC,CAAC;AA+GF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,GAAG,eAAe,CAEtF;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,GAAG,cAAc,CAiB3G"}
|
package/dist/deploy/clean.js
CHANGED
|
@@ -48,6 +48,31 @@ const DIR_TARGETS = [
|
|
|
48
48
|
{ name: '.next.staging', relativePath: '.next.staging' },
|
|
49
49
|
{ name: 'node_modules/.cache', relativePath: path.join('node_modules', '.cache') },
|
|
50
50
|
];
|
|
51
|
+
/**
|
|
52
|
+
* Ticket 03 (deploy-shared-dirs spec), user story 30: `deploy clean` must
|
|
53
|
+
* never delete through a shared-dir link. The three `DIR_TARGETS` above are
|
|
54
|
+
* fixed, well-known build-artifact paths that would never normally overlap
|
|
55
|
+
* an operator-declared `shared_dirs` entry (an uploads folder) — this is a
|
|
56
|
+
* defensive guard against misconfiguration, not the normal case. True when
|
|
57
|
+
* `relativePath` (one of DIR_TARGETS) is equal to, an ancestor of, or a
|
|
58
|
+
* descendant of ANY configured shared dir — in every one of those shapes,
|
|
59
|
+
* removing `relativePath` would touch (or BE) a shared-dir path. A pure
|
|
60
|
+
* config-level comparison (no fs calls): matches this module's existing
|
|
61
|
+
* discipline of only ever touching the filesystem through CommandRunner.
|
|
62
|
+
*/
|
|
63
|
+
function overlapsSharedDir(relativePath, sharedDirs) {
|
|
64
|
+
const target = path.normalize(relativePath);
|
|
65
|
+
return sharedDirs.some((dir) => {
|
|
66
|
+
const normalizedDir = path.normalize(dir);
|
|
67
|
+
if (normalizedDir === target)
|
|
68
|
+
return true;
|
|
69
|
+
const targetUnderDir = path.relative(normalizedDir, target);
|
|
70
|
+
if (!targetUnderDir.startsWith('..') && !path.isAbsolute(targetUnderDir))
|
|
71
|
+
return true;
|
|
72
|
+
const dirUnderTarget = path.relative(target, normalizedDir);
|
|
73
|
+
return !dirUnderTarget.startsWith('..') && !path.isAbsolute(dirUnderTarget);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
51
76
|
/** Parse `du -sk <path>` output's leading KB column. Lenient to platform/locale variance. */
|
|
52
77
|
function parseDuKb(duOutput) {
|
|
53
78
|
const token = duOutput.trim().split(/\s+/)[0];
|
|
@@ -61,8 +86,12 @@ function measureDirKb(runner, absPath) {
|
|
|
61
86
|
return undefined;
|
|
62
87
|
return parseDuKb(result.stdout);
|
|
63
88
|
}
|
|
64
|
-
function cleanDirTarget(runner, cwd, name, relativePath, warnings) {
|
|
89
|
+
function cleanDirTarget(runner, cwd, name, relativePath, sharedDirs, warnings) {
|
|
65
90
|
const absPath = path.join(cwd, relativePath);
|
|
91
|
+
if (overlapsSharedDir(relativePath, sharedDirs)) {
|
|
92
|
+
warnings.push(`skipping "${name}" (${absPath}) — it overlaps a configured shared dir; "deploy clean" never deletes through a shared-dir link.`);
|
|
93
|
+
return { target: name, path: absPath, bytesReclaimed: 0, skipped: true };
|
|
94
|
+
}
|
|
66
95
|
const beforeKb = measureDirKb(runner, absPath);
|
|
67
96
|
if (beforeKb === undefined) {
|
|
68
97
|
// Doesn't exist (or unreadable) — nothing to clean, not an error.
|
|
@@ -95,9 +124,9 @@ function cleanNpmCacheTarget(runner, warnings) {
|
|
|
95
124
|
const bytesReclaimed = Math.max(0, (beforeKb - afterKb) * 1024);
|
|
96
125
|
return { target: 'npm-cache', path: cachePath ?? '(unknown)', bytesReclaimed, skipped: false };
|
|
97
126
|
}
|
|
98
|
-
function cleanAllTargets(runner, cwd) {
|
|
127
|
+
function cleanAllTargets(runner, cwd, sharedDirs) {
|
|
99
128
|
const warnings = [];
|
|
100
|
-
const targets = DIR_TARGETS.map((t) => cleanDirTarget(runner, cwd, t.name, t.relativePath, warnings));
|
|
129
|
+
const targets = DIR_TARGETS.map((t) => cleanDirTarget(runner, cwd, t.name, t.relativePath, sharedDirs, warnings));
|
|
101
130
|
targets.push(cleanNpmCacheTarget(runner, warnings));
|
|
102
131
|
const totalBytesReclaimed = targets.reduce((sum, t) => sum + t.bytesReclaimed, 0);
|
|
103
132
|
return { targets, totalBytesReclaimed, warnings };
|
|
@@ -106,9 +135,10 @@ function cleanAllTargets(runner, cwd) {
|
|
|
106
135
|
* Safe-targets-only cleanup, for reuse by `deploy build`'s auto-clean step
|
|
107
136
|
* (Task 5). Stable 2-arg signature — do not add parameters here; use
|
|
108
137
|
* `runClean` for anything CLI-specific (--aggressive, swap suggestions).
|
|
138
|
+
* `config.shared_dirs` (ticket 03) is read here — see `overlapsSharedDir`.
|
|
109
139
|
*/
|
|
110
|
-
export function autoClean(
|
|
111
|
-
return cleanAllTargets(runner, process.cwd());
|
|
140
|
+
export function autoClean(config, runner) {
|
|
141
|
+
return cleanAllTargets(runner, process.cwd(), config.shared_dirs);
|
|
112
142
|
}
|
|
113
143
|
/**
|
|
114
144
|
* Full `deploy clean` behavior: runs the same safe-target cleanup as
|
|
@@ -119,7 +149,7 @@ export function autoClean(_config, runner) {
|
|
|
119
149
|
*/
|
|
120
150
|
export function runClean(config, runner, opts) {
|
|
121
151
|
const cwd = opts.cwd ?? process.cwd();
|
|
122
|
-
const auto = cleanAllTargets(runner, cwd);
|
|
152
|
+
const auto = cleanAllTargets(runner, cwd, config.shared_dirs);
|
|
123
153
|
const warnings = [...auto.warnings];
|
|
124
154
|
const memoryFreeMb = queryMemoryFreeMb(runner, warnings);
|
|
125
155
|
const memoryLow = memoryFreeMb !== undefined && memoryFreeMb < config.min_memory_mb;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-readme-cli.d.ts","sourceRoot":"","sources":["../../src/deploy/generate-readme-cli.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// hazo_env/src/deploy/generate-readme-cli.ts — regenerate README.md's
|
|
3
|
+
// generated "Deploy" section from src/deploy/help.ts.
|
|
4
|
+
//
|
|
5
|
+
// Run via `npm run docs:deploy` (builds first, then runs this compiled file —
|
|
6
|
+
// see package.json). Idempotent: re-running with no help.ts changes leaves
|
|
7
|
+
// README.md byte-identical. Fails loudly if the markers are missing or out
|
|
8
|
+
// of order, rather than silently appending or corrupting the file.
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { renderDeployReadmeSection, DEPLOY_README_MARKER_START, DEPLOY_README_MARKER_END } from './help.js';
|
|
13
|
+
function findReadmePath() {
|
|
14
|
+
// dist/deploy/generate-readme-cli.js -> package root is two levels up.
|
|
15
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
return path.resolve(here, '..', '..', 'README.md');
|
|
17
|
+
}
|
|
18
|
+
function main() {
|
|
19
|
+
const readmePath = findReadmePath();
|
|
20
|
+
const original = fs.readFileSync(readmePath, 'utf-8');
|
|
21
|
+
const startIdx = original.indexOf(DEPLOY_README_MARKER_START);
|
|
22
|
+
const endIdx = original.indexOf(DEPLOY_README_MARKER_END);
|
|
23
|
+
if (startIdx === -1 || endIdx === -1 || endIdx < startIdx) {
|
|
24
|
+
console.error(`Error: could not find both deploy-section markers in ${readmePath}.\n` +
|
|
25
|
+
`Expected:\n ${DEPLOY_README_MARKER_START}\n ...\n ${DEPLOY_README_MARKER_END}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const before = original.slice(0, startIdx);
|
|
30
|
+
const after = original.slice(endIdx + DEPLOY_README_MARKER_END.length);
|
|
31
|
+
const generated = `${DEPLOY_README_MARKER_START}\n\n${renderDeployReadmeSection()}\n\n${DEPLOY_README_MARKER_END}`;
|
|
32
|
+
const updated = `${before}${generated}${after}`;
|
|
33
|
+
if (updated === original) {
|
|
34
|
+
console.log(`README.md's deploy section is already up to date (${readmePath}).`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
fs.writeFileSync(readmePath, updated, 'utf-8');
|
|
38
|
+
console.log(`Regenerated README.md's deploy section (${readmePath}).`);
|
|
39
|
+
}
|
|
40
|
+
main();
|