Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

[TypeScript][Generator] Add special character validation #2033

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const templateName = "sample-assistant";
const languages = [`zh`, `de`, `en`, `fr`, `it`, `es`];
let assistantGenerationPath = process.cwd();
let isAlreadyCreated = false;
let containsSpecialCharacter = false;
let finalAssistantName = "";

const languagesChoice = [
{
Expand Down Expand Up @@ -254,6 +256,11 @@ module.exports = class extends Generator {
/([^a-z0-9-]+)/gi,
``
);

if (this.props.assistantName != assistantName) {
finalAssistantName = assistantName;
containsSpecialCharacter = true;
}

assistantGenerationPath = path.join(assistantGenerationPath, assistantName);
if (this.props.assistantGenerationPath !== undefined) {
Expand Down Expand Up @@ -328,6 +335,9 @@ module.exports = class extends Generator {
);
} else {
this.spawnCommandSync("npm run build", []);
if (containsSpecialCharacter) {
this.log(chalk.yellow(`\nYour virtual assistant name (${this.props.assistantName}) had special characters, it was changed to '${finalAssistantName}'`));
}
this.log(chalk.green(`------------------------ `));
this.log(chalk.green(` Your new assistant is ready! `));
this.log(chalk.green(`------------------------ `));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const templateName = "sample-skill";
const languages = [`zh`, `de`, `en`, `fr`, `it`, `es`];
let skillGenerationPath = process.cwd();
let isAlreadyCreated = false;

let containsSpecialCharacter = false;
let finalSkillName = "";
const languagesChoice = [
{
name: "Chinese",
Expand Down Expand Up @@ -256,6 +257,11 @@ module.exports = class extends Generator {
skillName
);
}

if (this.props.skillName != skillName) {
finalSkillName = skillName;
containsSpecialCharacter = true;
}

const skillNameCamelCase = _camelCase(this.props.skillName).replace(
/([^a-z0-9-]+)/gi,
Expand Down Expand Up @@ -320,6 +326,9 @@ module.exports = class extends Generator {
);
} else {
this.spawnCommandSync("npm run build", []);
if (containsSpecialCharacter) {
this.log(chalk.yellow(`\nYour skill name (${this.props.skillName}) had special characters, it was changed to '${finalSkillName}'`));
}
this.log(chalk.green(`------------------------ `));
this.log(chalk.green(` Your new skill is ready! `));
this.log(chalk.green(`------------------------ `));
Expand Down