Skip to content

Instantly share code, notes, and snippets.

@freshtonic
Created June 24, 2014 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freshtonic/072f7fec12f0b221d0b0 to your computer and use it in GitHub Desktop.
Save freshtonic/072f7fec12f0b221d0b0 to your computer and use it in GitHub Desktop.
Show the services, factories, filters, directives, controllers etc exported by an angular module (by regexing the source)
#!/usr/bin/env ruby
# Reads your JS on STDIN, minified JS is OK as angular methods names should be preserved.
# The reason this exists is because I was getting an erroroneous error message about missing
# module 'ngLocale', but googling that indicated that it really meant that one of my dependencies
# was unresolved. A change to the JS concatenation had caused this error.
# In order to resolve the error I wrote a script to parse the old minified and new minified JS to dump
# declared services to STDOUT. I could then see what was missing.
# Prints out something like the following:
# SERVICE
# sportsBetBuilderService
# FACTORY
# BaseSportsBetBuilderState
# BetSlip
# ConfirmState
# InterceptedState
# InterceptRejectedState
# RejectedState
# SoldState
# CONSTANT
# $moment
# VALUE
# CONTROLLER
# ngModel
# ngModel
# FILTER
# dateOnly
# timeOnly
content = STDIN.read
things = %w(service factory constant value controller filter)
matches = things.inject({}) do |hash,thing|
hash[thing] = content.scan(Regexp.new("\\.#{thing}\\([\"'][^\"']+[\"']")).map do |match|
begin
match[/["'][^"']+["']/][1..-2]
rescue
STDERR.puts "WTF: [#{match}]"
end
end
hash
end
things.each do |thing|
puts thing.upcase
matches[thing].sort{|a,b| a.downcase <=> b.downcase}.each{|match| puts " #{match}"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment