Skip to content

Instantly share code, notes, and snippets.

@freshtonic
Created June 24, 2014 04:57
Show Gist options
  • Select an option

  • Save freshtonic/072f7fec12f0b221d0b0 to your computer and use it in GitHub Desktop.

Select an option

Save freshtonic/072f7fec12f0b221d0b0 to your computer and use it in GitHub Desktop.

Revisions

  1. freshtonic created this gist Jun 24, 2014.
    54 changes: 54 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/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