forked from Shopify/polaris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·42 lines (34 loc) · 1.09 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/ruby --disable-gems
NON_COMMITTABLE_FILE_PATHS = ['playground/Playground.tsx']
COLOR_DOC_SOURCE_FILE_PATHS = ['src/utilities/theme/tokens.ts']
module PreCommit
extend self
def main
ignore_playground
generate_color_docs
end
private
def ignore_playground
changed_files.each do |path|
if NON_COMMITTABLE_FILE_PATHS.include? path
puts "WARNING: This commit has been aborted"
puts "Please remove changes from #{path} before committing"
puts "Or run `git update-index --assume-unchanged #{path}` to git ignore this file"
abort "Use `git commit --no-verify` to force add this file"
end
end
end
def generate_color_docs
changed_files.each do |path|
if COLOR_DOC_SOURCE_FILE_PATHS.include? path
puts "Color system changes detected. Generating new docs (may take a couple minutes)..."
%x(yarn run colordocs)
%x(git add "documentation/Color system.md")
end
end
end
def changed_files
@changed_files ||= %x(git diff --cached --name-only HEAD).lines.map(&:chomp)
end
end
PreCommit.main