Skip to content

Commit

Permalink
refactor(cli): extract helper logNamingIssues
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Sep 23, 2019
1 parent 78ebdc5 commit 6cce047
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 1 addition & 12 deletions packages/cli/lib/artifact-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,7 @@ module.exports = class ArtifactGenerator extends BaseGenerator {
* remind user the input might get changed if it contains _ or accented char
**/
promptWarningMsgForName() {
if (this.artifactInfo.name.includes('_')) {
this.log(
chalk.red('>>> ') +
`Underscores _ in the class name will get removed: ${this.artifactInfo.name}`,
);
}
if (this.artifactInfo.name.match(/[\u00C0-\u024F\u1E00-\u1EFF]/)) {
this.log(
chalk.red('>>> ') +
`Accented chars in the class name will get replaced: ${this.artifactInfo.name}`,
);
}
utils.logNamingIssues(this.artifactInfo.name, this.log.bind(this));
}

/**
Expand Down
16 changes: 16 additions & 0 deletions packages/cli/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

'use strict';

const chalk = require('chalk');
const debug = require('../lib/debug')('utils');
const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -103,6 +104,21 @@ exports.validateClassName = function(name) {
return util.format('Class name is invalid: %s', name);
};

exports.logNamingIssues = function(name, log) {
if (name.includes('_')) {
log(
chalk.red('>>> ') +
`Underscores _ in the class name will get removed: ${name}`,
);
}
if (name.match(/[\u00C0-\u024F\u1E00-\u1EFF]/)) {
log(
chalk.red('>>> ') +
`Accented chars in the class name will get replaced: ${name}`,
);
}
};

/**
* Validate project directory to not exist
*/
Expand Down

0 comments on commit 6cce047

Please sign in to comment.