Skip to content

Commit 470507f

Browse files
Layman806debck
authored andcommitted
Added create folder option, fixes (#8) (#13)
* Added create folder option, fixes (#8) * Reverted changes to json files to try to not break build * Better add folder option, fixes (#8)
1 parent 31de479 commit 470507f

File tree

4 files changed

+1750
-942
lines changed

4 files changed

+1750
-942
lines changed

bin/app.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@ const chalk = require('chalk');
66
const header = require('../lib/header');
77
const question = require('../lib/question');
88
const create = require('../lib/create');
9+
const ifdir = require('../lib/ifdir');
910

1011
const main = async () => {
11-
header.init();
12+
header.init();
1213

13-
const input = await question.questions();
14-
// console.log(input);
15-
const { filename, extension } = input;
16-
// console.log(filename);
17-
create.create(filename, extension);
14+
const result = await ifdir.ask();
1815

19-
console.log(chalk.blue('File created successfully') + chalk.red('!!!'));
16+
const { isdir } = result;
17+
18+
if (isdir === 'd') {
19+
const dir_res = await ifdir.getdir();
20+
const { dirname } = dir_res;
21+
create.createdir(dirname);
22+
23+
return;
24+
} else {
25+
const input = await question.questions();
26+
// console.log(input);
27+
const { filename, extension } = input;
28+
// console.log(filename);
29+
create.create(filename, extension);
30+
console.log(chalk.blue('File created successfully') + chalk.red('!!!'));
31+
}
2032
};
2133

2234
main();

lib/create.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const shell = require('shelljs');
22

33
exports.create = (filename, extension) => {
4-
const filePath = `${process.cwd()}/${filename}.${extension}`;
5-
// console.log(filePath);
6-
shell.touch(filePath);
4+
const filePath = `${process.cwd()}/${filename}.${extension}`;
5+
// console.log(filePath);
6+
shell.touch(filePath);
77
};
8+
9+
exports.createdir = (dirname) => {
10+
const path = `${process.cwd()}/${dirname}`;
11+
shell.mkdir(path);
12+
}

lib/ifdir.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const inquirer = require('inquirer')
2+
3+
exports.ask = () => {
4+
const question = [
5+
{
6+
name: 'isdir',
7+
type: 'input',
8+
message: 'Do you want to create directory (d) or file (f) ? (d/f) ',
9+
},
10+
];
11+
12+
return inquirer.prompt(question);
13+
};
14+
15+
exports.getdir = () => {
16+
const getdir = [
17+
{
18+
name: 'dirname',
19+
type: 'input',
20+
message: 'Directory name: ',
21+
},
22+
];
23+
24+
return inquirer.prompt(getdir);
25+
};

0 commit comments

Comments
 (0)