From fdbf542858ae8d72d146e319a6001732ce1d2449 Mon Sep 17 00:00:00 2001 From: Agnes Lin Date: Wed, 26 Jun 2019 10:14:00 -0400 Subject: [PATCH] fix(cli): project path not basedon cwd --- packages/cli/lib/project-generator.js | 3 ++- packages/cli/lib/utils.js | 8 ++++++++ packages/cli/test/unit/utils.unit.js | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) 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..710ef407f15e 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 should 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..08745b6e89d5 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("returns true on the path contains the root folder '~'", () => { + expect(utils.validateNotExisting('~/try/pathFromRoot')).to.be.eql( + 'The path should be based on current directory: ~/try/pathFromRoot.', + ); + }); + it("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();