Add librsync and dmd
This commit is contained in:
		
							
								
								
									
										16
									
								
								Rakefile
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								Rakefile
									
									
									
									
									
								
							| @@ -10,7 +10,6 @@ require 'open3' | |||||||
| require_relative 'config/config' | require_relative 'config/config' | ||||||
| require_relative 'lib/package' | require_relative 'lib/package' | ||||||
| require_relative 'lib/download' | require_relative 'lib/download' | ||||||
| require_relative 'lib/up2date' |  | ||||||
|  |  | ||||||
| task :dmd, [:version] do |_, arguments| | task :dmd, [:version] do |_, arguments| | ||||||
|   raise 'Version is not specified.' unless arguments.key? :version |   raise 'Version is not specified.' unless arguments.key? :version | ||||||
| @@ -42,18 +41,3 @@ task :hhvm, [:version] do |_, arguments| | |||||||
|  |  | ||||||
|   update_slackbuild_version 'development/hhvm', package.version |   update_slackbuild_version 'development/hhvm', package.version | ||||||
| end | end | ||||||
|  |  | ||||||
| AUTO_UPDATABLE = { |  | ||||||
|   'dmd' => [SlackBuilder::LatestText.new('https://downloads.dlang.org/releases/LATEST')] |  | ||||||
| }.freeze |  | ||||||
|  |  | ||||||
| task :up2date do |  | ||||||
|   AUTO_UPDATABLE.each do |key, value| |  | ||||||
|     repository, updater = value |  | ||||||
|     latest_version = SlackBuilder.check_for_latest key, repository |  | ||||||
|     next if latest_version.nil? || updater.nil? |  | ||||||
|  |  | ||||||
|     puts "Would like to update #{key} to #{latest_version} (y/N)? " |  | ||||||
|     updater.update latest_version if $stdin.gets.chomp.downcase.start_with? 'y' |  | ||||||
|   end |  | ||||||
| end |  | ||||||
|   | |||||||
							
								
								
									
										83
									
								
								app/Main.hs
									
									
									
									
									
								
							
							
						
						
									
										83
									
								
								app/Main.hs
									
									
									
									
									
								
							| @@ -7,7 +7,7 @@ import Control.Applicative (Applicative(liftA2)) | |||||||
| import Data.List.NonEmpty (NonEmpty(..)) | import Data.List.NonEmpty (NonEmpty(..)) | ||||||
| import qualified Data.List.NonEmpty as NonEmpty | import qualified Data.List.NonEmpty as NonEmpty | ||||||
| import Control.Monad.IO.Class (MonadIO(..)) | import Control.Monad.IO.Class (MonadIO(..)) | ||||||
| import Data.Maybe (fromJust, fromMaybe) | import Data.Maybe (fromJust) | ||||||
| import Options.Applicative (execParser) | import Options.Applicative (execParser) | ||||||
| import SlackBuilder.CommandLine | import SlackBuilder.CommandLine | ||||||
| import SlackBuilder.Config | import SlackBuilder.Config | ||||||
| @@ -23,9 +23,9 @@ import SlackBuilder.Download | |||||||
| import SlackBuilder.Package (Package(..)) | import SlackBuilder.Package (Package(..)) | ||||||
| import qualified SlackBuilder.Package as Package | import qualified SlackBuilder.Package as Package | ||||||
| import Text.URI (mkURI) | import Text.URI (mkURI) | ||||||
| import Data.Foldable (for_) | import Data.Foldable (for_, find) | ||||||
| import qualified Text.URI as URI | import qualified Text.URI as URI | ||||||
| import System.FilePath ((</>), (<.>), dropExtension, takeBaseName) | import System.FilePath ((</>), (<.>), dropExtension, takeBaseName, makeRelative, splitFileName) | ||||||
| import SlackBuilder.Info | import SlackBuilder.Info | ||||||
| import Text.Megaparsec (parse, errorBundlePretty) | import Text.Megaparsec (parse, errorBundlePretty) | ||||||
| import GHC.Records (HasField(..)) | import GHC.Records (HasField(..)) | ||||||
| @@ -37,6 +37,16 @@ import System.Process | |||||||
|     , withCreateProcess |     , withCreateProcess | ||||||
|     , waitForProcess |     , waitForProcess | ||||||
|     ) |     ) | ||||||
|  | import System.Console.ANSI | ||||||
|  |     ( setSGR | ||||||
|  |     , SGR(..) | ||||||
|  |     , ColorIntensity(..) | ||||||
|  |     , Color(..) | ||||||
|  |     , ConsoleLayer(..) | ||||||
|  |     ) | ||||||
|  | import System.Directory (listDirectory, doesDirectoryExist) | ||||||
|  | import Control.Monad (filterM) | ||||||
|  | import Data.List (isPrefixOf, isSuffixOf) | ||||||
|  |  | ||||||
| autoUpdatable :: [Package] | autoUpdatable :: [Package] | ||||||
| autoUpdatable = | autoUpdatable = | ||||||
| @@ -168,12 +178,51 @@ autoUpdatable = | |||||||
|         , name = "webex" |         , name = "webex" | ||||||
|         , reupload = Nothing |         , reupload = Nothing | ||||||
|         } |         } | ||||||
|  |     , Package | ||||||
|  |         { latest = | ||||||
|  |             let ghArguments = GhArguments | ||||||
|  |                     { owner = "librsync" | ||||||
|  |                     , name = "librsync" | ||||||
|  |                     , transform = Nothing | ||||||
|  |                     } | ||||||
|  |                 latest' = latestGitHub ghArguments $ Text.stripPrefix "v" | ||||||
|  |                 template = Package.DownloadTemplate | ||||||
|  |                     $ Package.StaticPlaceholder "https://github.com/librsync/librsync/archive/v" | ||||||
|  |                     :| Package.VersionPlaceholder | ||||||
|  |                     : Package.StaticPlaceholder "/librsync-" | ||||||
|  |                     : Package.VersionPlaceholder | ||||||
|  |                     : [Package.StaticPlaceholder ".tar.gz"] | ||||||
|  |              in Package.Updater latest' template | ||||||
|  |         , category = "libraries" | ||||||
|  |         , name = "librsync" | ||||||
|  |         , reupload = Just mempty | ||||||
|  |         } | ||||||
|  |     , Package | ||||||
|  |         { latest = | ||||||
|  |             let textArguments = TextArguments | ||||||
|  |                     { textURL = "https://downloads.dlang.org/releases/LATEST" | ||||||
|  |                     , versionPicker = Text.strip | ||||||
|  |                     } | ||||||
|  |                 latest' = latestText textArguments | ||||||
|  |                 template = Package.DownloadTemplate | ||||||
|  |                     $ Package.StaticPlaceholder "https://downloads.dlang.org/releases/2.x/" | ||||||
|  |                     :| Package.VersionPlaceholder | ||||||
|  |                     : Package.StaticPlaceholder "/dmd." | ||||||
|  |                     : Package.VersionPlaceholder | ||||||
|  |                     : [Package.StaticPlaceholder ".linux.tar.xz"] | ||||||
|  |              in Package.Updater latest' template | ||||||
|  |         , category = "development" | ||||||
|  |         , name = "dmd" | ||||||
|  |         , reupload = Nothing | ||||||
|  |         } | ||||||
|     ] |     ] | ||||||
|  |  | ||||||
| up2Date :: SlackBuilderT () | up2Date :: SlackBuilderT () | ||||||
| up2Date = for_ autoUpdatable go | up2Date = for_ autoUpdatable go | ||||||
|   where |   where | ||||||
|     go package = getAndLogLatest package >>= mapM_ (updatePackageIfRequired package) |     go package = getAndLogLatest package | ||||||
|  |         >>= mapM_ (updatePackageIfRequired package) | ||||||
|  |         >> liftIO (putStrLn "") | ||||||
|     getAndLogLatest Package{ latest = Package.Updater getLatest _, name } |     getAndLogLatest Package{ latest = Package.Updater getLatest _, name } | ||||||
|         = liftIO (putStrLn $ Text.unpack name <> ": Retreiving the latest version.") |         = liftIO (putStrLn $ Text.unpack name <> ": Retreiving the latest version.") | ||||||
|         >> getLatest |         >> getLatest | ||||||
| @@ -187,8 +236,11 @@ updatePackageIfRequired package@Package{..} version = do | |||||||
|     case parse parseInfoFile packagePath infoContents of |     case parse parseInfoFile packagePath infoContents of | ||||||
|         Right parsedInfoFile |         Right parsedInfoFile | ||||||
|             | version == getField @"version" parsedInfoFile -> |             | version == getField @"version" parsedInfoFile -> | ||||||
|                 liftIO $ Text.IO.putStrLn |                 liftIO $ do | ||||||
|                     $ name <> " is up to date (Version " <> version <> ")." |                     setSGR [SetColor Foreground Dull Green] | ||||||
|  |                     Text.IO.putStrLn | ||||||
|  |                         $ name <> " is up to date (Version " <> version <> ")." | ||||||
|  |                     setSGR [Reset] | ||||||
|             | otherwise -> updatePackage package parsedInfoFile version |             | otherwise -> updatePackage package parsedInfoFile version | ||||||
|         Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle |         Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle | ||||||
|  |  | ||||||
| @@ -256,6 +308,17 @@ updatePackage Package{..} info version = do | |||||||
|             , child_group = Nothing |             , child_group = Nothing | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | findCategory :: FilePath -> IO [FilePath] | ||||||
|  | findCategory currentDirectory = do | ||||||
|  |     contents <- liftIO $ listDirectory currentDirectory | ||||||
|  |     case find (isSuffixOf ".info") contents of | ||||||
|  |         Just _ -> pure [currentDirectory] | ||||||
|  |         Nothing -> do | ||||||
|  |             let contents' = (currentDirectory </>) <$> filter (not . isPrefixOf ".") contents | ||||||
|  |             directories <- filterM doesDirectoryExist contents' | ||||||
|  |             subCategories <- traverse findCategory directories | ||||||
|  |             pure $ concat subCategories | ||||||
|  |  | ||||||
| main :: IO () | main :: IO () | ||||||
| main = do | main = do | ||||||
|     programCommand <- execParser slackBuilderParser |     programCommand <- execParser slackBuilderParser | ||||||
| @@ -264,10 +327,14 @@ main = do | |||||||
|         $ runSlackBuilderT |         $ runSlackBuilderT | ||||||
|         $ executeCommand programCommand |         $ executeCommand programCommand | ||||||
|  |  | ||||||
|     Text.IO.putStrLn $ fromMaybe "" latestVersion |     maybe (pure ()) Text.IO.putStrLn latestVersion | ||||||
|   where |   where | ||||||
|     executeCommand = \case |     executeCommand = \case | ||||||
|         TextCommand textArguments -> latestText textArguments |         CategoryCommand _packageName -> do | ||||||
|  |             repository' <- SlackBuilderT $ asks repository | ||||||
|  |             categories <- liftIO $ findCategory repository' | ||||||
|  |             liftIO $ print $ splitFileName . makeRelative repository' <$> categories | ||||||
|  |             pure Nothing | ||||||
|         SlackBuildCommand packagePath version -> |         SlackBuildCommand packagePath version -> | ||||||
|             updateSlackBuildVersion packagePath version >> pure Nothing |             updateSlackBuildVersion packagePath version >> pure Nothing | ||||||
|         CommitCommand packagePath version -> |         CommitCommand packagePath version -> | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ module SlackBuilder.CommandLine | |||||||
|     ) where |     ) where | ||||||
|  |  | ||||||
| import Data.Text (Text) | import Data.Text (Text) | ||||||
| import qualified Data.Text as Text |  | ||||||
| import Options.Applicative | import Options.Applicative | ||||||
|     ( Parser |     ( Parser | ||||||
|     , ParserInfo(..) |     , ParserInfo(..) | ||||||
| @@ -21,7 +20,7 @@ import Options.Applicative | |||||||
|     ) |     ) | ||||||
|  |  | ||||||
| data SlackBuilderCommand | data SlackBuilderCommand | ||||||
|     = TextCommand TextArguments |     = CategoryCommand Text | ||||||
|     | SlackBuildCommand Text Text |     | SlackBuildCommand Text Text | ||||||
|     | CommitCommand Text Text |     | CommitCommand Text Text | ||||||
|     | ExistsCommand Text |     | ExistsCommand Text | ||||||
| @@ -47,16 +46,12 @@ data TextArguments = TextArguments | |||||||
|     , textURL :: Text |     , textURL :: Text | ||||||
|     } |     } | ||||||
|  |  | ||||||
| textArguments :: Parser TextArguments |  | ||||||
| textArguments = TextArguments Text.strip |  | ||||||
|     <$> argument str (metavar "URL") |  | ||||||
|  |  | ||||||
| slackBuilderParser :: ParserInfo SlackBuilderCommand | slackBuilderParser :: ParserInfo SlackBuilderCommand | ||||||
| slackBuilderParser = info slackBuilderCommand fullDesc | slackBuilderParser = info slackBuilderCommand fullDesc | ||||||
|  |  | ||||||
| slackBuilderCommand :: Parser SlackBuilderCommand | slackBuilderCommand :: Parser SlackBuilderCommand | ||||||
| slackBuilderCommand = subparser | slackBuilderCommand = subparser | ||||||
|     $ command "text" (info (TextCommand <$> textArguments) mempty) |     $ command "category" (info categoryCommand mempty) | ||||||
|     <> command "slackbuild" (info slackBuildCommand mempty) |     <> command "slackbuild" (info slackBuildCommand mempty) | ||||||
|     <> command "commit" (info commitCommand mempty) |     <> command "commit" (info commitCommand mempty) | ||||||
|     <> command "exists" (info existsCommand mempty) |     <> command "exists" (info existsCommand mempty) | ||||||
| @@ -66,6 +61,8 @@ slackBuilderCommand = subparser | |||||||
|     <> command "deploy" (info deployCommand mempty) |     <> command "deploy" (info deployCommand mempty) | ||||||
|     <> command "up2date" (info up2DateCommand mempty) |     <> command "up2date" (info up2DateCommand mempty) | ||||||
|   where |   where | ||||||
|  |     categoryCommand = CategoryCommand | ||||||
|  |         <$> argument str (metavar "PKGNAM") | ||||||
|     slackBuildCommand = SlackBuildCommand |     slackBuildCommand = SlackBuildCommand | ||||||
|         <$> argument str (metavar "PATH") |         <$> argument str (metavar "PATH") | ||||||
|         <*> argument str (metavar "VERSION") |         <*> argument str (metavar "VERSION") | ||||||
|   | |||||||
| @@ -1,58 +0,0 @@ | |||||||
| # This Source Code Form is subject to the terms of the Mozilla Public |  | ||||||
| # License, v. 2.0. If a copy of the MPL was not distributed with this |  | ||||||
| # file, You can obtain one at https://mozilla.org/MPL/2.0/. |  | ||||||
|  |  | ||||||
| # frozen_string_literal: true |  | ||||||
|  |  | ||||||
| require 'net/http' |  | ||||||
| require 'json' |  | ||||||
| require_relative '../config/config' |  | ||||||
| require 'term/ansicolor' |  | ||||||
|  |  | ||||||
| module SlackBuilder |  | ||||||
|   extend Term::ANSIColor |  | ||||||
|  |  | ||||||
|   # Remote repository for a single package. |  | ||||||
|   class Repository |  | ||||||
|     # Request the latest tag in the given repository. |  | ||||||
|     def latest |  | ||||||
|       raise NotImplementedError |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   # Reads a remote LATEST file. |  | ||||||
|   class LatestText < Repository |  | ||||||
|     def initialize(latest_url) |  | ||||||
|       super() |  | ||||||
|  |  | ||||||
|       @latest_url = latest_url |  | ||||||
|     end |  | ||||||
|  |  | ||||||
|     def latest |  | ||||||
|       `./bin/slackbuilder text #{@latest_url}`.strip |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   module_function |  | ||||||
|  |  | ||||||
|   # Checks if there is a new version for the package and returns the latest |  | ||||||
|   # version if an update is available, otherwise returns nil. |  | ||||||
|   def check_for_latest(package_name, repository) |  | ||||||
|     package = find_package_info package_name |  | ||||||
|     latest_version = repository.latest |  | ||||||
|  |  | ||||||
|     if package.version == latest_version |  | ||||||
|       puts green "#{package_name} is up to date (Version #{package.version})." |  | ||||||
|       nil |  | ||||||
|     else |  | ||||||
|       puts red "#{package_name}: Current version is #{package.version}, #{latest_version} is available." |  | ||||||
|       latest_version |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   private_class_method def find_package_info(package_name) |  | ||||||
|     package_path = Pathname.new Dir.glob("#{CONFIG[:repository]}/*/#{package_name}").first |  | ||||||
|     package_category = package_path.dirname.basename.to_s |  | ||||||
|     Package.parse("#{package_category}/#{package_name}", File.read("#{package_path}/#{package_name}.info")) |  | ||||||
|   end |  | ||||||
| end |  | ||||||
| @@ -20,6 +20,7 @@ common dependencies | |||||||
|     base ^>= 4.16.4.0, |     base ^>= 4.16.4.0, | ||||||
|     bytestring ^>= 0.11.0, |     bytestring ^>= 0.11.0, | ||||||
|     cryptonite >= 0.30, |     cryptonite >= 0.30, | ||||||
|  |     directory ^>= 1.3.8, | ||||||
|     filepath ^>= 1.4.2, |     filepath ^>= 1.4.2, | ||||||
|     megaparsec ^>= 9.5, |     megaparsec ^>= 9.5, | ||||||
|     modern-uri ^>= 0.3.6, |     modern-uri ^>= 0.3.6, | ||||||
| @@ -67,6 +68,7 @@ executable slackbuilder | |||||||
|     SlackBuilder.Updater |     SlackBuilder.Updater | ||||||
|   build-depends: |   build-depends: | ||||||
|     aeson ^>= 2.2.0, |     aeson ^>= 2.2.0, | ||||||
|  |     ansi-terminal ^>= 1.0, | ||||||
|     conduit ^>= 1.3.5, |     conduit ^>= 1.3.5, | ||||||
|     http-client ^>= 0.7, |     http-client ^>= 0.7, | ||||||
|     optparse-applicative ^>= 0.18.1, |     optparse-applicative ^>= 0.18.1, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user