From 060df8a3d72174b09a2718f7ffc8ac6b27c08f77 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Sat, 3 Feb 2018 16:18:10 -0800 Subject: [PATCH] Add Homebrew support (#230) Technically Homebrew support was added by sass/homebrew-sass@83b7db9, but this makes it official by documenting it and adding a semi-automated update process. --- README.md | 13 +++++++++++ tool/grind.dart | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/README.md b/README.md index 45816d78..b48088f0 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ A [Dart][dart] implementation of [Sass][sass]. **Sass makes CSS fun again**. * [Using Dart Sass](#using-dart-sass) * [From Chocolatey (Windows)](#from-chocolatey-windows) + * [From Homebrew (OS X)](#from-homebrew-os-x) * [Standalone](#standalone) * [From npm](#from-npm) * [From Pub](#from-pub) @@ -48,6 +49,18 @@ choco install sass -prerelease That'll give you a `sass` executable on your command line that will run Dart Sass. +### From Homebrew (OS X) + +If you use [the Homebrew package manager](https://brew.sh/) for Mac OS X, you +can install Dart Sass by running + +```sh +brew install --devel sass/sass/sass +``` + +That'll give you a `sass` executable on your command line that will run Dart +Sass. + ### Standalone You can download the standalone Dart Sass archive for your operating diff --git a/tool/grind.dart b/tool/grind.dart index 196bdfd2..fc148c00 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -9,6 +9,7 @@ import 'dart:io'; import 'package:archive/archive.dart'; import 'package:charcode/charcode.dart'; import 'package:collection/collection.dart'; +import 'package:crypto/crypto.dart'; import 'package:grinder/grinder.dart'; import 'package:http/http.dart' as http; import 'package:node_preamble/preamble.dart' as preamble; @@ -400,3 +401,61 @@ ArchiveFile _fileFromString(String path, String contents, ArchiveFile _file(String target, String source, {bool executable: false}) => _fileFromBytes(target, new File(source).readAsBytesSync(), executable: executable); + +/// A regular expression for locating the URL and SHA256 hash of the Sass +/// archive in the `homebrew-sass` formula. +final _homebrewRegExp = new RegExp(r'\n( *)url "[^"]+"' + r'\n *sha256 "[^"]+"'); + +@Task('Update the Homebrew formula for the current version.') +update_homebrew() async { + _ensureBuild(); + + var process = await Process.start("git", [ + "archive", + "--prefix=dart-sass-$_version/", + "--format=tar.gz", + _version + ]); + var digest = await sha256.bind(process.stdout).first; + var stderr = await UTF8.decodeStream(process.stderr); + if ((await process.exitCode) != 0) { + fail('git archive "$_version" failed:\n$stderr'); + } + + if (new Directory("build/homebrew-sass/.git").existsSync()) { + await runAsync("git", + arguments: ["fetch", "origin"], + workingDirectory: "build/homebrew-sass"); + await runAsync("git", + arguments: ["reset", "--hard", "origin/master"], + workingDirectory: "build/homebrew-sass"); + } else { + delete(new Directory("build/homebrew-sass")); + await runAsync("git", arguments: [ + "clone", + "git@github.com:sass/homebrew-sass.git", + "build/homebrew-sass" + ]); + } + + var formula = new File("build/homebrew-sass/sass.rb"); + log("updating ${formula.path}"); + formula.writeAsStringSync(formula.readAsStringSync().replaceFirstMapped( + _homebrewRegExp, + (match) => + '\n${match[1]}url "https://github.com/sass/dart-sass/archive/$_version.tar.gz"' + '\n${match[1]}sha256 "$digest"')); + + run("git", + arguments: [ + "commit", + "--all", + "--message", + "Update Dart Sass to $_version" + ], + workingDirectory: "build/homebrew-sass"); + + await runAsync("git", + arguments: ["push"], workingDirectory: "build/homebrew-sass"); +}