Skip to content

Commit

Permalink
improve regex and clean it up
Browse files Browse the repository at this point in the history
  • Loading branch information
Borzik committed Sep 27, 2016
1 parent 8cb2e6e commit d45cf46
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,16 @@ def map_dependencies
basename = File.basename path
file = File.read path

matchdata = file.match(/define\(.*\[[\S\s]+\]\, factory \);/m)
matchdata = file.match(/define\(\s*\[\s*([\"\.\/\,\w\s-\:]+)\]/m)

# fallback for core.js, which doesn't refer to factory
matchdata ||= file.match(/define\(.*\[[\S\s]+\](\, factory )?.*\);/m)

# skip if there's no dependencies
next if matchdata.nil?

# dirty string, with define([], factory) wrapping, comments and newlines
deps_str = matchdata[0]

# remove define([], factory) wrap
deps = deps_str.match(/\[[\s\S]*\]/)[0]
deps = matchdata[1]

# remove lines with comments
deps = deps.gsub(/\/\/.+\s/, "")

# remove all non-path symbols, leaving only commas, dots and shashes
# remove all non-path symbols
deps = deps.gsub(/[\r\n\t\"\[\]\s]/, "")

deps_paths = deps.split(',')
Expand Down

0 comments on commit d45cf46

Please sign in to comment.