Skip to content

Added create folder option, fixes (#8) #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 12, 2019
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
26 changes: 19 additions & 7 deletions bin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@ const chalk = require('chalk');
const header = require('../lib/header');
const question = require('../lib/question');
const create = require('../lib/create');
const ifdir = require('../lib/ifdir');

const main = async () => {
header.init();
header.init();

const input = await question.questions();
// console.log(input);
const { filename, extension } = input;
// console.log(filename);
create.create(filename, extension);
const result = await ifdir.ask();

console.log(chalk.blue('File created successfully') + chalk.red('!!!'));
const { isdir } = result;

if (isdir === 'd') {
const dir_res = await ifdir.getdir();
const { dirname } = dir_res;
create.createdir(dirname);

return;
} else {
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('!!!'));
}
};

main();
11 changes: 8 additions & 3 deletions lib/create.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const shell = require('shelljs');

exports.create = (filename, extension) => {
const filePath = `${process.cwd()}/${filename}.${extension}`;
// console.log(filePath);
shell.touch(filePath);
const filePath = `${process.cwd()}/${filename}.${extension}`;
// console.log(filePath);
shell.touch(filePath);
};

exports.createdir = (dirname) => {
const path = `${process.cwd()}/${dirname}`;
shell.mkdir(path);
}
25 changes: 25 additions & 0 deletions lib/ifdir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const inquirer = require('inquirer')

exports.ask = () => {
const question = [
{
name: 'isdir',
type: 'input',
message: 'Do you want to create directory (d) or file (f) ? (d/f) ',
},
];

return inquirer.prompt(question);
};

exports.getdir = () => {
const getdir = [
{
name: 'dirname',
type: 'input',
message: 'Directory name: ',
},
];

return inquirer.prompt(getdir);
};
Loading