2

We have a node_module bookiza which is essentially a command line tool that people install with --global flag and then use it to create and publish books online. We are following semver for it (mostly) but I envisage it will be done so strictly in the future.

Is there a way to make this module a self-updating one? So that all our clients (writers) are on the same version of bookiza at all the times (unless they disable autoupdate). Essentially, run npm update [-g] bookiza every 15 days or when a new release is outed.

How should I go about implementing this?

Marvin Danig
  • 3,738
  • 6
  • 39
  • 71
  • Take a look at this question and answer: http://stackoverflow.com/a/15957574/1756880 – Maru Feb 18 '16 at 15:17

2 Answers2

6

For those who are looking for the same thing, I have created a module for automatically updating node.js applications from git repositories. It compares the local package.json with the one from your repo, then automatically clones the repo and install dependencies.

Auto Git Update - https://github.com/chegele/AutoGitUpdate

import AutoGitUpdate from 'auto-git-update';

const config = {
    repository: 'https://github.com/chegele/BackupPurger'
    tempLocation: 'C:/Users/scheg/Desktop/tmp/',
    ignoreFiles: ['util/config.js'],
    executeOnComplete: 'C:\\Users\\scheg\\Desktop\\worksapce\\AutoGitUpdate\\startTest.bat',
    exitOnComplete: true
}

const updater = new AutoGitUpdate(config);

updater.autoUpdate();
Stephen Hegele
  • 118
  • 1
  • 6
1

Your users could install the command line tool a number of ways.. So it's not guaranteed that npm install -g will work, particularly in their environment.

I think the best thing to do here is make some sort of "latest version" check at start. If there's a new version, warn the user, and offer to automatically run the update command with a [Y/n].

This is what bower and a few other packages do.

Christian Stewart
  • 15,217
  • 20
  • 82
  • 139
  • > some sort of "latest version" check at start. That is correct. Start of the "terminal app", like `zsh` or bower does. I'm looking at what event does the bower latch on to… and if that event is fired cross-platform across linux, windows and mac. Thanks! – Marvin Danig Aug 25 '16 at 13:51