Guest User

Untitled

a guest
Apr 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/usr/bin/env node
  2. var fs = require('fs');
  3. var path = require('path');
  4.  
  5. console.log('Running hook...');
  6.  
  7. // TARGET is the variable that you have to specify
  8. // If you run TARGET=prod cordova build
  9. // The hook will look for a file named prod.js inside the config directory
  10. if (process.env.TARGET) {
  11. var srcFile = path.join('config', process.env.TARGET + '.js');
  12.  
  13. // Specify the files you would like to replace.
  14. // NOTE: The android path is for Cordova 7.
  15. // If you're running an older version, the path is:
  16. // "platforms/android/assets/www/index.html"
  17. var configFilesToReplace = {
  18. android: 'platforms/android/app/src/main/assets/www/js/defaults.js',
  19. ios: 'platforms/ios/www/js/defaults.js',
  20. };
  21.  
  22. for (var platform in configFilesToReplace) {
  23. console.log(
  24. 'Modifying config for platform ' +
  25. platform +
  26. ', TARGET=' +
  27. process.env.TARGET
  28. );
  29. var destFile = path.join(configFilesToReplace[platform]);
  30.  
  31. if (!fs.existsSync(srcFile)) {
  32. // Throw an error if the file does not exist
  33. throw 'Missing config file: ' + srcFile;
  34. } else {
  35. console.log('copying ' + srcFile + ' to ' + destFile);
  36. // The command that replaces the contents of the file
  37. fs.createReadStream(srcFile).pipe(fs.createWriteStream(destFile));
  38. }
  39. }
  40. } else {
  41. // If not target was specified, do nothing.
  42. console.log('TARGET environment variable is not set. Using default values.');
  43. }
Add Comment
Please, Sign In to add comment