📜 ⬆️ ⬇️

Remove calls to the firebug console before laying out on produciton

Foreword

Recently, Habré has somehow become a few posts related to web development. I hope my post will look better due to the contrast :)

The article itself:


One of these days it was necessary to go and show the customer’s representative how to use a new feature built into the project.

Half an hour before the release, he prepared a new build, tested it.
')
Upon arrival, it turned out that the client feature does not work. It was unpleasant, in general.

It turned out that I forgot to delete the firebug console call ( console.log ..., etc.) in the event-handler function. In general, it often happens to me that I’m sticking something on the keyboard by accident, then on the contrary, I delete it - in short, the use of editors without syntax highlighting and (preferably) analyzing the structure of the code is contraindicated to me.

Since I use apache ant to deploy the application to the combat server, I added a small script that will remove all the console.log(/* something */) or console.dir(/* something */) calls from your code.

Actually, here it is:

  1. <? xml version = "1.0" encoding = "UTF-8" ? >
  2. < project name = "deploy" default = "stripFirebugConsoleCalls" basedir = "." >
  3. <! - a place where our folded still uncompressed and merged into one file ->
  4. < property name = "js" value = "js /" />
  5. <! - a regular schedule for catching unhealthy elements (shamelessly pulled from the yui builder, and slightly brought with a file)
  6. github.com/yui/builder/blob/master/componentbuild/shared/properties.xml 79th row ->
  7. < property name = "firebug.console.regex" value = "^. *? (?: console.log | console.dir). *? (?:; | \). *; | (?: \ r? \ n. *?) *? \). *;). *;?. *? \ r? \ n " />
  8. < property name = "firebug.console.regex.flags" value = "mg" />
  9. < property name = "firebug.console.regex.byline" value = "false" />
  10. < property name = "firebug.console.regex.replace" value = "" />
  11. <! - The target itself is also “inspired” by YUI Builder, the original is here:
  12. github.com/yui/builder/blob/master/componentbuild/3.x/module.xml 19th line ->
  13. < target name = "stripFirebugConsoleCalls" description = "Replace firebug console calls" >
  14. < replaceregexp byline = "$ {firebug.console.regex.byline}"
  15. match = "$ {firebug.console.regex}"
  16. replace = "$ {firebug.console.regex.replace}"
  17. flags = "$ {firebug.console.regex.flags}" >
  18. < fileset dir = "$ {js}" includes = "*. js" />
  19. </ replaceregexp >
  20. </ target >
  21. </ project >
* This source code was highlighted with Source Code Highlighter .

Use this: create an xml file with a name that is convenient for you (for example, boom.xml) and copy this code into it. Of course, it is worth correcting the value of the js variable, which indicates the folder with the js scripts that are not yet compressed. After that, start the hell machine with this command (for bash):

ant stripFirebugConsoleCalls -buildfile /path/to/boom.xml

That's all. Whereupon I leave to the next state of emergency or the end of the project.

Source: https://habr.com/ru/post/71586/


All Articles