From b7a8ddb0bc8a41e5544fcaca76af5db828a4e8da Mon Sep 17 00:00:00 2001 From: Alex Windett Date: Fri, 17 Feb 2017 15:42:52 +0000 Subject: [PATCH] changing file permisisons --- README.md | 2 +- bin/sketch | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100755 bin/sketch diff --git a/README.md b/README.md index 07557f98..1b6b0051 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ running `make`, make continues without any errors, then you are good to go. [nod is also needed if deployment to Triton is required. ``` -make && make install +make && make install ``` Then to run each individual component locally (subject to change). diff --git a/bin/sketch b/bin/sketch new file mode 100755 index 00000000..11262833 --- /dev/null +++ b/bin/sketch @@ -0,0 +1,57 @@ +#!/usr/bin/env ruby +require 'fileutils' + +PROGNAME = 'pre-commit (auto-generate sketch previews)' + +def main + progress "Installing sketchtool" + system!(%W[/Applications/Sketch.app/Contents/Resources/sketchtool/install.sh]) + + progress "Looking for changed or added .sketch files" + diff_output = capture!(%W[git diff --name-only --cached --pretty=format:]) + sketch_files = diff_output.split("\n").grep(/\.sketch\z/) + if sketch_files.empty? + progress "No sketch files to create preview images for in this commit!" + end + puts sketch_files + + sketch_files.each do |f| + unless File.exist?(f) + progress "#{f} does not exist (anymore?)" + next + end + + png_output_dir = f.sub(/\.sketch\z/, '') + '-sketch-previews' + progress "deleting old previews" + FileUtils.rm_rf(png_output_dir) + + progress "exporting pages" + cmd = %W[sketchtool --overwriting=YES --output=#{png_output_dir} export pages #{f}] + system!(cmd) + + progress "adding to git" + system!(%W[git add #{png_output_dir}]) + end +end + +def system!(cmd) + puts "running: #{cmd.join(' ')}" + abort failure_message(cmd) unless system(*cmd) +end + +def capture!(cmd) + puts "capturing: #{cmd.join(' ')}" + result = IO.popen(cmd) { |io| io.read } + abort failure_message(cmd) unless $?.success? + result +end + +def failure_message(cmd) + "#{PROGNAME}: command failed: #{cmd.join(' ')}" +end + +def progress(msg) + puts "#{PROGNAME}: #{msg}" +end + +main diff --git a/package.json b/package.json index 4c7b4b62..91ac7b02 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "scripts": { "test": "make test", - "precommit": "make -j4 lint", + "precommit": "make -j4 lint && ./bin/sketch", "prepush": "make test" }, "dependencies": {