Permalink
Browse files

refactor(app): es6 syntatic sugar and add eslint

  • Loading branch information...
1 parent 445dc1f commit 4a057f955f96fd6e54bf4c09d42ffcf6d37da2f8 @somus somus committed May 24, 2016
View
@@ -12,7 +12,7 @@ pids
lib-cov
# Coverage directory used by tools like istanbul
-coverage
+coverage/
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
@@ -31,3 +31,9 @@ node_modules
# Optional REPL history
.node_repl_history
+
+#compiled code
+lib/
+
+# IDE
+.idea/
View
@@ -0,0 +1 @@
+src/
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require('../lib/commands/generate-container.js');
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require('../lib/commands/generate-dumb.js');
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require('../lib/commands/generate-fullstack.js');
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require('../lib/commands/generate-functional.js');
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require('../lib/commands/generate-model.js');
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -1,11 +1,53 @@
{
"name": "mern-cli",
- "version": "2.0.1",
+ "version": "2.1.0",
"description": "A cli for generating MERN boilerplate",
"main": "index.js",
"scripts": {
+ "compile": "babel --presets es2015,stage-0 -d lib/ src/",
+ "lint": "eslint . --ignore-path .gitignore",
+ "lint:staged": "eslint-staged",
+ "prepublish": "npm run compile",
+ "pretest": "npm run lint",
"test": "ava tests/*.js"
},
+ "pre-commit": "lint:staged",
+ "eslintConfig": {
+ "parser": "babel-eslint",
+ "extends": "airbnb-base",
+ "env": {
+ "node": true,
+ "es6": true,
+ "shelljs": true
+ },
+ "parserOptions": {
+ "ecmaVersion": 6,
+ "sourceType": "module"
+ },
+ "rules": {
+ "import/no-unresolved": 2,
+ "comma-dangle": [
+ 2,
+ "always-multiline"
+ ],
+ "indent": [
+ 2,
+ 4,
+ {
+ "SwitchCase": 1
+ }
+ ],
+ "max-len": 0,
+ "no-console": 0,
+ "prefer-template": 2,
+ "no-use-before-define": 0,
+ "newline-per-chained-call": 0,
+ "arrow-body-style": [
+ 2,
+ "as-needed"
+ ]
+ }
+ },
"engines": {
"node": ">=4"
},
@@ -45,6 +87,14 @@
},
"devDependencies": {
"ava": "^0.11.0",
+ "babel-cli": "^6.9.0",
+ "babel-eslint": "^6.0.4",
+ "babel-preset-es2015": "^6.9.0",
+ "babel-preset-stage-0": "^6.5.0",
+ "eslint": "^2.10.2",
+ "eslint-config-airbnb-base": "^3.0.1",
+ "eslint-plugin-import": "^1.8.0",
+ "lint-staged": "^0.2.2",
"pify": "^2.3.0"
}
}
View
@@ -1,7 +1,7 @@
module.exports = {
- PROJECT_DIR : __dirname,
- BLUEPRINT_NAME : 'blueprint.js',
- BLUEPRINT_DIRECTORY_NAME : 'blueprints',
+ PROJECT_DIR: __dirname,
+ BLUEPRINT_NAME: 'blueprint.ejs',
+ BLUEPRINT_DIRECTORY_NAME: 'blueprints',
CONFIG_FILE_NAME: 'mern.json',
- COMPONENTS: ['container','dumb','functional']
-};
+ COMPONENTS: ['container', 'dumb', 'functional'],
+};
@@ -0,0 +1,12 @@
+import program from 'commander';
+import Generate from '../tasks/generate';
+
+program
+ .action(() => {
+ new Generate().run(['container', ...program.args]);
+ })
+ .parse(process.argv);
+
+if (!program.args.length) {
+ program.help();
+}
@@ -0,0 +1,12 @@
+import program from 'commander';
+import Generate from '../tasks/generate';
+
+program
+ .action(() => {
+ new Generate().run(['dumb', ...program.args]);
+ })
+ .parse(process.argv);
+
+if (!program.args.length) {
+ program.help();
+}
@@ -0,0 +1,12 @@
+import program from 'commander';
+import Generate from '../tasks/generate';
+
+program
+ .action(() => {
+ new Generate().run(['fullstack', ...program.args]);
+ })
+ .parse(process.argv);
+
+if (!program.args.length) {
+ program.help();
+}
@@ -0,0 +1,12 @@
+import program from 'commander';
+import Generate from '../tasks/generate';
+
+program
+ .action(() => {
+ new Generate().run(['functional', ...program.args]);
+ })
+ .parse(process.argv);
+
+if (!program.args.length) {
+ program.help();
+}
@@ -0,0 +1,12 @@
+import program from 'commander';
+import Generate from '../tasks/generate';
+
+program
+ .action(() => {
+ new Generate().run(['model', ...program.args]);
+ })
+ .parse(process.argv);
+
+if (!program.args.length) {
+ program.help();
+}
@@ -1,15 +1,14 @@
-var program = require('commander');
-var generate = require('../tasks/generate');
-
-//program.description need to be refractored
+import program from 'commander';
program
-.description('Generate components, routes, controllers, models using mern generator\n\n merng dumb <componentname>\n merng functional <componentName>\n merng container <componentName>\n merng route <routeName>\n merng model <modelName>\n merng fullstack <modelName>\n')
-.action(function() {
- new generate().run(program.args);
-})
-.parse(process.argv);
+ .description('Generate components, routes, controllers, models using mern generator')
+ .command('dumb [component_name]', 'Generate a dumb component')
+ .command('functional [component_name]', 'Generate a functional component')
+ .command('container [component_name]', 'Generate a container component')
+ .command('model [model_name]', 'Generate a mongoose model')
+ .command('fullstack [component_name]', 'Generate a dumb component, controller and mongoose model')
+ .parse(process.argv);
-if(!program.args.length) {
- program.help();
-}
+if (!program.args.length) {
+ program.help();
+}
View
@@ -1,50 +1,51 @@
-var program = require('commander');
-var chalk = require('chalk');
-var elegantSpinner = require('elegant-spinner');
-var logUpdate = require('log-update');
-var frame = elegantSpinner();
+import program from 'commander';
+import chalk from 'chalk';
+import elegantSpinner from 'elegant-spinner';
+import logUpdate from 'log-update';
+import pjson from '../../package.json';
require('shelljs/global');
-var pjson = require('../../package.json');
+const frame = elegantSpinner();
program
-.version(pjson.version)
-.description('Create a MERN app in current directory!')
-.option('-v, --version', 'check version')
-.parse(process.argv);
+ .version(pjson.version)
+ .description('Create a MERN app in current directory!')
+ .option('-v, --version', 'check version')
+ .parse(process.argv);
if (!which('git')) {
- console.log(chalk.red('Sorry, this script requires git'));
- exit(1);
+ console.log(chalk.red('Sorry, this script requires git'));
+ exit(1);
}
-if(program.args.length > 1) {
- console.log(chalk.red('Please give only one argument as a directory name!!!'));
- exit(1);
+if (program.args.length > 1) {
+ console.log(chalk.red('Please give only one argument as a directory name!!!'));
+ exit(1);
}
-if(program.args.length === 1) {
- if(test('-d', program.args[0])) {
- console.log(chalk.red(program.args[0]+ ' directory already exits! Please choose some another name!!!'));
- exit(1);
- }
-
- mkdir('-p', program.args[0]);
- cd(program.args[0]);
- }
- exec('git init');
-
- var interval = setInterval(function() {
- logUpdate("Fetching the boilerplate..." + chalk.cyan.bold.dim(frame()));
- }, 50)
-
- var e = exec('git pull https://github.com/Hashnode/mern-starter.git', function(code, stdout, stderr) {
- clearInterval(interval);
- logUpdate.clear();
- if(code !== 0) {
- console.log(chalk.red.bold('Error! Try again'));
- exit(1);
- }
- console.log(chalk.green.bold('Completed.....You are good to go!'));
- });
+if (program.args.length === 1) {
+ if (test('-d', program.args[0])) {
+ console.log(chalk.red(`${program.args[0]} directory already exits! Please choose some another name!!!`));
+ exit(1);
+ }
+
+ mkdir('-p', program.args[0]);
+ cd(program.args[0]);
+}
+
+exec('git init');
+
+const interval = setInterval(() => {
+ logUpdate(`Fetching the boilerplate...${chalk.cyan.bold.dim(frame())}`);
+}, 50);
+
+exec('git pull https://github.com/Hashnode/mern-starter.git', (code) => {
+ clearInterval(interval);
+ logUpdate.clear();
+ if (code !== 0) {
+ console.log(chalk.red.bold('Error! Try again'));
+ exit(1);
+ }
+ console.log(chalk.green.bold('Completed.....You are good to go!'));
+});
@@ -1,18 +1,16 @@
-var fileExists = require('../util/fileExists');
-var fs = require('fs');
+import fileExists from '../util/fileExists';
+import fs from 'fs';
-module.exports = function(baseDirectoryMapping, blueprint, file, entityName, ui) {
- if(fileExists(process.cwd() + baseDirectoryMapping[blueprint] + '/' + entityName + '.js')) {
- ui.writeError("File already exists please choose another name.");
- return;
- }
- fs.writeFile(process.cwd() + baseDirectoryMapping[blueprint] + '/' + entityName + '.js',file , function(err) {
- if(err) {
- ui.writeError(err);
- }
-
- else {
- ui.writeInfoLine("Created " + entityName + '.js ' + "in " + process.cwd() + baseDirectoryMapping[blueprint]);
- }
- });
-}
+export default (baseDirectoryMapping, blueprint, file, entityName, ui) => {
+ if (fileExists(`${process.cwd() + baseDirectoryMapping[blueprint]}/${entityName}.js`)) {
+ ui.writeError('File already exists please choose another name.');
+ return;
+ }
+ fs.writeFile(`${process.cwd() + baseDirectoryMapping[blueprint]}/${entityName}.js`, file, err => {
+ if (err) {
+ ui.writeError(err);
+ } else {
+ ui.writeInfoLine(`Created ${entityName}.js in ${process.cwd()}${baseDirectoryMapping[blueprint]}`);
+ }
+ });
+};
Oops, something went wrong.

0 comments on commit 4a057f9

Please sign in to comment.