Skip to content

Commit

Permalink
added a step to check if the project name has special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdas committed May 16, 2024
1 parent 46c039a commit 077c5a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const { removeComments } = require("./parse");
const fs = require("fs");
const path = require("path");
const { has_special_characters, log } = require("./utils");

const distFolder = process.env.DIST_FOLDER || "build";

Expand Down Expand Up @@ -41,12 +42,19 @@ function generate_data_json() {
metadataFields[key] = fileContent[key];
});

// Check if project's name has special characters
if (has_special_characters(fileContent.name)) {
log.error("The project name cannot contain special characters.");
process.exit(1);
}

// Get the project name
const projectName = fileContent.name.replaceAll(" ", "-").toLowerCase();

// data.json structure
const data = {
widget: {
[fileContent.isIndex
? "Index"
: fileContent.name.replaceAll(" ", "-").toLowerCase()]: {
[fileContent.isIndex ? "Index" : projectName]: {
metadata: {
...metadataFields,
},
Expand Down
6 changes: 6 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ const is_script_file = (fileDir) =>
fileDir.endsWith("jsx") ||
fileDir.endsWith("js");

const has_special_characters = (str) => {
const regex = /[^\w\s]/g;
return regex.test(str);
};

module.exports = {
create_dist,
for_rfile,
Expand All @@ -214,4 +219,5 @@ module.exports = {
create_new_name,
reset_name_counter,
is_script_file,
has_special_characters,
};

0 comments on commit 077c5a6

Please sign in to comment.