diff --git a/packages/cli/lib/project-generator.js b/packages/cli/lib/project-generator.js index f6f3c0d03ccd..95092839fbbf 100644 --- a/packages/cli/lib/project-generator.js +++ b/packages/cli/lib/project-generator.js @@ -7,6 +7,7 @@ const BaseGenerator = require('./base-generator'); const utils = require('./utils'); const chalk = require('chalk'); +const path = require('path'); module.exports = class ProjectGenerator extends BaseGenerator { // Note: arguments and options should be defined in the constructor. @@ -131,7 +132,7 @@ module.exports = class ProjectGenerator extends BaseGenerator { name: 'name', message: 'Project name:', when: this.projectInfo.name == null, - default: this.options.name || this.appname, + default: this.options.name || path.basename(process.cwd()), validate: utils.validate, }, { diff --git a/packages/cli/lib/utils.js b/packages/cli/lib/utils.js index b7f68a96e874..4690b429e262 100644 --- a/packages/cli/lib/utils.js +++ b/packages/cli/lib/utils.js @@ -103,8 +103,16 @@ exports.validateClassName = function(name) { /** * Validate project directory to not exist + * and check if the directory path is based on CWD */ exports.validateNotExisting = function(projDir) { + const invalidPath = projDir.split('/').includes('~'); + if (invalidPath) { + return util.format( + 'The path sholud be based on current directory: %s.', + projDir, + ); + } if (fs.existsSync(projDir)) { return util.format('Directory %s already exists.', projDir); } diff --git a/packages/cli/test/unit/utils.unit.js b/packages/cli/test/unit/utils.unit.js index c29d38508cf9..a2d015030b40 100644 --- a/packages/cli/test/unit/utils.unit.js +++ b/packages/cli/test/unit/utils.unit.js @@ -469,6 +469,17 @@ describe('Utils', () => { }); }); + describe('validateNotExisting', () => { + it.only("returns true on the path contains the root folder '~'", () => { + expect(utils.validateNotExisting('~/try/pathFromRoot')).to.be.eql( + 'The path sholud be based on current directory: ~/try/pathFromRoot.', + ); + }); + it.only("returns false on the path that folder's name contains hyphens", () => { + expect(utils.validateNotExisting('/try~/validPath')).to.be.True(); + }); + }); + describe('getDataSourceName', () => { it('returns false on missing dataSourceClass parameter', () => { expect(utils.getDataSourceName('src/datasources')).to.be.False();