Skip to content

Commit

Permalink
Merge pull request #110 from rodrigobdz/master
Browse files Browse the repository at this point in the history
Implement Yarn packages lookup
  • Loading branch information
willfarrell authored Sep 7, 2017
2 parents eb132d4 + 7dd847d commit 0cde099
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
Binary file modified Package Managers.alfredworkflow
Binary file not shown.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Package Managers ([Download v3.18](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.18/Package.Managers.alfredworkflow))
# Package Managers ([Download v3.19](https://github.com/willfarrell/alfred-pkgman-workflow/releases/download/3.19/Package.Managers.alfredworkflow))

Package Repo Search

Expand Down Expand Up @@ -33,6 +33,7 @@ Quick package/plugin/component (repo) lookup for your favourite package managers
* `raspbian {query}`: [Rasberry Pi Packages](http://www.raspbian.org)
* `rpm {query}`: [Linux Packages](http://rpmfind.net)
* `st {query}`: [Sublime Text Packages](https://packagecontrol.io)
* `yarn {query}`: [Yarn Packages](https://yarnpkg.com/lang/en/)
* `yo {query}`: [Yeoman Generators](http://yeoman.io)

## Action Modifiers
Expand Down Expand Up @@ -93,4 +94,5 @@ Featured on [Smashing Magazine](http://www.smashingmagazine.com/2013/10/25/hidde
[pypi]: ./screenshots/pypi.png "Sample pypi result"
[rpm]: ./screenshots/rpm.png "Sample rpm result"
[st]: ./screenshots/stpm.png "Sample stpm result"
[yarn]: ./screenshots/yarn.png "Sample yarn result"
[yo]: ./screenshots/yo.png "Sample yo result"
Binary file added icon-cache/yarn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon-src/yarn-kitten-circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/yarn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions src/Yarn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace WillFarrell\AlfredPkgMan;

require_once('Cache.php');
require_once('Repo.php');

class Yarn extends Repo
{
protected $id = 'yarn';
protected $url = 'https://npms.io';
protected $search_url = 'https://api.npms.io/v2/search?q=';
protected $yarn_url = 'https://yarnpkg.com/en/package/';

public function search($query)
{
if (!$this->hasMinQueryLength($query)) {
return $this->xml();
}

$this->pkgs = $this->cache->get_query_json(
$this->id,
$query,
"{$this->search_url}{$query}&size={$this->max_return}"
);

foreach($this->pkgs->results as $pkg) {
$p = $pkg->package;
$name = $p->name;

$this->cache->w->result(
$this->id,
$this->makeArg($name, $yarn_url . $p->name, "{$p->name}: {$p->version}"),
$name,
$p->description,
"icon-cache/{$this->id}.png"
);

// only search till max return reached
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
break;
}
}

$this->noResults($query, "{$this->search_url}{$query}");

return $this->xml();
}
}

// Test code, uncomment to debug this script from the command-line
// $repo = new Yarn();
// echo $repo->search('gr');

0 comments on commit 0cde099

Please sign in to comment.