Skip to content

Instantly share code, notes, and snippets.

@Bastiani
Created March 7, 2018 04:01
Show Gist options
  • Save Bastiani/f938bae5f99010a881b825c243246b04 to your computer and use it in GitHub Desktop.
Save Bastiani/f938bae5f99010a881b825c243246b04 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
const paths = [
{ path: 'graphql/connection/', tag: 'Connection' },
{ path: 'graphql/loader/', tag: 'Loader' },
{ path: 'graphql/mutation/', tag: 'Mutation' },
{ path: 'graphql/type/', tag: 'Type' }
];
function CreateFiles(projectDir, fileName) {
paths.map(({ path, tag }) => {
fs.writeFile(`${projectDir}${path}${fileName}${tag}.js`, null, function (err) {
if (err) {
return console.log(err);
}
console.log(`${path}${fileName} file was saved!`);
});
});
}
let cont = 0;
let values = [];
rl.setPrompt('Project Folder: ');
rl.prompt();
rl.on('line', function (line) {
cont += 1;
values = [...values, line];
if (cont === 2) {
CreateFiles(values[0], values[1]);
rl.close();
process.stdin.destroy();
} else {
rl.setPrompt('File Name: ');
rl.prompt();
}
});
@renatobenks-zz
Copy link

great! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment