gitshift 2.2.0 → 2.3.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/README.md CHANGED
@@ -41,6 +41,7 @@ gitshift --help
41
41
  - `gitshift doctor` - Check whether Git, SSH, and GitHub CLI are installed.
42
42
  - `gitshift backup [file]` - Export profiles, folder mappings, and current profile to a JSON backup file (default: `gitshift-backup.json`).
43
43
  - `gitshift restore <file>` - Restore profiles and mappings from a previously created backup JSON file (prompts to confirm overwrite).
44
+ - `gitshift update` - Update GitShift to the latest version or manage automatic update checks.
44
45
 
45
46
  - `gitshift link <folder>` - Link a local folder to a profile (prompts to select or create a profile).
46
47
  - `gitshift unlink <folder>` - Remove an existing folder mapping.
@@ -128,6 +129,26 @@ This will overwrite current data. Continue? (y/N)
128
129
  Backup restored
129
130
  ```
130
131
 
132
+ ### Update Command
133
+
134
+ - `gitshift update` updates GitShift to the latest published version (runs `npm install -g gitshift@latest`).
135
+ - Options:
136
+ - `--enable-auto` — enable automatic update checks.
137
+ - `--disable-auto` — disable automatic update checks.
138
+
139
+ Examples:
140
+
141
+ ```bash
142
+ # Update GitShift to latest
143
+ $ gitshift update
144
+
145
+ # Enable automatic update checks
146
+ $ gitshift update --enable-auto
147
+
148
+ # Disable automatic update checks
149
+ $ gitshift update --disable-auto
150
+ ```
151
+
131
152
  ## How It Works
132
153
 
133
154
  Profiles are saved locally on your machine using the app's configuration store. Switching profiles updates your global Git identity with:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitshift",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "GitHub Account Switcher CLI",
5
5
  "main": "server.js",
6
6
  "bin": {
@@ -0,0 +1,40 @@
1
+ import { execa } from "execa";
2
+ import ora from "ora";
3
+ import { updateSettings } from "../services/profile.js";
4
+ import { error, success } from "../utils/logger.js";
5
+
6
+ export async function updateCommand(options) {
7
+ if (options.enableAuto) {
8
+ updateSettings({ autoUpdate: true, });
9
+ success("Auto update enabled");
10
+ return;
11
+ }
12
+
13
+ if (options.disableAuto) {
14
+ updateSettings({ autoUpdate: false });
15
+ success("Auto update disabled");
16
+ return;
17
+ }
18
+
19
+ const spinner = ora("Updating GitShift...").start();
20
+
21
+ try {
22
+ await execa(
23
+ "npm",
24
+ [
25
+ "install",
26
+ "-g",
27
+ "gitshift@latest",
28
+ ],
29
+ {
30
+ stdio:
31
+ "inherit",
32
+ }
33
+ );
34
+
35
+ spinner.succeed("GitShift updated");
36
+ } catch (err) {
37
+ spinner.fail("Update failed");
38
+ error(err.message);
39
+ }
40
+ }
package/src/server.js CHANGED
@@ -16,6 +16,7 @@ import { removeCommand } from "./commands/remove.js";
16
16
  import { restoreCommand } from "./commands/restore.js";
17
17
  import { scanCommand } from "./commands/scan.js";
18
18
  import { unlinkCommand } from "./commands/unlink.js";
19
+ import { updateCommand } from "./commands/update.js";
19
20
  import { useCommand } from "./commands/use.js";
20
21
 
21
22
  const require = createRequire(import.meta.url);
@@ -180,6 +181,20 @@ async function main() {
180
181
  )
181
182
  .argument("<file>")
182
183
  .action(restoreCommand);
184
+ program
185
+ .command("update")
186
+ .description(
187
+ "Update GitShift"
188
+ )
189
+ .option(
190
+ "--enable-auto",
191
+ "Enable automatic update checks"
192
+ )
193
+ .option(
194
+ "--disable-auto",
195
+ "Disable automatic update checks"
196
+ )
197
+ .action(updateCommand);
183
198
 
184
199
  program.exitOverride();
185
200
 
@@ -93,4 +93,20 @@ export function restoreData(data) {
93
93
  if (data.currentProfile) {
94
94
  config.set("current", data.currentProfile);
95
95
  }
96
+ }
97
+
98
+ export function getSettings() {
99
+ return config.get("settings", {
100
+ autoUpdate: false,
101
+ lastUpdateCheck: null,
102
+ });
103
+ }
104
+
105
+ export function updateSettings(settings) {
106
+ const current = getSettings();
107
+
108
+ config.set("settings", {
109
+ ...current,
110
+ ...settings,
111
+ });
96
112
  }
@@ -0,0 +1,39 @@
1
+ import { execa } from "execa";
2
+ import { getSettings, updateSettings } from "./profile.js";
3
+
4
+ const DAY =
5
+ 24 *
6
+ 60 *
7
+ 60 *
8
+ 1000;
9
+
10
+ export async function checkForUpdates() {
11
+ const settings = getSettings();
12
+
13
+ if (!settings.autoUpdate) {
14
+ return;
15
+ }
16
+
17
+ const lastCheck = settings.lastUpdateCheck;
18
+
19
+ if (lastCheck && Date.now() - new Date(lastCheck).getTime() < DAY) {
20
+ return;
21
+ }
22
+
23
+ try {
24
+ const { stdout, } = await execa(
25
+ "npm",
26
+ [
27
+ "view",
28
+ "gitshift",
29
+ "version",
30
+ ]
31
+ );
32
+
33
+ updateSettings({ lastUpdateCheck: new Date().toISOString() });
34
+
35
+ return stdout.trim();
36
+ } catch {
37
+ return null;
38
+ }
39
+ }