-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
73 lines (61 loc) · 2.43 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import path from "path";
import fs from "fs";
import ejs from "ejs";
import simpleGit from "simple-git";
export const ejsHelper = async ({ templatePath, fName, data, outFilePath }) => {
fs.mkdir(outFilePath, { recursive: true }, (err) => {
if (err) {
if (err.code === "EEXIST") {
// console.error("Directory already exists");
fs.readFile(templatePath, "utf8", (err, template) => {
if (err) throw err;
// Generate the output by rendering the template with the data
const output = ejs.render(template, data);
// Write the output to a new JavaScript file
let outputFinal = path.join(outFilePath, fName);
fs.writeFile(outputFinal, output, (err) => {
if (err) throw err;
// console.log("JavaScript file generated successfully!");
});
});
} else {
// console.error("Error creating directory:", err);
}
} else {
// console.log("Directory created successfully");
fs.readFile(templatePath, "utf8", (err, template) => {
if (err) throw err;
// Generate the output by rendering the template with the data
const output = ejs.render(template, data);
// Write the output to a new JavaScript file
let outputFinal = path.join(outFilePath, fName);
fs.writeFile(outputFinal, output, (err) => {
if (err) throw err;
// console.log("JavaScript file generated successfully!");
});
});
}
});
};
export const gitHelper = async ({ path, commitMessage = "Initial commit ✨" }) => {
const git = simpleGit(path);
try {
// Initialize Git repository
await git.init();
// Add all files
await git.add(".");
// Make the initial commit
await git.commit(commitMessage);
console.log("Git repository initialized and initial commit made.");
} catch (error) {
console.error("Error initializing Git repository:", error);
}
};
export const toConstantCase = (str) => {
return str
.replace(/([a-z])([A-Z])/g, "$1_$2")
.replace(/\W|_/g, " ")
.trim()
.replace(/ /g, "_")
.toUpperCase();
};