Skip to content

Commit e7ff322

Browse files
committed
Use .last-update-check for update timestamps
Switch update-check storage from .dev to .last-update-check and add it to .gitignore. Rename timestamp helper functions and variables accordingly, and update logic to treat empty/invalid timestamp as null (instead of returning a far-future value). Improve dev-mode messaging and ensure --force-update always overrides dev mode; update the timestamp file after running the self-update check.
1 parent c26d021 commit e7ff322

2 files changed

Lines changed: 26 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.dev
22
.quiet
3+
.last-update-check
34

45
# Created by https://www.toptal.com/developers/gitignore/api/macos,linux,windows,node,yarn,composer,phpstorm+all,visualstudiocode,sublimetext
56
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,linux,windows,node,yarn,composer,phpstorm+all,visualstudiocode,sublimetext

self-update.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,46 +75,45 @@ function team51_cli_self_update(): void {
7575
// region TIMESTAMP FUNCTIONS
7676

7777
/**
78-
* Gets the timestamp from the .dev file.
78+
* Gets the timestamp of the last update check.
7979
*
8080
* @return int|null The timestamp, or null if the file doesn't exist or doesn't contain a valid timestamp.
8181
*/
82-
function team51_cli_get_dev_timestamp(): ?int {
83-
$dev_file = TEAM51_CLI_ROOT_DIR . '/.dev';
82+
function team51_cli_get_last_update_check_timestamp(): ?int {
83+
$timestamp_file = TEAM51_CLI_ROOT_DIR . '/.last-update-check';
8484

85-
if ( ! file_exists( $dev_file ) ) {
85+
if ( ! file_exists( $timestamp_file ) ) {
8686
return null;
8787
}
8888

89-
$content = file_get_contents( $dev_file );
89+
$content = file_get_contents( $timestamp_file );
9090
if ( empty( $content ) || ! is_numeric( $content ) ) {
91-
// If the file is empty or doesn't contain a valid timestamp, return a far future date (2035) to force dev mode.
92-
return 2062837972;
91+
return null;
9392
}
9493

9594
return (int) $content;
9695
}
9796

9897
/**
99-
* Writes the current timestamp to the .dev file.
98+
* Records the current time as the last update check.
10099
*
101100
* @return void
102101
*/
103-
function team51_cli_update_dev_timestamp(): void {
104-
$dev_file = TEAM51_CLI_ROOT_DIR . '/.dev';
105-
$timestamp = time();
102+
function team51_cli_update_last_update_check_timestamp(): void {
103+
$timestamp_file = TEAM51_CLI_ROOT_DIR . '/.last-update-check';
106104

107-
file_put_contents( $dev_file, $timestamp );
105+
file_put_contents( $timestamp_file, time() );
108106
}
109107

110108
// endregion
111109

112110
// region EXECUTION LOGIC
113111

114-
$team51_cli_is_quiet = file_exists( TEAM51_CLI_ROOT_DIR . '/.quiet' );
115-
$team51_cli_is_dev = false; // Will be set based on .dev file timestamp or --dev flag
116-
$team51_is_autocomplete = false;
117-
$team51_cli_force_update = false;
112+
$team51_cli_is_quiet = file_exists( TEAM51_CLI_ROOT_DIR . '/.quiet' );
113+
$team51_cli_dev_file_exists = file_exists( TEAM51_CLI_ROOT_DIR . '/.dev' );
114+
$team51_cli_is_dev = $team51_cli_dev_file_exists;
115+
$team51_is_autocomplete = false;
116+
$team51_cli_force_update = false;
118117

119118
foreach ( $argv as $arg ) {
120119
switch ( $arg ) {
@@ -138,22 +137,25 @@ function team51_cli_update_dev_timestamp(): void {
138137
// Print the ASCII art.
139138
team51_cli_print_message( file_get_contents( TEAM51_CLI_ROOT_DIR . '/.ascii' ) );
140139

141-
// Check for updates.
142-
if ( $team51_cli_is_dev ) {
140+
// Check for updates. --force-update wins over dev mode so an explicit refresh always runs.
141+
if ( $team51_cli_is_dev && ! $team51_cli_force_update ) {
143142
team51_cli_print_message( "\033[44mRunning in developer mode. Skipping update check.\033[0m" );
143+
if ( $team51_cli_dev_file_exists ) {
144+
team51_cli_print_message( "\033[33m.dev file detected — run `team51 --force-update <command>` periodically to pick up CLI changes, or `rm .dev` to re-enable the 7-day update buffer.\033[0m" );
145+
}
144146
} else {
145-
$dev_timestamp = team51_cli_get_dev_timestamp();
147+
$last_check_timestamp = team51_cli_get_last_update_check_timestamp();
146148
$seven_days_in_seconds = 7 * 24 * 60 * 60; // 7 days in seconds
147149

148150
$should_update = $team51_cli_force_update ||
149-
null === $dev_timestamp ||
150-
( time() - $dev_timestamp ) >= $seven_days_in_seconds;
151+
null === $last_check_timestamp ||
152+
( time() - $last_check_timestamp ) >= $seven_days_in_seconds;
151153

152154
if ( $should_update ) {
153155
team51_cli_print_message( "\033[33mChecking for updates..\033[0m" );
154156
team51_cli_self_update();
155-
// Update the timestamp after checking for updates
156-
team51_cli_update_dev_timestamp();
157+
// Update the timestamp after checking for updates.
158+
team51_cli_update_last_update_check_timestamp();
157159
} else {
158160
team51_cli_print_message( "\033[33mSkipping update check (less than 7 days since last check).\033[0m" );
159161
}

0 commit comments

Comments
 (0)