Skip to content

Commit

Permalink
Better project hierarchy 🎉
Browse files Browse the repository at this point in the history
Change file naming conventions and couple of code cleanup
  • Loading branch information
jamesgeorge007 committed Feb 26, 2019
1 parent d193637 commit aa915a0
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 98 deletions.
48 changes: 24 additions & 24 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,67 @@ const program = require('commander');
const chalk = require('chalk');

// Initialize Command variables
const versionfn = require('../lib/commands/versionlib');
const initfn = require('../lib/commands/initlib');
const modelsfn = require('../lib/commands/modelslib');
const controllersfn = require('../lib/commands/controllerslib');
const componentsfn = require('../lib/commands/componentslib');
const codesplitfn = require('../lib/commands/codesplitlib');
const addPackagefn = require('../lib/commands/addPackagelib');
const routesfn = require('../lib/commands/routeslib');
const configfn = require('../lib/commands/configlib');
const { versionInfo } = require('../lib/commands/version');
const { initializeProject } = require('../lib/commands/init');
const { generateModel } = require('../lib/commands/createModel');
const { generateController } = require('../lib/commands/createController');
const { createComponent } = require('../lib/commands/component');
const { asyncRender } = require('../lib/commands/codesplit');
const { addPackage } = require('../lib/commands/package');
const { generateRoute } = require('../lib/commands/createRoute');
const { generateConfig } = require('../lib/commands/createConfig');
const { setupServer } = require('../lib/run/server');
const { setupClient } = require('../lib/run/client');
const dockerfn = require('../lib/deploy/docker');
const git_repofn = require('../lib/deploy/git_repo');
const dplyfn = require('../lib/deploy/docker_dply');
const { dockerize } = require('../lib/deploy/docker');
const { createRepo } = require('../lib/deploy/gitRepo');
const { deploy } = require('../lib/deploy/herokuDeploy');

// Define Commands in CLI TOOL

program
.command('version')
.description('Outputs version along with local development environment information')
.action(versionfn);
.action(versionInfo);

program
.command('init <appname>')
.description('To init the project')
.action(initfn);
.action(initializeProject);

program
.command('create:controller')
.description('To create controllers-file')
.action(controllersfn);
.action(generateController);

program
.command('create:component <componentname>')
.description('To create component-file')
.action(componentsfn);
.action(createComponent);

program
.command('codesplit <componentname>')
.description('To code split the required component')
.action(codesplitfn);
.action(asyncRender);

program
.command('create:route')
.description('To create router-file')
.action(routesfn);
.action(generateRoute);

program
.command('create:config')
.description('To create configuration file for database')
.action(configfn);
.action(generateConfig);

program
.command('create:model')
.description('To create models-file')
.action(modelsfn);
.action(generateModel);

program
.command('add:package')
.description('To add a new package to the project')
.action(addPackagefn);
.action(addPackage);

program
.command('run:client')
Expand All @@ -82,17 +82,17 @@ program
program
.command('dockerize')
.description('To dockerize the app')
.action(dockerfn);
.action(dockerize);

program
.command('deploy')
.description('To deploy the app to Heroku')
.action(dplyfn);
.action(deploy);

program
.command('create:git-repo')
.description('To create a GitHub repository and fire the first commit')
.action(git_repofn);
.action(createRepo);

program
.arguments('<command>')
Expand Down
6 changes: 2 additions & 4 deletions lib/commands/codesplitlib.js → lib/commands/codesplit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const fs = require('fs');
const chalk = require('chalk');
const shell = require('shelljs');

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

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

if(!fs.existsSync('./mevn.json')){
Expand Down Expand Up @@ -52,5 +52,3 @@ let codesplitfn = (componentName) => {
}
}, 100);
};

module.exports = codesplitfn;
9 changes: 3 additions & 6 deletions lib/commands/componentslib.js → lib/commands/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ const shell = require('shelljs');
const chalk = require('chalk');
const createFile = require('../utils/createFile');

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

const showBanner = require('../external/banner');
let componentsFile = fs.readFileSync(__dirname + '/../templates/components/component.vue', 'utf8');

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

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

if(!fs.existsSync('./mevn.json')){
Expand Down Expand Up @@ -74,5 +73,3 @@ let componentsfn = (componentName) => {


};

module.exports = componentsfn;
5 changes: 1 addition & 4 deletions lib/commands/configlib.js → lib/commands/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const inquirer = require('inquirer');
const chalk = require('chalk');
const createFile = require('../utils/createFile');

let configfn = () => {

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);
Expand All @@ -33,5 +32,3 @@ let configfn = () => {
});
});
};

module.exports = configfn;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ const os = require('os');
const chalk = require('chalk');
const createFile = require('../utils/createFile');

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

let controllersfn = () => {
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);
Expand All @@ -32,5 +31,3 @@ let controllersfn = () => {
console.log(chalk.yellow('File Created...!'));
});
};

module.exports = controllersfn;
7 changes: 2 additions & 5 deletions lib/commands/modelslib.js → lib/commands/createModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ const chalk = require('chalk');
const os = require('os');
const createFile = require('../utils/createFile');

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

let modelsfn = () => {
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);
Expand All @@ -32,5 +31,3 @@ let modelsfn = () => {
console.log(chalk.yellow('File Created...!'));
});
};

module.exports = modelsfn;
14 changes: 5 additions & 9 deletions lib/commands/routeslib.js → lib/commands/createRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const shell = require('shelljs');
const inquirer = require('inquirer');
const chalk = require('chalk');
const createFile = require('../utils/createFile');
const showBanner = require('../external/banner');
const { showBanner } = require('../external/banner');
const logUpdate = require('log-update');
const elegantSpinner = require('elegant-spinner');
const cmd = require('node-cmd');

let routesPath = '/../files/routes/';
let routesFile = fs.readFileSync(__dirname + '/../files/routes/index.js', 'utf8');
let routesFileWithPassPort = fs.readFileSync(__dirname + '/../files/routes/index_with_passport.js', 'utf8');
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');
let routesFileWithSocialMediaAuth = fs.readFileSync(`${__dirname}${routesPath}index_with_social_media_auth.js`, 'utf8');
let facebookRoutesFile = fs.readFileSync(`${__dirname}${routesPath}FacebookRoutes.js`, 'utf8');
let twitterRoutesFile = fs.readFileSync(`${__dirname}${routesPath}TwitterRoutes.js`, 'utf8');
Expand Down Expand Up @@ -96,12 +96,10 @@ let installPassportPackages = (withSocialMediaAuth, spinnerToClear) => {

};

let routesfn = () => {

exports.generateRoute = () => {
showBanner();

setTimeout(() => {

console.log('\n');

if(!fs.existsSync('./mevn.json')){
Expand Down Expand Up @@ -135,5 +133,3 @@ let routesfn = () => {
});
}, 1000);
};

module.exports = routesfn;
7 changes: 2 additions & 5 deletions lib/commands/initlib.js → lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const logUpdate = require('log-update');
const os = require('os');
const Table = require('cli-table');
const validate = require('validate-npm-package-name');
const showBanner = require('../external/banner');
const { showBanner } = require('../external/banner');
const boilerplate = require('../../config.json');

let serverCommands = new Table();
Expand Down Expand Up @@ -123,8 +123,7 @@ let fetchTemplate = (template) => {
}
};

let initfn = (appName) => {

exports.initializeProject = (appName) => {
showBanner();
console.log('\n');

Expand Down Expand Up @@ -188,5 +187,3 @@ let initfn = (appName) => {
}, 1000);

};

module.exports = initfn;
9 changes: 3 additions & 6 deletions lib/commands/addPackagelib.js → lib/commands/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ const inquirer = require('inquirer');
const chalk = require('chalk');
const logUpdate = require('log-update');
const elegantSpinner = require('elegant-spinner');
const showBanner = require('../external/banner');
const { showBanner } = require('../external/banner');

let storeFile = fs.readFileSync(__dirname + '/../files/vuex/store.js', 'utf8');
let storeFile = fs.readFileSync(__dirname + '/../templates/vuex/store.js', 'utf8');
let frame = elegantSpinner();

let addPackagefn = () => {

exports.addPackage = () => {
showBanner();

if(!fs.existsSync('./mevn.json')){
Expand Down Expand Up @@ -177,5 +176,3 @@ let addPackagefn = () => {
});
}, 1000);
};

module.exports = addPackagefn;
11 changes: 5 additions & 6 deletions lib/commands/versionlib.js → lib/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

const chalk = require('chalk');

const showBanner = require('../external/banner');
const version = require('../../package.json').version;
let versionfn = () => {
const { showBanner } = require('../external/banner');
const cliVersion = require('../../package.json').version;

exports.versionInfo = () => {
showBanner();
setTimeout(() => {
console.log(chalk.greenBright(`\n\n MEVN-CLI: ${version}`));
console.log(chalk.greenBright(`\n\n MEVN-CLI: ${cliVersion}`));
console.log(chalk.greenBright(`\n Node: ${require('child_process').execSync('node -v')}`));
console.log(chalk.greenBright(` OS: ${process.platform}`));
}, 100);
};

module.exports = versionfn;
12 changes: 4 additions & 8 deletions lib/deploy/docker.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';

const showBanner = require('../external/banner');
const { showBanner } = require('../external/banner');
const fs = require('fs');
const chalk = require('chalk');
const shell = require('shelljs');
const os = require('os');

let dockerfn = () => {

exports.dockerize = () => {
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);
Expand All @@ -21,8 +20,7 @@ let dockerfn = () => {
shell.cd(appname.project_name);

setTimeout(() => {

//currently works on linux only
// currently works on linux only
if(os.type() + '' === 'Linux') {

console.log('\n');
Expand All @@ -37,6 +35,4 @@ let dockerfn = () => {
}

}, 100);

};
module.exports = dockerfn;
8 changes: 2 additions & 6 deletions lib/deploy/git_repo.js → lib/deploy/gitRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ const shell = require('shelljs');
const inquirer = require('inquirer');
const chalk = require('chalk');

const showBanner = require('../external/banner');

const { showBanner } = require('../external/banner');
let deleteCommand; // Delete .git based on the platform
let git_repofn = () => {

exports.createRepo = () => {
showBanner();

if(!fs.existsSync('./mevn.json')){
Expand Down Expand Up @@ -127,7 +126,4 @@ let git_repofn = () => {
});
}
}, 100);


};
module.exports = git_repofn;
6 changes: 2 additions & 4 deletions lib/deploy/docker_dply.js → lib/deploy/herokuDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ const shell = require('shelljs');
const inquirer = require('inquirer');
const chalk = require('chalk');

const showBanner = require('../external/banner');

let dplyfn = () => {
const { showBanner } = require('../external/banner');

exports.deploy = () => {
showBanner();

if(!fs.existsSync('./mevn.json')){
Expand Down Expand Up @@ -99,4 +98,3 @@ let dplyfn = () => {
}, 100);

};
module.exports = dplyfn;
Loading

0 comments on commit aa915a0

Please sign in to comment.