mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
feat: unify create
default values & stop project name transform (#1213)
This commit is contained in:
parent
09c75237d9
commit
13bd3f4a9f
@ -197,15 +197,14 @@ exports.create = function (project_path, config, options, events) {
|
||||
options = options || {};
|
||||
|
||||
// Set default values for path, package and name
|
||||
project_path = path.relative(process.cwd(), (project_path || 'CordovaExample'));
|
||||
project_path = path.relative(process.cwd(), project_path);
|
||||
// Check if project already exists
|
||||
if (fs.existsSync(project_path)) {
|
||||
return Promise.reject(new CordovaError('Project already exists! Delete and recreate'));
|
||||
}
|
||||
|
||||
var package_name = config.android_packageName() || config.packageName() || 'my.cordova.project';
|
||||
var project_name = config.name()
|
||||
? config.name().replace(/[^\w.]/g, '_') : 'CordovaExample';
|
||||
var package_name = config.android_packageName() || config.packageName() || 'io.cordova.helloCordova';
|
||||
var project_name = config.name() || 'Hello Cordova';
|
||||
|
||||
var safe_activity_name = config.android_activityName() || options.activityName || 'MainActivity';
|
||||
var target_api = check_reqs.get_target(project_path);
|
||||
@ -215,7 +214,7 @@ exports.create = function (project_path, config, options, events) {
|
||||
.then(function () {
|
||||
return exports.validateProjectName(project_name);
|
||||
}).then(function () {
|
||||
// Log the given values for the project
|
||||
// Log the given values for the project
|
||||
events.emit('log', 'Creating Cordova project for the Android platform:');
|
||||
events.emit('log', '\tPath: ' + project_path);
|
||||
events.emit('log', '\tPackage: ' + package_name);
|
||||
|
@ -147,10 +147,10 @@ describe('create', function () {
|
||||
});
|
||||
|
||||
describe('parameter values and defaults', function () {
|
||||
it('should have a default package name of my.cordova.project', () => {
|
||||
it('should have a default package name of io.cordova.helloCordova', () => {
|
||||
config_mock.packageName.and.returnValue(undefined);
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(create.validatePackageName).toHaveBeenCalledWith('my.cordova.project');
|
||||
expect(create.validatePackageName).toHaveBeenCalledWith('io.cordova.helloCordova');
|
||||
});
|
||||
});
|
||||
|
||||
@ -161,10 +161,10 @@ describe('create', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should have a default project name of CordovaExample', () => {
|
||||
it('should have a default project name of Hello Cordova', () => {
|
||||
config_mock.name.and.returnValue(undefined);
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(create.validateProjectName).toHaveBeenCalledWith('CordovaExample');
|
||||
expect(create.validateProjectName).toHaveBeenCalledWith('Hello Cordova');
|
||||
});
|
||||
});
|
||||
|
||||
@ -175,10 +175,10 @@ describe('create', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should replace any non-word characters (including unicode and spaces) in the ConfigParser-provided project name with underscores', () => {
|
||||
it('should keep non-word characters (including unicode and spaces) in the ConfigParser-provided project name', () => {
|
||||
config_mock.name.and.returnValue('応応応応 hello 用用用用');
|
||||
return create.create(project_path, config_mock, {}, events_mock).then(() => {
|
||||
expect(create.validateProjectName).toHaveBeenCalledWith('_____hello_____');
|
||||
expect(create.validateProjectName).toHaveBeenCalledWith('応応応応 hello 用用用用');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user