This repository was archived by the owner on Feb 5, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +111
-1
lines changed Expand file tree Collapse file tree 6 files changed +111
-1
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,28 @@ Check your [Rust packages](https://crates.io) for updates.
55## Installation
66
77Run ` yarn global add crates-updater ` or ` npm i -g crates-updater ` .
8+
9+ ## Usage
10+
11+ ```
12+ Usage: crates-updater [options]
13+
14+ Check your Rust packages for updates.
15+
16+ Options:
17+ -p, --package <package> which package to check (required)
18+ -V, --package-version <version> which version to check
19+ -k, --api-key <key> set the API key for libraries.io (required)
20+ -v, --version output the version number
21+ -h, --help output usage information
22+ ```
23+
24+ ## Examples
25+
26+ ``` shell
27+ # returns either a newer version or nothing
28+ crates-updater -p ripgrep -V 0.9.0 -k < api key>
29+
30+ # returns the latest version
31+ crates-updater -p ripgrep -k < api key>
32+ ```
Original file line number Diff line number Diff line change 11{
22 "author" : " Florian Keller <github@floriankeller.de>" ,
33 "bin" : {
4+ "crates-updater" : " dist/cli.js" ,
45 "update-crate" : " dist/cli.js" ,
56 "update-crates" : " dist/cli.js"
67 },
78 "dependencies" : {
9+ "commander" : " 2.19.0" ,
10+ "compare-versions" : " 3.4.0" ,
811 "libraries.io" : " 1.2.2"
912 },
1013 "description" : " Check your Rust packages for updates." ,
Original file line number Diff line number Diff line change 1+ import compareVersions = require( 'compare-versions' ) ;
2+ import { LibrariesIO , ProjectVersion } from 'libraries.io' ;
3+
4+ class CratesUpdater {
5+ private readonly librariesIO : LibrariesIO ;
6+
7+ constructor ( apiKey : string ) {
8+ this . librariesIO = new LibrariesIO ( apiKey ) ;
9+ }
10+
11+ public async getVersions ( packageName : string ) : Promise < ProjectVersion [ ] > {
12+ const result = await this . librariesIO . api . project . getProject ( 'cargo' , packageName ) ;
13+ return result . data . versions ;
14+ }
15+
16+ public async getLatestVersion ( packageName : string ) : Promise < ProjectVersion > {
17+ const versions = await this . getVersions ( packageName ) ;
18+ const sorted = versions . sort ( ( a , b ) => compareVersions ( a . number , b . number ) ) ;
19+ return sorted [ versions . length - 1 ] ;
20+ }
21+
22+ public async checkForUpdate ( packageName : string , version : string ) : Promise < string | null > {
23+ const latestVersion = await this . getLatestVersion ( packageName ) ;
24+ if ( compareVersions ( latestVersion . number , version ) > 0 ) {
25+ return latestVersion . number ;
26+ }
27+
28+ return null ;
29+ }
30+ }
31+
32+ export { CratesUpdater } ;
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ import * as program from 'commander' ;
4+ import { CratesUpdater } from './CratesUpdater' ;
5+
6+ const { name, version, description} : { name : string ; version: string ; description: string } = require ( '../package.json' ) ;
7+
8+ program
9+ . name ( name )
10+ . description ( description )
11+ . option ( '-p, --package <package>' , 'which package to check (required)' )
12+ . option ( '-V, --package-version <version>' , 'which version to check' )
13+ . option ( '-k, --api-key <key>' , 'set the API key for libraries.io (required)' )
14+ . version ( version , '-v, --version' )
15+ . parse ( process . argv ) ;
16+
17+ if ( ! program . options . length || ! program . apiKey || ! program . package ) {
18+ program . outputHelp ( ) ;
19+ process . exit ( 1 ) ;
20+ }
21+
22+ const cratesUpdater = new CratesUpdater ( program . apiKey ) ;
23+
24+ if ( program . package && ! program . packageVersion ) {
25+ cratesUpdater
26+ . getLatestVersion ( program . package )
27+ . then ( version => console . log ( version . number ) )
28+ . catch ( error => {
29+ console . error ( error ) ;
30+ process . exit ( 1 ) ;
31+ } ) ;
32+ } else {
33+ cratesUpdater
34+ . checkForUpdate ( program . package , program . packageVersion )
35+ . then ( version => {
36+ if ( version ) {
37+ console . log ( version ) ;
38+ }
39+ } )
40+ . catch ( error => {
41+ console . error ( error ) ;
42+ process . exit ( 1 ) ;
43+ } ) ;
44+ }
Original file line number Diff line number Diff line change 1+ export * from './CratesUpdater' ;
Original file line number Diff line number Diff line change @@ -285,11 +285,16 @@ color-name@1.1.3:
285285 resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
286286 integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
287287
288- commander@^2.12.1, commander@^2.14.1, commander@^2.9.0 :
288+ commander@2.19.0, commander@ ^2.12.1, commander@^2.14.1, commander@^2.9.0 :
289289 version "2.19.0"
290290 resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
291291 integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==
292292
293+ compare-versions@3.4.0 :
294+ version "3.4.0"
295+ resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.4.0.tgz#e0747df5c9cb7f054d6d3dc3e1dbc444f9e92b26"
296+ integrity sha512-tK69D7oNXXqUW3ZNo/z7NXTEz22TCF0pTE+YF9cxvaAM9XnkLo1fV621xCLrRR6aevJlKxExkss0vWqUCUpqdg==
297+
293298component-emitter@^1.2.1 :
294299 version "1.2.1"
295300 resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
You can’t perform that action at this time.
0 commit comments