Skip to content

Commit

Permalink
feat: unify create default values & stop project name transform (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
ath0mas authored and wedgberto committed May 17, 2022
1 parent 2712a71 commit a8b5860
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 4 additions & 5 deletions lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand All @@ -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');
});
});

Expand All @@ -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 用用用用');
});
});

Expand Down

0 comments on commit a8b5860

Please sign in to comment.