Skip to content

Commit

Permalink
Adds Sublime Text recipe.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesiscoding committed Jul 12, 2022
1 parent 656a2c5 commit 1b210b0
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ $command[] = new DevCoding\Jss\Easy\Command\Preferences\CC\BackupCommand();
$command[] = new DevCoding\Jss\Easy\Command\Preferences\CC\TransferCommand();
// Other Commands
$command[] = new DevCoding\Jss\Easy\Command\PrepCommand();
$app = new Application('Jez', 'v4.0.9');
$app = new Application('Jez', 'v4.0.10');
$app->addCommands($command);
$app->run();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"prefer-stable": true,
"minimum-stability": "dev",
"version": "4.0.9",
"version": "4.0.10",
"require": {
"php": ">=7.1",
"ext-json": "*",
Expand Down
Binary file modified dist/jez.phar
Binary file not shown.
5 changes: 5 additions & 0 deletions src/Command/Download/AbstractInstallConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ protected function isVersionMatch($app_or_ver)
$new = $this->getAppVersion($this->getDestination());
$comp = ($app_or_ver instanceof MacApplication) ? $this->getAppVersion($app_or_ver) : $app_or_ver;

if (0 == strpos($new->getRaw(), 'Build _'))
{
$new = new SemanticVersion('0.0+'.$new->getBuild());
}

return $new instanceof SemanticVersion && $comp instanceof SemanticVersion && $new->eq($comp);
}

Expand Down
7 changes: 6 additions & 1 deletion src/Object/Recipe/GenericRecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ public function isMatch(MacApplication $offered)
}
else
{
$cVer = new SemanticVersion($this->getCurrentVersion());
$cVer = new SemanticVersion($ver);
$oVer = $offered->getShortVersion() ?? $offered->getVersion();

if (0 == strpos($oVer->getRaw(), 'Build _'))
{
$oVer = new SemanticVersion('0.0+'.$oVer->getBuild());
}

if ($oVer->eq($cVer))
{
return true;
Expand Down
89 changes: 89 additions & 0 deletions src/Object/Recipe/SublimeText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace DevCoding\Jss\Easy\Object\Recipe;

use DevCoding\Jss\Easy\Helper\DownloadHelper;
use Symfony\Component\DomCrawler\Crawler;

/**
* Installer recipe class for Sublime Text 4
*
* @author AMJones <am@jonesiscoding.com>
* @license https://github.com/deviscoding/jss-helper/blob/main/LICENSE
*/
class SublimeText extends AbstractRecipe
{
protected $version;

public function getName()
{
return 'Sublime Text';
}

public function getPath()
{
return '/Applications/Sublime Text.app';
}

public function getDownloadUrl()
{
$build = str_replace('0.0+', '', $this->getCurrentVersion());

return sprintf('https://download.sublimetext.com/sublime_text_build_%s_mac.zip', $build);
}

public function getDestinationUrl()
{
return $this->getDownloadUrl();
}

public function getInstallerType()
{
return $this->getInstallerTypeFromUrl($this->getDownloadUrl());
}

public function getCurrentVersion()
{
if (!isset($this->version))
{
if ($notes = $this->getReleaseNotes())
{
$crawler = new Crawler($notes);
$crawler = $crawler->filter('#changelog');
if ($crawler->count() > 0)
{
$crawler = $crawler->filter('article')->reduce(function (Crawler $node, $i) {
$href = $node->attr('class');

return false !== stripos($href, 'current');
});

if ($h3 = $crawler->filter('h3'))
{
$this->version = '0.0+'.str_replace('Build ', '', $h3->html());
}
}
}
}

return $this->version;
}

/**
* Grabs the HTML of the updates page.
*
* @return string|null
*/
protected function getReleaseNotes()
{
$url = 'https://www.sublimetext.com/download';
$ua = $this->getUserAgent();

if ($resp = (new DownloadHelper())->getUrl($url, null, null, $ua))
{
return $resp['body'] ?? null;
}

return null;
}
}

0 comments on commit 1b210b0

Please sign in to comment.