+8
-5
@@ -12,3 +12,3 @@ 'use strict'; | ||
| got(`https://api.cdnjs.com/libraries?search=${name}&fields=assets`, {json: true}) | ||
| got(`https://api.cdnjs.com/libraries?search=${name}&fields=version,assets`, {json: true}) | ||
| .then(res => { | ||
@@ -18,10 +18,13 @@ if (res.body.results.length > 0) { | ||
| const library = res.body.results[0]; | ||
| const versionAssets = library.assets.filter(files => { | ||
| return files.version === library.version; | ||
| }); | ||
| // https://cdnjs.cloudflare.com/ajax/libs/[library]/[version]/[files] | ||
| const rootDirectory = library.latest.substring( | ||
| 0, | ||
| (library.latest.indexOf(library.assets[0].version) + | ||
| library.assets[0].version.length) | ||
| (library.latest.indexOf(library.version) + | ||
| library.version.length) | ||
| ).concat('/'); | ||
| // Return only the latest version | ||
| let files = library.assets[0].files.map(item => urlResolve(rootDirectory, item)); | ||
| let files = versionAssets[0].files.map(item => urlResolve(rootDirectory, item)); | ||
@@ -42,3 +45,3 @@ if (opts && opts.only) { | ||
| name: library.name, | ||
| version: library.assets[0].version, | ||
| version: versionAssets[0].version, | ||
| files | ||
@@ -45,0 +48,0 @@ }); |
+1
-1
| { | ||
| "name": "latest-lib", | ||
| "version": "0.1.1", | ||
| "version": "0.1.2", | ||
| "description": "Get the latest version of a CSS or JavaScript library hosted on CDNJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
4989
2.05%66
4.76%