setToastCapable.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env node
  2. /*
  3. * Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
  4. *
  5. * @APPPLANT_LICENSE_HEADER_START@
  6. *
  7. * This file contains Original Code and/or Modifications of Original Code
  8. * as defined in and that are subject to the Apache License
  9. * Version 2.0 (the 'License'). You may not use this file except in
  10. * compliance with the License. Please obtain a copy of the License at
  11. * http://opensource.org/licenses/Apache-2.0/ and read it before using this
  12. * file.
  13. *
  14. * The Original Code and all software distributed under the License are
  15. * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  16. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  17. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  19. * Please see the License for the specific language governing rights and
  20. * limitations under the License.
  21. *
  22. * @APPPLANT_LICENSE_HEADER_END@
  23. */
  24. // Hook sets ToastCapable on true to enable local-notifications
  25. var fs = require('fs'),
  26. rootdir = process.argv[2];
  27. if (!rootdir)
  28. return;
  29. /**
  30. * Replaces a string with another one in a file.
  31. *
  32. * @param {String} path
  33. * Absolute or relative file path from cordova root project.
  34. * @param {String} to_replace
  35. * The string to replace.
  36. * @param {String}
  37. * The string to replace with.
  38. */
  39. function replace (filename, to_replace, replace_with) {
  40. var data = fs.readFileSync(filename, 'utf8'),
  41. result;
  42. if (data.indexOf('ToastCapable') > -1)
  43. return;
  44. result = data.replace(new RegExp(to_replace, 'g'), replace_with);
  45. fs.writeFileSync(filename, result, 'utf8');
  46. }
  47. // Set ToastCapable for Windows Phone
  48. replace('platforms/windows/package.phone.appxmanifest', '<m3:VisualElements', '<m3:VisualElements ToastCapable="true"');
  49. // Set ToastCapable for Windows 8.1
  50. replace('platforms/windows/package.windows.appxmanifest', '<m2:VisualElements', '<m2:VisualElements ToastCapable="true"');
  51. // Set ToastCapable for Windows 8.0
  52. replace('platforms/windows/package.windows80.appxmanifest', '<VisualElements', '<VisualElements ToastCapable="true"');