node.js - Converting a shell script to javascript using node js -


i have following shell script created modify plist of facebook plugin cordova applications.

#!/bin/bash                                                                                                      # put in /hooks/after_prepare/ plist=platforms/ios/*/*-info.plist                                                                               cat << 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                                                                                                                                                                                                                /usr/libexec/plistbuddy -c "$line" $plist                                                                     done                                                                                                             true 

on cordova hooks guide recommended hooks written in node.js cross platform. also, windows user script not work on system. referred this article try , convert shell script javascript using node not understand shell script. how convert script execute in node?

edit realise need explain did not understand in script. first 3 lines understand getting file in variable plist

4th line here tag. until point can write javascript read file platforms/ios//-info.plist as

var fs = require ('fs');  var plist = fs.readfilesync(filename); 

i dont understand next few lines do. part understand delete :lsapplicationqueriesschemes , deletes variable or section named lsapplicationqueriesschemes , rewrite new values.

you can use plist package generate/update plist file. here general flow (granted, have 1 .plist file):

var fs = require('fs'); var path = require('path'); var glob = require('glob'); var plist = require('plist'); var _ = require('lodash');  var p = path.normalize(__dirname + '/platforms/ios/*/*-info.plist'); var files = glob.sync(p);  // if have 1 file var filename = files[0];  // parse original file var obj = plist.parse(fs.readfilesync(filename, 'utf8'));  // build object add var objtoadd = {   nsapptransportsecurity: {     nsallowsarbitraryloads: true,     nsexceptiondomains: {       'fbcdn.net': {         nsincludessubdomains: true,         nsthirdpartyexceptionrequiresforwardsecrecy: false       },       // ...     }   } }  // modify original loaded data 'delete :lsapplicationqueriesschemes' obj.lsapplicationqueriesschemes = [   'fbapi',   'fbapi20130214',   'fbapi20130410',   // ... ];  // merge 2 objects var finalobj = _.merge(obj, objtoadd);  // build plist var finalplist = plist.build(finalobj);  // write file fs.writefilesync(filename, finalplist);  

needless have compare bash generated file , nodejs 1 sure have same result.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -