Skip to content

Commit

Permalink
Resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
rajikaimal committed Dec 23, 2018
1 parent bfb19d0 commit db362c4
Show file tree
Hide file tree
Showing 13 changed files with 1,476 additions and 726 deletions.
36 changes: 19 additions & 17 deletions bin/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,27 @@ program
} else {
const spinner = ora("creating directory structure").start();

init.initialize(projectname, gitrepository, options.eslint,
init.initialize(
projectname,
gitrepository,
options.eslint,
function initProject(res) {
if (res) {
setTimeout(() => {
spinner.text = "application created successfully";
spinner.succeed();
console.log(
`\t$ cd ${projectname}\n \t$ npm install \n \tHappy hacking ♥`
);
}, 1000);

} else {
setTimeout(() => {
spinner.text = "something went wrong!";
spinner.fail();
}, 1000);
if (res) {
setTimeout(() => {
spinner.text = "application created successfully";
spinner.succeed();
console.log(
`\t$ cd ${projectname}\n \t$ npm install \n \tHappy hacking ♥`
);
}, 1000);
} else {
setTimeout(() => {
spinner.text = "something went wrong!";
spinner.fail();
}, 1000);
}
}
});
);
}
})
.on("--help", function() {
Expand Down Expand Up @@ -325,5 +328,4 @@ program
/**
* parse commander object
*/

program.parse(process.argv);
1 change: 0 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const path = require("path");
* @param {string} value - value to be changed
* @param {function} cb - callback
*/

function configReactCliRc(key, value, cb) {
fs.readFile(path.join(process.cwd(), ".reactclirc"), (err, buffer) => {
let jsonContent = JSON.parse(buffer.toString());
Expand Down
5 changes: 0 additions & 5 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ generate.prototype.createComponentFile = function(re, componentName, answersInne
* @param {string} answersInner - options provided when creating component
* @param {function} cb - callback for status return
*/

generate.prototype.generateComponent = function(type, module, componentName, answers, answersInner, cb) {
try {
if(componentName !== undefined) {
Expand Down Expand Up @@ -90,7 +89,6 @@ generate.prototype.generateComponent = function(type, module, componentName, ans
* @param {string} answersInner - options provided when creating component
* @param {string} componentName - component name
*/

generate.prototype.createModFile = function(_modFile, answersInner, componentName) {
return _modFile.slice(0, Number(_modFile.indexOf('export'))-1) + this.generatePropTypesSet(answersInner, componentName) + _modFile.slice(Number(_modFile.indexOf('export'))-1);
}
Expand All @@ -100,7 +98,6 @@ generate.prototype.createModFile = function(_modFile, answersInner, componentNam
* @param {string} answersInner
* @param {string} componentName - component name
*/

generate.prototype.generatePropTypesSet = function(answersInner, componentName) {
let __propTypes = {};

Expand All @@ -123,7 +120,6 @@ generate.prototype.generatePropTypesSet = function(answersInner, componentName)
* @param {string} answersInner - options provided when creating component
* @param {function} cb - callback for status return
*/

generate.prototype.createComponent = function(module, componentName, answers, answersInner, cb) {
this.generateComponent(answers.componentType, module, componentName, answers, answersInner, cb);
}
Expand All @@ -134,7 +130,6 @@ generate.prototype.createComponent = function(module, componentName, answers, an
* @param {string} testName - test file name
* @param {function} cb - callback for status return
*/

generate.prototype.createTest = function(module, testName, cb) {
try {
if(testName !== undefined) {
Expand Down
153 changes: 70 additions & 83 deletions lib/init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require("fs.extra");
const path = require("path");
var clone = require('git-clone');
const init = function () { };
const clone = require("git-clone");
const init = function() {};
const ora = require("ora");

/**
Expand All @@ -11,39 +11,35 @@ const ora = require("ora");
* @param {string} options - additional options for the project example: eslint configuration
* @param {function} cb - callback for status return
*/

init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
init.prototype.initialize = function(projectName, gitrepository, eslint, cb) {
if (gitrepository === undefined) {
if (eslint === undefined) {
let projectPath = projectName;
if (!fs.existsSync(projectName)) {
fs.mkdirp(projectPath, error => {
if (error) {
cb(error);
} else {
//resolve all promises async-ly
Promise.all([
this.copyCommonTemplates(projectName),
this.copyTemplate(projectName, "webpack.config.js", false),
this.copyTemplate(projectName, "reactclirc", true),
this.copyTemplate(projectName, "gitignore", true),
this.copyPackageJson(projectName)
])
.then(values => {
cb(true);
})
.catch(err => {
console.log(err);
cb(false);
});
}
});
}
else {
console.log('\x1b[1m\x1b[31m%s\x1b[0m','\n This project name is already exists \n try with different project name');
cb(false);

}
fs.mkdirp(projectPath, error => {
if (error) {
cb(error);
} else {
//resolve all promises async-ly
Promise.all([
this.copyCommonTemplates(projectName),
this.copyTemplate(
projectName,
"webpack.config.js",
false
),
this.copyTemplate(projectName, "reactclirc", true),
this.copyTemplate(projectName, "gitignore", true),
this.copyPackageJson(projectName)
])
.then(values => {
cb(true);
})
.catch(err => {
console.log(err);
cb(false);
});
}
});
} else {
if (eslint) {
Promise.all([
Expand All @@ -65,50 +61,45 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
} else {
if (eslint === undefined) {
let projectPath = projectName;
if (!fs.existsSync(projectName)) {

fs.mkdirp(projectPath, error => {
if (error) {
cb(error);
} else {
// resolve all promises async-ly
Promise.all(
[

this.copyTemplate(projectName, "webpack.config.js", false),
this.copyTemplate(projectName, "reactclirc", true),
this.copyTemplate(projectName, "gitignore", true),
this.copyPackageJson(projectName)
])
.then(values => {
const spinner = ora("cloning template").start();

clone(gitrepository, projectName + '/src', value => {
fs.mkdirp(projectPath, error => {
if (error) {
cb(error);
} else {
// resolve all promises async-ly
Promise.all([
this.copyTemplate(
projectName,
"webpack.config.js",
false
),
this.copyTemplate(projectName, "reactclirc", true),
this.copyTemplate(projectName, "gitignore", true),
this.copyPackageJson(projectName)
])
.then(values => {
const spinner = ora("cloning template").start();

clone(
gitrepository,
projectName + "/src",
value => {
setTimeout(() => {
spinner.text = "template cloned successfully";
spinner.text =
"template cloned successfully";
spinner.succeed();
cb(true);
}, 1000);
}
)
})
.catch(err => {
console.log(err);
cb(false);
});


}
});
}
else {
console.log('\x1b[1m\x1b[31m%s\x1b[0m','\n This project name is already exists \n try with different project name');
cb(false);
}
);
})
.catch(err => {
console.log(err);
cb(false);
});
}
});
} else {
if (eslint) {


Promise.all([
this.copyTemplate(projectName, "webpack.config.js", false),
this.copyTemplate(projectName, "gitignore", true),
Expand All @@ -118,14 +109,13 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
.then(values => {
const spinner = ora("cloning template").start();

clone(gitrepository, projectName + '/src', value => {
clone(gitrepository, projectName + "/src", value => {
setTimeout(() => {
spinner.text = "template cloned successfully";
spinner.succeed();
cb(true);
}, 1000);
}
)
});
})
.catch(err => {
console.log(err);
Expand All @@ -140,13 +130,12 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
* copy common templates recursively
* @param {string} projectName - project name
*/

init.prototype.copyCommonTemplates = function (projectName) {
return new Promise(function (resolve, reject) {
init.prototype.copyCommonTemplates = function(projectName) {
return new Promise(function(resolve, reject) {
fs.copyRecursive(
path.join(__dirname, "..", "templates/src"),
path.join(projectName, "src"),
function (err) {
function(err) {
if (err) {
console.log(err);
reject(err);
Expand All @@ -163,9 +152,8 @@ init.prototype.copyCommonTemplates = function (projectName) {
* @param {string} projectName - project name
* @param {string} file - name of the file to be copied
*/

init.prototype.copyTemplate = function (projectName, file, dotFile) {
return new Promise(function (resolve, reject) {
init.prototype.copyTemplate = function(projectName, file, dotFile) {
return new Promise(function(resolve, reject) {
let destFile = null;
if (dotFile) {
destFile = "." + file;
Expand All @@ -176,7 +164,7 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
path.join(__dirname, "..", "templates", file),
path.join(projectName, destFile),
{ replace: false },
function (err) {
function(err) {
if (err) {
console.log(err);
reject(err);
Expand All @@ -192,9 +180,8 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
* copy package.json file to project destination
* @param {string} projectName - project name
*/

init.prototype.copyPackageJson = function (projectName) {
return new Promise(function (resolve, reject) {
init.prototype.copyPackageJson = function(projectName) {
return new Promise(function(resolve, reject) {
fs.readFile(
path.join(__dirname, "..", "templates/package.json"),
(err, buffer) => {
Expand Down
1 change: 0 additions & 1 deletion lib/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require("path");
/**
* get source directory file
*/

const getSourceDirectory = function() {
const buffer = fs.readFileSync(path.join(process.cwd(), ".reactclirc"));
const jsonContent = JSON.parse(buffer.toString());
Expand Down
1 change: 0 additions & 1 deletion lib/utils/checkduplicateelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const getSourceDirectory = require('../source');
* @param {string} elementName - propnames to compare
* @param {string} type - propnames to compare
*/

const checkDuplicateElement = function (type, moduleName, elementName) {

if(type === 'component'){
Expand Down
1 change: 0 additions & 1 deletion lib/utils/checkduplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* check for duplicates in provided set of propNames
* @param {string} propNames - propnames to compare
*/

const checkDuplicates = function(propNames) {
let currentValue = null;
for (let count = 0; count <= propNames.length; count++) {
Expand Down
1 change: 0 additions & 1 deletion lib/utils/checkspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* check for in a given array
* @param {string} propNames - propnames to check for spaces
*/

const checkSpaces = function(propNames) {
let sanitizedPropNames = [];
for (let count = 0; count <= propNames.length; count++) {
Expand Down
2 changes: 0 additions & 2 deletions lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const getSourceDirectory = require("./source");
* @param {string} test - test file
* @param {function} cb - callback for status return
*/

const viewDirectoryStructure = function(component, test, cb) {
const src = getSourceDirectory();
if (component) {
Expand All @@ -27,7 +26,6 @@ const viewDirectoryStructure = function(component, test, cb) {
* rendering table
* @param {string} type - component/test
*/

const renderView = function(type) {
const table = new AsciiTable().fromJSON({
title: "",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"react": "./bin/initialize.js"
},
"scripts": {
"test": "mocha --timeout 10000"
"test": "mocha --timeout=100000"
},
"repository": {
"type": "git",
Expand All @@ -28,11 +28,11 @@
"commander": "^2.9.0",
"directory-tree": "^2.0.0",
"fs.extra": "^1.3.2",
"git-clone": "^0.1.0",
"inquirer": "^3.2.2",
"install": "^0.10.1",
"npm": "^5.3.0",
"ora": "^1.3.0",
"git-clone": "^0.1.0",
"rx": "^4.1.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit db362c4

Please sign in to comment.