setToastCapable.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(replace_with) > -1)
  43. return;
  44. result = data.replace(new RegExp(to_replace, 'g'), replace_with);
  45. fs.writeFileSync(filename, result, 'utf8');
  46. }
  47. // Paths to all manifest files where the permission needs to be set
  48. var manifests = [
  49. 'platforms/windows/package.phone.appxmanifest',
  50. 'platforms/windows/package.windows.appxmanifest',
  51. 'platforms/windows/package.windows80.appxmanifest'
  52. ];
  53. // Includes the permission
  54. for (var i = 0; i < manifests.length; i++) {
  55. replace(manifests[i], '<m3:VisualElements ', '<m3:VisualElements ToastCapable="true" ');
  56. }