Skip to content

Commit f89f30e

Browse files
authored
Make branches even (#2)
* added webpack * added basic setup of html and js * added webpack-dev-server * added css support * added react-hot-loader for hot reload of statefull components * added git hooks for linting formatting and testing * added react strict mode * modified dev config for serving compressed bundle * added manifest and favicon * added script to copyfile and create directory * completed create script for creating new directory and copying content from template * removed unnecssory callback
1 parent 534e417 commit f89f30e

3 files changed

Lines changed: 25 additions & 15 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ dist
66

77
#system file
88
.DS_Store
9+
10+
#package-lock
11+
package-lock.json

scripts/create.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
const fs = require("fs");
21
const path = require("path");
3-
const { copyDirectory } = require("./helper");
2+
const { copyDirectory, ErrorMessage, SuccessMessage } = require("./helper");
43
const { SPECIALCHAR, TEMPLATE_PATH } = require("./constants");
54

65
var args = process.argv.slice(2);
76
var dirName = args[0];
87

9-
//use process.cwd if after deployment also path take path of scripts folder
10-
118
if (dirName[0].match("^[A-Z0-9]")) {
129
throw new Error(
13-
chalk.bold.red("directory name can't start from capital letters ")
10+
ErrorMessage("directory name can't start from capital letters ")
1411
);
1512
} else if (dirName.match(SPECIALCHAR)) {
1613
throw new Error(
17-
chalk.bold.red(
14+
ErrorMessage(
1815
"directory name can't start from capital letters or contain special characters in it"
1916
)
2017
);
2118
} else {
19+
//using process.cwd for getting current path
2220
let destination = path.join(process.cwd() + "/" + args[0]);
2321
copyDirectory(TEMPLATE_PATH, destination);
22+
console.log(SuccessMessage("Successfully created the directory"));
2423
}

scripts/helper.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,24 @@ function copyFile(source, destination) {
5151
*/
5252
function createDirectory(destination) {
5353
if (fs.existsSync(destination)) {
54-
throw new Error(chalk.bold.red("Directory Already Exists!"));
54+
throw new Error(ErrorMessage("Directory Already Exists!"));
5555
} else {
56-
fs.mkdirSync(destination, error => {
57-
if (error) {
58-
throw error;
59-
} else {
60-
console.log(chalk.bold.green("Successfully created the directory"));
61-
}
62-
});
56+
fs.mkdirSync(destination);
6357
}
6458
}
6559

66-
module.exports = { copyDirectory, copyFile, createDirectory };
60+
function ErrorMessage(message) {
61+
return chalk.bold.red(message);
62+
}
63+
64+
function SuccessMessage(message) {
65+
return chalk.bold.green(message);
66+
}
67+
68+
module.exports = {
69+
copyDirectory,
70+
copyFile,
71+
createDirectory,
72+
ErrorMessage,
73+
SuccessMessage
74+
};

0 commit comments

Comments
 (0)