mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-08 11:33:52 -05:00
Deduplicate polyglot files
This commit is contained in:
@@ -12,14 +12,6 @@ Dir.chdir(File.dirname(__dir__))
|
||||
|
||||
BASE_URL = 'https://raw.githubusercontent.com/github/linguist/master'
|
||||
|
||||
def read_section(name)
|
||||
section = File.read('polyglot.vim').split('""" ').find { |e| e.start_with?(name) }
|
||||
if section.nil?
|
||||
raise StandardError.new("Section not found: #{name}")
|
||||
end
|
||||
"\" Please do not edit this file directly, instead modify polyglot.vim or scripts/build\n" + section[(section.index("\n") + 1)..-1]
|
||||
end
|
||||
|
||||
def camelize(str)
|
||||
str.split(/[-_\.]/).map { |a| a.capitalize }.join("")
|
||||
end
|
||||
@@ -431,7 +423,7 @@ def rule_to_code(rule)
|
||||
end
|
||||
|
||||
def extract(packages)
|
||||
all_dirs = %w(syntax indent doc compiler autoload ftplugin ctags extras after)
|
||||
all_dirs = %w(syntax indent doc compiler ftplugin ctags extras after)
|
||||
|
||||
default_dirs = %w(
|
||||
syntax indent doc compiler autoload ftplugin ctags extras
|
||||
@@ -440,6 +432,12 @@ def extract(packages)
|
||||
|
||||
FileUtils.rm_rf(all_dirs)
|
||||
|
||||
for dir in Dir.glob("*", base: "autoload")
|
||||
if dir != "polyglot"
|
||||
FileUtils.rm_rf("autoload/" + dir)
|
||||
end
|
||||
end
|
||||
|
||||
output = []
|
||||
packages.map do |package|
|
||||
repo, branch, path, dir = parse_remote(package["remote"])
|
||||
@@ -582,17 +580,20 @@ def generate_ftdetect(packages, heuristics)
|
||||
output << "endif\n\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
show_warnings(all_filetypes, expected_filetypes)
|
||||
|
||||
ftdetect = read_section('ftdetect/polyglot.vim')
|
||||
ftdetect = File.read('ftdetect/polyglot.vim')
|
||||
|
||||
starting = '" DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE'
|
||||
ending = '" DO NOT EDIT CODE ABOVE, IT IS GENERATED WITH MAKEFILE'
|
||||
|
||||
File.write(
|
||||
'ftdetect/polyglot.vim',
|
||||
ftdetect.gsub('" scripts/build inserts here filetype detection autocommands') { output }
|
||||
ftdetect.gsub(/(?<=#{starting}\n)(.*)(?=#{ending})/m) { output }
|
||||
)
|
||||
|
||||
output = []
|
||||
output = ["\" DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE\n"]
|
||||
|
||||
for heuristic in heuristics
|
||||
output << <<~EOS
|
||||
@@ -616,8 +617,13 @@ def generate_ftdetect(packages, heuristics)
|
||||
|
||||
output << " \\ }"
|
||||
|
||||
autoload_script = read_section('autoload/polyglot/shebang.vim')
|
||||
File.write('autoload/polyglot/shebang.vim', autoload_script + "\n\n" + output)
|
||||
inject_code('autoload/polyglot/shebang.vim', output)
|
||||
end
|
||||
|
||||
def inject_code(path, code)
|
||||
header = "\" DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE\n"
|
||||
normal, generated = File.read(path).split(header)
|
||||
File.write(path, [normal, generated].join(header))
|
||||
end
|
||||
|
||||
def generate_tests(packages)
|
||||
@@ -734,7 +740,11 @@ def detect_filetypes(glob)
|
||||
end
|
||||
|
||||
def generate_plugins(packages)
|
||||
output = "let s:globs = {\n"
|
||||
output = <<~EOS
|
||||
" DO NOT EDIT CODE BELOW, IT IS GENERATED WITH MAKEFILE
|
||||
|
||||
let s:globs = {
|
||||
EOS
|
||||
|
||||
patterns = Hash.new { |h, k| h[k] = [] }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user