linkgravity 1.0.2 → 1.2.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.
Files changed (2) hide show
  1. package/bin/cli.js +64 -1
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -152,7 +152,10 @@ function verifyStartup() {
152
152
  cp.stderr.on('data', checkLog);
153
153
  }
154
154
 
155
- if (cmd === 'start') {
155
+ if (cmd === 'version' || cmd === '-v' || cmd === '--version') {
156
+ const pkg = require('../package.json');
157
+ console.log(`linkgravity v${pkg.version}`);
158
+ } else if (cmd === 'start') {
156
159
  info('Starting LinkGravity daemon...');
157
160
  runPm2(['start', botPath, '--interpreter', pythonExe, '--name', 'lgy']);
158
161
  verifyStartup();
@@ -222,6 +225,58 @@ if (cmd === 'start') {
222
225
  runSetup().catch((err) => {
223
226
  console.error('Setup wizard crashed:', err.message);
224
227
  });
228
+ } else if (cmd === 'update') {
229
+ const pkg = require('../package.json');
230
+ const currentVersion = pkg.version;
231
+
232
+ info('Checking npm for the latest version...');
233
+ const viewResult = spawnSync('npm', ['view', 'linkgravity', 'version'], { stdio: 'pipe' });
234
+ if (viewResult.error || viewResult.status !== 0) {
235
+ console.error(
236
+ (viewResult.stderr || '').toString().trim() ||
237
+ 'Failed to check the latest version on npm.',
238
+ );
239
+ process.exit(1);
240
+ }
241
+ const latestVersion = viewResult.stdout.toString().trim();
242
+
243
+ if (latestVersion === currentVersion) {
244
+ success(`Already up to date (v${currentVersion}).\n`);
245
+ process.exit(0);
246
+ }
247
+
248
+ info(`Updating: v${currentVersion} -> v${latestVersion}...`);
249
+ const installResult = spawnSync('npm', ['install', '-g', 'linkgravity@latest'], {
250
+ stdio: 'inherit',
251
+ });
252
+ if (installResult.status !== 0) {
253
+ console.error('npm install failed - update aborted, still on the old version.');
254
+ process.exit(1);
255
+ }
256
+ success(`Installed v${latestVersion}.`);
257
+
258
+ info('Restarting daemon to apply the update...');
259
+ const restartResult = spawnSync('npx', ['-y', 'pm2', 'restart', 'lgy', '--update-env'], {
260
+ stdio: 'pipe',
261
+ cwd: path.join(__dirname, '..'),
262
+ env: { ...process.env, PYTHONUNBUFFERED: '1' },
263
+ });
264
+
265
+ if (restartResult.status === 0) {
266
+ verifyStartup();
267
+ } else if ((restartResult.stderr || '').toString().includes('not found')) {
268
+ // Daemon wasn't running before the update - start it fresh instead
269
+ // of reporting a restart that never had anything to restart.
270
+ info("Daemon wasn't running - starting it fresh...");
271
+ runPm2(['start', botPath, '--interpreter', pythonExe, '--name', 'lgy']);
272
+ verifyStartup();
273
+ } else {
274
+ console.error((restartResult.stderr || '').toString().trim());
275
+ console.error(
276
+ `\n${color.yellow}⚠${color.reset} Update installed, but restarting the daemon failed - run 'lgy restart' manually.`,
277
+ );
278
+ process.exit(1);
279
+ }
225
280
  } else if (cmd === 'help') {
226
281
  console.log(
227
282
  [
@@ -231,6 +286,7 @@ if (cmd === 'start') {
231
286
  'Usage: lgy <command> [options]',
232
287
  '',
233
288
  'Commands:',
289
+ ' version Print the installed version (-v, --version)',
234
290
  ' start Start bot in the background (PM2 daemon)',
235
291
  ' stop Stop the background bot',
236
292
  ' restart Restart the background bot',
@@ -238,6 +294,7 @@ if (cmd === 'start') {
238
294
  ' enable Register bot to start automatically on system boot',
239
295
  ' disable Remove bot from system boot',
240
296
  ' setup Run the configuration wizard (init)',
297
+ ' update Check npm for a newer version and install + restart if found',
241
298
  ' help Show this help message',
242
299
  '',
243
300
  ].join('\n'),
@@ -256,6 +313,12 @@ if (cmd === 'start') {
256
313
  { label: 'Restart', value: 'restart', hint: 'Restart the running daemon' },
257
314
  { label: 'Logs', value: 'logs', hint: 'View the live console logs' },
258
315
  { label: 'Setup', value: 'setup', hint: 'Configure bot tokens and settings' },
316
+ {
317
+ label: 'Update',
318
+ value: 'update',
319
+ hint: 'Check npm for a newer version and install it',
320
+ },
321
+ { label: 'Version', value: 'version', hint: 'Print the installed version' },
259
322
  {
260
323
  label: 'Enable Auto-start',
261
324
  value: 'enable',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkgravity",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "description": "Discord bot bridge for the Antigravity (agy) CLI, with voice interaction support",
5
5
  "scripts": {
6
6
  "postinstall": "node npm-scripts/postinstall.js",