Skip to content

Commit db362c4

Browse files
committed
Resolve
1 parent bfb19d0 commit db362c4

File tree

13 files changed

+1476
-726
lines changed

13 files changed

+1476
-726
lines changed

bin/initialize.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,27 @@ program
3434
} else {
3535
const spinner = ora("creating directory structure").start();
3636

37-
init.initialize(projectname, gitrepository, options.eslint,
37+
init.initialize(
38+
projectname,
39+
gitrepository,
40+
options.eslint,
3841
function initProject(res) {
39-
if (res) {
40-
setTimeout(() => {
41-
spinner.text = "application created successfully";
42-
spinner.succeed();
43-
console.log(
44-
`\t$ cd ${projectname}\n \t$ npm install \n \tHappy hacking ♥`
45-
);
46-
}, 1000);
47-
48-
} else {
49-
setTimeout(() => {
50-
spinner.text = "something went wrong!";
51-
spinner.fail();
52-
}, 1000);
42+
if (res) {
43+
setTimeout(() => {
44+
spinner.text = "application created successfully";
45+
spinner.succeed();
46+
console.log(
47+
`\t$ cd ${projectname}\n \t$ npm install \n \tHappy hacking ♥`
48+
);
49+
}, 1000);
50+
} else {
51+
setTimeout(() => {
52+
spinner.text = "something went wrong!";
53+
spinner.fail();
54+
}, 1000);
55+
}
5356
}
54-
});
57+
);
5558
}
5659
})
5760
.on("--help", function() {
@@ -325,5 +328,4 @@ program
325328
/**
326329
* parse commander object
327330
*/
328-
329331
program.parse(process.argv);

lib/config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const path = require("path");
77
* @param {string} value - value to be changed
88
* @param {function} cb - callback
99
*/
10-
1110
function configReactCliRc(key, value, cb) {
1211
fs.readFile(path.join(process.cwd(), ".reactclirc"), (err, buffer) => {
1312
let jsonContent = JSON.parse(buffer.toString());

lib/generate.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ generate.prototype.createComponentFile = function(re, componentName, answersInne
2525
* @param {string} answersInner - options provided when creating component
2626
* @param {function} cb - callback for status return
2727
*/
28-
2928
generate.prototype.generateComponent = function(type, module, componentName, answers, answersInner, cb) {
3029
try {
3130
if(componentName !== undefined) {
@@ -90,7 +89,6 @@ generate.prototype.generateComponent = function(type, module, componentName, ans
9089
* @param {string} answersInner - options provided when creating component
9190
* @param {string} componentName - component name
9291
*/
93-
9492
generate.prototype.createModFile = function(_modFile, answersInner, componentName) {
9593
return _modFile.slice(0, Number(_modFile.indexOf('export'))-1) + this.generatePropTypesSet(answersInner, componentName) + _modFile.slice(Number(_modFile.indexOf('export'))-1);
9694
}
@@ -100,7 +98,6 @@ generate.prototype.createModFile = function(_modFile, answersInner, componentNam
10098
* @param {string} answersInner
10199
* @param {string} componentName - component name
102100
*/
103-
104101
generate.prototype.generatePropTypesSet = function(answersInner, componentName) {
105102
let __propTypes = {};
106103

@@ -123,7 +120,6 @@ generate.prototype.generatePropTypesSet = function(answersInner, componentName)
123120
* @param {string} answersInner - options provided when creating component
124121
* @param {function} cb - callback for status return
125122
*/
126-
127123
generate.prototype.createComponent = function(module, componentName, answers, answersInner, cb) {
128124
this.generateComponent(answers.componentType, module, componentName, answers, answersInner, cb);
129125
}
@@ -134,7 +130,6 @@ generate.prototype.createComponent = function(module, componentName, answers, an
134130
* @param {string} testName - test file name
135131
* @param {function} cb - callback for status return
136132
*/
137-
138133
generate.prototype.createTest = function(module, testName, cb) {
139134
try {
140135
if(testName !== undefined) {

lib/init.js

Lines changed: 70 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require("fs.extra");
22
const path = require("path");
3-
var clone = require('git-clone');
4-
const init = function () { };
3+
const clone = require("git-clone");
4+
const init = function() {};
55
const ora = require("ora");
66

77
/**
@@ -11,39 +11,35 @@ const ora = require("ora");
1111
* @param {string} options - additional options for the project example: eslint configuration
1212
* @param {function} cb - callback for status return
1313
*/
14-
15-
init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
14+
init.prototype.initialize = function(projectName, gitrepository, eslint, cb) {
1615
if (gitrepository === undefined) {
1716
if (eslint === undefined) {
1817
let projectPath = projectName;
19-
if (!fs.existsSync(projectName)) {
20-
fs.mkdirp(projectPath, error => {
21-
if (error) {
22-
cb(error);
23-
} else {
24-
//resolve all promises async-ly
25-
Promise.all([
26-
this.copyCommonTemplates(projectName),
27-
this.copyTemplate(projectName, "webpack.config.js", false),
28-
this.copyTemplate(projectName, "reactclirc", true),
29-
this.copyTemplate(projectName, "gitignore", true),
30-
this.copyPackageJson(projectName)
31-
])
32-
.then(values => {
33-
cb(true);
34-
})
35-
.catch(err => {
36-
console.log(err);
37-
cb(false);
38-
});
39-
}
40-
});
41-
}
42-
else {
43-
console.log('\x1b[1m\x1b[31m%s\x1b[0m','\n This project name is already exists \n try with different project name');
44-
cb(false);
45-
46-
}
18+
fs.mkdirp(projectPath, error => {
19+
if (error) {
20+
cb(error);
21+
} else {
22+
//resolve all promises async-ly
23+
Promise.all([
24+
this.copyCommonTemplates(projectName),
25+
this.copyTemplate(
26+
projectName,
27+
"webpack.config.js",
28+
false
29+
),
30+
this.copyTemplate(projectName, "reactclirc", true),
31+
this.copyTemplate(projectName, "gitignore", true),
32+
this.copyPackageJson(projectName)
33+
])
34+
.then(values => {
35+
cb(true);
36+
})
37+
.catch(err => {
38+
console.log(err);
39+
cb(false);
40+
});
41+
}
42+
});
4743
} else {
4844
if (eslint) {
4945
Promise.all([
@@ -65,50 +61,45 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
6561
} else {
6662
if (eslint === undefined) {
6763
let projectPath = projectName;
68-
if (!fs.existsSync(projectName)) {
69-
70-
fs.mkdirp(projectPath, error => {
71-
if (error) {
72-
cb(error);
73-
} else {
74-
// resolve all promises async-ly
75-
Promise.all(
76-
[
77-
78-
this.copyTemplate(projectName, "webpack.config.js", false),
79-
this.copyTemplate(projectName, "reactclirc", true),
80-
this.copyTemplate(projectName, "gitignore", true),
81-
this.copyPackageJson(projectName)
82-
])
83-
.then(values => {
84-
const spinner = ora("cloning template").start();
85-
86-
clone(gitrepository, projectName + '/src', value => {
64+
fs.mkdirp(projectPath, error => {
65+
if (error) {
66+
cb(error);
67+
} else {
68+
// resolve all promises async-ly
69+
Promise.all([
70+
this.copyTemplate(
71+
projectName,
72+
"webpack.config.js",
73+
false
74+
),
75+
this.copyTemplate(projectName, "reactclirc", true),
76+
this.copyTemplate(projectName, "gitignore", true),
77+
this.copyPackageJson(projectName)
78+
])
79+
.then(values => {
80+
const spinner = ora("cloning template").start();
81+
82+
clone(
83+
gitrepository,
84+
projectName + "/src",
85+
value => {
8786
setTimeout(() => {
88-
spinner.text = "template cloned successfully";
87+
spinner.text =
88+
"template cloned successfully";
8989
spinner.succeed();
9090
cb(true);
9191
}, 1000);
9292
}
93-
)
94-
})
95-
.catch(err => {
96-
console.log(err);
97-
cb(false);
98-
});
99-
100-
101-
}
102-
});
103-
}
104-
else {
105-
console.log('\x1b[1m\x1b[31m%s\x1b[0m','\n This project name is already exists \n try with different project name');
106-
cb(false);
107-
}
93+
);
94+
})
95+
.catch(err => {
96+
console.log(err);
97+
cb(false);
98+
});
99+
}
100+
});
108101
} else {
109102
if (eslint) {
110-
111-
112103
Promise.all([
113104
this.copyTemplate(projectName, "webpack.config.js", false),
114105
this.copyTemplate(projectName, "gitignore", true),
@@ -118,14 +109,13 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
118109
.then(values => {
119110
const spinner = ora("cloning template").start();
120111

121-
clone(gitrepository, projectName + '/src', value => {
112+
clone(gitrepository, projectName + "/src", value => {
122113
setTimeout(() => {
123114
spinner.text = "template cloned successfully";
124115
spinner.succeed();
125116
cb(true);
126117
}, 1000);
127-
}
128-
)
118+
});
129119
})
130120
.catch(err => {
131121
console.log(err);
@@ -140,13 +130,12 @@ init.prototype.initialize = function (projectName, gitrepository, eslint, cb) {
140130
* copy common templates recursively
141131
* @param {string} projectName - project name
142132
*/
143-
144-
init.prototype.copyCommonTemplates = function (projectName) {
145-
return new Promise(function (resolve, reject) {
133+
init.prototype.copyCommonTemplates = function(projectName) {
134+
return new Promise(function(resolve, reject) {
146135
fs.copyRecursive(
147136
path.join(__dirname, "..", "templates/src"),
148137
path.join(projectName, "src"),
149-
function (err) {
138+
function(err) {
150139
if (err) {
151140
console.log(err);
152141
reject(err);
@@ -163,9 +152,8 @@ init.prototype.copyCommonTemplates = function (projectName) {
163152
* @param {string} projectName - project name
164153
* @param {string} file - name of the file to be copied
165154
*/
166-
167-
init.prototype.copyTemplate = function (projectName, file, dotFile) {
168-
return new Promise(function (resolve, reject) {
155+
init.prototype.copyTemplate = function(projectName, file, dotFile) {
156+
return new Promise(function(resolve, reject) {
169157
let destFile = null;
170158
if (dotFile) {
171159
destFile = "." + file;
@@ -176,7 +164,7 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
176164
path.join(__dirname, "..", "templates", file),
177165
path.join(projectName, destFile),
178166
{ replace: false },
179-
function (err) {
167+
function(err) {
180168
if (err) {
181169
console.log(err);
182170
reject(err);
@@ -192,9 +180,8 @@ init.prototype.copyTemplate = function (projectName, file, dotFile) {
192180
* copy package.json file to project destination
193181
* @param {string} projectName - project name
194182
*/
195-
196-
init.prototype.copyPackageJson = function (projectName) {
197-
return new Promise(function (resolve, reject) {
183+
init.prototype.copyPackageJson = function(projectName) {
184+
return new Promise(function(resolve, reject) {
198185
fs.readFile(
199186
path.join(__dirname, "..", "templates/package.json"),
200187
(err, buffer) => {

lib/source.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const path = require("path");
44
/**
55
* get source directory file
66
*/
7-
87
const getSourceDirectory = function() {
98
const buffer = fs.readFileSync(path.join(process.cwd(), ".reactclirc"));
109
const jsonContent = JSON.parse(buffer.toString());

lib/utils/checkduplicateelement.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const getSourceDirectory = require('../source');
88
* @param {string} elementName - propnames to compare
99
* @param {string} type - propnames to compare
1010
*/
11-
1211
const checkDuplicateElement = function (type, moduleName, elementName) {
1312

1413
if(type === 'component'){

lib/utils/checkduplicates.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* check for duplicates in provided set of propNames
33
* @param {string} propNames - propnames to compare
44
*/
5-
65
const checkDuplicates = function(propNames) {
76
let currentValue = null;
87
for (let count = 0; count <= propNames.length; count++) {

lib/utils/checkspaces.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* check for in a given array
33
* @param {string} propNames - propnames to check for spaces
44
*/
5-
65
const checkSpaces = function(propNames) {
76
let sanitizedPropNames = [];
87
for (let count = 0; count <= propNames.length; count++) {

lib/view.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const getSourceDirectory = require("./source");
88
* @param {string} test - test file
99
* @param {function} cb - callback for status return
1010
*/
11-
1211
const viewDirectoryStructure = function(component, test, cb) {
1312
const src = getSourceDirectory();
1413
if (component) {
@@ -27,7 +26,6 @@ const viewDirectoryStructure = function(component, test, cb) {
2726
* rendering table
2827
* @param {string} type - component/test
2928
*/
30-
3129
const renderView = function(type) {
3230
const table = new AsciiTable().fromJSON({
3331
title: "",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"react": "./bin/initialize.js"
77
},
88
"scripts": {
9-
"test": "mocha --timeout 10000"
9+
"test": "mocha --timeout=100000"
1010
},
1111
"repository": {
1212
"type": "git",
@@ -28,11 +28,11 @@
2828
"commander": "^2.9.0",
2929
"directory-tree": "^2.0.0",
3030
"fs.extra": "^1.3.2",
31+
"git-clone": "^0.1.0",
3132
"inquirer": "^3.2.2",
3233
"install": "^0.10.1",
3334
"npm": "^5.3.0",
3435
"ora": "^1.3.0",
35-
"git-clone": "^0.1.0",
3636
"rx": "^4.1.0"
3737
},
3838
"devDependencies": {

0 commit comments

Comments
 (0)