This is an automated email from the ASF dual-hosted git repository.

normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git


The following commit(s) were added to refs/heads/master by this push:
     new 23a1710  feat(android-studio): display app name as project name (#1173)
23a1710 is described below

commit 23a1710557be5ba63cad840f142fd78475c15d3f
Author: Shashank Agrawal <[email protected]>
AuthorDate: Sat Mar 27 18:36:26 2021 +0530

    feat(android-studio): display app name as project name (#1173)
    
    * (android) Feature: Write name of the Android app to .idea/.name for 
Android Studio #1172
    
    * Missing space before function parentheses.
    
    * Add test for writeNameForAndroidStudio #1172
    
    * Use ES6 for new code. Code DRYness in test spec. #1172
---
 bin/lib/create.js        | 15 +++++++++++++++
 spec/unit/create.spec.js | 21 +++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/bin/lib/create.js b/bin/lib/create.js
index 4b8eb92..96d7437 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -36,6 +36,7 @@ exports.copyScripts = copyScripts;
 exports.copyBuildRules = copyBuildRules;
 exports.writeProjectProperties = writeProjectProperties;
 exports.prepBuildFiles = prepBuildFiles;
+exports.writeNameForAndroidStudio = writeNameForAndroidStudio;
 
 function getFrameworkDir (projectPath, shared) {
     return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 
'CordovaLib');
@@ -198,6 +199,19 @@ function validateProjectName (project_name) {
 }
 
 /**
+ * Write the name of the app in "platforms/android/.idea/.name" so that 
Android Studio can show that name in the
+ * project listing. This is helpful to quickly look in the Android Studio 
listing if there are so many projects in
+ * Android Studio.
+ *
+ * https://github.com/apache/cordova-android/issues/1172
+ */
+function writeNameForAndroidStudio (project_path, project_name) {
+    const ideaPath = path.join(project_path, '.idea');
+    fs.ensureDirSync(ideaPath);
+    fs.writeFileSync(path.join(ideaPath, '.name'), project_name);
+}
+
+/**
  * Creates an android application with the given options.
  *
  * @param   {String}  project_path  Path to the new Cordova android project.
@@ -294,6 +308,7 @@ exports.create = function (project_path, config, options, 
events) {
             // Link it to local android install.
             exports.writeProjectProperties(project_path, target_api);
             exports.prepBuildFiles(project_path);
+            exports.writeNameForAndroidStudio(project_path, project_name);
             events.emit('log', generateDoneMessage('create', options.link));
         }).then(() => project_path);
 };
diff --git a/spec/unit/create.spec.js b/spec/unit/create.spec.js
index 621a531..dbe4c3e 100644
--- a/spec/unit/create.spec.js
+++ b/spec/unit/create.spec.js
@@ -132,6 +132,7 @@ describe('create', function () {
             spyOn(create, 'copyBuildRules');
             spyOn(create, 'writeProjectProperties');
             spyOn(create, 'prepBuildFiles');
+            spyOn(create, 'writeNameForAndroidStudio');
             revert_manifest_mock = create.__set__('AndroidManifest', 
Manifest_mock);
             spyOn(fs, 'existsSync').and.returnValue(false);
             spyOn(fs, 'copySync');
@@ -300,4 +301,24 @@ describe('create', function () {
             });
         });
     });
+
+    describe('writeNameForAndroidStudio', () => {
+        const project_path = path.join('some', 'path');
+        const appName = 'Test Cordova';
+
+        beforeEach(function () {
+            spyOn(fs, 'ensureDirSync');
+            spyOn(fs, 'writeFileSync');
+        });
+
+        it('should call ensureDirSync with path', () => {
+            create.writeNameForAndroidStudio(project_path, appName);
+            
expect(fs.ensureDirSync).toHaveBeenCalledWith(path.join(project_path, '.idea'));
+        });
+
+        it('should call writeFileSync with content', () => {
+            create.writeNameForAndroidStudio(project_path, appName);
+            
expect(fs.writeFileSync).toHaveBeenCalledWith(path.join(project_path, '.idea', 
'.name'), appName);
+        });
+    });
 });

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to