Skip to content

Commit

Permalink
fix(cli): project path not basedon cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin committed Jun 26, 2019
1 parent 86fd23a commit 3ec96f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/cli/lib/project-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
},
{
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/test/unit/utils.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3ec96f2

Please sign in to comment.