{"_id":"@bszhct/pkg-updater","_rev":"1-05f91dac733e70ca5701cc636f9c39e7","name":"@bszhct/pkg-updater","dist-tags":{"latest":"1.0.5"},"versions":{"1.0.5":{"name":"@bszhct/pkg-updater","version":"1.0.5","description":"A simple updater which use in your cli tool.","main":"lib/index.js","scripts":{"test":"tap test/**/*.js"},"repository":{"type":"git","url":"git+ssh://git@github.com/bszhct/pkg-updater.git"},"author":{"name":"kohpoll,bszhct"},"license":"ISC","devDependencies":{"fixture-stdout":"^0.2.1","sinon":"^1.17.6","tap":"^7.1.2","tape":"^4.6.0","tape-co":"^1.0.1"},"dependencies":{"boxen":"^0.8.1","co":"^4.6.0","colors":"^1.1.2","got":"^6.5.0","lodash.template":"^4.4.0","normalize-url":"^1.6.1","semver":"^5.3.0","userhome":"^1.0.0"},"publishConfig":{"registry":"https://registry.npmjs.org"},"gitHead":"3821385237bd31db333a281b23520109b5bba817","bugs":{"url":"https://github.com/bszhct/pkg-updater/issues"},"homepage":"https://github.com/bszhct/pkg-updater#readme","_id":"@bszhct/pkg-updater@1.0.5","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"bszhct","email":"camel@bszhct.com"},"dist":{"integrity":"sha512-1FxVsbE9vU1RwSKuxBsur0J0LBjDkK6DAlrWWBmuW9W+uGON9fjXaIgBfnHEvbsfyje6uCUPT0NnaQAoyOqv9g==","shasum":"5f38410c2f59eb87ed9eb527dd915022412e34f3","tarball":"https://registry.npmjs.org/@bszhct/pkg-updater/-/pkg-updater-1.0.5.tgz","fileCount":5,"unpackedSize":11822,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe5uMdCRA9TVsSAnZWagAAvqkQAInH+uA7YQDzKLtlHvDD\nHvIEweQDtbx45byWtqa7KXEfmcGpFGJUl2V9ZhZEfOTMh8oxPFQst0wErDjb\nfRSwDix/HQj4Ogi65kQ+kH2BQvME6mg29OnNuFzHhHhvB7TdQdHE3hUZA46s\ns6kIy+FwPfvYzVb1U/lxlxdOyLXq9l860Ir9Wp6SEWYCgQSsYWRrDtNBh2GI\n+q8dJ0rPn4wttvOgnM9fym8I7dfdWHK62n2SPsz81lkM3Dxf/D9cTGsdwqF0\nMhmHDjIdf8F/JtqViOytxjlcze7pHESR3mDQ8ZWdyOLHQxgE5O2/X1MSRl9y\nKKbQ/D4O23fcarOpjVaZfwaRh9DXVljhOWR/mV4J6y4wV+KgFEVrk2jOVn9P\ntblT/PMdof+MQRnPKFaEuCrS4jwgomMsIbjU9yARplnvFXOiwQqgYqSEk775\ngbEmlRa1zrWzfudk2Yj0KycO8bool1BVEm6ZraBEs1/wwUZngYFh9VJMvqUB\nwYbnBX3c1+Bla30MbeQb/ig8MZW7wVLsZY0qw07rg4Fsqf7TUSyoFG+G8+/S\nWp3ZfCkTZwOkdZjrQ3s9C0BAOYwwx6ip8KNcYz21Y+OFodit5Z+i8O8k8jdz\nr0/1yp2pZvDd+mBhJgHqKGvRzuC4qfPhtntGmlxOJ1DFxdfUZmxYDd4KqwBc\nLamt\r\n=s8xG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCbo6Qiq8bQUF+ZXYMRrrzK617MmfzwjOI5267YAPSSGQIhAJBYonFT+2vNWorQv6d6wpFuAN8xzDKRFTBfBoW8BAz5"}]},"maintainers":[{"name":"bszhct","email":"camel@bszhct.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pkg-updater_1.0.5_1592189724597_0.33368421799137726"},"_hasShrinkwrap":false}},"time":{"created":"2020-06-15T02:55:24.562Z","1.0.5":"2020-06-15T02:55:24.765Z","modified":"2022-04-04T20:51:38.169Z"},"maintainers":[{"name":"bszhct","email":"camel@bszhct.com"}],"description":"A simple updater which use in your cli tool.","homepage":"https://github.com/bszhct/pkg-updater#readme","repository":{"type":"git","url":"git+ssh://git@github.com/bszhct/pkg-updater.git"},"author":{"name":"kohpoll,bszhct"},"bugs":{"url":"https://github.com/bszhct/pkg-updater/issues"},"license":"ISC","readme":"# pkg-updater\n**This version solves the problem of automatic update failure.**\n\nThis package is suitable for update checking of cli tools. It will check the version in background process, and notify the users when update is available.\n\n## Usage\nInstall the module with: `npm install pkg-updater --save`.\n\n```javascript\nconst updater = require('pkg-updater');\nconst pkg = require('./package.json'); // your cli tool's package.json\n\nupdater({'pkg': pkg}) .then(() => { /* start cli here */ });\n\nupdater({\n  'pkg': pkg,  \n  'registry': 'http://xxx.registry.com', // custom registry\n  'tag': 'next', // custom the check tag(default is latest)\n  'checkInterval': 24 * 60 * 60 * 1000, // custom the check interval(ms)\n  'updateMessage': 'package update from <%=current%> to <%=latest%>.' // custom notify message\n}).then(() => { /* start cli here */ });\n```\n\n## API\n### updater(options) -> {Promise}\n* `options` {Object}\n  * `pkg` {Object} (required)\n  * `registry` {String}\n  * `tag` {String}\n  * `level` {String}\n  * `checkInterval` {Integer}\n  * `updateMessage` {String}\n  * `onVersionChange` {Function}\n  * `logFile` {String}\n\n#### pkg\nThe package.json data, should contain `name` and `version` property. You can just write `require('./package.json')`.\n\n#### registry\nThe registry from which we fetch the package information. It is `https://registry.npmjs.org` by default.\n\n#### tag\nThe tag we use to fetch the package's version. We will request the `{registry}/{package.name}/{tag}` to get the remote version. It is `latest` by default.\n\n#### level\nThe incompatible level to decide whether we should `process.exit`. It is `major` by default.\n\nYou can provide:\n  - `major`: remote is `2.0.0`, current is `1.0.0`, we will `process.exit`\n  - `minor`: remote is `1.1.0`, current is `1.0.0`, we will `process.exit`\n  - `patch`: remote is `1.0.1`, current is `1.0.0`, we will `process.exit`\n\n#### checkInterval\nThe interval(ms) to create the daemon check process. It is `60 * 60 * 1000`(1h) by default.\n\n#### updateMessage\nThe message we use to notiy user in the terminal. It is a lodash template string. The default value is: \n\n```bash\n'Package update available:' +\n'<%=colors.dim(current)%> -> <%=colors.green(latest)%>' +\n'<%if(incompatible){%>\\n<%=colors.bold(\"This version is incompatible, you should update before continuing.\")%><%}%>\\n' +\n'Run <%=colors.cyan(command)%> to update.'\n```\n\nYou can use following variables:\n  - `name`: package's name\n  - `current`: package's current version\n  - `latest`: package's remote version\n  - `incompatible`: whether the `current` and `latest` is compatiable\n  - `command`: the update command, default is `npm i {package.name} -g`\n  - `colors`: the [colors](https://www.npmjs.com/package/colors) object\n\n#### onVersionChange\nThe function to execute when the remote version is newer than the current version. \n\nThe default behavior of this function is:\n  - use the boxen to display the updateMessage\n  - if the version is incompatible, exit the process\n\n*If you really know what you are doing, you can provide your custom function.* \n\nThis function can be a generator function, is called as followed:\n\n```javascript\nyield onVersionChange({\n  'incompatible': false,\n  'latestVersion': '2.0.1',\n  'pkg': {\n    'name': 'foo',\n    'version': '2.0.0'\n  },\n  'level': 'major',\n  'updateMessage': 'the default update message'\n});\n```\n\n#### logFile\nThe log file we use to store the check information. It is `{$HOME}/.pkg_updater.json`.\n\nThis file's format looks like this:\n\n```json\n{\n  \"foo\": {\n    \"latestVersion\": \"2.0.1\",\n    \"lastCheck\": 1477294183263\n  },\n  \"bar\": {\n    \"latestVersion\": \"1.0.1\",  \n    \"lastCheck\": 1477294183263     \n  }\n}\n```","readmeFilename":"README.md"}