Skip to content

Commit

Permalink
v1.0.8 (#87)
Browse files Browse the repository at this point in the history
* Towards #86 🎉

Change the path for mevn.json config file

* v1.0.8 release 🚀
  • Loading branch information
jamesgeorge007 authored and ajomadlabs committed Feb 28, 2019
1 parent aa915a0 commit 89a9b29
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 235 deletions.
4 changes: 2 additions & 2 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
lib/files/routes/*
lib/utils/createFile.js
lib/templates/routes/*
lib/utils/createFile.js
59 changes: 25 additions & 34 deletions lib/commands/codesplit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,39 @@ const chalk = require('chalk');
const shell = require('shelljs');

const { showBanner } = require('../external/banner');
const { configFileExists } = require('../utils/messages');

exports.asyncRender = (componentName) => {
showBanner();

if(!fs.existsSync('./mevn.json')){
console.log(chalk.red.bold('\n Make sure that you are having a valid MEVN stack project in path'));
process.exit(1);
}

let data = fs.readFileSync('./mevn.json', 'utf8');
let appname = JSON.parse(data);
shell.cd(appname.project_name);
shell.cd('client');
shell.cd('src');
shell.cd('router');

let componentNotFound = true;
let routerFile = fs.readFileSync('./index.js', 'utf8').toString().split('\n');

setTimeout(() => {

for(let index = 0; index < routerFile.length; index++){
// Checking whether the routes file already has the respective component
if(routerFile[index].includes(`${componentName}`)){
// Validating whether the respective component is already imported dynamically
if(routerFile[index].includes(`import ${componentName}`)){
routerFile[index] = `const ${componentName} = () => import('@/components/${componentName}')`;
componentNotFound = false;
break;
} else{
console.log(chalk.redBright(`\n ${componentName} component is already imported dynamically!`));
process.exit(1);
configFileExists();

shell.cd('client/src/router');

let componentNotFound = true;
let routerFile = fs.readFileSync('./index.js', 'utf8').toString().split('\n');
for (let index = 0; index < routerFile.length; index++) {
// Checking whether the routes file already has the respective component
if(routerFile[index].includes(`${componentName}`)){
// Validating whether the respective component is already imported dynamically
if(routerFile[index].includes(`import ${componentName}`)){
routerFile[index] = `const ${componentName} = () => import('@/components/${componentName}')`;
componentNotFound = false;
break;
} else {
console.log(chalk.redBright(`\n ${componentName} component is already imported dynamically!`));
process.exit(1);
}
}
}
if(!componentNotFound){
fs.writeFile('./index.js', routerFile.join('\n'), (err) => {
if(err){
throw err;
}
});
} else{
if (!componentNotFound) {
fs.writeFile('./index.js', routerFile.join('\n'), (err) => {
if (err) {
throw err;
}
});
} else {
console.log(chalk.yellowBright('\n Make sure that the component exists!'));
process.exit(1);
}
Expand Down
15 changes: 3 additions & 12 deletions lib/commands/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@ const chalk = require('chalk');
const createFile = require('../utils/createFile');

const { showBanner } = require('../external/banner');
const { configFileExists } = require('../utils/messages');

let componentsFile = fs.readFileSync(__dirname + '/../templates/components/component.vue', 'utf8');

exports.createComponent = (componentName) => {
showBanner();

if(!fs.existsSync('./mevn.json')){
console.log(chalk.red.bold('\n Make sure that you are having a valid MEVN stack project in path'));
process.exit(1);
}

let data = fs.readFileSync('./mevn.json', 'utf8');
let appname = JSON.parse(data);
shell.cd(appname.project_name);
shell.cd('client');
shell.cd('src');
shell.cd('components');

setTimeout(() => {
configFileExists();

shell.cd('client/src/components');
createFile(componentName + '.vue', componentsFile, { flag: 'wx' }, (err) => {
if (err) throw err;
console.log(chalk.green('\n File Created...!'));
Expand Down
42 changes: 22 additions & 20 deletions lib/commands/createConfig.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
'use strict';

const fs = require('fs');
const shell = require('shelljs');
const inquirer = require('inquirer');
const chalk = require('chalk');
const createFile = require('../utils/createFile');

const { showBanner } = require('../external/banner');
const { configFileExists } = require('../utils/messages');

exports.generateConfig = () => {
if(!fs.existsSync('./mevn.json')){
console.log(chalk.red.bold('\n Make sure that you are having a valid MEVN stack project in path'));
process.exit(1);
}
showBanner();
configFileExists();

let data = fs.readFileSync('./mevn.json', 'utf8');
let appname = JSON.parse(data);
shell.cd(appname.project_name);
shell.cd('server');
shell.cd('config');
setTimeout(() => {
shell.cd('server/config');

inquirer.prompt([{
name: 'db',
type: 'input',
message: 'Enter the url for the database : ',
}]).then((answers) => {
inquirer.prompt([{
name: 'db',
type: 'input',
message: 'Enter the url for the database : ',
}]).then((answer) => {

const content = 'module.exports = {\n \'url\': "' + answers.db + '"\n}';
const configFileContent = [
'{',
` "url": "${answer.db}"`,
'}'
];

createFile('./config.js', content, { flag: 'wx' }, (err) => {
if (err) throw err;
console.log(chalk.yellow('File Created...!'));
createFile('./config.js', configFileContent.join('\n').toString(), { flag: 'wx' }, (err) => {
if (err) throw err;
console.log(chalk.yellow('File Created...!'));
});
});
});
}, 200);
};
34 changes: 16 additions & 18 deletions lib/commands/createController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@ const os = require('os');
const chalk = require('chalk');
const createFile = require('../utils/createFile');

const { showBanner } = require('../external/banner');
const { configFileExists } = require('../utils/messages');

let controllersFile = fs.readFileSync(__dirname + '/../templates/controllers/user_controller.js', 'utf8');

exports.generateController = () => {
if(!fs.existsSync('./mevn.json')){
console.log(chalk.red.bold('\n Make sure that you are having a valid MEVN stack project in path'));
process.exit(1);
}
showBanner();
configFileExists();

let data = fs.readFileSync('./mevn.json', 'utf8');
let appname = JSON.parse(data);
shell.cd(appname.project_name);
shell.cd('server');
shell.cd('controllers');
setTimeout(() => {
shell.cd('server/controllers');

if(os.type() === 'Linux' || os.type() === 'darwin'){
shell.exec('rm default.js', {silent: true}, () => {});
} else{
shell.exec('del default.js', {silent: true}, () => {});
}
let removeCmd = os.type() === 'Windows_NT' ? 'del' : 'rm';
if (fs.existsSync('./default.js')) {
shell.exec(`${removeCmd} default.js`);
}

createFile('./user_controller.js', controllersFile, { flag: 'wx' }, (err) => {
if (err) throw err;
console.log(chalk.yellow('File Created...!'));
});
createFile('./user_controller.js', controllersFile, { flag: 'wx' }, (err) => {
if (err) throw err;
console.log(chalk.yellow('File Created...!'));
});
}, 200);
};
36 changes: 17 additions & 19 deletions lib/commands/createModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@ const chalk = require('chalk');
const os = require('os');
const createFile = require('../utils/createFile');

const { showBanner } = require('../external/banner');
const { configFileExists } = require('../utils/messages');

let userSchema = fs.readFileSync(__dirname + '/../templates/models/user_schema.js', 'utf8');

exports.generateModel = () => {
if(!fs.existsSync('./mevn.json')){
console.log(chalk.red.bold('\n Make sure that you are having a valid MEVN stack project in path'));
process.exit(1);
}

let data = fs.readFileSync('./mevn.json', 'utf8');
let appname = JSON.parse(data);
shell.cd(appname.project_name);
shell.cd('server');
shell.cd('models');
showBanner();
configFileExists();

if(os.type() === 'Linux' || os.type() === 'darwin'){
shell.exec('rm default.js', {silent: true}, () => {});
} else{
shell.exec('del default.js', {silent: true}, () => {});
}
setTimeout(() => {
shell.cd('server/models');

createFile('./user_schema.js', userSchema, { flag: 'wx' }, (err) => {
if (err) throw err;
console.log(chalk.yellow('File Created...!'));
});
let removeCmd = os.type() === 'Windows_NT' ? 'del' : 'rm';
if (fs.existsSync('./default.js')) {
shell.exec(`${removeCmd} default.js`);
}

createFile('./user_schema.js', userSchema, { flag: 'wx' }, (err) => {
if (err) throw err;
console.log(chalk.yellow('File Created...!'));
});
}, 200);
};
14 changes: 4 additions & 10 deletions lib/commands/createRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ const shell = require('shelljs');
const inquirer = require('inquirer');
const chalk = require('chalk');
const createFile = require('../utils/createFile');
const { showBanner } = require('../external/banner');
const logUpdate = require('log-update');
const elegantSpinner = require('elegant-spinner');
const cmd = require('node-cmd');

const { showBanner } = require('../external/banner');
const { configFileExists } = require('../utils/messages');

let routesPath = '/../templates/routes/';
let routesFile = fs.readFileSync(__dirname + '/../templates/routes/index.js', 'utf8');
let routesFileWithPassPort = fs.readFileSync(__dirname + '/../templates/routes/index_with_passport.js', 'utf8');
Expand Down Expand Up @@ -100,17 +102,9 @@ exports.generateRoute = () => {
showBanner();

setTimeout(() => {
configFileExists();
console.log('\n');

if(!fs.existsSync('./mevn.json')){
console.log(chalk.red.bold('\n Make sure that you are having a valid MEVN stack project in path'));
process.exit(1);
}

let data = fs.readFileSync('./mevn.json', 'utf8');
let appname = JSON.parse(data);
shell.cd(appname.project_name);

inquirer.prompt(questions)
.then(answer => {
if (answer.passportAuth) {
Expand Down
Loading

0 comments on commit 89a9b29

Please sign in to comment.