title: Converting a shell script to javascript using node js
body: <p>I have the following shell script which is created to modify plist of facebook plugin for cordova applications.</p>
  
  <pre><code>#!/bin/bash                                                                                                    
  
  # Put this in /hooks/after_prepare/
  PLIST=platforms/ios/*/*-Info.plist                                                                             
  
  cat &lt;&lt; EOF |                                                                                                   
  Add :NSAppTransportSecurity dict                                                                               
  Add :NSAppTransportSecurity:NSAllowsArbitraryLoads bool YES                                                    
  Add :NSAppTransportSecurity:NSExceptionDomains:facebook.com:NSIncludesSubdomains bool YES                      
  Add :NSAppTransportSecurity:NSExceptionDomains:facebook.com:NSThirdPartyExceptionRequiresForwardSecrecy bool NO
  Add :NSAppTransportSecurity:NSExceptionDomains:fbcdn.net:NSIncludesSubdomains bool YES                         
  Add :NSAppTransportSecurity:NSExceptionDomains:fbcdn.net:NSThirdPartyExceptionRequiresForwardSecrecy bool NO   
  Add :NSAppTransportSecurity:NSExceptionDomains:akamaihd.net:NSIncludesSubdomains bool YES                      
  Add :NSAppTransportSecurity:NSExceptionDomains:akamaihd.net:NSThirdPartyExceptionRequiresForwardSecrecy bool NO
  
  Delete :LSApplicationQueriesSchemes                                                                            
  
  Add :LSApplicationQueriesSchemes array                                                                         
  Add :LSApplicationQueriesSchemes:0 string  'fbapi'                                                             
  Add :LSApplicationQueriesSchemes:1 string  'fbapi20130214'                                                     
  Add :LSApplicationQueriesSchemes:2 string  'fbapi20130410'                                                     
  Add :LSApplicationQueriesSchemes:3 string  'fbapi20130702'                                                     
  Add :LSApplicationQueriesSchemes:4 string  'fbapi20131010'                                                     
  Add :LSApplicationQueriesSchemes:5 string  'fbapi20131219'                                                     
  Add :LSApplicationQueriesSchemes:6 string  'fbapi20140410'                                                     
  Add :LSApplicationQueriesSchemes:7 string  'fbapi20140116'                                                     
  Add :LSApplicationQueriesSchemes:8 string  'fbapi20150313'                                                     
  Add :LSApplicationQueriesSchemes:9 string  'fbapi20150629'                                                     
  Add :LSApplicationQueriesSchemes:10 string 'fbauth'                                                            
  Add :LSApplicationQueriesSchemes:11 string 'fbauth2'                                                           
  EOF                                                                                                            
  while read line                                                                                                
  do                                                                                                             
    /usr/libexec/PlistBuddy -c "$line" $PLIST                                                                    
  done                                                                                                           
  
  true
  </code></pre>
  
  <p>On the <a href="https://cordova.apache.org/docs/en/dev/guide/appdev/hooks/#link-non-javascript" rel="nofollow">cordova hooks guide</a> it is recommended that hooks be written in node.js so they are cross platform. Also, I am a windows user so this script does not work on my system. I referred <a href="http://www.2ality.com/2011/12/nodejs-shell-scripting.html" rel="nofollow">this</a> article to try and convert the shell script to javascript using node but i do not completely understand the shell script. How do I convert this script to execute in node?</p>
  
  <p><strong>EDIT</strong>
  I realise i need to explain what i did not understand in the script.
  First 3 lines i understand it is getting the file in variable PLIST</p>
  
  <p>4th line is the here tag.
  Until this point i can write javascript to read file from platforms/ios/<em>/</em>-Info.plist as</p>
  
  <pre><code>var fs = require ('fs');
  
  var PLIST = fs.readFileSync(fileName);
  </code></pre>
  
  <p>I dont understand what the next few lines do.
  The only part i understand is the delete :LSApplicationQueriesSchemes , It deletes some variable or a section named LSApplicationQueriesSchemes and probably rewrite with new values.</p>