Skip to content
Open
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
50 changes: 40 additions & 10 deletions bin/sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ exports.main = async() => {

const { isdir } = result;

if (isdir === 'd') {
const dirRes = await ifdir.getdir();
const { dirname } = dirRes;
create.createdir(dirname);
console.log(
chalk.blue('Directory created successfully') + chalk.red('!!!')
);
return 0;
}
if (isdir === 'f') {
// regex to check whether input string is file or directory
var isValid = (function(){
var rg1 = /^[^\\/:\*\?"<>\|]+$/; // forbidden characters \ / : * ? " < > |
var rg2 = /^\./; // cannot start with dot (.)
var rg3 = /^(nul|prn|con|lpt[0-9]|com[0-9])(\.|$)/i; // forbidden file names
return function isValid(fname){
return rg1.test(fname) && !rg2.test(fname) && !rg3.test(fname);
};
})();

if (isValid(isdir) === true){
const input = await question.questions();
// console.log(input);
const { filename, extension } = input;
Expand All @@ -33,6 +34,35 @@ exports.main = async() => {

return 0;
}

if (isValid(isdir) === false){
const dirRes = await ifdir.getdir();
const { dirname } = dirRes;
create.createdir(dirname);
console.log(
chalk.blue('Directory created successfully') + chalk.red('!!!'),
);
return 0;
}
// if (isdir === 'd') {
// const dirRes = await ifdir.getdir();
// const { dirname } = dirRes;
// create.createdir(dirname);
// console.log(
// chalk.blue('Directory created successfully') + chalk.red('!!!'),
// );
// return 0;
// } if (isdir === 'f') {
// const input = await question.questions();
// // console.log(input);
// const { filename, extension } = input;
// // console.log(filename);
// create.create(filename, extension);
// console.log(chalk.blue('File created successfully') + chalk.red('!!!'));

// return 0;
// }

if (isdir === 'dld') {
func.deletedirec();
} else if (isdir === 'df') {
Expand Down
Empty file added tmp
Empty file.