mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Compare commits
11 Commits
master
...
script-fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6efa18e071 | ||
|
|
573b158250 | ||
|
|
f810d7fe7d | ||
|
|
741bb6a76b | ||
|
|
e7f72cd528 | ||
|
|
6669270e84 | ||
|
|
f34c741c29 | ||
|
|
28ba2bc93d | ||
|
|
4fadaf80e0 | ||
|
|
d2f2f91a89 | ||
|
|
13f83372a2 |
@@ -43,24 +43,32 @@ def log(msg)
|
|||||||
puts msg if $verbose
|
puts msg if $verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
|
$aborted = false
|
||||||
|
|
||||||
def command(*args)
|
def command(*args)
|
||||||
log "$ #{args.join(' ')}"
|
log "$ #{args.join(' ')}"
|
||||||
output, status = Open3.capture2e(*args)
|
output, status = Open3.capture2e(*args)
|
||||||
if !status.success?
|
if !status.success?
|
||||||
output.each_line do |line|
|
output = output.each_line { |line| " > #{line}" }
|
||||||
log " > #{line}"
|
unless $aborted
|
||||||
|
$aborted = true
|
||||||
|
warn "Command failed. Aborting."
|
||||||
|
raise output
|
||||||
|
else
|
||||||
|
warn output
|
||||||
|
exit 1
|
||||||
end
|
end
|
||||||
warn "Command failed. Aborting."
|
|
||||||
exit 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
usage = """Usage:
|
usage = <<~EOH
|
||||||
|
Usage:
|
||||||
#{$0} [-v|--verbose] [--replace grammar] url
|
#{$0} [-v|--verbose] [--replace grammar] url
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
#{$0} https://github.com/Alhadis/language-roff
|
#{$0} https://github.com/Alhadis/language-roff
|
||||||
#{$0} --replace sublime-apl https://github.com/Alhadis/language-apl
|
#{$0} --replace sublime-apl https://github.com/Alhadis/language-apl
|
||||||
"""
|
EOH
|
||||||
|
|
||||||
$replace = nil
|
$replace = nil
|
||||||
$verbose = true
|
$verbose = true
|
||||||
@@ -81,41 +89,71 @@ $url = ARGV[0]
|
|||||||
# No URL? Print a usage message and bail.
|
# No URL? Print a usage message and bail.
|
||||||
unless $url
|
unless $url
|
||||||
warn usage
|
warn usage
|
||||||
exit 1;
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exit early if docker isn't installed or running.
|
# Flags to track which changes should be reverted on an error
|
||||||
log "Checking docker is installed and running"
|
$gitmodules = File.read("#{ROOT}/.gitmodules")
|
||||||
command('docker', 'ps')
|
$git_config = File.read("#{ROOT}/.git/config")
|
||||||
|
$vendor_list = File.read("#{ROOT}/vendor/README.md")
|
||||||
|
|
||||||
# Ensure the given URL is an HTTPS link
|
def restore_configs
|
||||||
parts = parse_url $url
|
File.write("#{ROOT}/.gitmodules", $gitmodules)
|
||||||
https = "https://#{parts[:host]}/#{parts[:user]}/#{parts[:repo]}"
|
File.write("#{ROOT}/.git/config", $git_config)
|
||||||
repo_new = "vendor/grammars/#{parts[:repo]}"
|
|
||||||
repo_old = parse_submodule($replace) if $replace
|
|
||||||
|
|
||||||
Dir.chdir(ROOT)
|
|
||||||
|
|
||||||
if repo_old
|
|
||||||
log "Deregistering: #{repo_old}"
|
|
||||||
command('git', 'submodule', 'deinit', repo_old)
|
|
||||||
command('git', 'rm', '-rf', repo_old)
|
|
||||||
command('script/grammar-compiler', 'update', '-f')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
log "Registering new submodule: #{repo_new}"
|
begin
|
||||||
command('git', 'submodule', 'add', '-f', https, repo_new)
|
# Exit early if Docker isn't installed or running.
|
||||||
command('script/grammar-compiler', 'add', repo_new)
|
log "Checking Docker is installed and running"
|
||||||
|
command('docker', 'ps')
|
||||||
|
|
||||||
log "Confirming license"
|
# Ensure the given URL is an HTTPS link
|
||||||
if repo_old
|
parts = parse_url $url
|
||||||
command('script/licensed')
|
$https = "https://#{parts[:host]}/#{parts[:user]}/#{parts[:repo]}"
|
||||||
else
|
$repo_new = "vendor/grammars/#{parts[:repo]}"
|
||||||
repo_new = File.absolute_path(repo_new)
|
$repo_old = parse_submodule($replace) if $replace
|
||||||
command('script/licensed', '--module', repo_new)
|
|
||||||
|
Dir.chdir(ROOT)
|
||||||
|
|
||||||
|
if $repo_old
|
||||||
|
log "Deregistering: #{$repo_old}"
|
||||||
|
command('git', 'submodule', 'deinit', '-f', $repo_old)
|
||||||
|
command('git', 'rm', '-rf', $repo_old)
|
||||||
|
command('script/grammar-compiler', 'update', '-f')
|
||||||
|
end
|
||||||
|
|
||||||
|
log "Registering new submodule: #{$repo_new}"
|
||||||
|
command('git', 'submodule', 'add', '-f', $https, $repo_new)
|
||||||
|
command('script/grammar-compiler', 'add', $repo_new)
|
||||||
|
|
||||||
|
log "Confirming license"
|
||||||
|
if $repo_old
|
||||||
|
command('script/licensed')
|
||||||
|
else
|
||||||
|
repo_abs = File.absolute_path($repo_new)
|
||||||
|
command('script/licensed', '--module', repo_abs)
|
||||||
|
end
|
||||||
|
|
||||||
|
log "Updating grammar documentation in vendor/README.md"
|
||||||
|
command('bundle', 'exec', 'rake', 'samples')
|
||||||
|
command('script/sort-submodules')
|
||||||
|
command('script/list-grammars')
|
||||||
|
rescue => ex
|
||||||
|
log ex
|
||||||
|
if $repo_new
|
||||||
|
`git reset HEAD .gitmodules #{$repo_new}`
|
||||||
|
`git checkout -- vendor/licenses`
|
||||||
|
`rm -rf #{$repo_new}`
|
||||||
|
`rm -rf .git/modules/#{$repo_new}/`
|
||||||
|
restore_configs()
|
||||||
|
end
|
||||||
|
if $repo_old
|
||||||
|
`rm -rf #{$repo_old}`
|
||||||
|
`git submodule add -f "#{$https}", "#{$repo_old}"`
|
||||||
|
restore_configs()
|
||||||
|
end
|
||||||
|
File.write("#{ROOT}/vendor/README.md", $vendor_list)
|
||||||
|
`git reset HEAD vendor/licenses`
|
||||||
|
`git checkout -- vendor/licenses`
|
||||||
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
log "Updating grammar documentation in vendor/README.md"
|
|
||||||
command('bundle', 'exec', 'rake', 'samples')
|
|
||||||
command('script/sort-submodules')
|
|
||||||
command('script/list-grammars')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user