Created
March 2, 2011 11:09
-
-
Save rarous/850783 to your computer and use it in GitHub Desktop.
Closure deps.js generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Write-JsDeps { | |
| param($root, $prefix, $exclusion) | |
| "// This file was autogenerated" | |
| "// Please do not edit." | |
| Get-ChildItem $root -Recurse -Include *.js -Exclude $exclusion | sort FullName | | |
| %{ Create-DepsLine $root $prefix $_.FullName } | |
| } | |
| function Create-DepsLine { | |
| param($root, $prefix, $path) | |
| $prefixedPath = Get-PrefixedPath $root $prefix $path | |
| $source = Get-Content $path -ReadCount 0 | |
| $provides = Parse 'provide' $source | |
| $requires = Parse 'require' $source | |
| "goog.addDependency('$prefixedPath', [$provides], [$requires]);" | |
| } | |
| $parsers = @{ provide = [regex] "goog\.provide\(([^\)]+)\)"; require = [regex] "goog\.require\(([^\)]+)\)" } | |
| function Parse { | |
| param($what, $from) | |
| ($parsers[$what].Matches($from ) | %{ $_.Groups[1].Value }) -join ', ' | |
| } | |
| function Get-PrefixedPath { | |
| $path.Replace($root, $prefix).Replace('\', '/').Replace('//', '/') | |
| } |
Author
jenže dynamickej lookup má pěknej (negativní) vliv na performance, potřebuju to mít co možná nejrychlejší :)
JJJJSK JKDJKJKDJDJKDJKDJK DJKLJKLJLKJKDJDLKJDJDKLJDKJLKDJKDJLKDJDJLK JDLJDKJDKJDKJDKJKJDKLJDLLLLLKJCKJCK JLCJCJCLLKJKJKJDJFKLJKJKJLKFKJFKJKLFJFKLJLKJ LJFJLJJJFLF
Tak to ti napsala dcera :) A teď já.
Dynamic lookup přece nemůže natolik zpomalit, ne? :) Každopádně pokud někdo chce velkou rychlost, tak PowerShell není dobrá volba (většinou).
Author
Nepotřebuju velkou rychlost, ale pokud to běží 5 s místo 9 s tak jsem radši. :) Ta původní verze (opis Pythonu) běžela něco kolem 20 s a to je strašně moc. :)
Jinak díky dcerce a že pozdravuju :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Zkouším. Poznámka:
PowerShell má dynamickej lookup proměnných. Takže $prefix si s klidným srdcem předávat nemusíš (a teď doufám, že se nepletu ;)).
K tomu array - tos myslel něco jako
function Parse {
param($what, $from)
($parsers[$what].Matches($from ) | %{ $_.Groups[1].Value }) -join ', '
}
?