AndroidStudio.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * This is a simple routine that checks if project is an Android Studio Project
  3. *
  4. * @param {String} root Root folder of the project
  5. */
  6. /*jshint esnext: false */
  7. var path = require('path');
  8. var fs = require('fs');
  9. var CordovaError = require('cordova-common').CordovaError;
  10. module.exports.isAndroidStudioProject = function isAndroidStudioProject(root) {
  11. var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res', 'project.properties', 'platform_www'];
  12. var androidStudioFiles = ['app', 'gradle', 'app/src/main/res'];
  13. // assume it is an AS project and not an Eclipse project
  14. var isEclipse = false;
  15. var isAS = true;
  16. if(!fs.existsSync(root)) {
  17. throw new CordovaError('AndroidStudio.js:inAndroidStudioProject root does not exist: ' + root);
  18. }
  19. // if any of the following exists, then we are not an ASProj
  20. eclipseFiles.forEach(function(file) {
  21. if(fs.existsSync(path.join(root, file))) {
  22. isEclipse = true;
  23. }
  24. });
  25. // if it is NOT an eclipse project, check that all required files exist
  26. if(!isEclipse) {
  27. androidStudioFiles.forEach(function(file){
  28. if(!fs.existsSync(path.join(root, file))) {
  29. console.log('missing file :: ' + file);
  30. isAS = false;
  31. }
  32. });
  33. }
  34. return (!isEclipse && isAS);
  35. };