mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-04 00:13:20 +08:00
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
This commit is contained in:
parent
774de78691
commit
23a1710557
@ -36,6 +36,7 @@ exports.copyScripts = copyScripts;
|
|||||||
exports.copyBuildRules = copyBuildRules;
|
exports.copyBuildRules = copyBuildRules;
|
||||||
exports.writeProjectProperties = writeProjectProperties;
|
exports.writeProjectProperties = writeProjectProperties;
|
||||||
exports.prepBuildFiles = prepBuildFiles;
|
exports.prepBuildFiles = prepBuildFiles;
|
||||||
|
exports.writeNameForAndroidStudio = writeNameForAndroidStudio;
|
||||||
|
|
||||||
function getFrameworkDir (projectPath, shared) {
|
function getFrameworkDir (projectPath, shared) {
|
||||||
return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
|
return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
|
||||||
@ -197,6 +198,19 @@ function validateProjectName (project_name) {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Creates an android application with the given options.
|
||||||
*
|
*
|
||||||
@ -294,6 +308,7 @@ exports.create = function (project_path, config, options, events) {
|
|||||||
// Link it to local android install.
|
// Link it to local android install.
|
||||||
exports.writeProjectProperties(project_path, target_api);
|
exports.writeProjectProperties(project_path, target_api);
|
||||||
exports.prepBuildFiles(project_path);
|
exports.prepBuildFiles(project_path);
|
||||||
|
exports.writeNameForAndroidStudio(project_path, project_name);
|
||||||
events.emit('log', generateDoneMessage('create', options.link));
|
events.emit('log', generateDoneMessage('create', options.link));
|
||||||
}).then(() => project_path);
|
}).then(() => project_path);
|
||||||
};
|
};
|
||||||
|
@ -132,6 +132,7 @@ describe('create', function () {
|
|||||||
spyOn(create, 'copyBuildRules');
|
spyOn(create, 'copyBuildRules');
|
||||||
spyOn(create, 'writeProjectProperties');
|
spyOn(create, 'writeProjectProperties');
|
||||||
spyOn(create, 'prepBuildFiles');
|
spyOn(create, 'prepBuildFiles');
|
||||||
|
spyOn(create, 'writeNameForAndroidStudio');
|
||||||
revert_manifest_mock = create.__set__('AndroidManifest', Manifest_mock);
|
revert_manifest_mock = create.__set__('AndroidManifest', Manifest_mock);
|
||||||
spyOn(fs, 'existsSync').and.returnValue(false);
|
spyOn(fs, 'existsSync').and.returnValue(false);
|
||||||
spyOn(fs, 'copySync');
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user